Skip to content

Commit 5b1b521

Browse files
authored
Add support for bwc for testclusters and convert full cluster restart (#45374)
1 parent be8fe0a commit 5b1b521

File tree

7 files changed

+176
-111
lines changed

7 files changed

+176
-111
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.gradle.testclusters;
2020

21-
import org.elasticsearch.gradle.ElasticsearchDistribution;
2221
import org.elasticsearch.gradle.FileSupplier;
2322
import org.elasticsearch.gradle.PropertyNormalization;
2423
import org.elasticsearch.gradle.ReaperService;
@@ -59,24 +58,23 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
5958
private final String clusterName;
6059
private final NamedDomainObjectContainer<ElasticsearchNode> nodes;
6160
private final File workingDirBase;
62-
private final Function<Integer, ElasticsearchDistribution> distributionFactory;
6361
private final LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>();
6462
private final Project project;
6563
private final ReaperService reaper;
64+
private int nodeIndex = 0;
6665

67-
public ElasticsearchCluster(String path, String clusterName, Project project, ReaperService reaper,
68-
Function<Integer, ElasticsearchDistribution> distributionFactory, File workingDirBase) {
66+
public ElasticsearchCluster(String path, String clusterName, Project project,
67+
ReaperService reaper, File workingDirBase) {
6968
this.path = path;
7069
this.clusterName = clusterName;
7170
this.project = project;
7271
this.reaper = reaper;
73-
this.distributionFactory = distributionFactory;
7472
this.workingDirBase = workingDirBase;
7573
this.nodes = project.container(ElasticsearchNode.class);
7674
this.nodes.add(
7775
new ElasticsearchNode(
7876
path, clusterName + "-0",
79-
project, reaper, workingDirBase, distributionFactory.apply(0)
77+
project, reaper, workingDirBase
8078
)
8179
);
8280
// configure the cluster name eagerly so nodes know about it
@@ -100,7 +98,7 @@ public void setNumberOfNodes(int numberOfNodes) {
10098

10199
for (int i = nodes.size() ; i < numberOfNodes; i++) {
102100
this.nodes.add(new ElasticsearchNode(
103-
path, clusterName + "-" + i, project, reaper, workingDirBase, distributionFactory.apply(i)
101+
path, clusterName + "-" + i, project, reaper, workingDirBase
104102
));
105103
}
106104
}
@@ -126,6 +124,11 @@ public void setVersion(String version) {
126124
nodes.all(each -> each.setVersion(version));
127125
}
128126

127+
@Override
128+
public void setVersions(List<String> version) {
129+
nodes.all(each -> each.setVersions(version));
130+
}
131+
129132
@Override
130133
public void setTestDistribution(TestDistribution distribution) {
131134
nodes.all(each -> each.setTestDistribution(distribution));
@@ -249,8 +252,8 @@ public void start() {
249252
if (nodes.stream().map(ElasticsearchNode::getName).anyMatch( name -> name == null)) {
250253
nodeNames = null;
251254
} else {
252-
nodeNames = nodes.stream().map(ElasticsearchNode::getName).collect(Collectors.joining(","));
253-
};
255+
nodeNames = nodes.stream().map(ElasticsearchNode::getName).map(this::safeName).collect(Collectors.joining(","));
256+
}
254257
for (ElasticsearchNode node : nodes) {
255258
if (nodeNames != null) {
256259
// Can only configure master nodes if we have node names defined
@@ -269,6 +272,19 @@ public void restart() {
269272
nodes.forEach(ElasticsearchNode::restart);
270273
}
271274

275+
@Override
276+
public void goToNextVersion() {
277+
nodes.all(ElasticsearchNode::goToNextVersion);
278+
}
279+
280+
public void nextNodeToNextVersion() {
281+
if (nodeIndex + 1 > nodes.size()) {
282+
throw new TestClustersException("Ran out of nodes to take to the next version");
283+
}
284+
nodes.getByName(clusterName + "-" + nodeIndex).goToNextVersion();
285+
nodeIndex += 1;
286+
}
287+
272288
@Override
273289
public void extraConfigFile(String destination, File from) {
274290
nodes.all(node -> node.extraConfigFile(destination, from));
@@ -363,7 +379,6 @@ private void addWaitForClusterHealth() {
363379
nodes.size()
364380
);
365381
if (httpSslEnabled) {
366-
367382
getFirstNode().configureHttpWait(wait);
368383
}
369384
List<Map<String, String>> credentials = getFirstNode().getCredentials();

0 commit comments

Comments
 (0)