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

Fixing support for a multi-node cluster via "gradle run" #1455

Merged
merged 1 commit into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -103,10 +103,9 @@ public OpenSearchCluster(
this.nodes = project.container(OpenSearchNode.class);
this.bwcJdk = bwcJdk;

this.nodes.add(
new OpenSearchNode(path, clusterName + "-0", project, reaper, fileSystemOperations, archiveOperations, workingDirBase, bwcJdk)
);
// configure the cluster name eagerly so nodes know about it
// Always add the first node
addNode(clusterName + "-0");
// configure the cluster name eagerly so all nodes know about it
this.nodes.all((node) -> node.defaultConfig.put("cluster.name", safeName(clusterName)));
kartg marked this conversation as resolved.
Show resolved Hide resolved

addWaitForClusterHealth();
Expand All @@ -126,21 +125,26 @@ public void setNumberOfNodes(int numberOfNodes) {
}

for (int i = nodes.size(); i < numberOfNodes; i++) {
this.nodes.add(
new OpenSearchNode(
path,
clusterName + "-" + i,
project,
reaper,
fileSystemOperations,
archiveOperations,
workingDirBase,
bwcJdk
)
);
addNode(clusterName + "-" + i);
}
}

private void addNode(String nodeName) {
OpenSearchNode newNode = new OpenSearchNode(
path,
nodeName,
project,
reaper,
fileSystemOperations,
archiveOperations,
workingDirBase,
bwcJdk
);
// configure the cluster name eagerly
newNode.defaultConfig.put("cluster.name", safeName(clusterName));
this.nodes.add(newNode);
}

@Internal
OpenSearchNode getFirstNode() {
return nodes.getAt(clusterName + "-0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ public class OpenSearchNode implements TestClusterConfiguration {
private static final TimeUnit NODE_UP_TIMEOUT_UNIT = TimeUnit.MINUTES;
private static final int ADDITIONAL_CONFIG_TIMEOUT = 15;
private static final TimeUnit ADDITIONAL_CONFIG_TIMEOUT_UNIT = TimeUnit.SECONDS;
private static final List<String> OVERRIDABLE_SETTINGS = Arrays.asList(
"path.repo",
"discovery.seed_providers"

);
private static final List<String> OVERRIDABLE_SETTINGS = Arrays.asList("path.repo", "discovery.seed_providers", "discovery.seed_hosts");

private static final int TAIL_LOG_MESSAGES_COUNT = 40;
private static final List<String> MESSAGES_WE_DONT_CARE_ABOUT = Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* Implementation of the "run" Gradle task used in run.gradle
*/
public class RunTask extends DefaultTestClustersTask {

private static final Logger logger = Logging.getLogger(RunTask.class);
public static final String CUSTOM_SETTINGS_PREFIX = "tests.opensearch.";
private static final int DEFAULT_HTTP_PORT = 9200;
private static final int DEFAULT_TRANSPORT_PORT = 9300;
private static final int DEFAULT_DEBUG_PORT = 5005;
public static final String LOCALHOST_ADDRESS_PREFIX = "127.0.0.1:";

private Boolean debug = false;

Expand Down Expand Up @@ -112,9 +119,9 @@ public String getDataDir() {

@Override
public void beforeStart() {
int debugPort = 5005;
int httpPort = 9200;
int transportPort = 9300;
int debugPort = DEFAULT_DEBUG_PORT;
int httpPort = DEFAULT_HTTP_PORT;
int transportPort = DEFAULT_TRANSPORT_PORT;
Map<String, String> additionalSettings = System.getProperties()
.entrySet()
.stream()
Expand All @@ -134,12 +141,22 @@ public void beforeStart() {
}

for (OpenSearchCluster cluster : getClusters()) {
cluster.getFirstNode().setHttpPort(String.valueOf(httpPort));
// Configure the first node with the default ports first
kartg marked this conversation as resolved.
Show resolved Hide resolved
OpenSearchNode firstNode = cluster.getFirstNode();
firstNode.setHttpPort(String.valueOf(httpPort));
httpPort++;
cluster.getFirstNode().setTransportPort(String.valueOf(transportPort));
firstNode.setTransportPort(String.valueOf(transportPort));
transportPort++;
firstNode.setting("discovery.seed_hosts", LOCALHOST_ADDRESS_PREFIX + DEFAULT_TRANSPORT_PORT);
cluster.setPreserveDataDir(preserveData);
for (OpenSearchNode node : cluster.getNodes()) {
if (node != firstNode) {
node.setHttpPort(String.valueOf(httpPort));
httpPort++;
node.setTransportPort(String.valueOf(transportPort));
transportPort++;
node.setting("discovery.seed_hosts", LOCALHOST_ADDRESS_PREFIX + DEFAULT_TRANSPORT_PORT);
}
additionalSettings.forEach(node::setting);
if (dataDir != null) {
node.setDataPath(getDataPath.apply(node));
Expand Down