Skip to content

Commit b1f9884

Browse files
authored
Convert repository-hdfs to testclusters (#41252)
* Convert repository-hdfs to testclusters Relates #40862
1 parent e76914c commit b1f9884

File tree

2 files changed

+51
-77
lines changed

2 files changed

+51
-77
lines changed

plugins/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@
2020
// only configure immediate children of plugins dir
2121
configure(subprojects.findAll { it.parent.path == project.path }) {
2222
group = 'org.elasticsearch.plugin'
23-
// TODO exclude some plugins as they require features not yet supproted by testclusters
24-
if (false == name in ['repository-hdfs']) {
25-
apply plugin: 'elasticsearch.testclusters'
26-
}
27-
23+
apply plugin: 'elasticsearch.testclusters'
2824
apply plugin: 'elasticsearch.esplugin'
2925

3026
esplugin {

plugins/repository-hdfs/build.gradle

Lines changed: 50 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
import org.apache.tools.ant.taskdefs.condition.Os
21-
import org.elasticsearch.gradle.test.ClusterConfiguration
2221
import org.elasticsearch.gradle.test.RestIntegTestTask
2322

2423
import java.nio.file.Files
@@ -64,15 +63,17 @@ dependencies {
6463
compile "org.apache.logging.log4j:log4j-slf4j-impl:${versions.log4j}"
6564

6665
hdfsFixture project(':test:fixtures:hdfs-fixture')
66+
// Set the keytab files in the classpath so that we can access them from test code without the security manager
67+
// freaking out.
68+
testRuntime fileTree(dir: project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs","hdfs_hdfs.build.elastic.co.keytab").parent, include: ['*.keytab'])
6769
}
6870

6971
dependencyLicenses {
7072
mapping from: /hadoop-.*/, to: 'hadoop'
7173
}
7274

73-
7475
String realm = "BUILD.ELASTIC.CO"
75-
76+
String krb5conf = project(':test:fixtures:krb5kdc-fixture').ext.krb5Conf("hdfs")
7677

7778
// Create HDFS File System Testing Fixtures for HA/Secure combinations
7879
for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', 'secureHaHdfsFixture']) {
@@ -91,9 +92,8 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture',
9192

9293
// If it's a secure fixture, then depend on Kerberos Fixture and principals + add the krb5conf to the JVM options
9394
if (fixtureName.equals('secureHdfsFixture') || fixtureName.equals('secureHaHdfsFixture')) {
94-
miniHDFSArgs.add("-Djava.security.krb5.conf=${project(':test:fixtures:krb5kdc-fixture').ext.krb5Conf("hdfs")}");
95+
miniHDFSArgs.add("-Djava.security.krb5.conf=${krb5conf}")
9596
}
96-
9797
// If it's an HA fixture, set a nameservice to use in the JVM options
9898
if (fixtureName.equals('haHdfsFixture') || fixtureName.equals('secureHaHdfsFixture')) {
9999
miniHDFSArgs.add("-Dha-nameservice=ha-hdfs")
@@ -107,70 +107,44 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture',
107107
if (fixtureName.equals('secureHdfsFixture') || fixtureName.equals('secureHaHdfsFixture')) {
108108
miniHDFSArgs.add("hdfs/hdfs.build.elastic.co@${realm}")
109109
miniHDFSArgs.add(
110-
project(':test:fixtures:krb5kdc-fixture')
111-
.ext.krb5Keytabs("hdfs", "hdfs_hdfs.build.elastic.co.keytab")
110+
project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs", "hdfs_hdfs.build.elastic.co.keytab")
112111
)
113112
}
114113

115114
args miniHDFSArgs.toArray()
116115
}
117116
}
118117

119-
// The following closure must execute before the afterEvaluate block in the constructor of the following integrationTest tasks:
120-
project.afterEvaluate {
121-
for (String integTestTaskName : ['integTestHa', 'integTestSecure', 'integTestSecureHa']) {
122-
ClusterConfiguration cluster = project.extensions.getByName("${integTestTaskName}Cluster") as ClusterConfiguration
123-
cluster.dependsOn(project.bundlePlugin)
124-
125-
Task restIntegTestTask = project.tasks.getByName(integTestTaskName)
126-
restIntegTestTask.clusterConfig.plugin(project.path)
127-
128-
// Default jvm arguments for all test clusters
129-
String jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') +
130-
" " + "-Xmx" + System.getProperty('tests.heap.size', '512m') +
131-
" " + System.getProperty('tests.jvm.argline', '')
132-
133-
// If it's a secure cluster, add the keytab as an extra config, and set the krb5 conf in the JVM options.
134-
if (integTestTaskName.equals('integTestSecure') || integTestTaskName.equals('integTestSecureHa')) {
135-
String krb5conf = project(':test:fixtures:krb5kdc-fixture').ext.krb5Conf("hdfs")
136-
restIntegTestTask.clusterConfig.extraConfigFile(
137-
"repository-hdfs/krb5.keytab",
138-
"${project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs", "elasticsearch.keytab")}"
139-
)
140-
jvmArgs = jvmArgs + " " + "-Djava.security.krb5.conf=${krb5conf}"
141-
142-
// If it's the HA + Secure tests then also set the Kerberos settings for the integration test JVM since we'll
143-
// need to auth to HDFS to trigger namenode failovers.
144-
if (integTestTaskName.equals('integTestSecureHa')) {
145-
Task restIntegTestTaskRunner = project.tasks.getByName("${integTestTaskName}Runner")
146-
restIntegTestTaskRunner.systemProperty "test.krb5.principal.es", "elasticsearch@${realm}"
147-
restIntegTestTaskRunner.systemProperty "test.krb5.principal.hdfs", "hdfs/hdfs.build.elastic.co@${realm}"
148-
restIntegTestTaskRunner.jvmArgs "-Djava.security.krb5.conf=${krb5conf}"
149-
restIntegTestTaskRunner.systemProperty (
118+
for (String integTestTaskName : ['integTestHa', 'integTestSecure', 'integTestSecureHa']) {
119+
task "${integTestTaskName}"(type: RestIntegTestTask) {
120+
description = "Runs rest tests against an elasticsearch cluster with HDFS."
121+
dependsOn(project.bundlePlugin)
122+
runner {
123+
if (integTestTaskName.contains("Secure")) {
124+
dependsOn secureHdfsFixture
125+
systemProperty "test.krb5.principal.es", "elasticsearch@${realm}"
126+
systemProperty "test.krb5.principal.hdfs", "hdfs/hdfs.build.elastic.co@${realm}"
127+
jvmArgs "-Djava.security.krb5.conf=${krb5conf}"
128+
systemProperty (
150129
"test.krb5.keytab.hdfs",
151130
project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs","hdfs_hdfs.build.elastic.co.keytab")
152131
)
153132
}
154133
}
155-
156-
restIntegTestTask.clusterConfig.jvmArgs = jvmArgs
157134
}
158-
}
159135

160-
// Create a Integration Test suite just for HA based tests
161-
RestIntegTestTask integTestHa = project.tasks.create('integTestHa', RestIntegTestTask.class) {
162-
description = "Runs rest tests against an elasticsearch cluster with HDFS configured with HA Namenode."
163-
}
164-
165-
// Create a Integration Test suite just for security based tests
166-
RestIntegTestTask integTestSecure = project.tasks.create('integTestSecure', RestIntegTestTask.class) {
167-
description = "Runs rest tests against an elasticsearch cluster with HDFS secured by MIT Kerberos."
136+
testClusters."${integTestTaskName}" {
137+
plugin(file(bundlePlugin.archiveFile))
138+
if (integTestTaskName.contains("Secure")) {
139+
systemProperty "java.security.krb5.conf", krb5conf
140+
extraConfigFile(
141+
"repository-hdfs/krb5.keytab",
142+
file("${project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs", "elasticsearch.keytab")}")
143+
)
144+
}
145+
}
168146
}
169147

170-
// Create a Integration Test suite just for HA related security based tests
171-
RestIntegTestTask integTestSecureHa = project.tasks.create('integTestSecureHa', RestIntegTestTask.class) {
172-
description = "Runs rest tests against an elasticsearch cluster with HDFS configured with HA Namenode and secured by MIT Kerberos."
173-
}
174148

175149
// Determine HDFS Fixture compatibility for the current build environment.
176150
boolean fixtureSupported = false
@@ -199,21 +173,27 @@ if (legalPath == false) {
199173

200174
// Always ignore HA integration tests in the normal integration test runner, they are included below as
201175
// part of their own HA-specific integration test tasks.
202-
integTestRunner.exclude('**/Ha*TestSuiteIT.class')
176+
integTest.runner {
177+
exclude('**/Ha*TestSuiteIT.class')
178+
}
203179

204180
if (fixtureSupported) {
205181
// Check depends on the HA test. Already depends on the standard test.
206182
project.check.dependsOn(integTestHa)
207183

208184
// Both standard and HA tests depend on their respective HDFS fixtures
209-
integTestCluster.dependsOn hdfsFixture
210-
integTestHaCluster.dependsOn haHdfsFixture
185+
integTest.dependsOn hdfsFixture
186+
integTestHa.dependsOn haHdfsFixture
211187

212188
// The normal test runner only runs the standard hdfs rest tests
213-
integTestRunner.systemProperty 'tests.rest.suite', 'hdfs_repository'
189+
integTest.runner {
190+
systemProperty 'tests.rest.suite', 'hdfs_repository'
191+
}
214192

215193
// Only include the HA integration tests for the HA test task
216-
integTestHaRunner.setIncludes(['**/Ha*TestSuiteIT.class'])
194+
integTestHa.runner {
195+
setIncludes(['**/Ha*TestSuiteIT.class'])
196+
}
217197
} else {
218198
if (legalPath) {
219199
logger.warn("hdfsFixture unsupported, please set HADOOP_HOME and put HADOOP_HOME\\bin in PATH")
@@ -222,29 +202,27 @@ if (fixtureSupported) {
222202
}
223203

224204
// The normal integration test runner will just test that the plugin loads
225-
integTestRunner.systemProperty 'tests.rest.suite', 'hdfs_repository/10_basic'
205+
integTest.runner {
206+
systemProperty 'tests.rest.suite', 'hdfs_repository/10_basic'
207+
}
226208
// HA fixture is unsupported. Don't run them.
227209
integTestHa.setEnabled(false)
228210
}
229211

230212
check.dependsOn(integTestSecure, integTestSecureHa)
231213

232-
// Fixture dependencies
233-
integTestSecureCluster.dependsOn secureHdfsFixture
234-
integTestSecureHaCluster.dependsOn secureHaHdfsFixture
235-
236-
// Set the keytab files in the classpath so that we can access them from test code without the security manager
237-
// freaking out.
238-
project.dependencies {
239-
testRuntime fileTree(dir: project(':test:fixtures:krb5kdc-fixture').ext.krb5Keytabs("hdfs","hdfs_hdfs.build.elastic.co.keytab").parent, include: ['*.keytab'])
240-
}
241-
242214
// Run just the secure hdfs rest test suite.
243-
integTestSecureRunner.systemProperty 'tests.rest.suite', 'secure_hdfs_repository'
215+
integTestSecure.runner {
216+
systemProperty 'tests.rest.suite', 'secure_hdfs_repository'
217+
}
244218
// Ignore HA integration Tests. They are included below as part of integTestSecureHa test runner.
245-
integTestSecureRunner.exclude('**/Ha*TestSuiteIT.class')
219+
integTestSecure.runner {
220+
exclude('**/Ha*TestSuiteIT.class')
221+
}
246222
// Only include the HA integration tests for the HA test task
247-
integTestSecureHaRunner.setIncludes(['**/Ha*TestSuiteIT.class'])
223+
integTestSecureHa.runner {
224+
setIncludes(['**/Ha*TestSuiteIT.class'])
225+
}
248226

249227
thirdPartyAudit {
250228
ignoreMissingClasses()

0 commit comments

Comments
 (0)