Search in sources :

Example 1 with AllocateEmptyPrimaryAllocationCommand

use of org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand in project OpenSearch by opensearch-project.

the class ClusterRerouteIT method rerouteWithAllocateLocalGateway.

private void rerouteWithAllocateLocalGateway(Settings commonSettings) throws Exception {
    logger.info("--> starting 2 nodes");
    String node_1 = internalCluster().startNode(commonSettings);
    internalCluster().startNode(commonSettings);
    assertThat(cluster().size(), equalTo(2));
    ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setWaitForNodes("2").execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    logger.info("--> create an index with 1 shard, 1 replica, nothing should allocate");
    client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).setSettings(Settings.builder().put("index.number_of_shards", 1)).execute().actionGet();
    final boolean closed = randomBoolean();
    if (closed) {
        client().admin().indices().prepareClose("test").get();
    }
    ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(2));
    logger.info("--> explicitly allocate shard 1, actually allocating, no dry run");
    state = client().admin().cluster().prepareReroute().setExplain(randomBoolean()).add(new AllocateEmptyPrimaryAllocationCommand("test", 0, node_1, true)).execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
    healthResponse = client().admin().cluster().prepareHealth().setIndices("test").setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    logger.info("--> get the state, verify shard 1 primary allocated");
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
    if (closed == false) {
        client().prepareIndex("test").setId("1").setSource("field", "value").setRefreshPolicy(RefreshPolicy.IMMEDIATE).get();
    }
    final Index index = resolveIndex("test");
    logger.info("--> closing all nodes");
    Path[] shardLocation = internalCluster().getInstance(NodeEnvironment.class, node_1).availableShardPaths(new ShardId(index, 0));
    // make sure the data is there!
    assertThat(FileSystemUtils.exists(shardLocation), equalTo(true));
    // don't wipe data directories the index needs to be there!
    internalCluster().closeNonSharedNodes(false);
    logger.info("--> deleting the shard data [{}] ", Arrays.toString(shardLocation));
    // verify again after cluster was shut down
    assertThat(FileSystemUtils.exists(shardLocation), equalTo(true));
    IOUtils.rm(shardLocation);
    logger.info("--> starting nodes back, will not allocate the shard since it has no data, but the index will be there");
    node_1 = internalCluster().startNode(commonSettings);
    internalCluster().startNode(commonSettings);
    // wait a bit for the cluster to realize that the shard is not there...
    // TODO can we get around this? the cluster is RED, so what do we wait for?
    client().admin().cluster().prepareReroute().get();
    assertThat(client().admin().cluster().prepareHealth().setIndices("test").setWaitForNodes("2").execute().actionGet().getStatus(), equalTo(ClusterHealthStatus.RED));
    logger.info("--> explicitly allocate primary");
    state = client().admin().cluster().prepareReroute().setExplain(randomBoolean()).add(new AllocateEmptyPrimaryAllocationCommand("test", 0, node_1, true)).execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
    logger.info("--> get the state, verify shard 1 primary allocated");
    final String nodeToCheck = node_1;
    assertBusy(() -> {
        ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
        String nodeId = clusterState.nodes().resolveNode(nodeToCheck).getId();
        assertThat(clusterState.getRoutingNodes().node(nodeId).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
    });
}
Also used : Path(java.nio.file.Path) ShardId(org.opensearch.index.shard.ShardId) ClusterState(org.opensearch.cluster.ClusterState) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) NodeEnvironment(org.opensearch.env.NodeEnvironment) AllocateEmptyPrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) Index(org.opensearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 2 with AllocateEmptyPrimaryAllocationCommand

use of org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand in project OpenSearch by opensearch-project.

the class ClusterRerouteIT method rerouteWithCommands.

private void rerouteWithCommands(Settings commonSettings) throws Exception {
    List<String> nodesIds = internalCluster().startNodes(2, commonSettings);
    final String node_1 = nodesIds.get(0);
    final String node_2 = nodesIds.get(1);
    logger.info("--> create an index with 1 shard, 1 replica, nothing should allocate");
    client().admin().indices().prepareCreate("test").setWaitForActiveShards(ActiveShardCount.NONE).setSettings(Settings.builder().put("index.number_of_shards", 1)).execute().actionGet();
    if (randomBoolean()) {
        client().admin().indices().prepareClose("test").get();
    }
    ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(2));
    logger.info("--> explicitly allocate shard 1, *under dry_run*");
    state = client().admin().cluster().prepareReroute().setExplain(randomBoolean()).add(new AllocateEmptyPrimaryAllocationCommand("test", 0, node_1, true)).setDryRun(true).execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
    logger.info("--> get the state, verify nothing changed because of the dry run");
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(2));
    logger.info("--> explicitly allocate shard 1, actually allocating, no dry run");
    state = client().admin().cluster().prepareReroute().setExplain(randomBoolean()).add(new AllocateEmptyPrimaryAllocationCommand("test", 0, node_1, true)).execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
    ClusterHealthResponse healthResponse = client().admin().cluster().prepareHealth().setIndices("test").setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    logger.info("--> get the state, verify shard 1 primary allocated");
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
    logger.info("--> move shard 1 primary from node1 to node2");
    state = client().admin().cluster().prepareReroute().setExplain(randomBoolean()).add(new MoveAllocationCommand("test", 0, node_1, node_2)).execute().actionGet().getState();
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_1).getId()).iterator().next().state(), equalTo(ShardRoutingState.RELOCATING));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_2).getId()).iterator().next().state(), equalTo(ShardRoutingState.INITIALIZING));
    healthResponse = client().admin().cluster().prepareHealth().setIndices("test").setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().setWaitForNoRelocatingShards(true).execute().actionGet();
    assertThat(healthResponse.isTimedOut(), equalTo(false));
    logger.info("--> get the state, verify shard 1 primary moved from node1 to node2");
    state = client().admin().cluster().prepareState().execute().actionGet().getState();
    assertThat(state.getRoutingNodes().unassigned().size(), equalTo(1));
    assertThat(state.getRoutingNodes().node(state.nodes().resolveNode(node_2).getId()).iterator().next().state(), equalTo(ShardRoutingState.STARTED));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) AllocateEmptyPrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) MoveAllocationCommand(org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 3 with AllocateEmptyPrimaryAllocationCommand

use of org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand in project OpenSearch by opensearch-project.

the class IndexRecoveryIT method testAllocateEmptyPrimaryResetsGlobalCheckpoint.

public void testAllocateEmptyPrimaryResetsGlobalCheckpoint() throws Exception {
    internalCluster().startMasterOnlyNode(Settings.EMPTY);
    final List<String> dataNodes = internalCluster().startDataOnlyNodes(2);
    final Settings randomNodeDataPathSettings = internalCluster().dataPathSettings(randomFrom(dataNodes));
    final String indexName = "test";
    assertAcked(client().admin().indices().prepareCreate(indexName).setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 1).put(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE.getKey(), randomBoolean())).get());
    final List<IndexRequestBuilder> indexRequests = IntStream.range(0, between(10, 500)).mapToObj(n -> client().prepareIndex(indexName).setSource("foo", "bar")).collect(Collectors.toList());
    indexRandom(randomBoolean(), true, true, indexRequests);
    ensureGreen();
    internalCluster().stopRandomDataNode();
    internalCluster().stopRandomDataNode();
    final String nodeWithoutData = internalCluster().startDataOnlyNode();
    assertAcked(client().admin().cluster().prepareReroute().add(new AllocateEmptyPrimaryAllocationCommand(indexName, 0, nodeWithoutData, true)).get());
    internalCluster().startDataOnlyNode(randomNodeDataPathSettings);
    ensureGreen();
    for (ShardStats shardStats : client().admin().indices().prepareStats(indexName).get().getIndex(indexName).getShards()) {
        assertThat(shardStats.getSeqNoStats().getMaxSeqNo(), equalTo(SequenceNumbers.NO_OPS_PERFORMED));
        assertThat(shardStats.getSeqNoStats().getLocalCheckpoint(), equalTo(SequenceNumbers.NO_OPS_PERFORMED));
        assertThat(shardStats.getSeqNoStats().getGlobalCheckpoint(), equalTo(SequenceNumbers.NO_OPS_PERFORMED));
    }
}
Also used : IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) SequenceNumbers(org.opensearch.index.seqno.SequenceNumbers) Arrays(java.util.Arrays) IndexResponse(org.opensearch.action.index.IndexResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) SnapshotRecoverySource(org.opensearch.cluster.routing.RecoverySource.SnapshotRecoverySource) Matchers.not(org.hamcrest.Matchers.not) SnapshotState(org.opensearch.snapshots.SnapshotState) ClusterScope(org.opensearch.test.OpenSearchIntegTestCase.ClusterScope) Version(org.opensearch.Version) Strings(org.opensearch.common.Strings) Transport(org.opensearch.transport.Transport) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Map(java.util.Map) ShardStateAction(org.opensearch.cluster.action.shard.ShardStateAction) Repository(org.opensearch.repositories.Repository) TimeValue(org.opensearch.common.unit.TimeValue) Index(org.opensearch.index.Index) AbstractTokenFilterFactory(org.opensearch.index.analysis.AbstractTokenFilterFactory) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) Settings(org.opensearch.common.settings.Settings) ReplicationTracker(org.opensearch.index.seqno.ReplicationTracker) Scope(org.opensearch.test.OpenSearchIntegTestCase.Scope) TransportService(org.opensearch.transport.TransportService) Engine(org.opensearch.index.engine.Engine) CountDownLatch(java.util.concurrent.CountDownLatch) UPDATED(org.opensearch.action.DocWriteResponse.Result.UPDATED) NodeStats(org.opensearch.action.admin.cluster.node.stats.NodeStats) IndicesStatsResponse(org.opensearch.action.admin.indices.stats.IndicesStatsResponse) XContentType(org.opensearch.common.xcontent.XContentType) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.is(org.hamcrest.Matchers.is) RepositoriesService(org.opensearch.repositories.RepositoriesService) TransportRequestHandler(org.opensearch.transport.TransportRequestHandler) CHUNK_SIZE_SETTING(org.opensearch.node.RecoverySettingsChunkSizePlugin.CHUNK_SIZE_SETTING) MapperParsingException(org.opensearch.index.mapper.MapperParsingException) Priority(org.opensearch.common.Priority) MockTransportService(org.opensearch.test.transport.MockTransportService) ArrayList(java.util.ArrayList) RecoverySource(org.opensearch.cluster.routing.RecoverySource) RestoreSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse) ClusterState(org.opensearch.cluster.ClusterState) ShardRoutingState(org.opensearch.cluster.routing.ShardRoutingState) BiConsumer(java.util.function.BiConsumer) Matchers.hasSize(org.hamcrest.Matchers.hasSize) StreamSupport(java.util.stream.StreamSupport) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) TokenStream(org.apache.lucene.analysis.TokenStream) SetOnce(org.apache.lucene.util.SetOnce) IOException(java.io.IOException) IndexService(org.opensearch.index.IndexService) Plugin(org.opensearch.plugins.Plugin) ExecutionException(java.util.concurrent.ExecutionException) RecoveryResponse(org.opensearch.action.admin.indices.recovery.RecoveryResponse) AnalysisModule(org.opensearch.indices.analysis.AnalysisModule) PluginsService(org.opensearch.plugins.PluginsService) RecoveryStats(org.opensearch.index.recovery.RecoveryStats) RetentionLeases(org.opensearch.index.seqno.RetentionLeases) ClusterService(org.opensearch.cluster.service.ClusterService) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) MockFSIndexStore(org.opensearch.test.store.MockFSIndexStore) StubbableTransport(org.opensearch.test.transport.StubbableTransport) ByteSizeUnit(org.opensearch.common.unit.ByteSizeUnit) OpenSearchException(org.opensearch.OpenSearchException) MoveAllocationCommand(org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand) CircuitBreaker(org.opensearch.common.breaker.CircuitBreaker) CommonStatsFlags(org.opensearch.action.admin.indices.stats.CommonStatsFlags) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) OpenSearchAssertions.assertHitCount(org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount) Matchers.everyItem(org.hamcrest.Matchers.everyItem) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeClosedException(org.opensearch.node.NodeClosedException) RecoveryRequest(org.opensearch.action.admin.indices.recovery.RecoveryRequest) UnassignedInfo(org.opensearch.cluster.routing.UnassignedInfo) IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) ReplicaShardAllocatorIT(org.opensearch.gateway.ReplicaShardAllocatorIT) TransportChannel(org.opensearch.transport.TransportChannel) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Collection(java.util.Collection) IndicesService(org.opensearch.indices.IndicesService) Task(org.opensearch.tasks.Task) Store(org.opensearch.index.store.Store) NodeIndicesStats(org.opensearch.indices.NodeIndicesStats) Collectors(java.util.stream.Collectors) List(java.util.List) ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) CREATED(org.opensearch.action.DocWriteResponse.Result.CREATED) Matchers.equalTo(org.hamcrest.Matchers.equalTo) IndexSettings(org.opensearch.index.IndexSettings) ReplicationResponse(org.opensearch.action.support.replication.ReplicationResponse) ConnectTransportException(org.opensearch.transport.ConnectTransportException) OpenSearchIntegTestCase(org.opensearch.test.OpenSearchIntegTestCase) AllocateEmptyPrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) RefreshPolicy(org.opensearch.action.support.WriteRequest.RefreshPolicy) IntStream(java.util.stream.IntStream) DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) Stage(org.opensearch.indices.recovery.RecoveryState.Stage) TokenFilterFactory(org.opensearch.index.analysis.TokenFilterFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteSizeValue(org.opensearch.common.unit.ByteSizeValue) InternalTestCluster(org.opensearch.test.InternalTestCluster) NodeConnectionsService(org.opensearch.cluster.NodeConnectionsService) IndexShard(org.opensearch.index.shard.IndexShard) InternalSettingsPlugin(org.opensearch.test.InternalSettingsPlugin) BackgroundIndexer(org.opensearch.test.BackgroundIndexer) Collections.singletonMap(java.util.Collections.singletonMap) SearchResponse(org.opensearch.action.search.SearchResponse) StoreStats(org.opensearch.index.store.StoreStats) OpenSearchAssertions.assertAcked(org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked) RepositoryData(org.opensearch.repositories.RepositoryData) CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) PeerRecoverySource(org.opensearch.cluster.routing.RecoverySource.PeerRecoverySource) Matchers.empty(org.hamcrest.Matchers.empty) MockEngineFactoryPlugin(org.opensearch.index.MockEngineFactoryPlugin) TransportRequest(org.opensearch.transport.TransportRequest) Semaphore(java.util.concurrent.Semaphore) MockEngineSupport(org.opensearch.test.engine.MockEngineSupport) ActiveShardCount(org.opensearch.action.support.ActiveShardCount) ShardRouting(org.opensearch.cluster.routing.ShardRouting) ShardId(org.opensearch.index.shard.ShardId) Consumer(java.util.function.Consumer) AnalysisPlugin(org.opensearch.plugins.AnalysisPlugin) Collectors.toList(java.util.stream.Collectors.toList) Snapshot(org.opensearch.snapshots.Snapshot) NodesStatsResponse(org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse) RecoverySettingsChunkSizePlugin(org.opensearch.node.RecoverySettingsChunkSizePlugin) Collections(java.util.Collections) ShardStats(org.opensearch.action.admin.indices.stats.ShardStats) AllocateEmptyPrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) Settings(org.opensearch.common.settings.Settings) IndexSettings(org.opensearch.index.IndexSettings)

Example 4 with AllocateEmptyPrimaryAllocationCommand

use of org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand in project OpenSearch by opensearch-project.

the class AllocationCommandsTests method testSerialization.

public void testSerialization() throws Exception {
    AllocationCommands commands = new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 1, "node1", true), new AllocateStalePrimaryAllocationCommand("test", 2, "node1", true), new AllocateReplicaAllocationCommand("test", 2, "node1"), new MoveAllocationCommand("test", 3, "node2", "node3"), new CancelAllocationCommand("test", 4, "node5", true));
    BytesStreamOutput bytes = new BytesStreamOutput();
    AllocationCommands.writeTo(commands, bytes);
    StreamInput in = bytes.bytes().streamInput();
    // Since the commands are named writeable we need to register them and wrap the input stream
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
    in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry);
    // Now we can read them!
    AllocationCommands sCommands = AllocationCommands.readFrom(in);
    assertThat(sCommands.commands().size(), equalTo(5));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(1));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).index(), equalTo("test"));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).node(), equalTo("node1"));
    assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).acceptDataLoss(), equalTo(true));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).shardId(), equalTo(2));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).index(), equalTo("test"));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).node(), equalTo("node1"));
    assertThat(((AllocateStalePrimaryAllocationCommand) (sCommands.commands().get(1))).acceptDataLoss(), equalTo(true));
    assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).shardId(), equalTo(2));
    assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).index(), equalTo("test"));
    assertThat(((AllocateReplicaAllocationCommand) (sCommands.commands().get(2))).node(), equalTo("node1"));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).shardId(), equalTo(3));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).index(), equalTo("test"));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).fromNode(), equalTo("node2"));
    assertThat(((MoveAllocationCommand) (sCommands.commands().get(3))).toNode(), equalTo("node3"));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).shardId(), equalTo(4));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).index(), equalTo("test"));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).node(), equalTo("node5"));
    assertThat(((CancelAllocationCommand) (sCommands.commands().get(4))).allowPrimary(), equalTo(true));
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) AllocateStalePrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand) CancelAllocationCommand(org.opensearch.cluster.routing.allocation.command.CancelAllocationCommand) AllocateEmptyPrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) MoveAllocationCommand(org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) AllocateReplicaAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput) AllocationCommands(org.opensearch.cluster.routing.allocation.command.AllocationCommands)

Example 5 with AllocateEmptyPrimaryAllocationCommand

use of org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand in project OpenSearch by opensearch-project.

the class ClusterRerouteTests method testSerializeRequest.

public void testSerializeRequest() throws IOException {
    ClusterRerouteRequest req = new ClusterRerouteRequest();
    req.setRetryFailed(randomBoolean());
    req.dryRun(randomBoolean());
    req.explain(randomBoolean());
    req.add(new AllocateEmptyPrimaryAllocationCommand("foo", 1, "bar", randomBoolean()));
    req.timeout(TimeValue.timeValueMillis(randomIntBetween(0, 100)));
    BytesStreamOutput out = new BytesStreamOutput();
    req.writeTo(out);
    BytesReference bytes = out.bytes();
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(NetworkModule.getNamedWriteables());
    StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(), namedWriteableRegistry);
    ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest(wrap);
    assertEquals(req.isRetryFailed(), deserializedReq.isRetryFailed());
    assertEquals(req.dryRun(), deserializedReq.dryRun());
    assertEquals(req.explain(), deserializedReq.explain());
    assertEquals(req.timeout(), deserializedReq.timeout());
    // allocation commands have their own tests
    assertEquals(1, deserializedReq.getCommands().commands().size());
    assertEquals(req.getCommands().commands().size(), deserializedReq.getCommands().commands().size());
}
Also used : BytesReference(org.opensearch.common.bytes.BytesReference) NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) AllocateEmptyPrimaryAllocationCommand(org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.opensearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.opensearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Aggregations

AllocateEmptyPrimaryAllocationCommand (org.opensearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand)13 ClusterState (org.opensearch.cluster.ClusterState)9 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)7 Matchers.containsString (org.hamcrest.Matchers.containsString)5 AllocationCommands (org.opensearch.cluster.routing.allocation.command.AllocationCommands)5 MoveAllocationCommand (org.opensearch.cluster.routing.allocation.command.MoveAllocationCommand)5 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)4 Metadata (org.opensearch.cluster.metadata.Metadata)4 RoutingTable (org.opensearch.cluster.routing.RoutingTable)4 AllocateStalePrimaryAllocationCommand (org.opensearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand)4 Path (java.nio.file.Path)3 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Matchers.empty (org.hamcrest.Matchers.empty)3 Matchers.hasSize (org.hamcrest.Matchers.hasSize)3 Matchers.is (org.hamcrest.Matchers.is)3 AllocateReplicaAllocationCommand (org.opensearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand)3