Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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