Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue:3933 -Multi-node setup for local gradle run #3958

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public class OpenSearchCluster implements TestClusterConfiguration, Named {
private final ArchiveOperations archiveOperations;
private int nodeIndex = 0;

private int zoneCount = 1;

public OpenSearchCluster(
String clusterName,
Project project,
Expand All @@ -104,13 +106,20 @@ public OpenSearchCluster(
this.bwcJdk = bwcJdk;

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

addWaitForClusterHealth();
}

public void setNumberOfZones(int zoneCount) {
if (zoneCount < 1) {
throw new IllegalArgumentException("Number of zones should be >= 1 but was " + zoneCount + " for " + this);
}
this.zoneCount = zoneCount;
}

public void setNumberOfNodes(int numberOfNodes) {
checkFrozen();

Expand All @@ -124,12 +133,21 @@ public void setNumberOfNodes(int numberOfNodes) {
);
}

if (numberOfNodes < zoneCount) {
reta marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalArgumentException(
"Number of nodes should be >= zoneCount but was " + numberOfNodes + " for " + this.zoneCount
);
}

int currentZone = 1;
for (int i = nodes.size(); i < numberOfNodes; i++) {
reta marked this conversation as resolved.
Show resolved Hide resolved
addNode(clusterName + "-" + i);
currentZone = (currentZone >= zoneCount) ? 1 : (currentZone + 1);
String zoneName = "zone-" + currentZone;
addNode(clusterName + "-" + i, zoneName);
}
}

private void addNode(String nodeName) {
private void addNode(String nodeName, String zoneName) {
OpenSearchNode newNode = new OpenSearchNode(
path,
nodeName,
Expand All @@ -138,7 +156,8 @@ private void addNode(String nodeName) {
fileSystemOperations,
archiveOperations,
workingDirBase,
bwcJdk
bwcJdk,
zoneName
);
// configure the cluster name eagerly
newNode.defaultConfig.put("cluster.name", safeName(clusterName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public class OpenSearchNode implements TestClusterConfiguration {
private final Config legacyESConfig;
private Config currentConfig;

private String zone;

OpenSearchNode(
String path,
String name,
Expand All @@ -183,7 +185,8 @@ public class OpenSearchNode implements TestClusterConfiguration {
FileSystemOperations fileSystemOperations,
ArchiveOperations archiveOperations,
File workingDirBase,
Jdk bwcJdk
Jdk bwcJdk,
String zone
) {
this.path = path;
this.name = name;
Expand All @@ -205,6 +208,7 @@ public class OpenSearchNode implements TestClusterConfiguration {
opensearchConfig = Config.getOpenSearchConfig(workingDir);
legacyESConfig = Config.getLegacyESConfig(workingDir);
currentConfig = opensearchConfig;
this.zone = zone;
}

/*
Expand Down Expand Up @@ -1239,6 +1243,9 @@ 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to check numZones? if (zone != null && !zone.isBlank()) { should be sufficient, right?

Copy link
Contributor Author

@pranikum pranikum Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are passing zone value for the first node as well. Which will be true for the scenario where -PnumZones will not be set. Hence wanted to check the existence of the property. instead of zone variable.
Don't want to add zone attribute for the single node cluster. i.e
./gradlew run .

https://github.com/opensearch-project/OpenSearch/pull/3958/files#diff-a22e2ce210c503bbd47be71cc6e770064e8a9e008738d28fee5b381918f1fb8cR109

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decision should be made in OpenSearchCluster: this class knows zones configuration (and should either associated node with zone or not).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the decision making to OpensearchCluster class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TY

baseConfig.put("node.attr.availabilityzone", zone);
}
baseConfig.put("node.portsfile", "true");
baseConfig.put("http.port", httpPort);
if (getVersion().onOrAfter(Version.fromString("6.7.0"))) {
Expand Down
5 changes: 5 additions & 0 deletions gradle/run.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ import org.opensearch.gradle.testclusters.RunTask

apply plugin: 'opensearch.testclusters'

def numNodes = findProperty('numNodes') as Integer ?: 1
def numZones = findProperty('numZones') as Integer ?: 1

testClusters {
pranikum marked this conversation as resolved.
Show resolved Hide resolved
runTask {
testDistribution = 'archive'
if (numZones > 1) numberOfZones = numZones
if (numNodes > 1) numberOfNodes = numNodes
}
}

Expand Down