Skip to content

Commit 0302dca

Browse files
authored
Update the QA project to use test cluster api (#1430)
Also update the project to run fixtures on the java 8 runtime. Java home can now be set on cluster configs and is used by fixtures. A cluster can be configured with a dependent ElasticsearchCluster. This cluster is depended on for any configuration tasks in case its cluster address is used. Settings are now stored as objects in cluster configurations instead of Strings since they may be GStrings with closures inside of them that must be resolved ONLY at configuration writing time. This is needed to resolve test cluster http addresses which are only discoverable once the cluster is started. In order to make this resolution process simpler, removed most of the Map<String, String> types in the code and replaced them with the FileSettings type which can resolve closures as needed when writing the configuration to a file. Upgraded Spark QA runtime to 2.3.4 as the older version has been removed from apache's mirrors. AbstractClusterTask now extends DefaultTestClustersTask, as it is the only way to ensure that Elasticsearch is still running when starting the task. In order to configure JAVA_HOME consistently, each AbstractClusterTask now has its environment variables resolved in its super class instead of with duplicated code in each task.
1 parent bc65f89 commit 0302dca

28 files changed

+421
-197
lines changed

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/ConfigFormats.groovy

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,30 @@
1919

2020
package org.elasticsearch.hadoop.gradle.fixture.hadoop
2121

22+
import static org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.SettingsContainer.FileSettings
23+
2224
class ConfigFormats {
2325

2426
static Closure<String> hadoopXML() {
25-
return { Map conf ->
26-
String props = conf.collect { key, value ->
27+
return { FileSettings conf ->
28+
String props = conf.resolve().collect { key, value ->
2729
"<property>\n\t\t<name>${key}</name>\n\t\t<value>${value}</value>\n\t</property>"
2830
}.join("\n\t")
2931
return "<configuration>\n\t${props}\n</configuration>"
3032
}
3133
}
3234

3335
static Closure<String> propertyFile() {
34-
return { Map conf ->
35-
conf.collect { key, value ->
36+
return { FileSettings conf ->
37+
conf.resolve().collect { key, value ->
3638
"${key}=${value}"
3739
}.join("\n")
3840
}
3941
}
4042

4143
static Closure<String> whiteSpaced() {
42-
return { Map conf ->
43-
conf.collect { key, value ->
44+
return { FileSettings conf ->
45+
conf.resolve().collect { key, value ->
4446
"${key} ${value}"
4547
}.join("\n")
4648
}

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/HadoopClusterFormationTasks.groovy

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.apache.tools.ant.DefaultLogger
2323
import org.elasticsearch.gradle.LoggedExec
2424
import org.elasticsearch.gradle.Version
2525
import org.elasticsearch.gradle.test.Fixture
26+
import org.elasticsearch.gradle.testclusters.DefaultTestClustersTask
2627
import org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.HadoopClusterConfiguration
2728
import org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.InstanceConfiguration
2829
import org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.RoleConfiguration
@@ -42,6 +43,8 @@ import org.apache.tools.ant.taskdefs.condition.Os
4243

4344
import java.nio.file.Paths
4445

46+
import static org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.SettingsContainer.FileSettings
47+
4548
/**
4649
* A helper for creating tasks to build a cluster that is used by a task, and tear down the cluster
4750
* when the task is finished.
@@ -68,8 +71,6 @@ class HadoopClusterFormationTasks {
6871
* Adds dependent tasks to the given task to start and stop a cluster with the given configuration.
6972
* <p>
7073
* Returns a list of NodeInfo objects for each node in the cluster.
71-
*
72-
* Based on {@link org.elasticsearch.gradle.test.ClusterFormationTasks}
7374
*/
7475
static List<InstanceInfo> setup(Project project, HadoopClusterConfiguration clusterConfiguration) {
7576
String prefix = clusterConfiguration.getName()
@@ -342,13 +343,16 @@ class HadoopClusterFormationTasks {
342343

343344
static Task configureWriteConfigTask(String name, Project project, Task setup, InstanceInfo node) {
344345
// Add all node level configs to node Configuration
345-
return project.tasks.create(name: name, type: DefaultTask, dependsOn: setup) {
346+
return project.tasks.create(name: name, type: DefaultTestClustersTask, dependsOn: setup) {
346347
group = 'hadoopFixture'
348+
if (node.elasticsearchCluster != null) {
349+
useCluster(node.elasticsearchCluster)
350+
}
347351
doFirst {
348352
// Write each config file needed
349353
node.configFiles.forEach { configFile ->
350354
String configName = configFile.getName()
351-
Map<String, String> configFileEntries = node.configContents.get(configName)
355+
FileSettings configFileEntries = node.configContents.get(configName)
352356
if (configFileEntries == null) {
353357
throw new GradleException("Could not find contents of [${configFile}] settings file from deployment options.")
354358
}
@@ -387,7 +391,6 @@ class HadoopClusterFormationTasks {
387391
return project.tasks.create(name: name, type: LoggedExec, dependsOn: setup) { Exec exec ->
388392
exec.group = 'hadoopFixture'
389393
exec.workingDir node.cwd
390-
exec.environment 'JAVA_HOME', node.getJavaHome()
391394
exec.environment(node.env)
392395

393396
// Configure HADOOP_OPTS (or similar env) - adds system properties, assertion flags, remote debug etc

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/InstanceInfo.groovy

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package org.elasticsearch.hadoop.gradle.fixture.hadoop
2121

2222
import org.apache.tools.ant.taskdefs.condition.Os
23-
import org.elasticsearch.gradle.info.BuildParams
23+
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
2424
import org.elasticsearch.hadoop.gradle.util.WaitForURL
2525
import org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.InstanceConfiguration
2626
import org.gradle.api.GradleException
@@ -30,6 +30,8 @@ import java.nio.file.Path
3030
import java.nio.file.Paths
3131
import java.util.concurrent.TimeUnit
3232

33+
import static org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.SettingsContainer.FileSettings
34+
3335
/**
3436
* Generic information for any process running in a hadoop ecosystem.
3537
*
@@ -70,7 +72,7 @@ class InstanceInfo {
7072
/** The config files */
7173
List<File> configFiles
7274

73-
Map<String, Map<String, String>> configContents
75+
Map<String, FileSettings> configContents
7476

7577
/** Closure that renders the contents of the config file */
7678
Closure<String> configFileFormatter
@@ -84,8 +86,8 @@ class InstanceInfo {
8486
/** stdout/stderr log of the service process for this instance */
8587
File startLog
8688

87-
/** Major version of java this node runs with, or {@code null} if using the runtime java version */
88-
Integer javaVersion
89+
/** Location of the java installation to use when running processes **/
90+
String javaHome
8991

9092
/** environment variables to start the node with */
9193
Map<String, String> env
@@ -108,6 +110,9 @@ class InstanceInfo {
108110
/** buffer for ant output when starting this node */
109111
ByteArrayOutputStream buffer = new ByteArrayOutputStream()
110112

113+
/** Elasticsearch cluster dependency for tasks **/
114+
ElasticsearchCluster elasticsearchCluster
115+
111116
/**
112117
* A closure to call before the cluster is considered ready. The closure is passed the node info,
113118
* as well as a groovy AntBuilder, to enable running ant condition checks. The default wait
@@ -155,13 +160,16 @@ class InstanceInfo {
155160
startLog = new File(cwd, 'run.log')
156161

157162
// We just default to the current runtime at this time
158-
javaVersion = 8
163+
javaHome = config.getJavaHome()
159164

160165
// Prepare Environment
161166
env = [:]
162167
env.putAll(config.getEnvironmentVariables())
163168
config.getServiceDescriptor().finalizeEnv(env, config)
164169

170+
// Add JAVA_HOME to the environment
171+
env['JAVA_HOME'] = javaHome
172+
165173
// Prepare startup command and arguments
166174
args = []
167175
List<String> startCommandLine = config.getServiceDescriptor().startCommand(config)
@@ -202,6 +210,8 @@ class InstanceInfo {
202210
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
203211
args.add('"') // end the entire command, quoted
204212
}
213+
214+
this.elasticsearchCluster = config.getElasticsearchCluster()
205215
}
206216

207217
Path binPath() {
@@ -235,19 +245,13 @@ class InstanceInfo {
235245
throw new UnsupportedOperationException("JNAKernal32Library is compiled for Java 10 and up.")
236246
}
237247

238-
/** Return the java home used by this node. */
239-
String getJavaHome() {
240-
return javaVersion == null ? project.runtimeJavaHome : BuildParams.javaVersions.find { it.version == javaVersion }.javaHome.absolutePath
241-
}
242-
243248
/** Returns debug string for the command that started this node. */
244249
String getCommandString() {
245250
String commandString = "\nService ${config.serviceDescriptor.serviceName()}: ${config.roleDescriptor.roleName()} configuration:\n"
246251
commandString += "|-----------------------------------------\n"
247252
commandString += "| cwd: ${cwd}\n"
248253
commandString += "| command: ${executable} ${args.join(' ')}\n"
249254
commandString += '| environment:\n'
250-
commandString += "| JAVA_HOME: ${javaHome}\n"
251255
env.each { k, v -> commandString += "| ${k}: ${v}\n" }
252256
commandString += "|\n| [${backgroundScript.name}]\n"
253257
backgroundScript.eachLine('UTF-8', { line -> commandString += " ${line}\n"})

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/ServiceDescriptor.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.InstanceConfiguration
2424
import org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.ServiceConfiguration
2525
import org.elasticsearch.hadoop.gradle.tasks.ApacheMirrorDownload
2626

27+
import static org.elasticsearch.hadoop.gradle.fixture.hadoop.conf.SettingsContainer.FileSettings
28+
2729
/**
2830
* Describes deployment characteristics for different Hadoop ecosystem projects.
2931
*
@@ -100,7 +102,7 @@ interface ServiceDescriptor {
100102
/**
101103
* Collect all configuration entries, setting defaults for the service, role, and instance.
102104
*/
103-
Map<String, Map<String, String>> collectConfigFilesContents(InstanceConfiguration configuration)
105+
Map<String, FileSettings> collectConfigFilesContents(InstanceConfiguration configuration)
104106

105107
/**
106108
* Closure that formats a configuration map into a String for the config file contents.
@@ -110,7 +112,7 @@ interface ServiceDescriptor {
110112
/**
111113
* Produces the HTTP/S URI to reach the web front end for a running instance, or null if there is no web interface.
112114
*/
113-
String httpUri(InstanceConfiguration configuration, Map<String, Map<String, String>> configFileContents)
115+
String httpUri(InstanceConfiguration configuration, Map<String, FileSettings> configFileContents)
114116

115117
/**
116118
* The command line to use for starting the given role and instance.

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/conf/EndProcessConfiguration.groovy

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
package org.elasticsearch.hadoop.gradle.fixture.hadoop.conf
2121

22+
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
23+
import org.gradle.api.Project
24+
2225
/**
2326
* Provides defaults and can be slotted in as the last parent configuration in a chain.
2427
*
@@ -29,8 +32,8 @@ package org.elasticsearch.hadoop.gradle.fixture.hadoop.conf
2932
*/
3033
class EndProcessConfiguration extends ProcessConfiguration {
3134

32-
EndProcessConfiguration() {
33-
super(null)
35+
EndProcessConfiguration(Project project) {
36+
super(project)
3437
}
3538

3639
@Override
@@ -68,6 +71,11 @@ class EndProcessConfiguration extends ProcessConfiguration {
6871
return Collections.emptyList()
6972
}
7073

74+
@Override
75+
String getJavaHome() {
76+
return project.runtimeJavaHome
77+
}
78+
7179
@Override
7280
String getJvmArgs() {
7381
return ""
@@ -77,4 +85,9 @@ class EndProcessConfiguration extends ProcessConfiguration {
7785
boolean getDebug() {
7886
return false
7987
}
88+
89+
@Override
90+
ElasticsearchCluster getElasticsearchCluster() {
91+
return null
92+
}
8093
}

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/conf/HadoopClusterConfiguration.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ class HadoopClusterConfiguration extends ProcessConfiguration {
4747
private static final Map<String, ServiceDescriptor> SUPPORTED_SERVICES = [HADOOP, HIVE, PIG, SPARK]
4848
.collectEntries { [(it.id()): it] }
4949

50-
private static final ProcessConfiguration END = new EndProcessConfiguration()
51-
5250
private final Project project
5351
private final String name
5452
private final List<Task> clusterTasks
53+
private final ProcessConfiguration defaultConfiguration
5554
private final Map<String, ServiceConfiguration> serviceConfigurations
5655
private final List<ServiceConfiguration> serviceCreationOrder
5756

@@ -60,6 +59,7 @@ class HadoopClusterConfiguration extends ProcessConfiguration {
6059
this.project = project
6160
this.name = name
6261
this.clusterTasks = []
62+
this.defaultConfiguration = new EndProcessConfiguration(project)
6363
this.serviceConfigurations = [:]
6464
this.serviceCreationOrder = []
6565
}
@@ -126,6 +126,6 @@ class HadoopClusterConfiguration extends ProcessConfiguration {
126126

127127
@Override
128128
protected ProcessConfiguration parent() {
129-
return END
129+
return defaultConfiguration
130130
}
131131
}

buildSrc/src/main/groovy/org/elasticsearch/hadoop/gradle/fixture/hadoop/conf/ProcessConfiguration.groovy

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.hadoop.gradle.fixture.hadoop.conf
2121

22+
import org.elasticsearch.gradle.testclusters.ElasticsearchCluster
2223
import org.gradle.api.InvalidUserDataException
2324
import org.gradle.api.Project
2425
import org.gradle.api.Task
@@ -38,16 +39,18 @@ abstract class ProcessConfiguration {
3839
this.project = project
3940
}
4041

41-
private final Project project
42+
protected final Project project
4243
private Map<String, String> systemProperties = new HashMap<>()
4344
private Map<String, String> environmentVariables = new HashMap<>()
4445
private SettingsContainer settingsContainer = new SettingsContainer()
4546
private Map<String, Object> extraConfigFiles = new HashMap<>()
4647
private LinkedHashMap<String, Object[]> setupCommands = new LinkedHashMap<>()
4748
private List<Object> dependencies = new ArrayList<>()
4849
private List<Task> clusterTasks = new ArrayList<>()
50+
private String javaHome = null
4951
private String jvmArgs = ''
5052
private boolean debug = false
53+
private ElasticsearchCluster elasticsearchCluster = null
5154

5255
void addSystemProperty(String key, String value) {
5356
systemProperties.put(key, value)
@@ -77,7 +80,7 @@ abstract class ProcessConfiguration {
7780
return combined
7881
}
7982

80-
void addSetting(String key, String value) {
83+
void addSetting(String key, Object value) {
8184
settingsContainer.addSetting(key, value)
8285
}
8386

@@ -145,6 +148,23 @@ abstract class ProcessConfiguration {
145148
return combined
146149
}
147150

151+
void setJavaHome(String javaHome) {
152+
this.javaHome = javaHome
153+
}
154+
155+
String getJavaHome() {
156+
if (this.javaHome != null) {
157+
return this.javaHome
158+
} else {
159+
ProcessConfiguration parent = parent()
160+
if (parent != null) {
161+
return parent.getJavaHome()
162+
} else {
163+
return null
164+
}
165+
}
166+
}
167+
148168
void setJvmArgs(String jvmArgs) {
149169
this.jvmArgs = jvmArgs
150170
}
@@ -178,6 +198,23 @@ abstract class ProcessConfiguration {
178198
return debug
179199
}
180200

201+
void useElasticsearchCluster(ElasticsearchCluster elasticsearchCluster) {
202+
this.elasticsearchCluster = elasticsearchCluster
203+
}
204+
205+
ElasticsearchCluster getElasticsearchCluster() {
206+
if (this.elasticsearchCluster != null) {
207+
return this.elasticsearchCluster
208+
} else {
209+
ProcessConfiguration parent = parent()
210+
if (parent != null) {
211+
return parent.getElasticsearchCluster()
212+
} else {
213+
return null
214+
}
215+
}
216+
}
217+
181218
Task createClusterTask(Map<String, ?> options) throws InvalidUserDataException {
182219
Task task = project.tasks.create(options)
183220
addClusterTask(task)

0 commit comments

Comments
 (0)