From 7b0a0ce0d9f757d65906d33a6fcf3c10d8633b71 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 24 Nov 2015 15:19:51 -0800 Subject: [PATCH] Build: Add ability to specify extra configuration files for integ test This change allows copy extra files into the integ test cluster before it runs. However, it explicitly forbids overwriting elasticsearch.yml, since that is generated. --- .../gradle/test/ClusterConfiguration.groovy | 16 ++++++++++++++++ .../gradle/test/ClusterFormationTasks.groovy | 9 ++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy index 202d20c81a9..79a199e98e4 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy @@ -18,6 +18,7 @@ */ package org.elasticsearch.gradle.test +import org.gradle.api.GradleException import org.gradle.api.Project import org.gradle.api.file.FileCollection import org.gradle.api.tasks.Input @@ -65,6 +66,9 @@ class ClusterConfiguration { Map settings = new HashMap<>() + // map from destination path, to source file + Map extraConfigFiles = new HashMap<>() + LinkedHashMap plugins = new LinkedHashMap<>() LinkedHashMap setupCommands = new LinkedHashMap<>() @@ -93,4 +97,16 @@ class ClusterConfiguration { void setupCommand(String name, Object... args) { setupCommands.put(name, args) } + + /** + * Add an extra configuration file. The path is relative to the config dir, and the sourceFile + * is anything accepted by project.file() + */ + @Input + void extraConfigFile(String path, Object sourceFile) { + if (path == 'elasticsearch.yml') { + throw new GradleException('Overwriting elasticsearch.yml is not allowed, add additional settings using cluster { setting "foo", "bar" }') + } + extraConfigFiles.put(path, sourceFile) + } } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy index 51d6ee7b4b8..fe92d9cdcfe 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -167,7 +167,14 @@ class ClusterFormationTasks { 'repositories.url.allowed_urls' : 'http://snapshot.test*' ] - return project.tasks.create(name: name, type: DefaultTask, dependsOn: setup) << { + Copy copyConfig = project.tasks.create(name: name, type: Copy, dependsOn: setup) + copyConfig.into(new File(node.homeDir, 'config')) // copy must always have a general dest dir, even though we don't use it + for (Map.Entry extraConfigFile : node.config.extraConfigFiles.entrySet()) { + copyConfig.from(extraConfigFile.getValue()) + .into(new File(node.homeDir, 'config/' + extraConfigFile.getKey())) + } + copyConfig.doLast { + // write elasticsearch.yml last, it cannot be overriden File configFile = new File(node.homeDir, 'config/elasticsearch.yml') logger.info("Configuring ${configFile}") configFile.setText(esConfig.collect { key, value -> "${key}: ${value}" }.join('\n'), 'UTF-8')