use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class CoordinatorTests method testSingleNodeDiscoveryWithoutQuorum.
public void testSingleNodeDiscoveryWithoutQuorum() {
try (Cluster cluster = new Cluster(3)) {
cluster.runRandomly();
cluster.stabilise();
final ClusterNode clusterNode = cluster.getAnyNode();
logger.debug("rebooting [{}]", clusterNode.getId());
clusterNode.close();
cluster.clusterNodes.forEach(cn -> cluster.deterministicTaskQueue.scheduleNow(cn.onNode(new Runnable() {
@Override
public void run() {
cn.transportService.disconnectFromNode(clusterNode.getLocalNode());
}
@Override
public String toString() {
return "disconnect from " + clusterNode.getLocalNode() + " after shutdown";
}
})));
IllegalStateException ise = expectThrows(IllegalStateException.class, () -> cluster.clusterNodes.replaceAll(cn -> cn == clusterNode ? cn.restartedNode(Function.identity(), Function.identity(), Settings.builder().put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), DiscoveryModule.SINGLE_NODE_DISCOVERY_TYPE).build()) : cn));
assertThat(ise.getMessage(), allOf(containsString("cannot start with [discovery.type] set to [single-node] when local node"), containsString("does not have quorum in voting configuration")));
// to avoid closing it twice
cluster.clusterNodes.remove(clusterNode);
}
}
use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class ReconfiguratorTests method testAutoShrinking.
public void testAutoShrinking() {
final String[] allNodes = new String[] { "a", "b", "c", "d", "e", "f", "g" };
final String[] liveNodes = new String[randomIntBetween(1, allNodes.length)];
randomSubsetOf(liveNodes.length, allNodes).toArray(liveNodes);
final String[] initialVotingNodes = new String[randomIntBetween(1, allNodes.length)];
randomSubsetOf(initialVotingNodes.length, allNodes).toArray(initialVotingNodes);
final Builder settingsBuilder = Settings.builder();
if (randomBoolean()) {
settingsBuilder.put(CLUSTER_AUTO_SHRINK_VOTING_CONFIGURATION.getKey(), true);
}
final Reconfigurator reconfigurator = makeReconfigurator(settingsBuilder.build());
final Set<DiscoveryNode> liveNodesSet = nodes(liveNodes);
final VotingConfiguration initialConfig = conf(initialVotingNodes);
final int quorumSize = Math.max(liveNodes.length / 2 + 1, initialVotingNodes.length < 3 ? 1 : 2);
final VotingConfiguration finalConfig = reconfigurator.reconfigure(liveNodesSet, emptySet(), randomFrom(liveNodesSet), initialConfig);
final String description = "reconfigure " + liveNodesSet + " from " + initialConfig + " yielded " + finalConfig;
if (quorumSize > liveNodes.length) {
assertFalse(description + " without a live quorum", finalConfig.hasQuorum(Arrays.asList(liveNodes)));
} else {
final List<String> expectedQuorum = randomSubsetOf(quorumSize, liveNodes);
assertTrue(description + " with quorum[" + quorumSize + "] of " + expectedQuorum, finalConfig.hasQuorum(expectedQuorum));
}
}
use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class InternalTestCluster method getNodeSettings.
private Settings getNodeSettings(final int nodeId, final long seed, final Settings extraSettings, final int defaultMinClusterManagerNodes) {
final Settings settings = getSettings(nodeId, seed, extraSettings);
final String name = buildNodeName(nodeId, settings);
final Settings.Builder updatedSettings = Settings.builder();
updatedSettings.put(Environment.PATH_HOME_SETTING.getKey(), baseDir);
if (numDataPaths > 1) {
updatedSettings.putList(Environment.PATH_DATA_SETTING.getKey(), IntStream.range(0, numDataPaths).mapToObj(i -> baseDir.resolve(name).resolve("d" + i).toString()).collect(Collectors.toList()));
} else {
updatedSettings.put(Environment.PATH_DATA_SETTING.getKey(), baseDir.resolve(name));
}
updatedSettings.put(Environment.PATH_SHARED_DATA_SETTING.getKey(), baseDir.resolve(name + "-shared"));
// allow overriding the above
updatedSettings.put(settings);
// force certain settings
updatedSettings.put("node.name", name);
updatedSettings.put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), seed);
final String discoveryType = DISCOVERY_TYPE_SETTING.get(updatedSettings.build());
final boolean usingSingleNodeDiscovery = discoveryType.equals("single-node");
if (usingSingleNodeDiscovery == false) {
if (autoManageClusterManagerNodes) {
assertThat("if cluster-manager nodes are automatically managed then nodes must complete a join cycle when starting", updatedSettings.get(DiscoverySettings.INITIAL_STATE_TIMEOUT_SETTING.getKey()), nullValue());
}
}
return updatedSettings.build();
}
use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class InternalTestCluster method startNodes.
/**
* Starts multiple nodes with the given settings and returns their names
*/
public synchronized List<String> startNodes(Settings... extraSettings) {
final int newClusterManagerCount = Math.toIntExact(Stream.of(extraSettings).filter(DiscoveryNode::isMasterNode).count());
final int defaultMinClusterManagerNodes;
if (autoManageClusterManagerNodes) {
defaultMinClusterManagerNodes = getMinClusterManagerNodes(getClusterManagerNodesCount() + newClusterManagerCount);
} else {
defaultMinClusterManagerNodes = -1;
}
final List<NodeAndClient> nodes = new ArrayList<>();
final int prevClusterManagerCount = getClusterManagerNodesCount();
int autoBootstrapClusterManagerNodeIndex = autoManageClusterManagerNodes && prevClusterManagerCount == 0 && newClusterManagerCount > 0 && Arrays.stream(extraSettings).allMatch(s -> DiscoveryNode.isMasterNode(s) == false || ZEN2_DISCOVERY_TYPE.equals(DISCOVERY_TYPE_SETTING.get(s))) ? RandomNumbers.randomIntBetween(random, 0, newClusterManagerCount - 1) : -1;
final int numOfNodes = extraSettings.length;
final int firstNodeId = nextNodeId.getAndIncrement();
final List<Settings> settings = new ArrayList<>();
for (int i = 0; i < numOfNodes; i++) {
settings.add(getNodeSettings(firstNodeId + i, random.nextLong(), extraSettings[i], defaultMinClusterManagerNodes));
}
nextNodeId.set(firstNodeId + numOfNodes);
final List<String> initialClusterManagerNodes = settings.stream().filter(DiscoveryNode::isMasterNode).map(Node.NODE_NAME_SETTING::get).collect(Collectors.toList());
final List<Settings> updatedSettings = bootstrapClusterManagerNodeWithSpecifiedIndex(settings);
for (int i = 0; i < numOfNodes; i++) {
final Settings nodeSettings = updatedSettings.get(i);
final Builder builder = Settings.builder();
if (DiscoveryNode.isMasterNode(nodeSettings)) {
if (autoBootstrapClusterManagerNodeIndex == 0) {
builder.putList(INITIAL_CLUSTER_MANAGER_NODES_SETTING.getKey(), initialClusterManagerNodes);
}
autoBootstrapClusterManagerNodeIndex -= 1;
}
final NodeAndClient nodeAndClient = buildNode(firstNodeId + i, builder.put(nodeSettings).build(), false, () -> rebuildUnicastHostFiles(nodes));
nodes.add(nodeAndClient);
}
startAndPublishNodesAndClients(nodes);
if (autoManageClusterManagerNodes) {
validateClusterFormed();
}
return nodes.stream().map(NodeAndClient::getName).collect(Collectors.toList());
}
use of org.opensearch.common.settings.Settings.Builder in project OpenSearch by opensearch-project.
the class InternalTestCluster method getSettings.
private Settings getSettings(int nodeOrdinal, long nodeSeed, Settings others) {
Builder builder = Settings.builder().put(defaultSettings).put(getRandomNodeSettings(nodeSeed));
Settings settings = nodeConfigurationSource.nodeSettings(nodeOrdinal);
if (settings != null) {
if (settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) != null) {
throw new IllegalStateException("Tests must not set a '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "' as a node setting set '" + ClusterName.CLUSTER_NAME_SETTING.getKey() + "': [" + settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()) + "]");
}
builder.put(settings);
}
if (others != null) {
builder.put(others);
}
builder.put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName);
return builder.build();
}
Aggregations