Skip to content

Commit

Permalink
Issue:3933: check for project property in OpensearchCluster instead o…
Browse files Browse the repository at this point in the history
…n OpensearchNode

Signed-off-by: Pranit Kumar <[email protected]>
  • Loading branch information
pranikum committed Jul 27, 2022
1 parent d3a8610 commit 8a18a9f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ public OpenSearchCluster(
this.bwcJdk = bwcJdk;

// Always add the first node
addNode(clusterName + "-0", "zone-1");
String zone = hasZoneProperty() ? "zone-1" : "";
addNode(clusterName + "-0", zone);
// configure the cluster name eagerly so all nodes know about it
this.nodes.all((node) -> node.defaultConfig.put("cluster.name", safeName(clusterName)));

Expand Down Expand Up @@ -141,12 +142,23 @@ public void setNumberOfNodes(int numberOfNodes) {

int currentZone = 1;
for (int i = nodes.size(); i < numberOfNodes; i++) {
currentZone = (currentZone >= zoneCount) ? 1 : (currentZone + 1);
String zoneName = "zone-" + currentZone;
currentZone = getZoneNumber(currentZone);
String zoneName = currentZone > 0 ? "zone-" + currentZone : "";
addNode(clusterName + "-" + i, zoneName);
}
}

private boolean hasZoneProperty() {
return this.project.findProperty("numZones") != null;
}

private int getZoneNumber(int currentZone) {
if (!hasZoneProperty()) {
return -1;
}
return currentZone >= zoneCount ? 1 : (currentZone + 1);
}

private void addNode(String nodeName, String zoneName) {
OpenSearchNode newNode = new OpenSearchNode(
path,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
package org.opensearch.gradle.testclusters;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.opensearch.gradle.Architecture;
import org.opensearch.gradle.DistributionDownloadPlugin;
import org.opensearch.gradle.OpenSearchDistribution;
Expand Down Expand Up @@ -1243,7 +1244,7 @@ private void createConfiguration() {
baseConfig.put("path.logs", confPathLogs.toAbsolutePath().toString());
baseConfig.put("path.shared_data", workingDir.resolve("sharedData").toString());
baseConfig.put("node.attr.testattr", "test");
if (this.project.findProperty("numZones") != null) {
if (StringUtils.isNotBlank(zone)) {
baseConfig.put("node.attr.availabilityzone", zone);
}
baseConfig.put("node.portsfile", "true");
Expand Down

0 comments on commit 8a18a9f

Please sign in to comment.