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.
This commit is contained in:
parent
b4671f3960
commit
7b0a0ce0d9
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.gradle.test
|
package org.elasticsearch.gradle.test
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
|
@ -65,6 +66,9 @@ class ClusterConfiguration {
|
||||||
|
|
||||||
Map<String, String> settings = new HashMap<>()
|
Map<String, String> settings = new HashMap<>()
|
||||||
|
|
||||||
|
// map from destination path, to source file
|
||||||
|
Map<String, Object> extraConfigFiles = new HashMap<>()
|
||||||
|
|
||||||
LinkedHashMap<String, Object> plugins = new LinkedHashMap<>()
|
LinkedHashMap<String, Object> plugins = new LinkedHashMap<>()
|
||||||
|
|
||||||
LinkedHashMap<String, Object[]> setupCommands = new LinkedHashMap<>()
|
LinkedHashMap<String, Object[]> setupCommands = new LinkedHashMap<>()
|
||||||
|
@ -93,4 +97,16 @@ class ClusterConfiguration {
|
||||||
void setupCommand(String name, Object... args) {
|
void setupCommand(String name, Object... args) {
|
||||||
setupCommands.put(name, 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,7 +167,14 @@ class ClusterFormationTasks {
|
||||||
'repositories.url.allowed_urls' : 'http://snapshot.test*'
|
'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<String,Object> 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')
|
File configFile = new File(node.homeDir, 'config/elasticsearch.yml')
|
||||||
logger.info("Configuring ${configFile}")
|
logger.info("Configuring ${configFile}")
|
||||||
configFile.setText(esConfig.collect { key, value -> "${key}: ${value}" }.join('\n'), 'UTF-8')
|
configFile.setText(esConfig.collect { key, value -> "${key}: ${value}" }.join('\n'), 'UTF-8')
|
||||||
|
|
Loading…
Reference in New Issue