Skip to content

Commit

Permalink
Setup keystore during integration tests (#22966)
Browse files Browse the repository at this point in the history
This commit creates a keystore and adds settings to it during the
cluster formation for integration tests. Users can define a
`keyStoreSetting` in build files for settings that need to be placed in
the keystore.
  • Loading branch information
Tim-Brooks authored and rjernst committed Apr 12, 2017
1 parent 74f0145 commit d593648
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class ClusterConfiguration {

Map<String, Object> settings = new HashMap<>()

Map<String, String> keystoreSettings = new HashMap<>()

// map from destination path, to source file
Map<String, Object> extraConfigFiles = new HashMap<>()

Expand All @@ -144,6 +146,11 @@ class ClusterConfiguration {
settings.put(name, value)
}

@Input
void keystoreSetting(String name, String value) {
keystoreSettings.put(name, value)
}

@Input
void plugin(String path) {
Project pluginProject = project.project(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.Exec

import java.nio.charset.StandardCharsets
import java.nio.file.Paths
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -157,10 +158,14 @@ class ClusterFormationTasks {
node.cwd.mkdirs()
}
}

setup = configureCheckPreviousTask(taskName(prefix, node, 'checkPrevious'), project, setup, node)
setup = configureStopTask(taskName(prefix, node, 'stopPrevious'), project, setup, node)
setup = configureExtractTask(taskName(prefix, node, 'extract'), project, setup, node, configuration)
setup = configureWriteConfigTask(taskName(prefix, node, 'configure'), project, setup, node, seedNode)
setup = configureCreateKeystoreTask(taskName(prefix, node, 'createKeystore'), project, setup, node)
setup = configureAddKeystoreSettingTasks(prefix, project, setup, node)

if (node.config.plugins.isEmpty() == false) {
if (node.nodeVersion == VersionProperties.elasticsearch) {
setup = configureCopyPluginsTask(taskName(prefix, node, 'copyPlugins'), project, setup, node)
Expand Down Expand Up @@ -303,6 +308,33 @@ class ClusterFormationTasks {
}
}

/** Adds a task to create keystore */
static Task configureCreateKeystoreTask(String name, Project project, Task setup, NodeInfo node) {
if (node.config.keystoreSettings.isEmpty()) {
return setup
} else {
File esKeystoreUtil = Paths.get(node.homeDir.toString(), "bin/" + "elasticsearch-keystore").toFile()
return configureExecTask(name, project, setup, node, esKeystoreUtil, 'create')
}
}

/** Adds tasks to add settings to the keystore */
static Task configureAddKeystoreSettingTasks(String parent, Project project, Task setup, NodeInfo node) {
Map kvs = node.config.keystoreSettings
File esKeystoreUtil = Paths.get(node.homeDir.toString(), "bin/" + "elasticsearch-keystore").toFile()
Task parentTask = setup
for (Map.Entry<String, String> entry in kvs) {
String key = entry.getKey()
String name = taskName(parent, node, 'addToKeystore#' + key)
Task t = configureExecTask(name, project, parentTask, node, esKeystoreUtil, 'add', key, '-x')
t.doFirst {
standardInput = new ByteArrayInputStream(entry.getValue().getBytes(StandardCharsets.UTF_8))
}
parentTask = t
}
return parentTask
}

static Task configureExtraConfigFilesTask(String name, Project project, Task setup, NodeInfo node) {
if (node.config.extraConfigFiles.isEmpty()) {
return setup
Expand Down

0 comments on commit d593648

Please sign in to comment.