use of org.elasticsearch.cluster.node.DiscoveryNodes.Builder in project crate by crate.
the class TransportAddVotingConfigExclusionsActionTests method testSucceedsEvenIfAllExclusionsAlreadyAdded.
public void testSucceedsEvenIfAllExclusionsAlreadyAdded() 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(new String[] { "other1" }), expectSuccess(r -> {
assertNotNull(r);
countDownLatch.countDown();
}));
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), contains(otherNode1Exclusion));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes.Builder in project crate by crate.
the class TransportClearVotingConfigExclusionsActionTests method setupForTest.
@Before
public void setupForTest() {
final MockTransport transport = new MockTransport();
transportService = transport.createTransportService(Settings.EMPTY, threadPool, boundTransportAddress -> localNode, null);
new TransportClearVotingConfigExclusionsAction(transportService, clusterService, threadPool, // registers action
new IndexNameExpressionResolver());
transportService.start();
transportService.acceptIncomingRequests();
final ClusterState.Builder builder = builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).localNodeId(localNode.getId()).masterNodeId(localNode.getId()));
builder.metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().addVotingConfigExclusion(otherNode1Exclusion).addVotingConfigExclusion(otherNode2Exclusion).build()));
setState(clusterService, builder);
}
use of org.elasticsearch.cluster.node.DiscoveryNodes.Builder in project crate by crate.
the class TransportClearVotingConfigExclusionsActionTests method testSucceedsIfNodesAreRemovedWhileWaiting.
public void testSucceedsIfNodesAreRemovedWhileWaiting() throws InterruptedException {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final SetOnce<ClearVotingConfigExclusionsResponse> responseHolder = new SetOnce<>();
transportService.sendRequest(localNode, ClearVotingConfigExclusionsAction.NAME, new ClearVotingConfigExclusionsRequest(), expectSuccess(r -> {
responseHolder.set(r);
countDownLatch.countDown();
}));
final ClusterState.Builder builder = builder(clusterService.state());
builder.nodes(DiscoveryNodes.builder(clusterService.state().nodes()).remove(otherNode1).remove(otherNode2));
setState(clusterService, builder);
assertTrue(countDownLatch.await(30, TimeUnit.SECONDS));
assertThat(clusterService.getClusterApplierService().state().getVotingConfigExclusions(), empty());
}
use of org.elasticsearch.cluster.node.DiscoveryNodes.Builder in project crate by crate.
the class AddVotingConfigExclusionsRequestTests method testResolveAndCheckMaximum.
public void testResolveAndCheckMaximum() {
final DiscoveryNode localNode = new DiscoveryNode("local", "local", buildNewFakeTransportAddress(), emptyMap(), Set.of(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
final DiscoveryNode otherNode1 = new DiscoveryNode("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), Set.of(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
final DiscoveryNode otherNode2 = new DiscoveryNode("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), Set.of(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(makeRequest().resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 3, "setting.name"), containsInAnyOrder(localNodeExclusion, otherNode2Exclusion));
assertThat(makeRequest("_local").resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 2, "setting.name"), contains(localNodeExclusion));
assertThat(expectThrows(IllegalArgumentException.class, () -> makeRequest().resolveVotingConfigExclusionsAndCheckMaximum(clusterState, 2, "setting.name")).getMessage(), equalTo("add voting config exclusions request for [] would add [2] exclusions to the existing [1] which would exceed " + "the maximum of [2] set by [setting.name]"));
assertThat(expectThrows(IllegalArgumentException.class, () -> makeRequest("_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]"));
}
use of org.elasticsearch.cluster.node.DiscoveryNodes.Builder in project crate by crate.
the class AddVotingConfigExclusionsRequestTests method testResolve.
public void testResolve() {
final DiscoveryNode localNode = new DiscoveryNode("local", "local", buildNewFakeTransportAddress(), emptyMap(), Set.of(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
final DiscoveryNode otherNode1 = new DiscoveryNode("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), Set.of(DiscoveryNodeRole.MASTER_ROLE), Version.CURRENT);
final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
final DiscoveryNode otherNode2 = new DiscoveryNode("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), Set.of(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(makeRequest().resolveVotingConfigExclusions(clusterState), containsInAnyOrder(localNodeExclusion, otherNode1Exclusion, otherNode2Exclusion));
assertThat(makeRequest("_all").resolveVotingConfigExclusions(clusterState), containsInAnyOrder(localNodeExclusion, otherNode1Exclusion, otherNode2Exclusion));
assertThat(makeRequest("_local").resolveVotingConfigExclusions(clusterState), contains(localNodeExclusion));
assertThat(makeRequest("other*").resolveVotingConfigExclusions(clusterState), containsInAnyOrder(otherNode1Exclusion, otherNode2Exclusion));
assertThat(expectThrows(IllegalArgumentException.class, () -> makeRequest("not-a-node").resolveVotingConfigExclusions(clusterState)).getMessage(), equalTo("add voting config exclusions request for [not-a-node] matched no master-eligible nodes"));
}
Aggregations