Skip to content
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> keyStoreSetting = new HashMap<>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plural please? Also, just for consistency with the code in ES, can we use all lower case for keystore, so keystoreSettings?


// 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) {
keyStoreSetting.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 @@ -164,6 +165,8 @@ class ClusterFormationTasks {
setup = configureStopTask(taskName(task, node, 'stopPrevious'), project, setup, node)
setup = configureExtractTask(taskName(task, node, 'extract'), project, setup, node, configuration)
setup = configureWriteConfigTask(taskName(task, node, 'configure'), project, setup, node, seedNode)
setup = configureCreateKeyStoreTask(taskName(task, node, 'createKeyStore'), project, setup, node)
setup = configureAddKeyStoreTasks(task, project, setup, node)
if (node.config.plugins.isEmpty() == false) {
if (node.nodeVersion == VersionProperties.elasticsearch) {
setup = configureCopyPluginsTask(taskName(task, node, 'copyPlugins'), project, setup, node)
Expand Down Expand Up @@ -306,6 +309,32 @@ class ClusterFormationTasks {
}
}

/** Adds a task to create keystore */
static Task configureCreateKeyStoreTask(String name, Project project, Task setup, NodeInfo node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this a no-op when the keystoreSettings are empty?

File esKeyStoreUtil = Paths.get(node.homeDir.toString(), "bin/" + "elasticsearch-keystore").toFile()
Task createKeyStore = project.tasks.create(name: name, type: LoggedExec, dependsOn: setup) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing: you should use configureExecTask so this will work correctly on windows.

commandLine esKeyStoreUtil, 'create'
}
}

/** Adds tasks to add to keystore */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to add settings to the keystore"

static Task configureAddKeyStoreTasks(Task parent, Project project, Task setup, NodeInfo node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe call this configureAddKeystoreSettingTasks

Map kvs = node.config.keyStoreSetting
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()
Task t = project.tasks.create(name: taskName(parent, node, 'addToKeyStore#' + key), type: LoggedExec, dependsOn: parentTask) {
commandLine 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