org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest. 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: AlterTableReroutePlan.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    var rerouteCommand = createRerouteCommand(
        rerouteStatement,
        plannerContext.transactionContext(),
        plannerContext.functions(),
        params,
        subQueryResults,
        dependencies.clusterService().state().nodes());

    dependencies
        .transportActionProvider()
        .transportClusterRerouteAction()
        .execute(
            new ClusterRerouteRequest().add(rerouteCommand),
            new OneRowActionListener<>(
                consumer, r -> new Row1(r == null ? -1L : 1L)));
}
 
Example #3
Source File: ClusterRerouteRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(ClusterRerouteRequest request, ClusterRerouteResponse response, XContentBuilder builder) throws IOException {
    builder.startObject();
    builder.field(Fields.OK, true);
    builder.startObject("state");
    response.getState().settingsFilter(new SettingsFilter(ImmutableSettings.settingsBuilder().build())).toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.endObject();

    builder.endObject();

    return builder;
}
 
Example #4
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<ClusterRerouteResponse> reroute(final ClusterRerouteRequest request) {
    return execute(ClusterRerouteAction.INSTANCE, request);
}
 
Example #5
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void reroute(final ClusterRerouteRequest request, final ActionListener<ClusterRerouteResponse> listener) {
    execute(ClusterRerouteAction.INSTANCE, request, listener);
}
 
Example #6
Source File: Requests.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static ClusterRerouteRequest clusterRerouteRequest() {
    return new ClusterRerouteRequest();
}
 
Example #7
Source File: ClusterRerouteRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public ClusterRerouteRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new ClusterRerouteRequest(), jsonToString, stringToJson);
}
 
Example #8
Source File: ClusterRerouteRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<ClusterRerouteResponse> doExecute(ClusterRerouteRequest request) {
    return client.admin().cluster().reroute(request);
}
 
Example #9
Source File: RerouteRetryFailedPlan.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) throws Exception {
    dependencies
        .transportActionProvider()
        .transportClusterRerouteAction()
        .execute(
            new ClusterRerouteRequest().setRetryFailed(true),
            new OneRowActionListener<>(
                consumer,
                response -> {
                    if (response.isAcknowledged()) {
                        long rowCount = 0L;
                        for (RoutingNode routingNode : response.getState().getRoutingNodes()) {
                            // filter shards with failed allocation attempts
                            // failed allocation attempts can appear for shards
                            // with state UNASSIGNED and INITIALIZING
                            rowCount += routingNode.shardsWithState(
                                ShardRoutingState.UNASSIGNED,
                                ShardRoutingState.INITIALIZING)
                                .stream()
                                .filter(s -> {
                                    if (s.unassignedInfo() != null) {
                                        return s.unassignedInfo().getReason()
                                            .equals(UnassignedInfo.Reason.ALLOCATION_FAILED);
                                    }
                                    return false;
                                })
                                .count();
                        }
                        return new Row1(rowCount);
                    } else {
                        return new Row1(-1L);
                    }
                }
            )
        );
}
 
Example #10
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Reroutes allocation of shards. Advance API.
 */
ActionFuture<ClusterRerouteResponse> reroute(ClusterRerouteRequest request);
 
Example #11
Source File: ClusterAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Reroutes allocation of shards. Advance API.
 */
void reroute(ClusterRerouteRequest request, ActionListener<ClusterRerouteResponse> listener);