add internal cluster reroute api
This commit is contained in:
parent
1047cebabe
commit
bcd582b8c1
|
@ -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();
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
||||
}
|
||||
}
|
|
@ -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<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.
|
||||
*
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,6 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.transport.TransportService;
|
||||
|
||||
/**
|
||||
* @author kimchy (Shay Banon)
|
||||
*/
|
||||
public class ClientTransportClusterStateAction extends BaseClientTransportAction<ClusterStateRequest, ClusterStateResponse> {
|
||||
|
||||
|
|
|
@ -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<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 {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue