use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class PeerFinderTests method updateLastAcceptedNodes.
private void updateLastAcceptedNodes(Consumer<DiscoveryNodes.Builder> onBuilder) {
final Builder builder = DiscoveryNodes.builder(lastAcceptedNodes);
onBuilder.accept(builder);
lastAcceptedNodes = builder.build();
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class TransportAddVotingConfigExclusionsActionTests method testReturnsErrorIfMaximumExclusionCountExceeded.
public void testReturnsErrorIfMaximumExclusionCountExceeded() throws InterruptedException {
final Metadata.Builder metadataBuilder = Metadata.builder(clusterService.state().metadata());
CoordinationMetadata.Builder coordinationMetadataBuilder = CoordinationMetadata.builder(clusterService.state().coordinationMetadata()).addVotingConfigExclusion(localNodeExclusion);
final int actualMaximum;
if (randomBoolean()) {
actualMaximum = staticMaximum;
} else {
actualMaximum = between(2, 15);
clusterSettings.applySettings(Settings.builder().put(clusterService.state().metadata().persistentSettings()).put(MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey(), actualMaximum).build());
}
for (int i = 2; i < actualMaximum; i++) {
coordinationMetadataBuilder.addVotingConfigExclusion(new VotingConfigExclusion(randomAlphaOfLength(10), randomAlphaOfLength(10)));
}
final int existingCount, newCount;
if (randomBoolean()) {
coordinationMetadataBuilder.addVotingConfigExclusion(otherNode1Exclusion);
existingCount = actualMaximum;
newCount = 1;
} else {
existingCount = actualMaximum - 1;
newCount = 2;
}
metadataBuilder.coordinationMetadata(coordinationMetadataBuilder.build());
final ClusterState.Builder builder = builder(clusterService.state()).metadata(metadataBuilder);
setState(clusterService, builder);
final CountDownLatch countDownLatch = new CountDownLatch(1);
final SetOnce<TransportException> exceptionHolder = new SetOnce<>();
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, makeRequestWithNodeDescriptions("other*"), expectError(e -> {
exceptionHolder.set(e);
countDownLatch.countDown();
}));
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
final Throwable rootCause = exceptionHolder.get().getRootCause();
assertThat(rootCause, instanceOf(IllegalArgumentException.class));
assertThat(rootCause.getMessage(), equalTo("add voting config exclusions request for [other*] would add [" + newCount + "] exclusions to the existing [" + existingCount + "] which would exceed the maximum of [" + actualMaximum + "] set by [cluster.max_voting_config_exclusions]"));
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class TransportAddVotingConfigExclusionsActionTests method testExcludeByNodeIdSucceedsEvenIfAllExclusionsAlreadyAdded.
public void testExcludeByNodeIdSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedException {
final ClusterState state = clusterService.state();
final ClusterState.Builder builder = builder(state);
builder.metadata(Metadata.builder(state.metadata()).coordinationMetadata(CoordinationMetadata.builder(state.coordinationMetadata()).addVotingConfigExclusion(otherNode1Exclusion).build()));
setState(clusterService, builder);
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, new String[] { "other1" }, Strings.EMPTY_ARRAY, TimeValue.timeValueSeconds(30)), expectSuccess(r -> {
assertNotNull(r);
countDownLatch.countDown();
}));
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class TransportAddVotingConfigExclusionsActionTests method testExcludeByNodeNameSucceedsEvenIfAllExclusionsAlreadyAdded.
public void testExcludeByNodeNameSucceedsEvenIfAllExclusionsAlreadyAdded() throws InterruptedException {
final ClusterState state = clusterService.state();
final ClusterState.Builder builder = builder(state);
builder.metadata(Metadata.builder(state.metadata()).coordinationMetadata(CoordinationMetadata.builder(state.coordinationMetadata()).addVotingConfigExclusion(otherNode1Exclusion).build()));
setState(clusterService, builder);
final CountDownLatch countDownLatch = new CountDownLatch(1);
transportService.sendRequest(localNode, AddVotingConfigExclusionsAction.NAME, new AddVotingConfigExclusionsRequest("other1"), expectSuccess(r -> {
assertNotNull(r);
countDownLatch.countDown();
}));
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class AddVotingConfigExclusionsRequestTests method testResolveByNodeIds.
public void testResolveByNodeIds() {
final DiscoveryNode node1 = new DiscoveryNode("nodeName1", "nodeId1", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1);
final DiscoveryNode node2 = new DiscoveryNode("nodeName2", "nodeId2", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2);
final DiscoveryNode node3 = new DiscoveryNode("nodeName3", "nodeId3", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion unresolvableVotingConfigExclusion = new VotingConfigExclusion("unresolvableNodeId", VotingConfigExclusion.MISSING_VALUE_MARKER);
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder().add(node1).add(node2).add(node3).localNodeId(node1.getId())).build();
assertThat(new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, new String[] { "nodeId1", "nodeId2" }, Strings.EMPTY_ARRAY, TimeValue.ZERO).resolveVotingConfigExclusions(clusterState), containsInAnyOrder(node1Exclusion, node2Exclusion));
assertThat(new AddVotingConfigExclusionsRequest(Strings.EMPTY_ARRAY, new String[] { "nodeId1", "unresolvableNodeId" }, Strings.EMPTY_ARRAY, TimeValue.ZERO).resolveVotingConfigExclusions(clusterState), containsInAnyOrder(node1Exclusion, unresolvableVotingConfigExclusion));
}
Aggregations