Skip to content

Commit

Permalink
Add REST scaffolding for node shutdown API (elastic#70697)
Browse files Browse the repository at this point in the history
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
dakrone authored Mar 23, 2021
1 parent 1f6a66d commit 5764a18
Show file tree
Hide file tree
Showing 17 changed files with 701 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ testClusters.matching { it.name == "integTest"}.configureEach {
setting 'xpack.license.self_generated.type', 'trial'
setting 'indices.lifecycle.history_index_enabled', 'false'
systemProperty 'es.rollup_v2_feature_flag_enabled', 'true'
systemProperty 'es.shutdown_feature_flag_enabled', 'true'
keystorePassword 'keystore-password'
}

Expand Down
1 change: 1 addition & 0 deletions gradle/run.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ testClusters {
setting 'xpack.security.enabled', 'true'
keystore 'bootstrap.password', 'password'
user username: 'elastic-admin', password: 'elastic-password', role: 'superuser'
systemProperty 'es.shutdown_feature_flag_enabled', 'true'
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugin/shutdown/build.gradle
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()
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;
}
}

}
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 {

}
}
}
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;
}
}
}
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)
);
}
}
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)
);
}
}
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)
);
}
}
Loading

0 comments on commit 5764a18

Please sign in to comment.