Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shutdown API: allow to shutdown node(s) or the whole, closes #64.
- Loading branch information
Showing
23 changed files
with
548 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
.../main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.node.shutdown; | ||
|
||
import org.elasticsearch.action.support.nodes.NodesOperationRequest; | ||
import org.elasticsearch.util.TimeValue; | ||
|
||
import java.io.DataInput; | ||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
|
||
import static org.elasticsearch.util.TimeValue.*; | ||
|
||
/** | ||
* A request to shutdown one ore more nodes (or the whole cluster). | ||
* | ||
* @author kimchy (shay.banon) | ||
*/ | ||
public class NodesShutdownRequest extends NodesOperationRequest { | ||
|
||
TimeValue delay = TimeValue.timeValueSeconds(1); | ||
|
||
protected NodesShutdownRequest() { | ||
} | ||
|
||
/** | ||
* Shuts down nodes based on the nodes ids specified. If none are passed, <b>all</b> | ||
* nodes will be shutdown. | ||
*/ | ||
public NodesShutdownRequest(String... nodesIds) { | ||
super(nodesIds); | ||
} | ||
|
||
/** | ||
* The delay for the shutdown to occur. Defaults to <tt>1s</tt>. | ||
*/ | ||
public NodesShutdownRequest delay(TimeValue delay) { | ||
this.delay = delay; | ||
return this; | ||
} | ||
|
||
public TimeValue delay() { | ||
return this.delay; | ||
} | ||
|
||
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException { | ||
super.readFrom(in); | ||
delay = readTimeValue(in); | ||
} | ||
|
||
@Override public void writeTo(DataOutput out) throws IOException { | ||
super.writeTo(out); | ||
delay.writeTo(out); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...main/java/org/elasticsearch/action/admin/cluster/node/shutdown/NodesShutdownResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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.node.shutdown; | ||
|
||
import org.elasticsearch.action.support.nodes.NodeOperationResponse; | ||
import org.elasticsearch.action.support.nodes.NodesOperationResponse; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.node.Node; | ||
|
||
import java.io.DataInput; | ||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author kimchy (Shay Banon) | ||
*/ | ||
public class NodesShutdownResponse extends NodesOperationResponse<NodesShutdownResponse.NodeShutdownResponse> { | ||
|
||
NodesShutdownResponse() { | ||
} | ||
|
||
public NodesShutdownResponse(ClusterName clusterName, NodeShutdownResponse[] nodes) { | ||
super(clusterName, nodes); | ||
} | ||
|
||
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException { | ||
super.readFrom(in); | ||
nodes = new NodeShutdownResponse[in.readInt()]; | ||
for (int i = 0; i < nodes.length; i++) { | ||
nodes[i] = NodeShutdownResponse.readNodeShutdownResponse(in); | ||
} | ||
} | ||
|
||
@Override public void writeTo(DataOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeInt(nodes.length); | ||
for (NodeShutdownResponse node : nodes) { | ||
node.writeTo(out); | ||
} | ||
} | ||
|
||
public static class NodeShutdownResponse extends NodeOperationResponse { | ||
|
||
NodeShutdownResponse() { | ||
} | ||
|
||
public NodeShutdownResponse(Node node) { | ||
super(node); | ||
} | ||
|
||
public static NodeShutdownResponse readNodeShutdownResponse(DataInput in) throws ClassNotFoundException, IOException { | ||
NodeShutdownResponse res = new NodeShutdownResponse(); | ||
res.readFrom(in); | ||
return res; | ||
} | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
...ain/java/org/elasticsearch/action/admin/cluster/node/shutdown/TransportNodesShutdown.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* 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.node.shutdown; | ||
|
||
import com.google.inject.Inject; | ||
import org.elasticsearch.ElasticSearchException; | ||
import org.elasticsearch.ElasticSearchIllegalStateException; | ||
import org.elasticsearch.action.TransportActions; | ||
import org.elasticsearch.action.support.nodes.NodeOperationRequest; | ||
import org.elasticsearch.action.support.nodes.TransportNodesOperationAction; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterService; | ||
import org.elasticsearch.server.Server; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.util.TimeValue; | ||
import org.elasticsearch.util.settings.Settings; | ||
|
||
import java.io.DataInput; | ||
import java.io.DataOutput; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicReferenceArray; | ||
|
||
import static com.google.common.collect.Lists.*; | ||
import static org.elasticsearch.util.TimeValue.*; | ||
|
||
/** | ||
* @author kimchy (shay.banon) | ||
*/ | ||
public class TransportNodesShutdown extends TransportNodesOperationAction<NodesShutdownRequest, NodesShutdownResponse, TransportNodesShutdown.NodeShutdownRequest, NodesShutdownResponse.NodeShutdownResponse> { | ||
|
||
private final Server server; | ||
|
||
private final boolean disabled; | ||
|
||
@Inject public TransportNodesShutdown(Settings settings, ClusterName clusterName, ThreadPool threadPool, | ||
ClusterService clusterService, TransportService transportService, | ||
Server server) { | ||
super(settings, clusterName, threadPool, clusterService, transportService); | ||
this.server = server; | ||
disabled = componentSettings.getAsBoolean("disabled", false); | ||
} | ||
|
||
@Override protected String transportAction() { | ||
return TransportActions.Admin.Cluster.Node.SHUTDOWN; | ||
} | ||
|
||
@Override protected String transportNodeAction() { | ||
return "/cluster/nodes/shutdown/node"; | ||
} | ||
|
||
@Override protected NodesShutdownResponse newResponse(NodesShutdownRequest nodesShutdownRequest, AtomicReferenceArray responses) { | ||
final List<NodesShutdownResponse.NodeShutdownResponse> nodeShutdownResponses = newArrayList(); | ||
for (int i = 0; i < responses.length(); i++) { | ||
Object resp = responses.get(i); | ||
if (resp instanceof NodesShutdownResponse.NodeShutdownResponse) { | ||
nodeShutdownResponses.add((NodesShutdownResponse.NodeShutdownResponse) resp); | ||
} | ||
} | ||
return new NodesShutdownResponse(clusterName, nodeShutdownResponses.toArray(new NodesShutdownResponse.NodeShutdownResponse[nodeShutdownResponses.size()])); | ||
} | ||
|
||
@Override protected NodesShutdownRequest newRequest() { | ||
return new NodesShutdownRequest(); | ||
} | ||
|
||
@Override protected NodeShutdownRequest newNodeRequest() { | ||
return new NodeShutdownRequest(); | ||
} | ||
|
||
@Override protected NodeShutdownRequest newNodeRequest(String nodeId, NodesShutdownRequest request) { | ||
return new NodeShutdownRequest(nodeId, request.delay); | ||
} | ||
|
||
@Override protected NodesShutdownResponse.NodeShutdownResponse newNodeResponse() { | ||
return new NodesShutdownResponse.NodeShutdownResponse(); | ||
} | ||
|
||
@Override protected NodesShutdownResponse.NodeShutdownResponse nodeOperation(NodeShutdownRequest request) throws ElasticSearchException { | ||
if (disabled) { | ||
throw new ElasticSearchIllegalStateException("Shutdown is disabled"); | ||
} | ||
logger.info("Shutting down in [{}]", request.delay); | ||
threadPool.schedule(new Runnable() { | ||
@Override public void run() { | ||
server.close(); | ||
} | ||
}, request.delay.millis(), TimeUnit.MILLISECONDS); | ||
return new NodesShutdownResponse.NodeShutdownResponse(clusterService.state().nodes().localNode()); | ||
} | ||
|
||
@Override protected boolean accumulateExceptions() { | ||
return false; | ||
} | ||
|
||
protected static class NodeShutdownRequest extends NodeOperationRequest { | ||
|
||
TimeValue delay; | ||
|
||
private NodeShutdownRequest() { | ||
} | ||
|
||
private NodeShutdownRequest(String nodeId, TimeValue delay) { | ||
super(nodeId); | ||
this.delay = delay; | ||
} | ||
|
||
@Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException { | ||
super.readFrom(in); | ||
delay = readTimeValue(in); | ||
} | ||
|
||
@Override public void writeTo(DataOutput out) throws IOException { | ||
super.writeTo(out); | ||
delay.writeTo(out); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.