use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class TransportAddVotingConfigExclusionsActionTests method testReturnsImmediatelyIfVoteAlreadyWithdrawn.
public void testReturnsImmediatelyIfVoteAlreadyWithdrawn() throws InterruptedException {
final ClusterState state = clusterService.state();
setState(clusterService, builder(state).metadata(Metadata.builder(state.metadata()).coordinationMetadata(CoordinationMetadata.builder(state.coordinationMetadata()).lastCommittedConfiguration(VotingConfiguration.of(localNode, otherNode2)).lastAcceptedConfiguration(VotingConfiguration.of(localNode, otherNode2)).build())));
final CountDownLatch countDownLatch = new CountDownLatch(1);
// no observer to reconfigure
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 testResolveByNodeNames.
public void testResolveByNodeNames() {
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(VotingConfigExclusion.MISSING_VALUE_MARKER, "unresolvableNodeName");
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder().add(node1).add(node2).add(node3).localNodeId(node1.getId())).build();
assertThat(new AddVotingConfigExclusionsRequest("nodeName1", "nodeName2").resolveVotingConfigExclusions(clusterState), containsInAnyOrder(node1Exclusion, node2Exclusion));
assertThat(new AddVotingConfigExclusionsRequest("nodeName1", "unresolvableNodeName").resolveVotingConfigExclusions(clusterState), containsInAnyOrder(node1Exclusion, unresolvableVotingConfigExclusion));
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class AddVotingConfigExclusionsRequestTests method testResolveRemoveExistingVotingConfigExclusions.
public void testResolveRemoveExistingVotingConfigExclusions() {
final DiscoveryNode node1 = new DiscoveryNode("nodeName1", "nodeId1", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
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 existingVotingConfigExclusion = new VotingConfigExclusion(node1);
Metadata metadata = Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().addVotingConfigExclusion(existingVotingConfigExclusion).build()).build();
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).metadata(metadata).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), contains(node2Exclusion));
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class AddVotingConfigExclusionsRequestTests method testResolve.
public void testResolve() {
final DiscoveryNode localNode = new DiscoveryNode("local", "local", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
final DiscoveryNode otherNode1 = new DiscoveryNode("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
final DiscoveryNode otherNode2 = new DiscoveryNode("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2);
final DiscoveryNode otherDataNode = new DiscoveryNode("data", "data", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId())).build();
assertThat(makeRequestWithNodeDescriptions("_all").resolveVotingConfigExclusions(clusterState), containsInAnyOrder(localNodeExclusion, otherNode1Exclusion, otherNode2Exclusion));
assertThat(makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusions(clusterState), contains(localNodeExclusion));
assertThat(makeRequestWithNodeDescriptions("other*").resolveVotingConfigExclusions(clusterState), containsInAnyOrder(otherNode1Exclusion, otherNode2Exclusion));
assertThat(expectThrows(IllegalArgumentException.class, () -> makeRequestWithNodeDescriptions("not-a-node").resolveVotingConfigExclusions(clusterState)).getMessage(), equalTo("add voting config exclusions request for [not-a-node] matched no master-eligible nodes"));
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
}
use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.
the class AddVotingConfigExclusionsRequestTests method testResolveAndCheckMaximum.
public void testResolveAndCheckMaximum() {
final DiscoveryNode localNode = new DiscoveryNode("local", "local", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
final DiscoveryNode otherNode1 = new DiscoveryNode("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
final DiscoveryNode otherNode2 = new DiscoveryNode("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), singleton(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2);
final ClusterState.Builder builder = ClusterState.builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).localNodeId(localNode.getId()));
builder.metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().addVotingConfigExclusion(otherNode1Exclusion).build()));
final ClusterState clusterState = builder.build();
assertThat(makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 2, "setting.name"), contains(localNodeExclusion));
assertThat(expectThrows(IllegalArgumentException.class, () -> makeRequestWithNodeDescriptions("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 1, "setting.name")).getMessage(), equalTo("add voting config exclusions request for [_local] would add [1] exclusions to the existing [1] which would " + "exceed the maximum of [1] set by [setting.name]"));
assertWarnings(AddVotingConfigExclusionsRequest.DEPRECATION_MESSAGE);
}
Aggregations