Fixing support for a multi-node cluster via "gradle run" (#1455)
This change updates the logic in RunTask to use deterministic port values for all nodes rather than just the first node in a cluster. The local address of the first node is also used as the seed_hosts value to allow the cluster to form correctly. The seed_hosts setting is also allow-listed as an overrideable value. Signed-off-by: Kartik Ganesh <85275476+kartg@users.noreply.github.com>
This commit is contained in:
parent
9c514d3734
commit
2c1e89a1f9
|
@ -103,10 +103,9 @@ public class OpenSearchCluster implements TestClusterConfiguration, Named {
|
|||
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)));
|
||||
|
||||
addWaitForClusterHealth();
|
||||
|
@ -126,21 +125,26 @@ public class OpenSearchCluster implements TestClusterConfiguration, Named {
|
|||
}
|
||||
|
||||
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");
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -52,10 +52,17 @@ import java.util.function.BooleanSupplier;
|
|||
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;
|
||||
|
||||
|
@ -112,9 +119,9 @@ public class RunTask extends DefaultTestClustersTask {
|
|||
|
||||
@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()
|
||||
|
@ -134,12 +141,22 @@ public class RunTask extends DefaultTestClustersTask {
|
|||
}
|
||||
|
||||
for (OpenSearchCluster cluster : getClusters()) {
|
||||
cluster.getFirstNode().setHttpPort(String.valueOf(httpPort));
|
||||
// Configure the first node with the default ports first
|
||||
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));
|
||||
|
|
Loading…
Reference in New Issue