forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add REST scaffolding for node shutdown API (elastic#70697)
This commit adds the rest endpoints for the node shutdown API. These APIs are behind the `es.shutdown_feature_flag_enabled` feature flag for now, as development is ongoing. Currently these APIs do not do anything, returning immediately. We plan to implement them for real in subsequent work. Relates to elastic#70338
- Loading branch information
Showing
17 changed files
with
701 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
apply plugin: 'elasticsearch.esplugin' | ||
|
||
esplugin { | ||
name 'x-pack-shutdown' | ||
description 'Elasticsearch Expanded Pack Plugin - Shutdown' | ||
classname 'org.elasticsearch.xpack.shutdown.ShutdownPlugin' | ||
extendedPlugins = ['x-pack-core'] | ||
} | ||
archivesBaseName = 'x-pack-shutdown' | ||
|
||
dependencies { | ||
compileOnly project(path: xpackModule('core')) | ||
testImplementation(testArtifact(project(xpackModule('core')))) | ||
} | ||
|
||
addQaCheckDependencies() |
61 changes: 61 additions & 0 deletions
61
...gin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/DeleteShutdownNodeAction.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,61 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.shutdown; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
public class DeleteShutdownNodeAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final DeleteShutdownNodeAction INSTANCE = new DeleteShutdownNodeAction(); | ||
public static final String NAME = "cluster:admin/shutdown/delete"; | ||
|
||
public DeleteShutdownNodeAction() { | ||
super(NAME, AcknowledgedResponse::readFrom); | ||
} | ||
|
||
public static class Request extends MasterNodeRequest<DeleteShutdownNodeAction.Request> { | ||
|
||
private final String nodeId; | ||
|
||
public Request(String nodeId) { | ||
this.nodeId = nodeId; | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
this.nodeId = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(this.nodeId); | ||
} | ||
|
||
public String getNodeId() { | ||
return nodeId; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (Strings.hasText(nodeId) == false) { | ||
ActionRequestValidationException arve = new ActionRequestValidationException(); | ||
arve.addValidationError("the node id to remove from shutdown is required"); | ||
return arve; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
...ugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/GetShutdownStatusAction.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,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.shutdown; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionResponse; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
public class GetShutdownStatusAction extends ActionType<GetShutdownStatusAction.Response> { | ||
|
||
public static final GetShutdownStatusAction INSTANCE = new GetShutdownStatusAction(); | ||
public static final String NAME = "cluster:admin/shutdown/get"; | ||
|
||
public GetShutdownStatusAction() { | ||
super(NAME, Response::new); | ||
} | ||
|
||
public static class Request extends MasterNodeRequest<Request> { | ||
|
||
private final String[] nodeIds; | ||
|
||
public Request(String... nodeIds) { | ||
this.nodeIds = nodeIds; | ||
} | ||
|
||
public static Request readFrom(StreamInput in) throws IOException { | ||
return new Request(in.readStringArray()); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeStringArray(this.nodeIds); | ||
} | ||
|
||
public String[] getNodeIds() { | ||
return nodeIds; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} | ||
|
||
public static class Response extends ActionResponse implements ToXContentObject { | ||
|
||
public Response(StreamInput in) throws IOException { | ||
|
||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
|
||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/PutShutdownNodeAction.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,60 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.shutdown; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.action.ActionType; | ||
import org.elasticsearch.action.support.master.AcknowledgedResponse; | ||
import org.elasticsearch.action.support.master.MasterNodeRequest; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
|
||
import java.io.IOException; | ||
|
||
public class PutShutdownNodeAction extends ActionType<AcknowledgedResponse> { | ||
|
||
public static final PutShutdownNodeAction INSTANCE = new PutShutdownNodeAction(); | ||
public static final String NAME = "cluster:admin/shutdown/create"; | ||
|
||
public PutShutdownNodeAction() { | ||
super(NAME, AcknowledgedResponse::readFrom); | ||
} | ||
|
||
public static class Request extends MasterNodeRequest<Request> { | ||
|
||
private final String nodeId; | ||
|
||
public Request(String nodeId) { | ||
this.nodeId = nodeId; | ||
} | ||
|
||
public Request(StreamInput in) throws IOException { | ||
this.nodeId = in.readString(); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
out.writeString(this.nodeId); | ||
} | ||
|
||
public String getNodeId() { | ||
return nodeId; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
if (Strings.hasText(nodeId) == false) { | ||
ActionRequestValidationException arve = new ActionRequestValidationException(); | ||
arve.addValidationError("the node id to shutdown is required"); | ||
return arve; | ||
} | ||
return null; | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...shutdown/src/main/java/org/elasticsearch/xpack/shutdown/RestDeleteShutdownNodeAction.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,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.shutdown; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.util.List; | ||
|
||
public class RestDeleteShutdownNodeAction extends BaseRestHandler { | ||
|
||
@Override | ||
public String getName() { | ||
return "delete_shutdown_node"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(RestRequest.Method.DELETE, "/_nodes/{nodeId}/shutdown")); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
String nodeId = request.param("nodeId"); | ||
return channel -> client.execute( | ||
DeleteShutdownNodeAction.INSTANCE, | ||
new DeleteShutdownNodeAction.Request(nodeId), | ||
new RestToXContentListener<>(channel) | ||
); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
.../shutdown/src/main/java/org/elasticsearch/xpack/shutdown/RestGetShutdownStatusAction.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,42 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.shutdown; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.util.List; | ||
|
||
public class RestGetShutdownStatusAction extends BaseRestHandler { | ||
|
||
@Override | ||
public String getName() { | ||
return "get_shutdown_status"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of( | ||
new Route(RestRequest.Method.GET, "/_nodes/{nodeId}/shutdown"), | ||
new Route(RestRequest.Method.GET, "/_nodes/shutdown") | ||
); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
String[] nodeIds = Strings.commaDelimitedListToStringArray(request.param("nodeId")); | ||
return channel -> client.execute( | ||
GetShutdownStatusAction.INSTANCE, | ||
new GetShutdownStatusAction.Request(nodeIds), | ||
new RestToXContentListener<>(channel) | ||
); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...in/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/RestPutShutdownNodeAction.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,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.shutdown; | ||
|
||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.util.List; | ||
|
||
public class RestPutShutdownNodeAction extends BaseRestHandler { | ||
|
||
@Override | ||
public String getName() { | ||
return "put_shutdown_node"; | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(RestRequest.Method.PUT, "/_nodes/{nodeId}/shutdown")); | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
String nodeId = request.param("nodeId"); | ||
return channel -> client.execute( | ||
PutShutdownNodeAction.INSTANCE, | ||
new PutShutdownNodeAction.Request(nodeId), | ||
new RestToXContentListener<>(channel) | ||
); | ||
} | ||
} |
Oops, something went wrong.