Permalink
Browse files

add internal cluster reroute api

  • Loading branch information...
1 parent 1047ceb commit bcd582b8c121fdc63f3d33a77924b70dd1141c25 @kimchy kimchy committed Oct 16, 2011
Showing with 439 additions and 3 deletions.
  1. +2 −0 modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java
  2. +1 −0 modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java
  3. +47 −0 ...ticsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java
  4. +40 −0 ...icsearch/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteResponse.java
  5. +108 −0 ...h/src/main/java/org/elasticsearch/action/admin/cluster/reroute/TransportClusterRerouteAction.java
  6. +18 −0 modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java
  7. +5 −0 modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java
  8. +56 −0 ...main/java/org/elasticsearch/client/action/admin/cluster/reroute/ClusterRerouteRequestBuilder.java
  9. +15 −1 modules/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java
  10. +5 −0 modules/elasticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java
  11. +2 −0 ...icsearch/src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java
  12. +42 −0 ...sticsearch/client/transport/action/admin/cluster/reroute/ClientTransportClusterRerouteAction.java
  13. +0 −1 .../elasticsearch/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java
  14. +23 −1 ...src/main/java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java
  15. +2 −0 modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java
  16. +73 −0 ...h/src/main/java/org/elasticsearch/rest/action/admin/cluster/reroute/RestClusterRerouteAction.java
View
2 modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActionModule.java
@@ -29,6 +29,7 @@
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 @@
bind(TransportClusterStateAction.class).asEagerSingleton();
bind(TransportClusterHealthAction.class).asEagerSingleton();
bind(TransportClusterUpdateSettingsAction.class).asEagerSingleton();
+ bind(TransportClusterRerouteAction.class).asEagerSingleton();
bind(TransportSinglePingAction.class).asEagerSingleton();
bind(TransportBroadcastPingAction.class).asEagerSingleton();
View
1 modules/elasticsearch/src/main/java/org/elasticsearch/action/TransportActions.java
@@ -87,6 +87,7 @@
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";
View
47 ...h/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);
+ }
+}
View
40 .../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 {
+ }
+}
View
108 ...in/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<ClusterRerouteRequest, ClusterRerouteResponse> {
+
+ 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<Throwable> failureRef = new AtomicReference<Throwable>();
+ 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();
+
+ }
+}
View
18 modules/elasticsearch/src/main/java/org/elasticsearch/client/ClusterAdminClient.java
@@ -37,6 +37,8 @@
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.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;
@@ -122,6 +125,21 @@
ClusterUpdateSettingsRequestBuilder prepareUpdateSettings();
/**
+ * Reroutes allocation of shards. Advance API.
+ */
+ ActionFuture<ClusterRerouteResponse> reroute(ClusterRerouteRequest request);
+
+ /**
+ * Reroutes allocation of shards. Advance API.
+ */
+ void reroute(ClusterRerouteRequest request, ActionListener<ClusterRerouteResponse> listener);
+
+ /**
+ * Update settings in the cluster.
+ */
+ ClusterRerouteRequestBuilder prepareReroute();
+
+ /**
* Nodes info of the cluster.
*
* @param request The nodes info request
View
5 modules/elasticsearch/src/main/java/org/elasticsearch/client/Requests.java
@@ -27,6 +27,7 @@
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 static ClusterStateRequest clusterStateRequest() {
return new ClusterStateRequest();
}
+ public static ClusterRerouteRequest clusterRerouteRequest() {
+ return new ClusterRerouteRequest();
+ }
+
public static ClusterUpdateSettingsRequest clusterUpdateSettingsRequest() {
return new ClusterUpdateSettingsRequest();
}
View
56 ...a/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<ClusterRerouteRequest, ClusterRerouteResponse> {
+
+ 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<ClusterRerouteResponse> listener) {
+ client.reroute(request, listener);
+ }
+}
View
16 ...les/elasticsearch/src/main/java/org/elasticsearch/client/node/NodeClusterAdminClient.java
@@ -45,6 +45,9 @@
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 @@
private final TransportClusterStateAction clusterStateAction;
+ private final TransportClusterRerouteAction clusterRerouteAction;
+
private final TransportClusterUpdateSettingsAction clusterUpdateSettingsAction;
private final TransportSinglePingAction singlePingAction;
@@ -85,10 +90,11 @@
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 @@
clusterStateAction.execute(request, listener);
}
+ @Override public ActionFuture<ClusterRerouteResponse> reroute(ClusterRerouteRequest request) {
+ return clusterRerouteAction.execute(request);
+ }
+
+ @Override public void reroute(ClusterRerouteRequest request, ActionListener<ClusterRerouteResponse> listener) {
+ clusterRerouteAction.execute(request, listener);
+ }
+
@Override public ActionFuture<ClusterUpdateSettingsResponse> updateSettings(ClusterUpdateSettingsRequest request) {
return clusterUpdateSettingsAction.execute(request);
}
View
5 ...sticsearch/src/main/java/org/elasticsearch/client/support/AbstractClusterAdminClient.java
@@ -27,6 +27,7 @@
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 @@
return new ClusterStateRequestBuilder(this);
}
+ @Override public ClusterRerouteRequestBuilder prepareReroute() {
+ return new ClusterRerouteRequestBuilder(this);
+ }
+
@Override public ClusterUpdateSettingsRequestBuilder prepareUpdateSettings() {
return new ClusterUpdateSettingsRequestBuilder(this);
}
View
2 .../src/main/java/org/elasticsearch/client/transport/action/ClientTransportActionModule.java
@@ -27,6 +27,7 @@
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 @@
bind(ClientTransportClusterStateAction.class).asEagerSingleton();
bind(ClientTransportClusterHealthAction.class).asEagerSingleton();
bind(ClientTransportClusterUpdateSettingsAction.class).asEagerSingleton();
+ bind(ClientTransportClusterRerouteAction.class).asEagerSingleton();
}
}
View
42 ...ch/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<ClusterRerouteRequest, ClusterRerouteResponse> {
+
+ @Inject public ClientTransportClusterRerouteAction(Settings settings, TransportService transportService) {
+ super(settings, transportService, ClusterRerouteResponse.class);
+ }
+
+ @Override protected String action() {
+ return TransportActions.Admin.Cluster.REROUTE;
+ }
+}
View
1 ...search/client/transport/action/admin/cluster/state/ClientTransportClusterStateAction.java
@@ -28,7 +28,6 @@
import org.elasticsearch.transport.TransportService;
/**
- * @author kimchy (Shay Banon)
*/
public class ClientTransportClusterStateAction extends BaseClientTransportAction<ClusterStateRequest, ClusterStateResponse> {
View
24 .../java/org/elasticsearch/client/transport/support/InternalTransportClusterAdminClient.java
@@ -38,6 +38,8 @@
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.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 @@
private final ClientTransportClusterStateAction clusterStateAction;
+ private final ClientTransportClusterRerouteAction clusterRerouteAction;
+
private final ClientTransportClusterUpdateSettingsAction clusterUpdateSettingsAction;
private final ClientTransportSinglePingAction singlePingAction;
@@ -90,12 +95,13 @@
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 @@
}, listener);
}
+ @Override public ActionFuture<ClusterRerouteResponse> reroute(final ClusterRerouteRequest request) {
+ return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<ClusterRerouteResponse>>() {
+ @Override public ActionFuture<ClusterRerouteResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {
+ return clusterRerouteAction.execute(node, request);
+ }
+ });
+ }
+
+ @Override public void reroute(final ClusterRerouteRequest request, final ActionListener<ClusterRerouteResponse> listener) {
+ nodesService.execute(new TransportClientNodesService.NodeListenerCallback<ClusterRerouteResponse>() {
+ @Override public void doWithNode(DiscoveryNode node, ActionListener<ClusterRerouteResponse> listener) throws ElasticSearchException {
+ clusterRerouteAction.execute(node, request, listener);
+ }
+ }, listener);
+ }
+
@Override public ActionFuture<ClusterUpdateSettingsResponse> updateSettings(final ClusterUpdateSettingsRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<ClusterUpdateSettingsResponse>>() {
@Override public ActionFuture<ClusterUpdateSettingsResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {
View
2 modules/elasticsearch/src/main/java/org/elasticsearch/rest/action/RestActionModule.java
@@ -30,6 +30,7 @@
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 RestActionModule(List<Class<? extends BaseRestHandler>> restPluginsAction
bind(RestClusterHealthAction.class).asEagerSingleton();
bind(RestClusterUpdateSettingsAction.class).asEagerSingleton();
bind(RestClusterGetSettingsAction.class).asEagerSingleton();
+ bind(RestClusterRerouteAction.class).asEagerSingleton();
bind(RestSinglePingAction.class).asEagerSingleton();
bind(RestBroadcastPingAction.class).asEagerSingleton();
View
73 ...in/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<ClusterRerouteResponse>() {
+ @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);
+ }
+ }
+ });
+ }
+}

0 comments on commit bcd582b

Please sign in to comment.