Skip to content

Commit

Permalink
Add support for bwc for testclusters and convert full cluster restart (
Browse files Browse the repository at this point in the history
  • Loading branch information
alpar-t committed Aug 16, 2019
1 parent c31cddf commit 98ffebc
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.elasticsearch.gradle.testclusters;

import org.elasticsearch.gradle.ElasticsearchDistribution;
import org.elasticsearch.gradle.FileSupplier;
import org.elasticsearch.gradle.PropertyNormalization;
import org.elasticsearch.gradle.ReaperService;
Expand Down Expand Up @@ -59,24 +58,23 @@ public class ElasticsearchCluster implements TestClusterConfiguration, Named {
private final String clusterName;
private final NamedDomainObjectContainer<ElasticsearchNode> nodes;
private final File workingDirBase;
private final Function<Integer, ElasticsearchDistribution> distributionFactory;
private final LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions = new LinkedHashMap<>();
private final Project project;
private final ReaperService reaper;
private int nodeIndex = 0;

public ElasticsearchCluster(String path, String clusterName, Project project, ReaperService reaper,
Function<Integer, ElasticsearchDistribution> distributionFactory, File workingDirBase) {
public ElasticsearchCluster(String path, String clusterName, Project project,
ReaperService reaper, File workingDirBase) {
this.path = path;
this.clusterName = clusterName;
this.project = project;
this.reaper = reaper;
this.distributionFactory = distributionFactory;
this.workingDirBase = workingDirBase;
this.nodes = project.container(ElasticsearchNode.class);
this.nodes.add(
new ElasticsearchNode(
path, clusterName + "-0",
project, reaper, workingDirBase, distributionFactory.apply(0)
project, reaper, workingDirBase
)
);
// configure the cluster name eagerly so nodes know about it
Expand All @@ -100,7 +98,7 @@ public void setNumberOfNodes(int numberOfNodes) {

for (int i = nodes.size() ; i < numberOfNodes; i++) {
this.nodes.add(new ElasticsearchNode(
path, clusterName + "-" + i, project, reaper, workingDirBase, distributionFactory.apply(i)
path, clusterName + "-" + i, project, reaper, workingDirBase
));
}
}
Expand All @@ -126,6 +124,11 @@ public void setVersion(String version) {
nodes.all(each -> each.setVersion(version));
}

@Override
public void setVersions(List<String> version) {
nodes.all(each -> each.setVersions(version));
}

@Override
public void setTestDistribution(TestDistribution distribution) {
nodes.all(each -> each.setTestDistribution(distribution));
Expand Down Expand Up @@ -249,8 +252,8 @@ public void start() {
if (nodes.stream().map(ElasticsearchNode::getName).anyMatch( name -> name == null)) {
nodeNames = null;
} else {
nodeNames = nodes.stream().map(ElasticsearchNode::getName).collect(Collectors.joining(","));
};
nodeNames = nodes.stream().map(ElasticsearchNode::getName).map(this::safeName).collect(Collectors.joining(","));
}
for (ElasticsearchNode node : nodes) {
if (nodeNames != null) {
// Can only configure master nodes if we have node names defined
Expand All @@ -269,6 +272,19 @@ public void restart() {
nodes.forEach(ElasticsearchNode::restart);
}

@Override
public void goToNextVersion() {
nodes.all(ElasticsearchNode::goToNextVersion);
}

public void nextNodeToNextVersion() {
if (nodeIndex + 1 > nodes.size()) {
throw new TestClustersException("Ran out of nodes to take to the next version");
}
nodes.getByName(clusterName + "-" + nodeIndex).goToNextVersion();
nodeIndex += 1;
}

@Override
public void extraConfigFile(String destination, File from) {
nodes.all(node -> node.extraConfigFile(destination, from));
Expand Down Expand Up @@ -363,7 +379,6 @@ private void addWaitForClusterHealth() {
nodes.size()
);
if (httpSslEnabled) {

getFirstNode().configureHttpWait(wait);
}
List<Map<String, String>> credentials = getFirstNode().getCredentials();
Expand Down
Loading

0 comments on commit 98ffebc

Please sign in to comment.