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);
}
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;
}
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);
}
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));
}
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());
}
Aggregations