Search in sources :

Example 6 with Builder

use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.

the class PrimaryTermsTests method initPrimaries.

/**
 * puts primary shard indexRoutings into initializing state
 */
private void initPrimaries() {
    logger.info("adding {} nodes and performing rerouting", this.numberOfReplicas + 1);
    Builder discoBuilder = DiscoveryNodes.builder();
    for (int i = 0; i < this.numberOfReplicas + 1; i++) {
        discoBuilder = discoBuilder.add(newNode("node" + i));
    }
    this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
    ClusterState rerouteResult = allocationService.reroute(clusterState, "reroute");
    assertThat(rerouteResult, not(equalTo(this.clusterState)));
    applyRerouteResult(rerouteResult);
    primaryTermsPerIndex.keySet().forEach(this::incrementPrimaryTerm);
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder)

Example 7 with Builder

use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.

the class RoutingTableTests method initPrimaries.

/**
 * puts primary shard indexRoutings into initializing state
 */
private void initPrimaries() {
    logger.info("adding {} nodes and performing rerouting", this.numberOfReplicas + 1);
    Builder discoBuilder = DiscoveryNodes.builder();
    for (int i = 0; i < this.numberOfReplicas + 1; i++) {
        discoBuilder = discoBuilder.add(newNode("node" + i));
    }
    this.clusterState = ClusterState.builder(clusterState).nodes(discoBuilder).build();
    ClusterState rerouteResult = ALLOCATION_SERVICE.reroute(clusterState, "reroute");
    assertThat(rerouteResult, not(equalTo(this.clusterState)));
    this.clusterState = rerouteResult;
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder)

Example 8 with Builder

use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.

the class TransportClearVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    new TransportClearVotingConfigExclusionsAction(transportService, clusterService, threadPool, new ActionFilters(emptySet()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
    // registers action
    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);
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) VotingConfigExclusion(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion) Metadata(org.opensearch.cluster.metadata.Metadata) BeforeClass(org.junit.BeforeClass) ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Version(org.opensearch.Version) ClusterServiceUtils.setState(org.opensearch.test.ClusterServiceUtils.setState) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) CoordinationMetadata(org.opensearch.cluster.coordination.CoordinationMetadata) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockTransport(org.opensearch.test.transport.MockTransport) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Collections.emptyMap(java.util.Collections.emptyMap) AfterClass(org.junit.AfterClass) Matchers.empty(org.hamcrest.Matchers.empty) TimeValue(org.opensearch.common.unit.TimeValue) ClusterServiceUtils.createClusterService(org.opensearch.test.ClusterServiceUtils.createClusterService) SetOnce(org.apache.lucene.util.SetOnce) Collections.emptySet(java.util.Collections.emptySet) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) ClusterState.builder(org.opensearch.cluster.ClusterState.builder) TransportService(org.opensearch.transport.TransportService) Matchers.startsWith(org.hamcrest.Matchers.startsWith) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ActionFilters(org.opensearch.action.support.ActionFilters) CountDownLatch(java.util.concurrent.CountDownLatch) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) OpenSearchTimeoutException(org.opensearch.OpenSearchTimeoutException) ClusterService(org.opensearch.cluster.service.ClusterService) ClusterName(org.opensearch.cluster.ClusterName) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) TransportException(org.opensearch.transport.TransportException) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Names(org.opensearch.threadpool.ThreadPool.Names) ClusterState(org.opensearch.cluster.ClusterState) MockTransport(org.opensearch.test.transport.MockTransport) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClusterName(org.opensearch.cluster.ClusterName) ActionFilters(org.opensearch.action.support.ActionFilters) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Before(org.junit.Before)

Example 9 with Builder

use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.

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("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 10 with Builder

use of org.opensearch.cluster.node.DiscoveryNodes.Builder in project OpenSearch by opensearch-project.

the class TransportAddVotingConfigExclusionsActionTests method setupForTest.

@Before
public void setupForTest() {
    final MockTransport transport = new MockTransport();
    transportService = transport.createTransportService(Settings.EMPTY, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> localNode, null, emptySet());
    final Settings.Builder nodeSettingsBuilder = Settings.builder();
    if (randomBoolean()) {
        staticMaximum = between(5, 15);
        nodeSettingsBuilder.put(MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.getKey(), staticMaximum);
    } else {
        staticMaximum = MAXIMUM_VOTING_CONFIG_EXCLUSIONS_SETTING.get(Settings.EMPTY);
    }
    final Settings nodeSettings = nodeSettingsBuilder.build();
    clusterSettings = new ClusterSettings(nodeSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    new TransportAddVotingConfigExclusionsAction(nodeSettings, clusterSettings, transportService, clusterService, threadPool, new ActionFilters(emptySet()), new IndexNameExpressionResolver(new ThreadContext(Settings.EMPTY)));
    // registers action
    transportService.start();
    transportService.acceptIncomingRequests();
    final VotingConfiguration allNodesConfig = VotingConfiguration.of(localNode, otherNode1, otherNode2);
    setState(clusterService, builder(new ClusterName("cluster")).nodes(new Builder().add(localNode).add(otherNode1).add(otherNode2).add(otherDataNode).localNodeId(localNode.getId()).masterNodeId(localNode.getId())).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().lastAcceptedConfiguration(allNodesConfig).lastCommittedConfiguration(allNodesConfig).build())));
    clusterStateObserver = new ClusterStateObserver(clusterService, null, logger, threadPool.getThreadContext());
}
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) ClusterStateObserver(org.opensearch.cluster.ClusterStateObserver) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Builder(org.opensearch.cluster.node.DiscoveryNodes.Builder) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ActionFilters(org.opensearch.action.support.ActionFilters) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) MockTransport(org.opensearch.test.transport.MockTransport) ClusterName(org.opensearch.cluster.ClusterName) IndexNameExpressionResolver(org.opensearch.cluster.metadata.IndexNameExpressionResolver) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Before(org.junit.Before)

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