org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand Java Examples

The following examples show how to use org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClusterRerouteManager.java    From foxtrot with Apache License 2.0 6 votes vote down vote up
private boolean reallocateShard(ShardId shardId, String fromNode, String toNode) {
    MoveAllocationCommand moveAllocationCommand = new MoveAllocationCommand(shardId.getIndexName(),
                                                                            shardId.getId(),
                                                                            fromNode,
                                                                            toNode);
    ClusterRerouteRequest clusterRerouteRequest = new ClusterRerouteRequest();
    clusterRerouteRequest.add(moveAllocationCommand);
    try {
        ClusterRerouteResponse clusterRerouteResponse = connection.getClient()
                .admin()
                .cluster()
                .reroute(clusterRerouteRequest)
                .actionGet();
        log.info(String.format("Reallocating Shard. From Node: %s To Node: %s", fromNode, toNode));
        Thread.sleep((new Date(DateTime.now()).getHourOfDay() + 1) * 4000L);
        return clusterRerouteResponse.isAcknowledged();
    }
    catch (Exception e) {
        log.error(String.format("Error in Reallocating Shard. From Node: %s To Node: %s. Error Message: %s",
                                fromNode,
                                toNode,
                                e.getMessage()), e);
        return false;
    }
}
 
Example #2
Source File: ShellScope.java    From elasticshell with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new <code>ShellScope</code> given the actual scope object
 * @param scope the actual scope object that depends on the engine in use
 */
ShellScope(Scope scope, ResourceRegistry resourceRegistry) {
    this.scope = scope;
    this.resourceRegistry = resourceRegistry;
    registerJavaClass(Requests.class);
    registerJavaClass(SearchSourceBuilder.class);
    registerJavaClass(QueryBuilders.class);
    registerJavaClass(FilterBuilders.class);
    registerJavaClass(SortBuilders.class);
    registerJavaClass(FacetBuilders.class);
    registerJavaClass(RescoreBuilder.class);
    registerJavaClass(SuggestBuilder.class);
    registerJavaClass(AliasAction.class);
    registerJavaClass(HttpParameters.class);
    registerJavaClass(AllocateAllocationCommand.class);
    registerJavaClass(CancelAllocationCommand.class);
    registerJavaClass(MoveAllocationCommand.class);
    registerJavaClass(ShardId.class);
}
 
Example #3
Source File: AlterTableReroutePlan.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
protected AllocationCommand visitRerouteMoveShard(AnalyzedRerouteMoveShard statement,
                                                  Context context) {
    var boundedMoveShard = statement.rerouteMoveShard().map(context.eval);

    String index = getRerouteIndex(
        statement.shardedTable(),
        Lists2.map(statement.partitionProperties(), x -> x.map(context.eval)));
    String toNodeId = resolveNodeId(
        context.nodes,
        DataTypes.STRING.value(boundedMoveShard.toNodeIdOrName()));

    return new MoveAllocationCommand(
        index,
        DataTypes.INTEGER.value(boundedMoveShard.shardId()),
        DataTypes.STRING.value(boundedMoveShard.fromNodeIdOrName()),
        toNodeId
    );
}
 
Example #4
Source File: AlterTableRerouteAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testRerouteMoveShardWithLiterals() {
    MoveAllocationCommand command = analyze(
        "ALTER TABLE users REROUTE MOVE SHARD 0 FROM 'n2' TO 'n1'");
    assertThat(command.index(), is("users"));
    assertThat(command.shardId(), is(0));
    assertThat(command.fromNode(), is("n2"));
    assertThat(command.toNode(), is("n1"));
}
 
Example #5
Source File: AlterTableRerouteAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testRerouteMoveShardWithParameters() {
    MoveAllocationCommand command = analyze(
        "ALTER TABLE users REROUTE MOVE SHARD 0 FROM ? TO ?", "n2", "n1");
    assertThat(command.index(), is("users"));
    assertThat(command.shardId(), is(0));
    assertThat(command.fromNode(), is("n2"));
    assertThat(command.toNode(), is("n1"));
}
 
Example #6
Source File: AlterTableRerouteAnalyzerTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
public void testRerouteMoveShardPartitionedTable() {
    MoveAllocationCommand command = analyze(
        "ALTER TABLE parted PARTITION (date = 1395874800000) REROUTE MOVE SHARD 0 FROM 'n1' TO 'n2'");
    assertThat(command.index(), is(".partitioned.parted.04732cpp6ks3ed1o60o30c1g"));
    assertThat(command.shardId(), is(0));
    assertThat(command.fromNode(), is("n1"));
    assertThat(command.toNode(), is("n2"));
}
 
Example #7
Source File: AlterTableRerouteAnalyzerTest.java    From crate with Apache License 2.0 4 votes vote down vote up
@Test
public void testRerouteOnBlobTable() {
    MoveAllocationCommand command = analyze(
        "ALTER TABLE blob.blobs REROUTE MOVE SHARD 0 FROM 'n1' TO 'n2'");
    assertThat(command.index(), is(".blob_blobs"));
}