@@ -122,8 +122,31 @@ class ClusterFormationTasks {
122
122
}
123
123
NodeInfo node = new NodeInfo (config, i, project, prefix, elasticsearchVersion, sharedDir)
124
124
nodes. add(node)
125
- Object dependsOn = startTasks. empty ? startDependencies : startTasks. get(0 )
126
- startTasks. add(configureNode(project, prefix, runner, dependsOn, node, config, distro, nodes. get(0 )))
125
+ Closure<Map > writeConfigSetup
126
+ Object dependsOn
127
+ if (node. nodeVersion. onOrAfter(" 6.5.0-SNAPSHOT" )) {
128
+ writeConfigSetup = { Map esConfig ->
129
+ // Don't force discovery provider if one is set by the test cluster specs already
130
+ if (esConfig. containsKey(' discovery.zen.hosts_provider' ) == false ) {
131
+ esConfig[' discovery.zen.hosts_provider' ] = ' file'
132
+ }
133
+ esConfig[' discovery.zen.ping.unicast.hosts' ] = []
134
+ esConfig
135
+ }
136
+ dependsOn = startDependencies
137
+ } else {
138
+ dependsOn = startTasks. empty ? startDependencies : startTasks. get(0 )
139
+ writeConfigSetup = { Map esConfig ->
140
+ String unicastTransportUri = node. config. unicastTransportUri(nodes. get(0 ), node, project. ant)
141
+ if (unicastTransportUri == null ) {
142
+ esConfig[' discovery.zen.ping.unicast.hosts' ] = []
143
+ } else {
144
+ esConfig[' discovery.zen.ping.unicast.hosts' ] = " \" ${ unicastTransportUri} \" "
145
+ }
146
+ esConfig
147
+ }
148
+ }
149
+ startTasks. add(configureNode(project, prefix, runner, dependsOn, node, config, distro, writeConfigSetup))
127
150
}
128
151
129
152
Task wait = configureWaitTask(" ${ prefix} #wait" , project, nodes, startTasks, config. nodeStartupWaitSeconds)
@@ -182,7 +205,7 @@ class ClusterFormationTasks {
182
205
* @return a task which starts the node.
183
206
*/
184
207
static Task configureNode (Project project , String prefix , Task runner , Object dependsOn , NodeInfo node , ClusterConfiguration config ,
185
- Configuration distribution , NodeInfo seedNode ) {
208
+ Configuration distribution , Closure< Map > writeConfig ) {
186
209
187
210
// tasks are chained so their execution order is maintained
188
211
Task setup = project. tasks. create(name : taskName(prefix, node, ' clean' ), type : Delete , dependsOn : dependsOn) {
@@ -198,7 +221,7 @@ class ClusterFormationTasks {
198
221
setup = configureCheckPreviousTask(taskName(prefix, node, ' checkPrevious' ), project, setup, node)
199
222
setup = configureStopTask(taskName(prefix, node, ' stopPrevious' ), project, setup, node)
200
223
setup = configureExtractTask(taskName(prefix, node, ' extract' ), project, setup, node, distribution)
201
- setup = configureWriteConfigTask(taskName(prefix, node, ' configure' ), project, setup, node, seedNode )
224
+ setup = configureWriteConfigTask(taskName(prefix, node, ' configure' ), project, setup, node, writeConfig )
202
225
setup = configureCreateKeystoreTask(taskName(prefix, node, ' createKeystore' ), project, setup, node)
203
226
setup = configureAddKeystoreSettingTasks(prefix, project, setup, node)
204
227
setup = configureAddKeystoreFileTasks(prefix, project, setup, node)
@@ -301,7 +324,7 @@ class ClusterFormationTasks {
301
324
}
302
325
303
326
/* * Adds a task to write elasticsearch.yml for the given node configuration */
304
- static Task configureWriteConfigTask (String name , Project project , Task setup , NodeInfo node , NodeInfo seedNode ) {
327
+ static Task configureWriteConfigTask (String name , Project project , Task setup , NodeInfo node , Closure< Map > configFilter ) {
305
328
Map esConfig = [
306
329
' cluster.name' : node. clusterName,
307
330
' node.name' : " node-" + node. nodeNum,
@@ -347,10 +370,7 @@ class ClusterFormationTasks {
347
370
348
371
Task writeConfig = project. tasks. create(name : name, type : DefaultTask , dependsOn : setup)
349
372
writeConfig. doFirst {
350
- String unicastTransportUri = node. config. unicastTransportUri(seedNode, node, project. ant)
351
- if (unicastTransportUri != null ) {
352
- esConfig[' discovery.zen.ping.unicast.hosts' ] = " \" ${ unicastTransportUri} \" "
353
- }
373
+ esConfig = configFilter. call(esConfig)
354
374
File configFile = new File (node. pathConf, ' elasticsearch.yml' )
355
375
logger. info(" Configuring ${ configFile} " )
356
376
configFile. setText(esConfig. collect { key , value -> " ${ key} : ${ value} " }. join(' \n ' ), ' UTF-8' )
@@ -681,6 +701,19 @@ class ClusterFormationTasks {
681
701
static Task configureWaitTask (String name , Project project , List<NodeInfo > nodes , List<Task > startTasks , int waitSeconds ) {
682
702
Task wait = project. tasks. create(name : name, dependsOn : startTasks)
683
703
wait. doLast {
704
+
705
+ Collection<String > unicastHosts = new HashSet<> ()
706
+ nodes. forEach { otherNode ->
707
+ String unicastHost = otherNode. config. unicastTransportUri(otherNode, null , project. ant)
708
+ if (unicastHost != null ) {
709
+ unicastHosts. addAll(Arrays . asList(unicastHost. split(" ," )))
710
+ }
711
+ }
712
+ String unicastHostsTxt = String . join(" \n " , unicastHosts)
713
+ nodes. forEach { node ->
714
+ node. pathConf. toPath(). resolve(" unicast_hosts.txt" ). setText(unicastHostsTxt)
715
+ }
716
+
684
717
ant. waitfor(maxwait : " ${ waitSeconds} " , maxwaitunit : ' second' , checkevery : ' 500' , checkeveryunit : ' millisecond' , timeoutproperty : " failed${ name} " ) {
685
718
or {
686
719
for (NodeInfo node : nodes) {
0 commit comments