diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java index 37364afb9e9..f06bf1a13bf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java @@ -29,6 +29,7 @@ import org.elasticsearch.action.admin.cluster.ping.replication.TransportIndexRep import org.elasticsearch.action.admin.cluster.ping.replication.TransportReplicationPingAction; import org.elasticsearch.action.admin.cluster.ping.replication.TransportShardReplicationPingAction; import org.elasticsearch.action.admin.cluster.ping.single.TransportSinglePingAction; +import org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction; import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction; import org.elasticsearch.action.admin.cluster.state.TransportClusterStateAction; import org.elasticsearch.action.admin.indices.alias.TransportIndicesAliasesAction; @@ -93,6 +94,7 @@ public class TransportActionModule extends AbstractModule { bind(TransportClusterStateAction.class).asEagerSingleton(); bind(TransportClusterHealthAction.class).asEagerSingleton(); bind(TransportClusterUpdateSettingsAction.class).asEagerSingleton(); + bind(TransportClusterRerouteAction.class).asEagerSingleton(); bind(TransportSinglePingAction.class).asEagerSingleton(); bind(TransportBroadcastPingAction.class).asEagerSingleton(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java index e779ccc4c8d..6b77ea74e46 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java @@ -87,6 +87,7 @@ public class TransportActions { public static final String STATE = "/cluster/state"; public static final String HEALTH = "/cluster/health"; public static final String UPDATE_SETTINGS = "/cluster/updateSettings"; + public static final String REROUTE = "/cluster/reroute"; public static class Node { public static final String INFO = "/cluster/nodes/info"; diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java new file mode 100644 index 00000000000..3afd9b50f97 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java @@ -0,0 +1,47 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.cluster.reroute; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.master.MasterNodeOperationRequest; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +/** + */ +public class ClusterRerouteRequest extends MasterNodeOperationRequest { + + public ClusterRerouteRequest() { + } + + @Override public ActionRequestValidationException validate() { + return null; + } + + @Override public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + } + + @Override public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java new file mode 100644 index 00000000000..87016b7083a --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java @@ -0,0 +1,40 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.cluster.reroute; + +import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +/** + */ +public class ClusterRerouteResponse implements ActionResponse { + + ClusterRerouteResponse() { + } + + @Override public void readFrom(StreamInput in) throws IOException { + } + + @Override public void writeTo(StreamOutput out) throws IOException { + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java new file mode 100644 index 00000000000..c872294bd70 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java @@ -0,0 +1,108 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.action.admin.cluster.reroute; + +import org.elasticsearch.ElasticSearchException; +import org.elasticsearch.action.TransportActions; +import org.elasticsearch.action.support.master.TransportMasterNodeOperationAction; +import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ProcessedClusterStateUpdateTask; +import org.elasticsearch.cluster.routing.allocation.AllocationService; +import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; + +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; + +import static org.elasticsearch.cluster.ClusterState.*; + +/** + */ +public class TransportClusterRerouteAction extends TransportMasterNodeOperationAction { + + private final AllocationService allocationService; + + @Inject public TransportClusterRerouteAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, + AllocationService allocationService) { + super(settings, transportService, clusterService, threadPool); + this.allocationService = allocationService; + } + + @Override protected String executor() { + return ThreadPool.Names.CACHED; + } + + @Override protected String transportAction() { + return TransportActions.Admin.Cluster.REROUTE; + } + + @Override protected ClusterRerouteRequest newRequest() { + return new ClusterRerouteRequest(); + } + + @Override protected ClusterRerouteResponse newResponse() { + return new ClusterRerouteResponse(); + } + + @Override protected ClusterRerouteResponse masterOperation(ClusterRerouteRequest request, ClusterState state) throws ElasticSearchException { + final AtomicReference failureRef = new AtomicReference(); + final CountDownLatch latch = new CountDownLatch(1); + + clusterService.submitStateUpdateTask("cluster_reroute (api)", new ProcessedClusterStateUpdateTask() { + @Override public ClusterState execute(ClusterState currentState) { + try { + RoutingAllocation.Result routingResult = allocationService.reroute(currentState); + return newClusterStateBuilder().state(currentState).routingResult(routingResult).build(); + } catch (Exception e) { + latch.countDown(); + logger.warn("failed to reroute", e); + return currentState; + } finally { + // we don't release the latch here, only after we rerouted + } + } + + @Override public void clusterStateProcessed(ClusterState clusterState) { + latch.countDown(); + } + }); + + try { + latch.await(); + } catch (InterruptedException e) { + failureRef.set(e); + } + + if (failureRef.get() != null) { + if (failureRef.get() instanceof ElasticSearchException) { + throw (ElasticSearchException) failureRef.get(); + } else { + throw new ElasticSearchException(failureRef.get().getMessage(), failureRef.get()); + } + } + + return new ClusterRerouteResponse(); + + } +} \ No newline at end of file diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java index bee4f3d15d4..47e67eb7a54 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java @@ -37,6 +37,8 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRe import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; @@ -49,6 +51,7 @@ import org.elasticsearch.client.action.admin.cluster.node.stats.NodesStatsReques import org.elasticsearch.client.action.admin.cluster.ping.broadcast.BroadcastPingRequestBuilder; import org.elasticsearch.client.action.admin.cluster.ping.replication.ReplicationPingRequestBuilder; import org.elasticsearch.client.action.admin.cluster.ping.single.SinglePingRequestBuilder; +import org.elasticsearch.client.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.elasticsearch.client.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.client.action.admin.cluster.state.ClusterStateRequestBuilder; @@ -121,6 +124,21 @@ public interface ClusterAdminClient { */ ClusterUpdateSettingsRequestBuilder prepareUpdateSettings(); + /** + * Reroutes allocation of shards. Advance API. + */ + ActionFuture reroute(ClusterRerouteRequest request); + + /** + * Reroutes allocation of shards. Advance API. + */ + void reroute(ClusterRerouteRequest request, ActionListener listener); + + /** + * Update settings in the cluster. + */ + ClusterRerouteRequestBuilder prepareReroute(); + /** * Nodes info of the cluster. * diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java index f3df746817b..2f9808ff8ac 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java @@ -27,6 +27,7 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest; import org.elasticsearch.action.admin.cluster.ping.broadcast.BroadcastPingRequest; import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest; @@ -354,6 +355,10 @@ public class Requests { return new ClusterStateRequest(); } + public static ClusterRerouteRequest clusterRerouteRequest() { + return new ClusterRerouteRequest(); + } + public static ClusterUpdateSettingsRequest clusterUpdateSettingsRequest() { return new ClusterUpdateSettingsRequest(); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java new file mode 100644 index 00000000000..da63e1aae39 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java @@ -0,0 +1,56 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.action.admin.cluster.reroute; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; +import org.elasticsearch.client.ClusterAdminClient; +import org.elasticsearch.client.action.admin.cluster.support.BaseClusterRequestBuilder; +import org.elasticsearch.common.unit.TimeValue; + +/** + */ +public class ClusterRerouteRequestBuilder extends BaseClusterRequestBuilder { + + public ClusterRerouteRequestBuilder(ClusterAdminClient clusterClient) { + super(clusterClient, new ClusterRerouteRequest()); + } + + /** + * Sets the master node timeout in case the master has not yet been discovered. + */ + public ClusterRerouteRequestBuilder setMasterNodeTimeout(TimeValue timeout) { + request.masterNodeTimeout(timeout); + return this; + } + + /** + * Sets the master node timeout in case the master has not yet been discovered. + */ + public ClusterRerouteRequestBuilder setMasterNodeTimeout(String timeout) { + request.masterNodeTimeout(timeout); + return this; + } + + @Override protected void doExecute(ActionListener listener) { + client.reroute(request, listener); + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java index 5adac35a08d..cd5f4549166 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java @@ -45,6 +45,9 @@ import org.elasticsearch.action.admin.cluster.ping.replication.TransportReplicat import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; import org.elasticsearch.action.admin.cluster.ping.single.TransportSinglePingAction; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; +import org.elasticsearch.action.admin.cluster.reroute.TransportClusterRerouteAction; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; import org.elasticsearch.action.admin.cluster.settings.TransportClusterUpdateSettingsAction; @@ -68,6 +71,8 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement private final TransportClusterStateAction clusterStateAction; + private final TransportClusterRerouteAction clusterRerouteAction; + private final TransportClusterUpdateSettingsAction clusterUpdateSettingsAction; private final TransportSinglePingAction singlePingAction; @@ -85,10 +90,11 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement private final TransportNodesRestartAction nodesRestart; @Inject public NodeClusterAdminClient(Settings settings, ThreadPool threadPool, - TransportClusterHealthAction clusterHealthAction, TransportClusterStateAction clusterStateAction, TransportClusterUpdateSettingsAction clusterUpdateSettingsAction, + TransportClusterHealthAction clusterHealthAction, TransportClusterStateAction clusterStateAction, TransportClusterRerouteAction clusterRerouteAction, TransportClusterUpdateSettingsAction clusterUpdateSettingsAction, TransportSinglePingAction singlePingAction, TransportBroadcastPingAction broadcastPingAction, TransportReplicationPingAction replicationPingAction, TransportNodesInfoAction nodesInfoAction, TransportNodesShutdownAction nodesShutdown, TransportNodesRestartAction nodesRestart, TransportNodesStatsAction nodesStatsAction) { this.threadPool = threadPool; + this.clusterRerouteAction = clusterRerouteAction; this.clusterHealthAction = clusterHealthAction; this.clusterStateAction = clusterStateAction; this.clusterUpdateSettingsAction = clusterUpdateSettingsAction; @@ -121,6 +127,14 @@ public class NodeClusterAdminClient extends AbstractClusterAdminClient implement clusterStateAction.execute(request, listener); } + @Override public ActionFuture reroute(ClusterRerouteRequest request) { + return clusterRerouteAction.execute(request); + } + + @Override public void reroute(ClusterRerouteRequest request, ActionListener listener) { + clusterRerouteAction.execute(request, listener); + } + @Override public ActionFuture updateSettings(ClusterUpdateSettingsRequest request) { return clusterUpdateSettingsAction.execute(request); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java index a2499cd552d..da133613950 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java @@ -27,6 +27,7 @@ import org.elasticsearch.client.action.admin.cluster.node.stats.NodesStatsReques import org.elasticsearch.client.action.admin.cluster.ping.broadcast.BroadcastPingRequestBuilder; import org.elasticsearch.client.action.admin.cluster.ping.replication.ReplicationPingRequestBuilder; import org.elasticsearch.client.action.admin.cluster.ping.single.SinglePingRequestBuilder; +import org.elasticsearch.client.action.admin.cluster.reroute.ClusterRerouteRequestBuilder; import org.elasticsearch.client.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder; import org.elasticsearch.client.action.admin.cluster.state.ClusterStateRequestBuilder; import org.elasticsearch.client.internal.InternalClusterAdminClient; @@ -44,6 +45,10 @@ public abstract class AbstractClusterAdminClient implements InternalClusterAdmin return new ClusterStateRequestBuilder(this); } + @Override public ClusterRerouteRequestBuilder prepareReroute() { + return new ClusterRerouteRequestBuilder(this); + } + @Override public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() { return new ClusterUpdateSettingsRequestBuilder(this); } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java index 9d4a061cb84..caabf58dc7a 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java @@ -27,6 +27,7 @@ import org.elasticsearch.client.transport.action.admin.cluster.node.stats.Client import org.elasticsearch.client.transport.action.admin.cluster.ping.broadcast.ClientTransportBroadcastPingAction; import org.elasticsearch.client.transport.action.admin.cluster.ping.replication.ClientTransportReplicationPingAction; import org.elasticsearch.client.transport.action.admin.cluster.ping.single.ClientTransportSinglePingAction; +import org.elasticsearch.client.transport.action.admin.cluster.reroute.ClientTransportClusterRerouteAction; import org.elasticsearch.client.transport.action.admin.cluster.settings.ClientTransportClusterUpdateSettingsAction; import org.elasticsearch.client.transport.action.admin.cluster.state.ClientTransportClusterStateAction; import org.elasticsearch.client.transport.action.admin.indices.alias.ClientTransportIndicesAliasesAction; @@ -109,5 +110,6 @@ public class ClientTransportActionModule extends AbstractModule { bind(ClientTransportClusterStateAction.class).asEagerSingleton(); bind(ClientTransportClusterHealthAction.class).asEagerSingleton(); bind(ClientTransportClusterUpdateSettingsAction.class).asEagerSingleton(); + bind(ClientTransportClusterRerouteAction.class).asEagerSingleton(); } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/reroute/ClientTransportClusterRerouteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/reroute/ClientTransportClusterRerouteAction.java new file mode 100644 index 00000000000..21ff3e43c8f --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/reroute/ClientTransportClusterRerouteAction.java @@ -0,0 +1,42 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.client.transport.action.admin.cluster.reroute; + +import org.elasticsearch.action.TransportActions; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; +import org.elasticsearch.client.transport.action.support.BaseClientTransportAction; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.transport.TransportService; + +/** + * @author kimchy (Shay Banon) + */ +public class ClientTransportClusterRerouteAction extends BaseClientTransportAction { + + @Inject public ClientTransportClusterRerouteAction(Settings settings, TransportService transportService) { + super(settings, transportService, ClusterRerouteResponse.class); + } + + @Override protected String action() { + return TransportActions.Admin.Cluster.REROUTE; + } +} diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java index 1249cb5efd6..1b338201e54 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.transport.TransportService; /** - * @author kimchy (Shay Banon) */ public class ClientTransportClusterStateAction extends BaseClientTransportAction { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java index d3ff80187aa..cbd581ad21c 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java @@ -38,6 +38,8 @@ import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingRe import org.elasticsearch.action.admin.cluster.ping.replication.ReplicationPingResponse; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingRequest; import org.elasticsearch.action.admin.cluster.ping.single.SinglePingResponse; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsResponse; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; @@ -53,6 +55,7 @@ import org.elasticsearch.client.transport.action.admin.cluster.node.stats.Client import org.elasticsearch.client.transport.action.admin.cluster.ping.broadcast.ClientTransportBroadcastPingAction; import org.elasticsearch.client.transport.action.admin.cluster.ping.replication.ClientTransportReplicationPingAction; import org.elasticsearch.client.transport.action.admin.cluster.ping.single.ClientTransportSinglePingAction; +import org.elasticsearch.client.transport.action.admin.cluster.reroute.ClientTransportClusterRerouteAction; import org.elasticsearch.client.transport.action.admin.cluster.settings.ClientTransportClusterUpdateSettingsAction; import org.elasticsearch.client.transport.action.admin.cluster.state.ClientTransportClusterStateAction; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -73,6 +76,8 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli private final ClientTransportClusterStateAction clusterStateAction; + private final ClientTransportClusterRerouteAction clusterRerouteAction; + private final ClientTransportClusterUpdateSettingsAction clusterUpdateSettingsAction; private final ClientTransportSinglePingAction singlePingAction; @@ -90,12 +95,13 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli private final ClientTransportNodesRestartAction nodesRestartAction; @Inject public InternalTransportClusterAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool, - ClientTransportClusterHealthAction clusterHealthAction, ClientTransportClusterStateAction clusterStateAction, ClientTransportClusterUpdateSettingsAction clusterUpdateSettingsAction, + ClientTransportClusterHealthAction clusterHealthAction, ClientTransportClusterStateAction clusterStateAction, ClientTransportClusterRerouteAction clusterRerouteAction, ClientTransportClusterUpdateSettingsAction clusterUpdateSettingsAction, ClientTransportSinglePingAction singlePingAction, ClientTransportReplicationPingAction replicationPingAction, ClientTransportBroadcastPingAction broadcastPingAction, ClientTransportNodesInfoAction nodesInfoAction, ClientTransportNodesShutdownAction nodesShutdownAction, ClientTransportNodesRestartAction nodesRestartAction, ClientTransportNodesStatsAction nodesStatsAction) { this.nodesService = nodesService; this.threadPool = threadPool; this.clusterHealthAction = clusterHealthAction; + this.clusterRerouteAction = clusterRerouteAction; this.clusterStateAction = clusterStateAction; this.clusterUpdateSettingsAction = clusterUpdateSettingsAction; this.nodesInfoAction = nodesInfoAction; @@ -143,6 +149,22 @@ public class InternalTransportClusterAdminClient extends AbstractClusterAdminCli }, listener); } + @Override public ActionFuture reroute(final ClusterRerouteRequest request) { + return nodesService.execute(new TransportClientNodesService.NodeCallback>() { + @Override public ActionFuture doWithNode(DiscoveryNode node) throws ElasticSearchException { + return clusterRerouteAction.execute(node, request); + } + }); + } + + @Override public void reroute(final ClusterRerouteRequest request, final ActionListener listener) { + nodesService.execute(new TransportClientNodesService.NodeListenerCallback() { + @Override public void doWithNode(DiscoveryNode node, ActionListener listener) throws ElasticSearchException { + clusterRerouteAction.execute(node, request, listener); + } + }, listener); + } + @Override public ActionFuture updateSettings(final ClusterUpdateSettingsRequest request) { return nodesService.execute(new TransportClientNodesService.NodeCallback>() { @Override public ActionFuture doWithNode(DiscoveryNode node) throws ElasticSearchException { diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java index a9cc4ffa7fa..085baba9f59 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java @@ -30,6 +30,7 @@ import org.elasticsearch.rest.action.admin.cluster.node.stats.RestNodesStatsActi import org.elasticsearch.rest.action.admin.cluster.ping.broadcast.RestBroadcastPingAction; import org.elasticsearch.rest.action.admin.cluster.ping.replication.RestReplicationPingAction; import org.elasticsearch.rest.action.admin.cluster.ping.single.RestSinglePingAction; +import org.elasticsearch.rest.action.admin.cluster.reroute.RestClusterRerouteAction; import org.elasticsearch.rest.action.admin.cluster.settings.RestClusterGetSettingsAction; import org.elasticsearch.rest.action.admin.cluster.settings.RestClusterUpdateSettingsAction; import org.elasticsearch.rest.action.admin.cluster.state.RestClusterStateAction; @@ -97,6 +98,7 @@ public class RestActionModule extends AbstractModule { bind(RestClusterHealthAction.class).asEagerSingleton(); bind(RestClusterUpdateSettingsAction.class).asEagerSingleton(); bind(RestClusterGetSettingsAction.class).asEagerSingleton(); + bind(RestClusterRerouteAction.class).asEagerSingleton(); bind(RestSinglePingAction.class).asEagerSingleton(); bind(RestBroadcastPingAction.class).asEagerSingleton(); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java new file mode 100644 index 00000000000..d8ddb2e56a8 --- /dev/null +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java @@ -0,0 +1,73 @@ +/* + * Licensed to Elastic Search and Shay Banon under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. Elastic Search licenses this + * file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.rest.action.admin.cluster.reroute; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; +import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.Requests; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestChannel; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.RestStatus; +import org.elasticsearch.rest.StringRestResponse; +import org.elasticsearch.rest.XContentThrowableRestResponse; + +import java.io.IOException; + +/** + */ +public class RestClusterRerouteAction extends BaseRestHandler { + + @Inject public RestClusterRerouteAction(Settings settings, Client client, RestController controller, + SettingsFilter settingsFilter) { + super(settings, client); + controller.registerHandler(RestRequest.Method.POST, "/_cluster/reroute", this); + } + + @Override public void handleRequest(final RestRequest request, final RestChannel channel) { + final ClusterRerouteRequest clusterRerouteRequest = Requests.clusterRerouteRequest(); + client.admin().cluster().reroute(clusterRerouteRequest, new ActionListener() { + @Override public void onResponse(ClusterRerouteResponse response) { + try { + channel.sendResponse(new StringRestResponse(RestStatus.OK)); + } catch (Exception e) { + onFailure(e); + } + } + + @Override public void onFailure(Throwable e) { + if (logger.isDebugEnabled()) { + logger.debug("failed to handle cluster reroute", e); + } + try { + channel.sendResponse(new XContentThrowableRestResponse(request, e)); + } catch (IOException e1) { + logger.error("Failed to send failure response", e1); + } + } + }); + } +} \ No newline at end of file