Search in sources :

Example 1 with AllocateReplicaAllocationCommand

use of org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand in project elasticsearch by elastic.

the class AllocationCommandsTests method testAllocateCommand.

public void testAllocateCommand() {
    AllocationService allocation = createAllocationService(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none").put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none").build());
    final String index = "test";
    logger.info("--> building initial routing table");
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder(index).settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1).putInSyncAllocationIds(0, Collections.singleton("asdf")).putInSyncAllocationIds(1, Collections.singleton("qwertz"))).build();
    // shard routing is added as "from recovery" instead of "new index creation" so that we can test below that allocating an empty
    // primary with accept_data_loss flag set to false fails
    RoutingTable routingTable = RoutingTable.builder().addAsRecovery(metaData.index(index)).build();
    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
    final ShardId shardId = new ShardId(metaData.index(index).getIndex(), 0);
    logger.info("--> adding 3 nodes on same rack and do rerouting");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4", singleton(DiscoveryNode.Role.MASTER)))).build();
    clusterState = allocation.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
    logger.info("--> allocating to non-existent node, should fail");
    try {
        allocation.reroute(clusterState, new AllocationCommands(randomAllocateCommand(index, shardId.id(), "node42")), false, false);
        fail("expected IllegalArgumentException when allocating to non-existing node");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("failed to resolve [node42], no matching nodes"));
    }
    logger.info("--> allocating to non-data node, should fail");
    try {
        allocation.reroute(clusterState, new AllocationCommands(randomAllocateCommand(index, shardId.id(), "node4")), false, false);
        fail("expected IllegalArgumentException when allocating to non-data node");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("allocation can only be done on data nodes"));
    }
    logger.info("--> allocating non-existing shard, should fail");
    try {
        allocation.reroute(clusterState, new AllocationCommands(randomAllocateCommand("test", 1, "node2")), false, false);
        fail("expected ShardNotFoundException when allocating non-existing shard");
    } catch (ShardNotFoundException e) {
        assertThat(e.getMessage(), containsString("no such shard"));
    }
    logger.info("--> allocating non-existing index, should fail");
    try {
        allocation.reroute(clusterState, new AllocationCommands(randomAllocateCommand("test2", 0, "node2")), false, false);
        fail("expected ShardNotFoundException when allocating non-existing index");
    } catch (IndexNotFoundException e) {
        assertThat(e.getMessage(), containsString("no such index"));
    }
    logger.info("--> allocating empty primary with acceptDataLoss flag set to false");
    try {
        allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", false)), false, false);
        fail("expected IllegalArgumentException when allocating empty primary with acceptDataLoss flag set to false");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("allocating an empty primary for " + shardId + " can result in data loss. Please confirm by setting the accept_data_loss parameter to true"));
    }
    logger.info("--> allocating stale primary with acceptDataLoss flag set to false");
    try {
        allocation.reroute(clusterState, new AllocationCommands(new AllocateStalePrimaryAllocationCommand(index, shardId.id(), "node1", false)), false, false);
        fail("expected IllegalArgumentException when allocating stale primary with acceptDataLoss flag set to false");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), containsString("allocating an empty primary for " + shardId + " can result in data loss. Please confirm by setting the accept_data_loss parameter to true"));
    }
    logger.info("--> allocating empty primary with acceptDataLoss flag set to true");
    ClusterState newState = allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    logger.info("--> start the primary shard");
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    logger.info("--> allocate the replica shard on the primary shard node, should fail");
    try {
        allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node1")), false, false);
        fail("expected IllegalArgumentException when allocating replica shard on the primary shard node");
    } catch (IllegalArgumentException e) {
    }
    logger.info("--> allocate the replica shard on on the second node");
    newState = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
    logger.info("--> start the replica shard");
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
    logger.info("--> verify that we fail when there are no unassigned shards");
    try {
        allocation.reroute(clusterState, new AllocationCommands(randomAllocateCommand("test", 0, "node3")), false, false);
        fail("expected IllegalArgumentException when allocating shard while no unassigned shard available");
    } catch (IllegalArgumentException e) {
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) AllocateStalePrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand) AllocateEmptyPrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) AllocateReplicaAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand) Matchers.containsString(org.hamcrest.Matchers.containsString) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands) ShardId(org.elasticsearch.index.shard.ShardId) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) ShardNotFoundException(org.elasticsearch.index.shard.ShardNotFoundException) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexNotFoundException(org.elasticsearch.index.IndexNotFoundException)

Example 2 with AllocateReplicaAllocationCommand

use of org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand in project elasticsearch by elastic.

the class AllocationCommandsTests method testCancelCommand.

public void testCancelCommand() {
    AllocationService allocation = createAllocationService(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.getKey(), "none").put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none").build());
    logger.info("--> building initial routing table");
    MetaData metaData = MetaData.builder().put(IndexMetaData.builder("test").settings(settings(Version.CURRENT)).numberOfShards(1).numberOfReplicas(1)).build();
    RoutingTable routingTable = RoutingTable.builder().addAsNew(metaData.index("test")).build();
    ClusterState clusterState = ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)).metaData(metaData).routingTable(routingTable).build();
    logger.info("--> adding 3 nodes");
    clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3"))).build();
    clusterState = allocation.reroute(clusterState, "reroute");
    assertThat(clusterState.getRoutingNodes().shardsWithState(INITIALIZING).size(), equalTo(0));
    logger.info("--> allocating empty primary shard with accept_data_loss flag set to true");
    ClusterState newState = allocation.reroute(clusterState, new AllocationCommands(new AllocateEmptyPrimaryAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(INITIALIZING).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    logger.info("--> cancel primary allocation, make sure it fails...");
    try {
        allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", false)), false, false);
        fail();
    } catch (IllegalArgumentException e) {
    }
    logger.info("--> start the primary shard");
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    logger.info("--> cancel primary allocation, make sure it fails...");
    try {
        allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", false)), false, false);
        fail();
    } catch (IllegalArgumentException e) {
    }
    logger.info("--> allocate the replica shard on on the second node");
    newState = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
    logger.info("--> cancel the relocation allocation");
    newState = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
    logger.info("--> allocate the replica shard on on the second node");
    newState = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
    logger.info("--> cancel the primary being replicated, make sure it fails");
    try {
        allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", false)), false, false);
        fail();
    } catch (IllegalArgumentException e) {
    }
    logger.info("--> start the replica shard");
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
    logger.info("--> cancel allocation of the replica shard");
    newState = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
    logger.info("--> allocate the replica shard on on the second node");
    newState = allocation.reroute(clusterState, new AllocationCommands(new AllocateReplicaAllocationCommand("test", 0, "node2")), false, false).getClusterState();
    assertThat(newState, not(equalTo(clusterState)));
    clusterState = newState;
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(INITIALIZING).size(), equalTo(1));
    logger.info("--> start the replica shard");
    clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
    logger.info("--> move the replica shard");
    clusterState = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false).getClusterState();
    assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(RELOCATING).size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(1));
    assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).size(), equalTo(1));
    if (randomBoolean()) {
        logger.info("--> cancel the primary allocation (with allow_primary set to true)");
        newState = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
        assertThat(newState, not(equalTo(clusterState)));
        clusterState = newState;
        assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
        assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).iterator().next().primary(), equalTo(true));
        assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(0));
    } else {
        logger.info("--> cancel the move of the replica shard");
        clusterState = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node3", false)), false, false).getClusterState();
        assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(STARTED).size(), equalTo(1));
        logger.info("--> move the replica shard again");
        clusterState = allocation.reroute(clusterState, new AllocationCommands(new MoveAllocationCommand("test", 0, "node2", "node3")), false, false).getClusterState();
        assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node2").shardsWithState(RELOCATING).size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).size(), equalTo(1));
        logger.info("--> cancel the source replica shard");
        clusterState = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node2", false)), false, false).getClusterState();
        assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
        assertThat(clusterState.getRoutingNodes().node("node3").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(INITIALIZING).get(0).relocatingNodeId(), nullValue());
        logger.info("--> start the former target replica shard");
        clusterState = allocation.applyStartedShards(clusterState, clusterState.getRoutingNodes().shardsWithState(INITIALIZING));
        assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node1").shardsWithState(STARTED).size(), equalTo(1));
        assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
        assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(STARTED).size(), equalTo(1));
        logger.info("--> cancel the primary allocation (with allow_primary set to true)");
        newState = allocation.reroute(clusterState, new AllocationCommands(new CancelAllocationCommand("test", 0, "node1", true)), false, false).getClusterState();
        assertThat(newState, not(equalTo(clusterState)));
        clusterState = newState;
        assertThat(clusterState.getRoutingNodes().node("node3").shardsWithState(STARTED).iterator().next().primary(), equalTo(true));
        assertThat(clusterState.getRoutingNodes().node("node1").size(), equalTo(0));
        assertThat(clusterState.getRoutingNodes().node("node2").size(), equalTo(0));
    }
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) CancelAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand) AllocateEmptyPrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) AllocateReplicaAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands)

Example 3 with AllocateReplicaAllocationCommand

use of org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand in project elasticsearch by elastic.

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.elasticsearch.common.io.stream.NamedWriteableRegistry) AllocateStalePrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand) CancelAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand) AllocateEmptyPrimaryAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand) MoveAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) AllocateReplicaAllocationCommand(org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) AllocationCommands(org.elasticsearch.cluster.routing.allocation.command.AllocationCommands)

Aggregations

AllocateEmptyPrimaryAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.AllocateEmptyPrimaryAllocationCommand)3 AllocateReplicaAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.AllocateReplicaAllocationCommand)3 AllocationCommands (org.elasticsearch.cluster.routing.allocation.command.AllocationCommands)3 ClusterState (org.elasticsearch.cluster.ClusterState)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)2 AllocateStalePrimaryAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.AllocateStalePrimaryAllocationCommand)2 CancelAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand)2 MoveAllocationCommand (org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand)2 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)1 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1 IndexNotFoundException (org.elasticsearch.index.IndexNotFoundException)1 ShardId (org.elasticsearch.index.shard.ShardId)1 ShardNotFoundException (org.elasticsearch.index.shard.ShardNotFoundException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1