Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft]: Recommission api support #4271

Closed
wants to merge 3 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,8 @@ public void testApiNamingConventions() throws Exception {
"nodes.usage",
"nodes.reload_secure_settings",
"search_shards",
"remote_store.restore", };
"remote_store.restore",
"cluster.management_decommission", };
List<String> booleanReturnMethods = Arrays.asList("security.enable_user", "security.disable_user", "security.change_password");
Set<String> deprecatedMethods = new HashSet<>();
deprecatedMethods.add("indices.force_merge");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"cluster.management_decommission": {
"documentation": {
"url": "TBA",
"description": "TBA"
},
"stability": "experimental",
"url": {
"paths": [
{
"path": "/_cluster/management/decommission",
"methods": [
"PUT"
]
}
]
},
"params":{
"node_ids":{
"type":"string",
"description":"A comma-separated list of the persistent ids of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_names."
},
"node_names":{
"type":"string",
"description":"A comma-separated list of the names of the nodes to exclude from the voting configuration. If specified, you may not also specify ?node_ids."
},
"timeout":{
"type":"time",
"description":"Explicit operation timeout",
"default":"30s"
}
},
"body":{
"description":"Node attribute for decommissioning",
"required":false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1601,8 +1601,13 @@ private enum OpenSearchExceptionHandle {
org.opensearch.indices.replication.common.ReplicationFailedException::new,
161,
V_2_1_0
),
DECOMMISSION_FAILED_EXCEPTION(
org.opensearch.cluster.decommission.DecommissionFailedException.class,
org.opensearch.cluster.decommission.DecommissionFailedException::new,
162,
V_2_1_0
);

final Class<? extends OpenSearchException> exceptionClass;
final CheckedFunction<StreamInput, ? extends OpenSearchException, IOException> constructor;
final int id;
Expand Down
15 changes: 15 additions & 0 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@
import org.opensearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
import org.opensearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction;
import org.opensearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction;
import org.opensearch.action.admin.cluster.decommission.delete.DeleteDecommissionAction;
import org.opensearch.action.admin.cluster.decommission.delete.TransportDeleteDecommissionAction;
import org.opensearch.action.admin.cluster.decommission.get.GetDecommissionAction;
import org.opensearch.action.admin.cluster.decommission.get.TransportGetDecommissionAction;
import org.opensearch.action.admin.cluster.health.ClusterHealthAction;
import org.opensearch.action.admin.cluster.health.TransportClusterHealthAction;
import org.opensearch.action.admin.cluster.decommission.put.PutDecommissionAction;
import org.opensearch.action.admin.cluster.decommission.put.TransportPutDecommissionAction;
import org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction;
import org.opensearch.action.admin.cluster.node.hotthreads.TransportNodesHotThreadsAction;
import org.opensearch.action.admin.cluster.node.info.NodesInfoAction;
Expand Down Expand Up @@ -298,9 +304,11 @@
import org.opensearch.rest.action.admin.cluster.RestClusterStatsAction;
import org.opensearch.rest.action.admin.cluster.RestClusterUpdateSettingsAction;
import org.opensearch.rest.action.admin.cluster.RestCreateSnapshotAction;
import org.opensearch.rest.action.admin.cluster.RestDeleteDecommissionAction;
import org.opensearch.rest.action.admin.cluster.RestDeleteRepositoryAction;
import org.opensearch.rest.action.admin.cluster.RestDeleteSnapshotAction;
import org.opensearch.rest.action.admin.cluster.RestDeleteStoredScriptAction;
import org.opensearch.rest.action.admin.cluster.RestGetDecommissionAction;
import org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction;
import org.opensearch.rest.action.admin.cluster.RestGetScriptContextAction;
import org.opensearch.rest.action.admin.cluster.RestGetScriptLanguageAction;
Expand All @@ -313,6 +321,7 @@
import org.opensearch.rest.action.admin.cluster.RestNodesStatsAction;
import org.opensearch.rest.action.admin.cluster.RestNodesUsageAction;
import org.opensearch.rest.action.admin.cluster.RestPendingClusterTasksAction;
import org.opensearch.rest.action.admin.cluster.RestPutDecommissionAction;
import org.opensearch.rest.action.admin.cluster.RestPutRepositoryAction;
import org.opensearch.rest.action.admin.cluster.RestPutStoredScriptAction;
import org.opensearch.rest.action.admin.cluster.RestReloadSecureSettingsAction;
Expand Down Expand Up @@ -556,6 +565,9 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
actions.register(CloneSnapshotAction.INSTANCE, TransportCloneSnapshotAction.class);
actions.register(RestoreSnapshotAction.INSTANCE, TransportRestoreSnapshotAction.class);
actions.register(SnapshotsStatusAction.INSTANCE, TransportSnapshotsStatusAction.class);
actions.register(PutDecommissionAction.INSTANCE, TransportPutDecommissionAction.class);
actions.register(GetDecommissionAction.INSTANCE, TransportGetDecommissionAction.class);
actions.register(DeleteDecommissionAction.INSTANCE, TransportDeleteDecommissionAction.class);

actions.register(IndicesStatsAction.INSTANCE, TransportIndicesStatsAction.class);
actions.register(IndicesSegmentsAction.INSTANCE, TransportIndicesSegmentsAction.class);
Expand Down Expand Up @@ -860,6 +872,9 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
}
}
registerHandler.accept(new RestCatAction(catActions));
registerHandler.accept(new RestPutDecommissionAction());
registerHandler.accept(new RestGetDecommissionAction());
registerHandler.accept(new RestDeleteDecommissionAction());

// Remote Store APIs
if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.decommission.delete;

import org.opensearch.action.ActionType;

public class DeleteDecommissionAction extends ActionType<DeleteDecommissionResponse> {
public static final DeleteDecommissionAction INSTANCE = new DeleteDecommissionAction();
public static final String NAME = "cluster:admin/management/decommission/delete";

private DeleteDecommissionAction() {
super(NAME, DeleteDecommissionResponse::new);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.decommission.delete;

import org.opensearch.OpenSearchGenerationException;
import org.opensearch.OpenSearchParseException;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.action.admin.cluster.decommission.put.PutDecommissionRequest;
import org.opensearch.action.support.master.AcknowledgedRequest;
import org.opensearch.cluster.decommission.DecommissionAttribute;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.DeprecationHandler;
import org.opensearch.common.xcontent.NamedXContentRegistry;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentParser;
import org.opensearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class DeleteDecommissionRequest extends AcknowledgedRequest<DeleteDecommissionRequest> {
private String name;
private DecommissionAttribute decommissionAttribute;

public DeleteDecommissionRequest() {
}

public DeleteDecommissionRequest(String name, DecommissionAttribute decommissionAttribute) {
this.name = name;
this.decommissionAttribute = decommissionAttribute;
}

public DeleteDecommissionRequest(StreamInput in) throws IOException {
super(in);
name = in.readString();
decommissionAttribute = new DecommissionAttribute(in);
}

/**
* Sets the decommission attribute name for decommission request
*
* @param name of the decommission attribute
* @return the current object
*/
public DeleteDecommissionRequest setName(String name) {
this.name = name;
return this;
}

/**
* @return Returns the name of the decommission attribute
*/
public String getName() {
return this.name;
}

/**
* Sets decommission attribute for decommission request
*
* @param decommissionAttribute values that needs to be decommissioned
* @return the current object
*/
public DeleteDecommissionRequest setDecommissionAttribute(DecommissionAttribute decommissionAttribute) {
this.decommissionAttribute = decommissionAttribute;
return this;
}

public DeleteDecommissionRequest setDecommissionAttribute(Map<String, Object> source) {
try {
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.map(source);
return setDecommissionAttribute(BytesReference.bytes(builder), builder.contentType());
} catch (IOException e) {
throw new OpenSearchGenerationException("Failed to generate [" + source + "]", e);
}
}

public DeleteDecommissionRequest setDecommissionAttribute(BytesReference source, XContentType contentType) {
try (
XContentParser parser = XContentHelper.createParser(
NamedXContentRegistry.EMPTY,
DeprecationHandler.THROW_UNSUPPORTED_OPERATION,
source,
contentType
)
) {
XContentParser.Token token;
if ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
token = parser.nextToken();
if (token == XContentParser.Token.FIELD_NAME) {
String fieldName = parser.currentName();
String value;
token = parser.nextToken();
if (token == XContentParser.Token.VALUE_STRING) {
value = parser.text();
} else {
throw new OpenSearchParseException("failed to parse attribute [{}], expected string for attribute value", fieldName);
}
decommissionAttribute = new DecommissionAttribute(fieldName, value);
} else {
throw new OpenSearchParseException("failed to parse attribute type, unexpected type");
}
}
return this;
} catch (IOException e) {
throw new OpenSearchParseException("Failed to parse decommission attribute", e);
}
}

/**
* @return Returns the decommission attribute values
*/
public DecommissionAttribute getDecommissionAttribute() {
return this.decommissionAttribute;
}

@SuppressWarnings("unchecked")
public DeleteDecommissionRequest source(Map<String, Object> source) {
for (Map.Entry<String, ?> entry : source.entrySet()) {
setName(entry.getKey());
if (!(entry.getValue() instanceof Map)) {
throw new OpenSearchParseException("key [decommissionAttribute] must be an object");
}
setDecommissionAttribute((Map<String, Object>) entry.getValue());
}
return this;
}

@Override
public ActionRequestValidationException validate() {
// TODO - Add request validators here
return null;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(name);
decommissionAttribute.writeTo(out);
}

@Override
public String toString() {
return "DeleteDecommissionRequest{" +
"name='" + name + '\'' +
", decommissionAttribute=" + decommissionAttribute +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.decommission.delete;

import org.opensearch.action.support.master.AcknowledgedRequestBuilder;
import org.opensearch.client.OpenSearchClient;
import org.opensearch.cluster.decommission.DecommissionAttribute;

public class DeleteDecommissionRequestBuilder extends AcknowledgedRequestBuilder<
DeleteDecommissionRequest,
DeleteDecommissionResponse,
DeleteDecommissionRequestBuilder> {

public DeleteDecommissionRequestBuilder(OpenSearchClient client, DeleteDecommissionAction action) {
super(client, action, new DeleteDecommissionRequest());
}

/**
*
* @param name name of the attribute
* @return current object
*/
public DeleteDecommissionRequestBuilder setName(String name) {
request.setName(name);
return this;
}

/**
* @param decommissionAttribute decommission attribute
* @return current object
*/
public DeleteDecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttribute decommissionAttribute) {
request.setDecommissionAttribute(decommissionAttribute);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.action.admin.cluster.decommission.delete;

import org.opensearch.action.support.master.AcknowledgedResponse;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.common.xcontent.ToXContentObject;

import java.io.IOException;

public class DeleteDecommissionResponse extends AcknowledgedResponse implements ToXContentObject {

DeleteDecommissionResponse(StreamInput in) throws IOException {
super(in);
}

DeleteDecommissionResponse(boolean acknowledged) {
super(acknowledged);
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
}
}
Loading