Search in sources :

Example 11 with Builder

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));
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) Strings(org.opensearch.common.Strings) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Collections.singleton(java.util.Collections.singleton) AfterClass(org.junit.AfterClass) TimeValue(org.opensearch.common.unit.TimeValue) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterStateUpdateTask(org.opensearch.cluster.ClusterStateUpdateTask) Matchers.contains(org.hamcrest.Matchers.contains) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Matchers.equalTo(org.hamcrest.Matchers.equalTo) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING(org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction.MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) Listener(org.opensearch.cluster.ClusterStateObserver.Listener) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) ClusterState(org.opensearch.cluster.ClusterState) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with Builder

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));
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ClusterName(org.opensearch.cluster.ClusterName)

Example 13 with Builder

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));
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) Metadata(org.opensearch.cluster.metadata.Metadata) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) ClusterName(org.opensearch.cluster.ClusterName)

Example 14 with Builder

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);
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ClusterName(org.opensearch.cluster.ClusterName)

Example 15 with Builder

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);
}
Also used : VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ClusterName(org.opensearch.cluster.ClusterName)

Aggregations

Builder (org.opensearch.cluster.node.DiscoveryNodes.Builder)16 ClusterState (org.opensearch.cluster.ClusterState)15 ClusterName (org.opensearch.cluster.ClusterName)13 VotingConfigExclusion (org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion)13 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)13 CoordinationMetadata (org.opensearch.cluster.coordination.CoordinationMetadata)9 Metadata (org.opensearch.cluster.metadata.Metadata)9 IOException (java.io.IOException)8 Collections.emptyMap (java.util.Collections.emptyMap)8 Collections.emptySet (java.util.Collections.emptySet)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 TimeUnit (java.util.concurrent.TimeUnit)8 Consumer (java.util.function.Consumer)8 SetOnce (org.apache.lucene.util.SetOnce)8 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)8 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)8 Matchers.startsWith (org.hamcrest.Matchers.startsWith)8 AfterClass (org.junit.AfterClass)8 Before (org.junit.Before)8 BeforeClass (org.junit.BeforeClass)8