Skip to content

Commit be8c094

Browse files
authored
Build: Add mavenPlugin cluster configuration method (#30541)
This commit adds the ability to specify a plugin from maven for a test cluster to use. Currently, only local projects may be used as plugins, except when testing bwc, where the coordinates of the project are used. However, that assumes all projects always keep the same coordinates, or are even still plugins, which is no longer the case for x-pack. The full cluster and rolling restart tests are changed to use this new method when pulling x-pack versions before 6.3.0.
1 parent 4c130a1 commit be8c094

File tree

5 files changed

+70
-46
lines changed

5 files changed

+70
-46
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterConfiguration.groovy

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class ClusterConfiguration {
147147
// map from destination path, to source file
148148
Map<String, Object> extraConfigFiles = new HashMap<>()
149149

150-
LinkedHashMap<String, Project> plugins = new LinkedHashMap<>()
150+
LinkedHashMap<String, Object> plugins = new LinkedHashMap<>()
151151

152152
List<Project> modules = new ArrayList<>()
153153

@@ -185,6 +185,11 @@ class ClusterConfiguration {
185185
plugins.put(pluginProject.name, pluginProject)
186186
}
187187

188+
@Input
189+
void mavenPlugin(String name, String mavenCoords) {
190+
plugins.put(name, mavenCoords)
191+
}
192+
188193
/** Add a module to the cluster. The project must be an esplugin and have a single zip default artifact. */
189194
@Input
190195
void module(Project moduleProject) {

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ class ClusterFormationTasks {
9999
// from mirrors using gradles built-in mechanism etc.
100100

101101
configureDistributionDependency(project, config.distribution, bwcDistro, config.bwcVersion)
102-
for (Map.Entry<String, Project> entry : config.plugins.entrySet()) {
103-
configureBwcPluginDependency("${prefix}_elasticsearchBwcPlugins", project, entry.getValue(), bwcPlugins, config.bwcVersion)
102+
for (Map.Entry<String, Object> entry : config.plugins.entrySet()) {
103+
configureBwcPluginDependency(project, entry.getValue(), bwcPlugins, config.bwcVersion)
104104
}
105105
bwcDistro.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
106106
bwcPlugins.resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
@@ -150,10 +150,15 @@ class ClusterFormationTasks {
150150
}
151151

152152
/** Adds a dependency on a different version of the given plugin, which will be retrieved using gradle's dependency resolution */
153-
static void configureBwcPluginDependency(String name, Project project, Project pluginProject, Configuration configuration, Version elasticsearchVersion) {
154-
verifyProjectHasBuildPlugin(name, elasticsearchVersion, project, pluginProject)
155-
final String pluginName = findPluginName(pluginProject)
156-
project.dependencies.add(configuration.name, "org.elasticsearch.plugin:${pluginName}:${elasticsearchVersion}@zip")
153+
static void configureBwcPluginDependency(Project project, Object plugin, Configuration configuration, Version elasticsearchVersion) {
154+
if (plugin instanceof Project) {
155+
Project pluginProject = (Project)plugin
156+
verifyProjectHasBuildPlugin(configuration.name, elasticsearchVersion, project, pluginProject)
157+
final String pluginName = findPluginName(pluginProject)
158+
project.dependencies.add(configuration.name, "org.elasticsearch.plugin:${pluginName}:${elasticsearchVersion}@zip")
159+
} else {
160+
project.dependencies.add(configuration.name, "${plugin}@zip")
161+
}
157162
}
158163

159164
/**
@@ -210,9 +215,9 @@ class ClusterFormationTasks {
210215
}
211216

212217
// install plugins
213-
for (Map.Entry<String, Project> plugin : node.config.plugins.entrySet()) {
214-
String actionName = pluginTaskName('install', plugin.getKey(), 'Plugin')
215-
setup = configureInstallPluginTask(taskName(prefix, node, actionName), project, setup, node, plugin.getValue(), prefix)
218+
for (String pluginName : node.config.plugins.keySet()) {
219+
String actionName = pluginTaskName('install', pluginName, 'Plugin')
220+
setup = configureInstallPluginTask(taskName(prefix, node, actionName), project, setup, node, pluginName, prefix)
216221
}
217222

218223
// sets up any extra config files that need to be copied over to the ES instance;
@@ -444,31 +449,40 @@ class ClusterFormationTasks {
444449
Copy copyPlugins = project.tasks.create(name: name, type: Copy, dependsOn: setup)
445450

446451
List<FileCollection> pluginFiles = []
447-
for (Map.Entry<String, Project> plugin : node.config.plugins.entrySet()) {
452+
for (Map.Entry<String, Object> plugin : node.config.plugins.entrySet()) {
448453

449-
Project pluginProject = plugin.getValue()
450-
verifyProjectHasBuildPlugin(name, node.nodeVersion, project, pluginProject)
451-
String configurationName = pluginConfigurationName(prefix, pluginProject)
454+
String configurationName = pluginConfigurationName(prefix, plugin.key)
452455
Configuration configuration = project.configurations.findByName(configurationName)
453456
if (configuration == null) {
454457
configuration = project.configurations.create(configurationName)
455458
}
456-
project.dependencies.add(configurationName, project.dependencies.project(path: pluginProject.path, configuration: 'zip'))
457-
setup.dependsOn(pluginProject.tasks.bundlePlugin)
458-
459-
// also allow rest tests to use the rest spec from the plugin
460-
String copyRestSpecTaskName = pluginTaskName('copy', plugin.getKey(), 'PluginRestSpec')
461-
Copy copyRestSpec = project.tasks.findByName(copyRestSpecTaskName)
462-
for (File resourceDir : pluginProject.sourceSets.test.resources.srcDirs) {
463-
File restApiDir = new File(resourceDir, 'rest-api-spec/api')
464-
if (restApiDir.exists() == false) continue
465-
if (copyRestSpec == null) {
466-
copyRestSpec = project.tasks.create(name: copyRestSpecTaskName, type: Copy)
467-
copyPlugins.dependsOn(copyRestSpec)
468-
copyRestSpec.into(project.sourceSets.test.output.resourcesDir)
459+
460+
if (plugin.getValue() instanceof Project) {
461+
Project pluginProject = plugin.getValue()
462+
verifyProjectHasBuildPlugin(name, node.nodeVersion, project, pluginProject)
463+
464+
project.dependencies.add(configurationName, project.dependencies.project(path: pluginProject.path, configuration: 'zip'))
465+
setup.dependsOn(pluginProject.tasks.bundlePlugin)
466+
467+
// also allow rest tests to use the rest spec from the plugin
468+
String copyRestSpecTaskName = pluginTaskName('copy', plugin.getKey(), 'PluginRestSpec')
469+
Copy copyRestSpec = project.tasks.findByName(copyRestSpecTaskName)
470+
for (File resourceDir : pluginProject.sourceSets.test.resources.srcDirs) {
471+
File restApiDir = new File(resourceDir, 'rest-api-spec/api')
472+
if (restApiDir.exists() == false) continue
473+
if (copyRestSpec == null) {
474+
copyRestSpec = project.tasks.create(name: copyRestSpecTaskName, type: Copy)
475+
copyPlugins.dependsOn(copyRestSpec)
476+
copyRestSpec.into(project.sourceSets.test.output.resourcesDir)
477+
}
478+
copyRestSpec.from(resourceDir).include('rest-api-spec/api/**')
469479
}
470-
copyRestSpec.from(resourceDir).include('rest-api-spec/api/**')
480+
} else {
481+
project.dependencies.add(configurationName, "${plugin.getValue()}@zip")
471482
}
483+
484+
485+
472486
pluginFiles.add(configuration)
473487
}
474488

@@ -477,32 +491,37 @@ class ClusterFormationTasks {
477491
return copyPlugins
478492
}
479493

480-
private static String pluginConfigurationName(final String prefix, final Project project) {
481-
return "_plugin_${prefix}_${project.path}".replace(':', '_')
494+
private static String pluginConfigurationName(final String prefix, final String name) {
495+
return "_plugin_${prefix}_${name}".replace(':', '_')
482496
}
483497

484-
private static String pluginBwcConfigurationName(final String prefix, final Project project) {
485-
return "_plugin_bwc_${prefix}_${project.path}".replace(':', '_')
498+
private static String pluginBwcConfigurationName(final String prefix, final String name) {
499+
return "_plugin_bwc_${prefix}_${name}".replace(':', '_')
486500
}
487501

488502
/** Configures task to copy a plugin based on a zip file resolved using dependencies for an older version */
489503
static Task configureCopyBwcPluginsTask(String name, Project project, Task setup, NodeInfo node, String prefix) {
490504
Configuration bwcPlugins = project.configurations.getByName("${prefix}_elasticsearchBwcPlugins")
491-
for (Map.Entry<String, Project> plugin : node.config.plugins.entrySet()) {
492-
Project pluginProject = plugin.getValue()
493-
verifyProjectHasBuildPlugin(name, node.nodeVersion, project, pluginProject)
494-
String configurationName = pluginBwcConfigurationName(prefix, pluginProject)
505+
for (Map.Entry<String, Object> plugin : node.config.plugins.entrySet()) {
506+
String configurationName = pluginBwcConfigurationName(prefix, plugin.key)
495507
Configuration configuration = project.configurations.findByName(configurationName)
496508
if (configuration == null) {
497509
configuration = project.configurations.create(configurationName)
498510
}
499511

500-
final String depName = findPluginName(pluginProject)
512+
if (plugin.getValue() instanceof Project) {
513+
Project pluginProject = plugin.getValue()
514+
verifyProjectHasBuildPlugin(name, node.nodeVersion, project, pluginProject)
501515

502-
Dependency dep = bwcPlugins.dependencies.find {
503-
it.name == depName
516+
final String depName = findPluginName(pluginProject)
517+
518+
Dependency dep = bwcPlugins.dependencies.find {
519+
it.name == depName
520+
}
521+
configuration.dependencies.add(dep)
522+
} else {
523+
project.dependencies.add(configurationName, "${plugin.getValue()}@zip")
504524
}
505-
configuration.dependencies.add(dep)
506525
}
507526

508527
Copy copyPlugins = project.tasks.create(name: name, type: Copy, dependsOn: setup) {
@@ -527,12 +546,12 @@ class ClusterFormationTasks {
527546
return installModule
528547
}
529548

530-
static Task configureInstallPluginTask(String name, Project project, Task setup, NodeInfo node, Project plugin, String prefix) {
549+
static Task configureInstallPluginTask(String name, Project project, Task setup, NodeInfo node, String pluginName, String prefix) {
531550
final FileCollection pluginZip;
532551
if (node.nodeVersion != VersionProperties.elasticsearch) {
533-
pluginZip = project.configurations.getByName(pluginBwcConfigurationName(prefix, plugin))
552+
pluginZip = project.configurations.getByName(pluginBwcConfigurationName(prefix, pluginName))
534553
} else {
535-
pluginZip = project.configurations.getByName(pluginConfigurationName(prefix, plugin))
554+
pluginZip = project.configurations.getByName(pluginConfigurationName(prefix, pluginName))
536555
}
537556
// delay reading the file location until execution time by wrapping in a closure within a GString
538557
final Object file = "${-> new File(node.pluginsTmpDir, pluginZip.singleFile.getName()).toURI().toURL().toString()}"

x-pack/qa/full-cluster-restart/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ subprojects {
141141
configure(extensions.findByName("${baseName}#oldClusterTestCluster")) {
142142
dependsOn copyTestNodeKeystore
143143
if (version.before('6.3.0')) {
144-
plugin xpackProject('plugin').path
144+
mavenPlugin 'x-pack', "org.elasticsearch.plugin:x-pack:${version}"
145145
}
146146
bwcVersion = version
147147
numBwcNodes = 2

x-pack/qa/rolling-upgrade-basic/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ for (Version version : bwcVersions.wireCompatible) {
8282

8383
configure(extensions.findByName("${baseName}#oldClusterTestCluster")) {
8484
if (version.before('6.3.0')) {
85-
plugin xpackProject('plugin').path
85+
mavenPlugin 'x-pack', "org.elasticsearch.plugin:x-pack:${version}"
8686
}
8787
bwcVersion = version
8888
numBwcNodes = 2

x-pack/qa/rolling-upgrade/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ subprojects {
123123
configure(extensions.findByName("${baseName}#oldClusterTestCluster")) {
124124
dependsOn copyTestNodeKeystore
125125
if (version.before('6.3.0')) {
126-
plugin xpackProject('plugin').path
126+
mavenPlugin 'x-pack', "org.elasticsearch.plugin:x-pack:${version}"
127127
}
128128
String usersCli = version.before('6.3.0') ? 'bin/x-pack/users' : 'bin/elasticsearch-users'
129129
setupCommand 'setupTestUser', usersCli, 'useradd', 'test_user', '-p', 'x-pack-test-password', '-r', 'superuser'

0 commit comments

Comments
 (0)