From e3dcf4afb807b1d5fdd9ad99c44cc1886ef17dd2 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 18 Aug 2022 16:17:48 +0530 Subject: [PATCH 01/31] Add APIs (GET/PUT) to decommission awareness attribute Signed-off-by: Rishab Nahata --- ...cluster.delete_decommission_awareness.json | 35 ++++++ .../cluster.get_decommission_awareness.json | 29 +++++ .../cluster.put_decommission_awareness.json | 35 ++++++ .../org/opensearch/action/ActionModule.java | 7 ++ .../awareness/put/PutDecommissionAction.java | 20 ++++ .../awareness/put/PutDecommissionRequest.java | 106 ++++++++++++++++++ .../put/PutDecommissionRequestBuilder.java | 43 +++++++ .../put/PutDecommissionResponse.java | 32 ++++++ .../put/TransportPutDecommissionAction.java | 85 ++++++++++++++ .../opensearch/client/ClusterAdminClient.java | 18 +++ .../java/org/opensearch/client/Requests.java | 8 ++ .../client/support/AbstractClient.java | 19 ++++ .../cluster/RestPutDecommissionAction.java | 65 +++++++++++ 13 files changed, 502 insertions(+) create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json create mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java create mode 100644 server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json new file mode 100644 index 0000000000000..a28eba8429fd0 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json @@ -0,0 +1,35 @@ +{ + "cluster.delete_decommission_awareness": { + "documentation": { + "url": "TBA", + "description": "TBA" + }, + "stability": "experimental", + "url": { + "paths": [ + { + "path": "/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}", + "methods": [ + "DELETE" + ], + "parts": { + "awareness_attribute_name": { + "type": "string", + "description": "Awareness attribute name" + }, + "awareness_attribute_value": { + "type": "string", + "description": "Awareness attribute value" + } + } + } + ] + }, + "params": { + "timeout": { + "type": "time", + "description": "Explicit operation timeout" + } + } + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json new file mode 100644 index 0000000000000..b5aa1787fd87c --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json @@ -0,0 +1,29 @@ +{ + "cluster.get_decommission_awareness": { + "documentation": { + "url": "TBA", + "description": "TBA" + }, + "stability": "experimental", + "url": { + "paths": [ + { + "path": "/_cluster/decommission/awareness/_status", + "methods": [ + "GET" + ] + } + ] + }, + "params": { + "timeout": { + "type": "time", + "description": "Explicit operation timeout" + }, + "local": { + "type": "boolean", + "description": "Return local information, do not retrieve the state from master node (default: false)" + } + } + } +} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json new file mode 100644 index 0000000000000..3dfd0f50851f3 --- /dev/null +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json @@ -0,0 +1,35 @@ +{ + "cluster.put_decommission_awareness": { + "documentation": { + "url": "TBA", + "description": "TBA" + }, + "stability": "experimental", + "url": { + "paths": [ + { + "path": "/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}", + "methods": [ + "PUT" + ], + "parts": { + "awareness_attribute_name": { + "type": "string", + "description": "Awareness attribute name" + }, + "awareness_attribute_value": { + "type": "string", + "description": "Awareness attribute value" + } + } + } + ] + }, + "params": { + "timeout": { + "type": "time", + "description": "Explicit operation timeout" + } + } + } +} diff --git a/server/src/main/java/org/opensearch/action/ActionModule.java b/server/src/main/java/org/opensearch/action/ActionModule.java index 74be544123d9f..5f53b0f1074bf 100644 --- a/server/src/main/java/org/opensearch/action/ActionModule.java +++ b/server/src/main/java/org/opensearch/action/ActionModule.java @@ -40,6 +40,8 @@ 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.awareness.put.PutDecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.put.TransportPutDecommissionAction; import org.opensearch.action.admin.cluster.health.ClusterHealthAction; import org.opensearch.action.admin.cluster.health.TransportClusterHealthAction; import org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; @@ -317,6 +319,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; @@ -683,6 +686,9 @@ public void reg // Remote Store actions.register(RestoreRemoteStoreAction.INSTANCE, TransportRestoreRemoteStoreAction.class); + // Decommission actions + actions.register(PutDecommissionAction.INSTANCE, TransportPutDecommissionAction.class); + return unmodifiableMap(actions.getRegistry()); } @@ -873,6 +879,7 @@ public void initRestHandlers(Supplier nodesInCluster) { } } registerHandler.accept(new RestCatAction(catActions)); + registerHandler.accept(new RestPutDecommissionAction()); // Remote Store APIs if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java new file mode 100644 index 0000000000000..5e033f7d0b355 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java @@ -0,0 +1,20 @@ +/* + * 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.awareness.put; + +import org.opensearch.action.ActionType; + +public final class PutDecommissionAction extends ActionType { + public static final PutDecommissionAction INSTANCE = new PutDecommissionAction(); + public static final String NAME = "cluster:admin/decommission/awareness/put"; + + private PutDecommissionAction() { + super(NAME, PutDecommissionResponse::new); + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java new file mode 100644 index 0000000000000..fcbc77727b5c8 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java @@ -0,0 +1,106 @@ +/* + * 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.awareness.put; + +import org.opensearch.action.ActionRequestValidationException; +import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest; +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.unit.TimeValue; + +import java.io.IOException; + +import static org.opensearch.action.ValidateActions.addValidationError; + +public class PutDecommissionRequest extends ClusterManagerNodeRequest { + + private DecommissionAttribute decommissionAttribute; + private TimeValue timeout; + + public PutDecommissionRequest() { + } + + public PutDecommissionRequest(DecommissionAttribute decommissionAttribute, TimeValue timeout) { + this.decommissionAttribute = decommissionAttribute; + this.timeout = timeout; + } + + public PutDecommissionRequest(DecommissionAttribute decommissionAttribute) { + this.decommissionAttribute = decommissionAttribute; + } + + public PutDecommissionRequest(StreamInput in) throws IOException { + super(in); + decommissionAttribute = new DecommissionAttribute(in); + timeout = in.readTimeValue(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + decommissionAttribute.writeTo(out); + out.writeTimeValue(timeout); + } + + /** + * Sets decommission attribute for decommission request + * + * @param decommissionAttribute attribute key-value that needs to be decommissioned + * @return this request + */ + public PutDecommissionRequest setDecommissionAttribute(DecommissionAttribute decommissionAttribute) { + this.decommissionAttribute = decommissionAttribute; + return this; + } + + /** + * Sets the timeout for the request + * + * @param timeout time out for the request + * @return this request + */ + public PutDecommissionRequest setTimeout(TimeValue timeout) { + this.timeout = timeout; + return this; + } + + /** + * @return Returns the decommission attribute key-value + */ + public DecommissionAttribute getDecommissionAttribute() { + return this.decommissionAttribute; + } + + public TimeValue getTimeout() { + return this.timeout; + } + + @Override + public ActionRequestValidationException validate() { + ActionRequestValidationException validationException = null; + if (decommissionAttribute.attributeName() == null) { + validationException = addValidationError("attribute name is missing", validationException); + } + if (decommissionAttribute.attributeValue() == null) { + validationException = addValidationError("attribute value is missing", validationException); + } + return validationException; + } + + @Override + public String toString() { + return "PutDecommissionRequest{" + + "decommissionAttribute=" + + decommissionAttribute + + ", timeout=" + + timeout + + '}'; + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java new file mode 100644 index 0000000000000..e772cd33a42b2 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java @@ -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.awareness.put; + +import org.opensearch.action.ActionType; +import org.opensearch.action.support.clustermanager.ClusterManagerNodeOperationRequestBuilder; +import org.opensearch.client.OpenSearchClient; +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.common.unit.TimeValue; + +public class PutDecommissionRequestBuilder extends ClusterManagerNodeOperationRequestBuilder< + PutDecommissionRequest, + PutDecommissionResponse, + PutDecommissionRequestBuilder> { + + public PutDecommissionRequestBuilder(OpenSearchClient client, ActionType action, PutDecommissionRequest request) { + super(client, action, request); + } + + /** + * @param decommissionAttribute decommission attribute + * @return current object + */ + public PutDecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttribute decommissionAttribute) { + request.setDecommissionAttribute(decommissionAttribute); + return this; + } + + /** + * @param timeout time out for the request + * @return current object + */ + public PutDecommissionRequestBuilder setTimeout(TimeValue timeout) { + request.setTimeout(timeout); + return this; + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java new file mode 100644 index 0000000000000..695e894aaa886 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java @@ -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.awareness.put; + +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 PutDecommissionResponse extends AcknowledgedResponse implements ToXContentObject { + + public PutDecommissionResponse(StreamInput in) throws IOException { + super(in); + } + + public PutDecommissionResponse(boolean acknowledged) { + super(acknowledged); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java new file mode 100644 index 0000000000000..e7a37853ef9bd --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java @@ -0,0 +1,85 @@ +/* + * 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.awareness.put; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.action.ActionListener; +import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeAction; +import org.opensearch.cluster.ClusterState; +import org.opensearch.cluster.block.ClusterBlockException; +import org.opensearch.cluster.block.ClusterBlockLevel; +import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.inject.Inject; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.threadpool.ThreadPool; +import org.opensearch.transport.TransportService; + +import java.io.IOException; + +public class TransportPutDecommissionAction extends TransportClusterManagerNodeAction< + PutDecommissionRequest, + PutDecommissionResponse> { + + private static final Logger logger = LogManager.getLogger(TransportPutDecommissionAction.class); + + @Inject + public TransportPutDecommissionAction( + TransportService transportService, + ClusterService clusterService, +// DecommissionService decommissionService, + ThreadPool threadPool, + ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver + ) { + super( + PutDecommissionAction.NAME, + transportService, + clusterService, + threadPool, + actionFilters, + PutDecommissionRequest::new, + indexNameExpressionResolver + ); + //TODO - uncomment when integrating with the service +// this.decommissionService = decommissionService; + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected PutDecommissionResponse read(StreamInput in) throws IOException { + return new PutDecommissionResponse(in); + } + + @Override + protected ClusterBlockException checkBlock(PutDecommissionRequest request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } + + @Override + protected void clusterManagerOperation( + PutDecommissionRequest request, + ClusterState state, + ActionListener listener + ) throws Exception { + logger.info("initiating awareness attribute [{}] decommissioning", request.getDecommissionAttribute().toString()); + // TODO - uncomment when integrating with the service +// decommissionService.initiateAttributeDecommissioning( +// request.getDecommissionAttribute(), +// listener, +// state +// ); + } +} diff --git a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java index 7a7b98bf724f6..b8536f0fabbaf 100644 --- a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java @@ -37,6 +37,9 @@ import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionResponse; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequestBuilder; import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; @@ -791,4 +794,19 @@ public interface ClusterAdminClient extends OpenSearchClient { * Delete specified dangling indices. */ ActionFuture deleteDanglingIndex(DeleteDanglingIndexRequest request); + + /** + * Decommission a node + */ + ActionFuture putDecommission(PutDecommissionRequest request); + + /** + * Decommission a node + */ + void putDecommission(PutDecommissionRequest request, ActionListener listener); + + /** + * Decommission a node + */ + PutDecommissionRequestBuilder preparePutDecommission(PutDecommissionRequest request); } diff --git a/server/src/main/java/org/opensearch/client/Requests.java b/server/src/main/java/org/opensearch/client/Requests.java index b04de7830a780..44b8b9e210bf7 100644 --- a/server/src/main/java/org/opensearch/client/Requests.java +++ b/server/src/main/java/org/opensearch/client/Requests.java @@ -32,6 +32,7 @@ package org.opensearch.client; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; @@ -548,4 +549,11 @@ public static DeleteSnapshotRequest deleteSnapshotRequest(String repository, Str public static SnapshotsStatusRequest snapshotsStatusRequest(String repository) { return new SnapshotsStatusRequest(repository); } + + /** + * Creates a new decommission request. + */ + public static PutDecommissionRequest putDecommissionRequest() { + return new PutDecommissionRequest(); + } } diff --git a/server/src/main/java/org/opensearch/client/support/AbstractClient.java b/server/src/main/java/org/opensearch/client/support/AbstractClient.java index bc80a2ba92bf8..26073d84c92f1 100644 --- a/server/src/main/java/org/opensearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/opensearch/client/support/AbstractClient.java @@ -43,6 +43,10 @@ import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionResponse; import org.opensearch.action.admin.cluster.health.ClusterHealthAction; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequestBuilder; @@ -1314,6 +1318,21 @@ public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript() { public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(String id) { return prepareDeleteStoredScript().setId(id); } + + @Override + public ActionFuture putDecommission(PutDecommissionRequest request) { + return execute(PutDecommissionAction.INSTANCE, request); + } + + @Override + public void putDecommission(PutDecommissionRequest request, ActionListener listener) { + execute(PutDecommissionAction.INSTANCE, request, listener); + } + + @Override + public PutDecommissionRequestBuilder preparePutDecommission(PutDecommissionRequest request) { + return new PutDecommissionRequestBuilder(this, PutDecommissionAction.INSTANCE, request); + } } static class IndicesAdmin implements IndicesAdminClient { diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java new file mode 100644 index 0000000000000..9ad6d04703e60 --- /dev/null +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java @@ -0,0 +1,65 @@ +/* + * 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.rest.action.admin.cluster; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.client.Requests; +import org.opensearch.client.node.NodeClient; +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.common.unit.TimeValue; +import org.opensearch.rest.BaseRestHandler; +import org.opensearch.rest.RestRequest; +import org.opensearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.opensearch.rest.RestRequest.Method.PUT; + +public class RestPutDecommissionAction extends BaseRestHandler { + + private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(300L); + + @Override + public List routes() { + return singletonList(new Route(PUT, "/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}")); + } + + @Override + public String getName() { + return "put_decommission_action"; + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { + PutDecommissionRequest putDecommissionRequest = createRequest(request); + return channel -> client.admin() + .cluster() + .putDecommission(putDecommissionRequest, new RestToXContentListener<>(channel)); + } + + PutDecommissionRequest createRequest(RestRequest request) throws IOException { + String attributeName = null; + String attributeValue = null; + PutDecommissionRequest putDecommissionRequest = Requests.putDecommissionRequest(); + if (request.hasParam("awareness_attribute_name")) { + attributeName = request.param("awareness_attribute_name"); + } + + if (request.hasParam("awareness_attribute_value")) { + attributeValue = request.param("awareness_attribute_value"); + } + return putDecommissionRequest + .setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)) + .setTimeout(TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")); + } +} From 1dfc3cd1b1ac5e9fe4e020418cf5947cccfed2d9 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 18 Aug 2022 17:43:26 +0530 Subject: [PATCH 02/31] Add Get Decommission API Signed-off-by: Rishab Nahata --- .../org/opensearch/action/ActionModule.java | 5 + .../awareness/get/GetDecommissionAction.java | 21 ++++ .../awareness/get/GetDecommissionRequest.java | 41 +++++++ .../get/GetDecommissionRequestBuilder.java | 27 +++++ .../get/GetDecommissionResponse.java | 104 ++++++++++++++++++ .../get/TransportGetDecommissionAction.java | 83 ++++++++++++++ .../opensearch/client/ClusterAdminClient.java | 18 +++ .../java/org/opensearch/client/Requests.java | 12 ++ .../client/support/AbstractClient.java | 20 ++++ .../cluster/RestGetDecommissionAction.java | 55 +++++++++ 10 files changed, 386 insertions(+) create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java create mode 100644 server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java diff --git a/server/src/main/java/org/opensearch/action/ActionModule.java b/server/src/main/java/org/opensearch/action/ActionModule.java index 5f53b0f1074bf..900d50a155c92 100644 --- a/server/src/main/java/org/opensearch/action/ActionModule.java +++ b/server/src/main/java/org/opensearch/action/ActionModule.java @@ -40,6 +40,8 @@ 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.awareness.get.GetDecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.get.TransportGetDecommissionAction; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionAction; import org.opensearch.action.admin.cluster.decommission.awareness.put.TransportPutDecommissionAction; import org.opensearch.action.admin.cluster.health.ClusterHealthAction; @@ -307,6 +309,7 @@ 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; @@ -688,6 +691,7 @@ public void reg // Decommission actions actions.register(PutDecommissionAction.INSTANCE, TransportPutDecommissionAction.class); + actions.register(GetDecommissionAction.INSTANCE, TransportGetDecommissionAction.class); return unmodifiableMap(actions.getRegistry()); } @@ -880,6 +884,7 @@ public void initRestHandlers(Supplier nodesInCluster) { } registerHandler.accept(new RestCatAction(catActions)); registerHandler.accept(new RestPutDecommissionAction()); + registerHandler.accept(new RestGetDecommissionAction()); // Remote Store APIs if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java new file mode 100644 index 0000000000000..21e75c1dfee3e --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java @@ -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.awareness.get; + +import org.opensearch.action.ActionType; + +public class GetDecommissionAction extends ActionType { + + public static final GetDecommissionAction INSTANCE = new GetDecommissionAction(); + public static final String NAME = "cluster:admin/decommission/awareness/get"; + + private GetDecommissionAction() { + super(NAME, GetDecommissionResponse::new); + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java new file mode 100644 index 0000000000000..63114cfa8ec25 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java @@ -0,0 +1,41 @@ +/* + * 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.awareness.get; + +import org.opensearch.action.ActionRequestValidationException; +import org.opensearch.action.support.clustermanager.ClusterManagerNodeReadRequest; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.io.stream.StreamOutput; + +import java.io.IOException; + +/** + * Get Decommissioned attribute request + * + * @opensearch.internal + */ +public class GetDecommissionRequest extends ClusterManagerNodeReadRequest { + + public GetDecommissionRequest() { + } + + public GetDecommissionRequest(StreamInput in) throws IOException { + super(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + } + + @Override + public ActionRequestValidationException validate() { + return null; + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java new file mode 100644 index 0000000000000..6a1d93cfebe34 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java @@ -0,0 +1,27 @@ +/* + * 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.awareness.get; + +import org.opensearch.action.support.clustermanager.ClusterManagerNodeReadOperationRequestBuilder; +import org.opensearch.client.OpenSearchClient; + +public class GetDecommissionRequestBuilder extends ClusterManagerNodeReadOperationRequestBuilder< + GetDecommissionRequest, + GetDecommissionResponse, + GetDecommissionRequestBuilder> { + + // TODO - Support for get attribute with the name? + + /** + * Creates new get decommissioned attributes request builder + */ + public GetDecommissionRequestBuilder(OpenSearchClient client, GetDecommissionAction action) { + super(client, action, new GetDecommissionRequest()); + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java new file mode 100644 index 0000000000000..484ce261e502f --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -0,0 +1,104 @@ +/* + * 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.awareness.get; + +import org.opensearch.OpenSearchParseException; +import org.opensearch.action.ActionResponse; +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.cluster.decommission.DecommissionStatus; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.xcontent.ToXContentObject; +import org.opensearch.common.xcontent.XContentBuilder; +import org.opensearch.common.xcontent.XContentParser; + +import java.io.IOException; + +import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; + +public class GetDecommissionResponse extends ActionResponse implements ToXContentObject { + + private final DecommissionStatus status; + private final DecommissionAttribute decommissionedAttribute; + + + GetDecommissionResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { + this.decommissionedAttribute = decommissionedAttribute; + this.status = status; + } + + GetDecommissionResponse(StreamInput in) throws IOException { + this.decommissionedAttribute = new DecommissionAttribute(in); + this.status = DecommissionStatus.fromValue(in.readByte()); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + decommissionedAttribute.writeTo(out); + out.writeByte(status.value()); + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + builder.startObject("awareness"); + builder.field(decommissionedAttribute.attributeName(), decommissionedAttribute.attributeValue()); + builder.endObject(); + builder.field("status", status); + builder.endObject(); + return builder; + } + + public static GetDecommissionResponse fromXContent(XContentParser parser) throws IOException { + ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); + String attributeType = "awareness"; + XContentParser.Token token; + DecommissionAttribute decommissionAttribute = null; + DecommissionStatus status = null; + if ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + String currentFieldName = parser.currentName(); + if (attributeType.equals(currentFieldName)) { + if (parser.nextToken() != XContentParser.Token.START_OBJECT) { + throw new OpenSearchParseException("failed to parse decommission attribute type [{}], expected object", attributeType); + } + token = parser.nextToken(); + if (token != XContentParser.Token.END_OBJECT) { + 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", attributeType); + } + } else { + throw new OpenSearchParseException("failed to parse attribute type [{}]", attributeType); + } + } else if ("status".equals(currentFieldName)) { + if (parser.nextToken() != XContentParser.Token.VALUE_STRING) { + throw new OpenSearchParseException("failed to parse status of decommissioning, expected string but found unknown type"); + } + status = DecommissionStatus.fromString(parser.text()); + } else { + throw new OpenSearchParseException( + "unknown field found [{}], failed to parse the decommission attribute", + currentFieldName + ); + } + } + } + return new GetDecommissionResponse(decommissionAttribute, status); + } +} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java new file mode 100644 index 0000000000000..6627b78d664f0 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java @@ -0,0 +1,83 @@ +/* + * 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.awareness.get; + +import org.opensearch.action.ActionListener; +import org.opensearch.action.support.ActionFilters; +import org.opensearch.action.support.clustermanager.TransportClusterManagerNodeReadAction; +import org.opensearch.cluster.ClusterState; +import org.opensearch.cluster.block.ClusterBlockException; +import org.opensearch.cluster.block.ClusterBlockLevel; +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.cluster.decommission.DecommissionStatus; +import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.metadata.Metadata; +import org.opensearch.cluster.service.ClusterService; +import org.opensearch.common.inject.Inject; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.threadpool.ThreadPool; +import org.opensearch.transport.TransportService; + +import java.io.IOException; + +public class TransportGetDecommissionAction extends TransportClusterManagerNodeReadAction< + GetDecommissionRequest, + GetDecommissionResponse> { + + @Inject + public TransportGetDecommissionAction( + TransportService transportService, + ClusterService clusterService, + ThreadPool threadPool, + ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver + ) { + super( + GetDecommissionAction.NAME, + transportService, + clusterService, + threadPool, + actionFilters, + GetDecommissionRequest::new, + indexNameExpressionResolver + ); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected GetDecommissionResponse read(StreamInput in) throws IOException { + return new GetDecommissionResponse(in); + } + + @Override + protected void clusterManagerOperation( + GetDecommissionRequest request, + ClusterState state, + ActionListener listener + ) throws Exception { + Metadata metadata = state.metadata(); +// DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); + // TODO - update once service layer changes are merged + listener.onResponse( + new GetDecommissionResponse( + new DecommissionAttribute("zone", "zone-1"), + DecommissionStatus.DECOMMISSIONED + ) + ); + } + + @Override + protected ClusterBlockException checkBlock(GetDecommissionRequest request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); + } +} diff --git a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java index b8536f0fabbaf..0c5a7c2b30809 100644 --- a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java @@ -37,6 +37,9 @@ import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionResponse; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequestBuilder; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionResponse; @@ -809,4 +812,19 @@ public interface ClusterAdminClient extends OpenSearchClient { * Decommission a node */ PutDecommissionRequestBuilder preparePutDecommission(PutDecommissionRequest request); + + /** + * Get Decommissioned attribute + */ + ActionFuture getDecommission(GetDecommissionRequest request); + + /** + * Get Decommissioned attribute + */ + void getDecommission(GetDecommissionRequest request, ActionListener listener); + + /** + * Get Decommissioned attribute + */ + GetDecommissionRequestBuilder prepareGetDecommission(); } diff --git a/server/src/main/java/org/opensearch/client/Requests.java b/server/src/main/java/org/opensearch/client/Requests.java index 44b8b9e210bf7..ee97d0412a7c9 100644 --- a/server/src/main/java/org/opensearch/client/Requests.java +++ b/server/src/main/java/org/opensearch/client/Requests.java @@ -32,6 +32,7 @@ package org.opensearch.client; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; @@ -552,8 +553,19 @@ public static SnapshotsStatusRequest snapshotsStatusRequest(String repository) { /** * Creates a new decommission request. + * + * @return returns put decommission request */ public static PutDecommissionRequest putDecommissionRequest() { return new PutDecommissionRequest(); } + + /** + * Get decommissioned attribute from metadata + * + * @return returns get decommission request + */ + public static GetDecommissionRequest getDecommissionRequest() { + return new GetDecommissionRequest(); + } } diff --git a/server/src/main/java/org/opensearch/client/support/AbstractClient.java b/server/src/main/java/org/opensearch/client/support/AbstractClient.java index 26073d84c92f1..c120b24b1efd9 100644 --- a/server/src/main/java/org/opensearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/opensearch/client/support/AbstractClient.java @@ -43,6 +43,10 @@ import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionResponse; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionAction; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequestBuilder; @@ -1333,6 +1337,22 @@ public void putDecommission(PutDecommissionRequest request, ActionListener getDecommission(GetDecommissionRequest request) { + return execute(GetDecommissionAction.INSTANCE, request); + } + + @Override + public void getDecommission(GetDecommissionRequest request, ActionListener listener) { + execute(GetDecommissionAction.INSTANCE, request, listener); + } + + @Override + public GetDecommissionRequestBuilder prepareGetDecommission() { + return new GetDecommissionRequestBuilder(this, GetDecommissionAction.INSTANCE); + } + } static class IndicesAdmin implements IndicesAdminClient { diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java new file mode 100644 index 0000000000000..d9d0631c90268 --- /dev/null +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java @@ -0,0 +1,55 @@ +/* + * 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.rest.action.admin.cluster; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; +import org.opensearch.client.Requests; +import org.opensearch.client.node.NodeClient; +import org.opensearch.rest.BaseRestHandler; +import org.opensearch.rest.RestRequest; +import org.opensearch.rest.action.RestToXContentListener; + +import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.opensearch.rest.RestRequest.Method.GET; + +/** + * Returns decommissioned attribute information + * + * @opensearch.api + */ +public class RestGetDecommissionAction extends BaseRestHandler { + + private static final Logger logger = LogManager.getLogger(RestPutDecommissionAction.class); + + @Override + public List routes() { + return singletonList(new Route(GET, "/_cluster/decommission/awareness/_status")); + } + + @Override + public String getName() { + return "get_decommission_action"; + } + + @Override + public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { + GetDecommissionRequest getDecommissionRequest = Requests.getDecommissionRequest(); + getDecommissionRequest.clusterManagerNodeTimeout( + request.paramAsTime("cluster_manager_timeout", getDecommissionRequest.clusterManagerNodeTimeout()) + ); + return channel -> client.admin() + .cluster() + .getDecommission(getDecommissionRequest, new RestToXContentListener<>(channel)); + } +} From f5f676a9d97917543e02a6d78285be7667b0ac4d Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 22 Aug 2022 12:27:41 +0530 Subject: [PATCH 03/31] Adding UT Signed-off-by: Rishab Nahata --- .../put/PutDecommissionRequestTests.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java new file mode 100644 index 0000000000000..6ef6eff44b136 --- /dev/null +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java @@ -0,0 +1,39 @@ +/* + * 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.awareness.put; + +import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest; +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.common.unit.TimeValue; +import org.opensearch.test.OpenSearchTestCase; + +import java.io.IOException; + +public class PutDecommissionRequestTests extends OpenSearchTestCase { + + public void testSerialization() throws IOException { + String attributeName = "zone"; + String attributeValue = "zone-1"; + DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); + TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); + final PutDecommissionRequest originalRequest = new PutDecommissionRequest( + decommissionAttribute, + timeout + ); + + final PutDecommissionRequest deserialized = copyWriteable( + originalRequest, + writableRegistry(), + PutDecommissionRequest::new + ); + + assertEquals(deserialized.getDecommissionAttribute(), originalRequest.getDecommissionAttribute()); + assertEquals(deserialized.getTimeout(), originalRequest.getTimeout()); + } +} From 4c8b65b32377e2c46a964defc2a00528a370df3e Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 22 Aug 2022 16:15:56 +0530 Subject: [PATCH 04/31] Add UTs for Rest Layer Signed-off-by: Rishab Nahata --- ...cluster.delete_decommission_awareness.json | 35 ---------- .../get/GetDecommissionRequestBuilder.java | 2 - .../get/GetDecommissionResponse.java | 28 +++++++- .../awareness/put/PutDecommissionRequest.java | 8 +-- .../put/PutDecommissionResponse.java | 1 + .../cluster/RestGetDecommissionAction.java | 2 - .../get/GetDecommissionResponseTests.java | 37 +++++++++++ .../put/PutDecommissionRequestTests.java | 46 ++++++++++++- .../put/PutDecommissionResponseTests.java | 21 ++++++ .../RestPutDecommissionActionTests.java | 65 +++++++++++++++++++ 10 files changed, 196 insertions(+), 49 deletions(-) delete mode 100644 rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json create mode 100644 server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java create mode 100644 server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java create mode 100644 server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json deleted file mode 100644 index a28eba8429fd0..0000000000000 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.delete_decommission_awareness.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "cluster.delete_decommission_awareness": { - "documentation": { - "url": "TBA", - "description": "TBA" - }, - "stability": "experimental", - "url": { - "paths": [ - { - "path": "/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}", - "methods": [ - "DELETE" - ], - "parts": { - "awareness_attribute_name": { - "type": "string", - "description": "Awareness attribute name" - }, - "awareness_attribute_value": { - "type": "string", - "description": "Awareness attribute value" - } - } - } - ] - }, - "params": { - "timeout": { - "type": "time", - "description": "Explicit operation timeout" - } - } - } -} diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java index 6a1d93cfebe34..08a702cdc7524 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java @@ -16,8 +16,6 @@ public class GetDecommissionRequestBuilder extends ClusterManagerNodeReadOperati GetDecommissionResponse, GetDecommissionRequestBuilder> { - // TODO - Support for get attribute with the name? - /** * Creates new get decommissioned attributes request builder */ diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java index 484ce261e502f..1b3aa32c18393 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -19,14 +19,14 @@ import org.opensearch.common.xcontent.XContentParser; import java.io.IOException; +import java.util.Objects; import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; public class GetDecommissionResponse extends ActionResponse implements ToXContentObject { - private final DecommissionStatus status; private final DecommissionAttribute decommissionedAttribute; - + private final DecommissionStatus status; GetDecommissionResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { this.decommissionedAttribute = decommissionedAttribute; @@ -44,6 +44,14 @@ public void writeTo(StreamOutput out) throws IOException { out.writeByte(status.value()); } + public DecommissionAttribute getDecommissionedAttribute() { + return decommissionedAttribute; + } + + public DecommissionStatus getDecommissionStatus() { + return status; + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); @@ -61,7 +69,7 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws XContentParser.Token token; DecommissionAttribute decommissionAttribute = null; DecommissionStatus status = null; - if ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { String currentFieldName = parser.currentName(); if (attributeType.equals(currentFieldName)) { @@ -80,6 +88,7 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws throw new OpenSearchParseException("failed to parse attribute [{}], expected string for attribute value", fieldName); } decommissionAttribute = new DecommissionAttribute(fieldName, value); + token = parser.nextToken(); } else { throw new OpenSearchParseException("failed to parse attribute type [{}], unexpected type", attributeType); } @@ -101,4 +110,17 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws } return new GetDecommissionResponse(decommissionAttribute, status); } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + GetDecommissionResponse that = (GetDecommissionResponse) o; + return decommissionedAttribute.equals(that.decommissionedAttribute) && status == that.status; + } + + @Override + public int hashCode() { + return Objects.hash(decommissionedAttribute, status); + } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java index fcbc77727b5c8..fd78deb86614b 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java @@ -32,10 +32,6 @@ public PutDecommissionRequest(DecommissionAttribute decommissionAttribute, TimeV this.timeout = timeout; } - public PutDecommissionRequest(DecommissionAttribute decommissionAttribute) { - this.decommissionAttribute = decommissionAttribute; - } - public PutDecommissionRequest(StreamInput in) throws IOException { super(in); decommissionAttribute = new DecommissionAttribute(in); @@ -85,10 +81,10 @@ public TimeValue getTimeout() { @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; - if (decommissionAttribute.attributeName() == null) { + if (decommissionAttribute.attributeName() == null || decommissionAttribute.attributeName().isEmpty()) { validationException = addValidationError("attribute name is missing", validationException); } - if (decommissionAttribute.attributeValue() == null) { + if (decommissionAttribute.attributeValue() == null || decommissionAttribute.attributeValue().isEmpty()) { validationException = addValidationError("attribute value is missing", validationException); } return validationException; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java index 695e894aaa886..c2fdbc48ab286 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java @@ -12,6 +12,7 @@ import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; import org.opensearch.common.xcontent.ToXContentObject; +import org.opensearch.common.xcontent.XContentBuilder; import java.io.IOException; diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java index d9d0631c90268..8381317253a17 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java @@ -30,8 +30,6 @@ */ public class RestGetDecommissionAction extends BaseRestHandler { - private static final Logger logger = LogManager.getLogger(RestPutDecommissionAction.class); - @Override public List routes() { return singletonList(new Route(GET, "/_cluster/decommission/awareness/_status")); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java new file mode 100644 index 0000000000000..be6d336128882 --- /dev/null +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java @@ -0,0 +1,37 @@ +/* + * 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.awareness.get; + +import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.cluster.decommission.DecommissionStatus; +import org.opensearch.common.xcontent.XContentParser; +import org.opensearch.test.AbstractXContentTestCase; + +import java.io.IOException; + +public class GetDecommissionResponseTests extends AbstractXContentTestCase { + @Override + protected GetDecommissionResponse createTestInstance() { + DecommissionStatus status = DecommissionStatus.fromValue((byte) randomIntBetween(0, 5)); + String attributeName = randomAlphaOfLength(10); + String attributeValue = randomAlphaOfLength(10); + DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); + return new GetDecommissionResponse(decommissionAttribute, status); + } + + @Override + protected GetDecommissionResponse doParseInstance(XContentParser parser) throws IOException { + return GetDecommissionResponse.fromXContent(parser); + } + + @Override + protected boolean supportsUnknownFields() { + return false; + } +} diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java index 6ef6eff44b136..7f1be10232f3e 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java @@ -8,7 +8,7 @@ package org.opensearch.action.admin.cluster.decommission.awareness.put; -import org.opensearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest; +import org.opensearch.action.ActionRequestValidationException; import org.opensearch.cluster.decommission.DecommissionAttribute; import org.opensearch.common.unit.TimeValue; import org.opensearch.test.OpenSearchTestCase; @@ -36,4 +36,48 @@ public void testSerialization() throws IOException { assertEquals(deserialized.getDecommissionAttribute(), originalRequest.getDecommissionAttribute()); assertEquals(deserialized.getTimeout(), originalRequest.getTimeout()); } + + public void testValidation() { + { + String attributeName = null; + String attributeValue = "test"; + DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); + TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); + + final PutDecommissionRequest request = new PutDecommissionRequest( + decommissionAttribute, + timeout + ); + ActionRequestValidationException e = request.validate(); + assertNotNull(e); + assertTrue(e.getMessage().contains("attribute name is missing")); + } + { + String attributeName = "zone"; + String attributeValue = ""; + DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); + TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); + + final PutDecommissionRequest request = new PutDecommissionRequest( + decommissionAttribute, + timeout + ); + ActionRequestValidationException e = request.validate(); + assertNotNull(e); + assertTrue(e.getMessage().contains("attribute value is missing")); + } + { + String attributeName = "zone"; + String attributeValue = "test"; + DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); + TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); + + final PutDecommissionRequest request = new PutDecommissionRequest( + decommissionAttribute, + timeout + ); + ActionRequestValidationException e = request.validate(); + assertNull(e); + } + } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java new file mode 100644 index 0000000000000..91f1cf3d9eb66 --- /dev/null +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java @@ -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.awareness.put; + +import org.opensearch.test.OpenSearchTestCase; + +import java.io.IOException; + +public class PutDecommissionResponseTests extends OpenSearchTestCase { + public void testSerialization() throws IOException { + final PutDecommissionResponse originalRequest = new PutDecommissionResponse(true); + copyWriteable(originalRequest, writableRegistry(), PutDecommissionResponse::new); + // there are no fields so we're just checking that this doesn't throw anything + } +} diff --git a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java new file mode 100644 index 0000000000000..f5ff48e787637 --- /dev/null +++ b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java @@ -0,0 +1,65 @@ +/* + * 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.rest.action.admin.cluster; + +import org.junit.Before; +import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.common.unit.TimeValue; +import org.opensearch.rest.RestRequest; +import org.opensearch.test.rest.FakeRestRequest; +import org.opensearch.test.rest.RestActionTestCase; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +public class RestPutDecommissionActionTests extends RestActionTestCase { + + private RestPutDecommissionAction action; + + @Before + public void setupAction() { + action = new RestPutDecommissionAction(); + controller().registerHandler(action); + } + + public void testCreateRequest() throws IOException { + Map params = new HashMap<>(); + params.put("awareness_attribute_name", "zone"); + params.put("awareness_attribute_value", "zone-1"); + params.put("timeout", "10s"); + + RestRequest deprecatedRequest = buildRestRequest(params); + + PutDecommissionRequest request = action.createRequest(deprecatedRequest); + assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); + assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); + assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(10L)); + } + + public void testCreateRequestWithDefaultTimeout() throws IOException { + Map params = new HashMap<>(); + params.put("awareness_attribute_name", "zone"); + params.put("awareness_attribute_value", "zone-1"); + + RestRequest deprecatedRequest = buildRestRequest(params); + + PutDecommissionRequest request = action.createRequest(deprecatedRequest); + assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); + assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); + assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(300L)); + } + + private FakeRestRequest buildRestRequest(Map params) { + return new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.GET) + .withPath("/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}") + .withParams(params) + .build(); + } +} From 8c2ddbcef4cc72734894ae735f5a7cf92b06b033 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 22 Aug 2022 16:22:53 +0530 Subject: [PATCH 05/31] Fix Signed-off-by: Rishab Nahata --- .../awareness/put/TransportPutDecommissionAction.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java index e7a37853ef9bd..7617385dbefb4 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java @@ -75,6 +75,7 @@ protected void clusterManagerOperation( ActionListener listener ) throws Exception { logger.info("initiating awareness attribute [{}] decommissioning", request.getDecommissionAttribute().toString()); + listener.onResponse(new PutDecommissionResponse(true)); // TODO - remove after integration // TODO - uncomment when integrating with the service // decommissionService.initiateAttributeDecommissioning( // request.getDecommissionAttribute(), From c7e4bccc533e6d9752ea36f8a5cc406df5eb6540 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 22 Aug 2022 16:51:55 +0530 Subject: [PATCH 06/31] Applying spotless check Signed-off-by: Rishab Nahata --- .../awareness/get/GetDecommissionRequest.java | 3 +-- .../get/GetDecommissionResponse.java | 14 +++++++--- .../get/TransportGetDecommissionAction.java | 13 +++------- .../awareness/put/PutDecommissionRequest.java | 10 ++----- .../put/PutDecommissionRequestBuilder.java | 6 ++++- .../put/PutDecommissionResponse.java | 1 - .../put/TransportPutDecommissionAction.java | 20 +++++++------- .../cluster/RestGetDecommissionAction.java | 6 +---- .../cluster/RestPutDecommissionAction.java | 9 ++----- .../put/PutDecommissionRequestTests.java | 26 ++++--------------- 10 files changed, 39 insertions(+), 69 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java index 63114cfa8ec25..fa979544129c2 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java @@ -22,8 +22,7 @@ */ public class GetDecommissionRequest extends ClusterManagerNodeReadRequest { - public GetDecommissionRequest() { - } + public GetDecommissionRequest() {} public GetDecommissionRequest(StreamInput in) throws IOException { super(in); diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java index 1b3aa32c18393..343868894620a 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -74,7 +74,10 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws String currentFieldName = parser.currentName(); if (attributeType.equals(currentFieldName)) { if (parser.nextToken() != XContentParser.Token.START_OBJECT) { - throw new OpenSearchParseException("failed to parse decommission attribute type [{}], expected object", attributeType); + throw new OpenSearchParseException( + "failed to parse decommission attribute type [{}], expected object", + attributeType + ); } token = parser.nextToken(); if (token != XContentParser.Token.END_OBJECT) { @@ -85,7 +88,10 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws if (token == XContentParser.Token.VALUE_STRING) { value = parser.text(); } else { - throw new OpenSearchParseException("failed to parse attribute [{}], expected string for attribute value", fieldName); + throw new OpenSearchParseException( + "failed to parse attribute [{}], expected string for attribute value", + fieldName + ); } decommissionAttribute = new DecommissionAttribute(fieldName, value); token = parser.nextToken(); @@ -97,7 +103,9 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws } } else if ("status".equals(currentFieldName)) { if (parser.nextToken() != XContentParser.Token.VALUE_STRING) { - throw new OpenSearchParseException("failed to parse status of decommissioning, expected string but found unknown type"); + throw new OpenSearchParseException( + "failed to parse status of decommissioning, expected string but found unknown type" + ); } status = DecommissionStatus.fromString(parser.text()); } else { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java index 6627b78d664f0..1f875d2df96df 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java @@ -26,9 +26,7 @@ import java.io.IOException; -public class TransportGetDecommissionAction extends TransportClusterManagerNodeReadAction< - GetDecommissionRequest, - GetDecommissionResponse> { +public class TransportGetDecommissionAction extends TransportClusterManagerNodeReadAction { @Inject public TransportGetDecommissionAction( @@ -66,14 +64,9 @@ protected void clusterManagerOperation( ActionListener listener ) throws Exception { Metadata metadata = state.metadata(); -// DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); + // DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); // TODO - update once service layer changes are merged - listener.onResponse( - new GetDecommissionResponse( - new DecommissionAttribute("zone", "zone-1"), - DecommissionStatus.DECOMMISSIONED - ) - ); + listener.onResponse(new GetDecommissionResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED)); } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java index fd78deb86614b..c570791003199 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java @@ -24,8 +24,7 @@ public class PutDecommissionRequest extends ClusterManagerNodeRequest client.admin() - .cluster() - .getDecommission(getDecommissionRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().cluster().getDecommission(getDecommissionRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java index 9ad6d04703e60..458d73a6e8dd8 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java @@ -8,8 +8,6 @@ package org.opensearch.rest.action.admin.cluster; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; import org.opensearch.client.Requests; import org.opensearch.client.node.NodeClient; @@ -42,9 +40,7 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { PutDecommissionRequest putDecommissionRequest = createRequest(request); - return channel -> client.admin() - .cluster() - .putDecommission(putDecommissionRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().cluster().putDecommission(putDecommissionRequest, new RestToXContentListener<>(channel)); } PutDecommissionRequest createRequest(RestRequest request) throws IOException { @@ -58,8 +54,7 @@ PutDecommissionRequest createRequest(RestRequest request) throws IOException { if (request.hasParam("awareness_attribute_value")) { attributeValue = request.param("awareness_attribute_value"); } - return putDecommissionRequest - .setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)) + return putDecommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)) .setTimeout(TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java index 7f1be10232f3e..606158725c955 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java @@ -22,16 +22,9 @@ public void testSerialization() throws IOException { String attributeValue = "zone-1"; DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest originalRequest = new PutDecommissionRequest( - decommissionAttribute, - timeout - ); + final PutDecommissionRequest originalRequest = new PutDecommissionRequest(decommissionAttribute, timeout); - final PutDecommissionRequest deserialized = copyWriteable( - originalRequest, - writableRegistry(), - PutDecommissionRequest::new - ); + final PutDecommissionRequest deserialized = copyWriteable(originalRequest, writableRegistry(), PutDecommissionRequest::new); assertEquals(deserialized.getDecommissionAttribute(), originalRequest.getDecommissionAttribute()); assertEquals(deserialized.getTimeout(), originalRequest.getTimeout()); @@ -44,10 +37,7 @@ public void testValidation() { DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest request = new PutDecommissionRequest( - decommissionAttribute, - timeout - ); + final PutDecommissionRequest request = new PutDecommissionRequest(decommissionAttribute, timeout); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertTrue(e.getMessage().contains("attribute name is missing")); @@ -58,10 +48,7 @@ public void testValidation() { DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest request = new PutDecommissionRequest( - decommissionAttribute, - timeout - ); + final PutDecommissionRequest request = new PutDecommissionRequest(decommissionAttribute, timeout); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertTrue(e.getMessage().contains("attribute value is missing")); @@ -72,10 +59,7 @@ public void testValidation() { DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest request = new PutDecommissionRequest( - decommissionAttribute, - timeout - ); + final PutDecommissionRequest request = new PutDecommissionRequest(decommissionAttribute, timeout); ActionRequestValidationException e = request.validate(); assertNull(e); } From e2b38cbb26ee39ff5f1a11a8aabdd2731eafcd2c Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 22 Aug 2022 17:25:21 +0530 Subject: [PATCH 07/31] Add temp URL Signed-off-by: Rishab Nahata --- .../rest-api-spec/api/cluster.get_decommission_awareness.json | 4 ++-- .../rest-api-spec/api/cluster.put_decommission_awareness.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json index b5aa1787fd87c..19cb03aaf20c4 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json @@ -1,8 +1,8 @@ { "cluster.get_decommission_awareness": { "documentation": { - "url": "TBA", - "description": "TBA" + "url": "https://opensearch.org/docs/latest/opensearch/rest-api/decommission/", + "description": "Get details and status of decommissioned attribute" }, "stability": "experimental", "url": { diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json index 3dfd0f50851f3..815964e49e7a0 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json @@ -1,8 +1,8 @@ { "cluster.put_decommission_awareness": { "documentation": { - "url": "TBA", - "description": "TBA" + "url": "https://opensearch.org/docs/latest/opensearch/rest-api/decommission/", + "description": "Decommissions an awareness attribute" }, "stability": "experimental", "url": { From 1c9fe9f9b75c9d1149cd41fc2a47bc6525ab0293 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 22 Aug 2022 17:55:21 +0530 Subject: [PATCH 08/31] Bug fix Signed-off-by: Rishab Nahata --- .../java/org/opensearch/client/RestHighLevelClientTests.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java b/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java index cdd63743f2644..1384e99019793 100644 --- a/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java +++ b/client/rest-high-level/src/test/java/org/opensearch/client/RestHighLevelClientTests.java @@ -887,7 +887,9 @@ public void testApiNamingConventions() throws Exception { "nodes.usage", "nodes.reload_secure_settings", "search_shards", - "remote_store.restore", }; + "remote_store.restore", + "cluster.put_decommission_awareness", + "cluster.get_decommission_awareness", }; List booleanReturnMethods = Arrays.asList("security.enable_user", "security.disable_user", "security.change_password"); Set deprecatedMethods = new HashSet<>(); deprecatedMethods.add("indices.force_merge"); From 17f2548469f55d91b78f699ef03484b4d7667ec4 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Tue, 23 Aug 2022 20:06:18 +0530 Subject: [PATCH 09/31] Fix Signed-off-by: Rishab Nahata --- .../awareness/get/GetDecommissionResponse.java | 12 ++++++++++-- .../get/TransportGetDecommissionAction.java | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java index 343868894620a..8826bd5d479d5 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -28,6 +28,10 @@ public class GetDecommissionResponse extends ActionResponse implements ToXConten private final DecommissionAttribute decommissionedAttribute; private final DecommissionStatus status; + GetDecommissionResponse() { + this(null, null); + } + GetDecommissionResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { this.decommissionedAttribute = decommissionedAttribute; this.status = status; @@ -56,9 +60,13 @@ public DecommissionStatus getDecommissionStatus() { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.startObject("awareness"); - builder.field(decommissionedAttribute.attributeName(), decommissionedAttribute.attributeValue()); + if (decommissionedAttribute != null) { + builder.field(decommissionedAttribute.attributeName(), decommissionedAttribute.attributeValue()); + } builder.endObject(); - builder.field("status", status); + if (status!=null) { + builder.field("status", status); + } builder.endObject(); return builder; } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java index 1f875d2df96df..74d2c3363eb52 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java @@ -66,7 +66,16 @@ protected void clusterManagerOperation( Metadata metadata = state.metadata(); // DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); // TODO - update once service layer changes are merged +//<<<<<<< HEAD listener.onResponse(new GetDecommissionResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED)); +//======= +// if (decommissionedAttributes!=null) { +// listener.onResponse(new GetDecommissionResponse(decommissionedAttributes.decommissionAttribute(), decommissionedAttributes.status())); +// } +// else { +// listener.onResponse(new GetDecommissionResponse()); +// } +//>>>>>>> 1025b6e3e3e (Fix GET without PUT) } @Override From f9bfff9a83f9c3e92bfe43a64be6bb053df75fdb Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 25 Aug 2022 15:33:51 +0530 Subject: [PATCH 10/31] Fixes Signed-off-by: Rishab Nahata --- .../decommission/awareness/get/GetDecommissionResponse.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java index 8826bd5d479d5..7b971049ac4b5 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -28,10 +28,6 @@ public class GetDecommissionResponse extends ActionResponse implements ToXConten private final DecommissionAttribute decommissionedAttribute; private final DecommissionStatus status; - GetDecommissionResponse() { - this(null, null); - } - GetDecommissionResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { this.decommissionedAttribute = decommissionedAttribute; this.status = status; From 6ba62c24756eba78da3b433b6cf580f7a96a4818 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 25 Aug 2022 16:22:42 +0530 Subject: [PATCH 11/31] Fix spotless and precommit checks Signed-off-by: Rishab Nahata --- .../get/GetDecommissionResponse.java | 2 +- .../get/TransportGetDecommissionAction.java | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java index 7b971049ac4b5..21b5140035f7d 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -60,7 +60,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws builder.field(decommissionedAttribute.attributeName(), decommissionedAttribute.attributeValue()); } builder.endObject(); - if (status!=null) { + if (status != null) { builder.field("status", status); } builder.endObject(); diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java index 74d2c3363eb52..70d56bd73b341 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java @@ -66,16 +66,17 @@ protected void clusterManagerOperation( Metadata metadata = state.metadata(); // DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); // TODO - update once service layer changes are merged -//<<<<<<< HEAD + // <<<<<<< HEAD listener.onResponse(new GetDecommissionResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED)); -//======= -// if (decommissionedAttributes!=null) { -// listener.onResponse(new GetDecommissionResponse(decommissionedAttributes.decommissionAttribute(), decommissionedAttributes.status())); -// } -// else { -// listener.onResponse(new GetDecommissionResponse()); -// } -//>>>>>>> 1025b6e3e3e (Fix GET without PUT) + // ======= + // if (decommissionedAttributes!=null) { + // listener.onResponse(new GetDecommissionResponse(decommissionedAttributes.decommissionAttribute(), + // decommissionedAttributes.status())); + // } + // else { + // listener.onResponse(new GetDecommissionResponse()); + // } + // >>>>>>> 1025b6e3e3e (Fix GET without PUT) } @Override From 6f2f3d34680263808e8811be8da28d7618e7fc1f Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 1 Sep 2022 15:33:44 +0530 Subject: [PATCH 12/31] Add java docs and fix test Signed-off-by: Rishab Nahata --- .../awareness/get/GetDecommissionAction.java | 5 +++++ .../awareness/get/GetDecommissionRequestBuilder.java | 5 +++++ .../awareness/get/GetDecommissionResponse.java | 5 +++++ .../awareness/get/TransportGetDecommissionAction.java | 5 +++++ .../decommission/awareness/get/package-info.java | 10 ++++++++++ .../cluster/decommission/awareness/package-info.java | 10 ++++++++++ .../awareness/put/PutDecommissionAction.java | 5 +++++ .../awareness/put/PutDecommissionRequest.java | 7 +++++++ .../awareness/put/PutDecommissionRequestBuilder.java | 5 +++++ .../awareness/put/PutDecommissionResponse.java | 5 +++++ .../awareness/put/TransportPutDecommissionAction.java | 5 +++++ .../decommission/awareness/put/package-info.java | 10 ++++++++++ .../admin/cluster/RestPutDecommissionAction.java | 5 +++++ .../admin/cluster/RestPutDecommissionActionTests.java | 4 +++- 14 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/package-info.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/package-info.java create mode 100644 server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/package-info.java diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java index 21e75c1dfee3e..72a7d5d53ce77 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java @@ -10,6 +10,11 @@ import org.opensearch.action.ActionType; +/** + * Get decommission action + * + * @opensearch.internal + */ public class GetDecommissionAction extends ActionType { public static final GetDecommissionAction INSTANCE = new GetDecommissionAction(); diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java index 08a702cdc7524..c6a5925d87860 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java @@ -11,6 +11,11 @@ import org.opensearch.action.support.clustermanager.ClusterManagerNodeReadOperationRequestBuilder; import org.opensearch.client.OpenSearchClient; +/** + * Get decommission request builder + * + * @opensearch.internal + */ public class GetDecommissionRequestBuilder extends ClusterManagerNodeReadOperationRequestBuilder< GetDecommissionRequest, GetDecommissionResponse, diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java index 21b5140035f7d..29c307065a700 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java @@ -23,6 +23,11 @@ import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; +/** + * Response for decommission status + * + * @opensearch.internal + */ public class GetDecommissionResponse extends ActionResponse implements ToXContentObject { private final DecommissionAttribute decommissionedAttribute; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java index 70d56bd73b341..28d91fd454d20 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java @@ -26,6 +26,11 @@ import java.io.IOException; +/** + * Transport action for getting decommission status + * + * @opensearch.internal + */ public class TransportGetDecommissionAction extends TransportClusterManagerNodeReadAction { @Inject diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/package-info.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/package-info.java new file mode 100644 index 0000000000000..5b88e91cf4f9d --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/package-info.java @@ -0,0 +1,10 @@ +/* + * 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. + */ + +/** Transport handlers for getting status of decommission request */ +package org.opensearch.action.admin.cluster.decommission.awareness.get; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/package-info.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/package-info.java new file mode 100644 index 0000000000000..e1260e638c91d --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/package-info.java @@ -0,0 +1,10 @@ +/* + * 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. + */ + +/** Decommission transport handlers. */ +package org.opensearch.action.admin.cluster.decommission.awareness; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java index 5e033f7d0b355..78d6270247c97 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java @@ -10,6 +10,11 @@ import org.opensearch.action.ActionType; +/** + * Register decommission action + * + * @opensearch.internal + */ public final class PutDecommissionAction extends ActionType { public static final PutDecommissionAction INSTANCE = new PutDecommissionAction(); public static final String NAME = "cluster:admin/decommission/awareness/put"; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java index c570791003199..d92e2c002a0c8 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java @@ -19,6 +19,13 @@ import static org.opensearch.action.ValidateActions.addValidationError; +/** + * Register decommission request. + *

+ * Registers a decommission request with decommission attribute and timeout + * + * @opensearch.internal + */ public class PutDecommissionRequest extends ClusterManagerNodeRequest { private DecommissionAttribute decommissionAttribute; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java index 3ff874865382c..300ed202df98c 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java @@ -14,6 +14,11 @@ import org.opensearch.cluster.decommission.DecommissionAttribute; import org.opensearch.common.unit.TimeValue; +/** + * Register decommission request builder + * + * @opensearch.internal + */ public class PutDecommissionRequestBuilder extends ClusterManagerNodeOperationRequestBuilder< PutDecommissionRequest, PutDecommissionResponse, diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java index 695e894aaa886..c584c039e2d93 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java @@ -15,6 +15,11 @@ import java.io.IOException; +/** + * Response for decommission request + * + * @opensearch.internal + */ public class PutDecommissionResponse extends AcknowledgedResponse implements ToXContentObject { public PutDecommissionResponse(StreamInput in) throws IOException { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java index d813378d15c62..08769e575fa5e 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java @@ -25,6 +25,11 @@ import java.io.IOException; +/** + * Transport action for registering decommission + * + * @opensearch.internal + */ public class TransportPutDecommissionAction extends TransportClusterManagerNodeAction { private static final Logger logger = LogManager.getLogger(TransportPutDecommissionAction.class); diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/package-info.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/package-info.java new file mode 100644 index 0000000000000..c361f4b95a484 --- /dev/null +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/package-info.java @@ -0,0 +1,10 @@ +/* + * 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. + */ + +/** Transport handlers for putting a new decommission request */ +package org.opensearch.action.admin.cluster.decommission.awareness.put; diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java index 458d73a6e8dd8..9155634c59239 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java @@ -23,6 +23,11 @@ import static java.util.Collections.singletonList; import static org.opensearch.rest.RestRequest.Method.PUT; +/** + * Registers decommission action + * + * @opensearch.api + */ public class RestPutDecommissionAction extends BaseRestHandler { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(300L); diff --git a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java index f5ff48e787637..71be108e1637d 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java @@ -41,6 +41,7 @@ public void testCreateRequest() throws IOException { assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(10L)); + assertEquals(deprecatedRequest.getHttpRequest().method(), RestRequest.Method.PUT); } public void testCreateRequestWithDefaultTimeout() throws IOException { @@ -54,10 +55,11 @@ public void testCreateRequestWithDefaultTimeout() throws IOException { assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(300L)); + assertEquals(deprecatedRequest.getHttpRequest().method(), RestRequest.Method.PUT); } private FakeRestRequest buildRestRequest(Map params) { - return new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.GET) + return new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.PUT) .withPath("/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}") .withParams(params) .build(); From 81748c1e9908451bca7be2f6047051bf4f03119d Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 1 Sep 2022 17:59:23 +0530 Subject: [PATCH 13/31] Empty-Commit Signed-off-by: Rishab Nahata From f4ec9085d0f82cb4b6c25123bc45f363742cb17d Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 2 Sep 2022 16:27:01 +0530 Subject: [PATCH 14/31] Rename PutDecommissionAction to DecommissionAction Signed-off-by: Rishab Nahata --- .../org/opensearch/action/ActionModule.java | 10 ++++----- ...ionAction.java => DecommissionAction.java} | 8 +++---- ...nRequest.java => DecommissionRequest.java} | 14 ++++++------ ...r.java => DecommissionRequestBuilder.java} | 18 +++++++-------- ...esponse.java => DecommissionResponse.java} | 6 ++--- ....java => TransportDecommissionAction.java} | 22 +++++++++---------- .../opensearch/client/ClusterAdminClient.java | 12 +++++----- .../java/org/opensearch/client/Requests.java | 6 ++--- .../client/support/AbstractClient.java | 20 ++++++++--------- ...ction.java => RestDecommissionAction.java} | 14 ++++++------ ...sts.java => DecommissionRequestTests.java} | 12 +++++----- ...ts.java => DecommissionResponseTests.java} | 6 ++--- ....java => RestDecommissionActionTests.java} | 12 +++++----- 13 files changed, 80 insertions(+), 80 deletions(-) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{PutDecommissionAction.java => DecommissionAction.java} (64%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{PutDecommissionRequest.java => DecommissionRequest.java} (82%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{PutDecommissionRequestBuilder.java => DecommissionRequestBuilder.java} (68%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{PutDecommissionResponse.java => DecommissionResponse.java} (77%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{TransportPutDecommissionAction.java => TransportDecommissionAction.java} (77%) rename server/src/main/java/org/opensearch/rest/action/admin/cluster/{RestPutDecommissionAction.java => RestDecommissionAction.java} (75%) rename server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{PutDecommissionRequestTests.java => DecommissionRequestTests.java} (78%) rename server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/{PutDecommissionResponseTests.java => DecommissionResponseTests.java} (66%) rename server/src/test/java/org/opensearch/rest/action/admin/cluster/{RestPutDecommissionActionTests.java => RestDecommissionActionTests.java} (86%) diff --git a/server/src/main/java/org/opensearch/action/ActionModule.java b/server/src/main/java/org/opensearch/action/ActionModule.java index 900d50a155c92..fd389cb69cc0e 100644 --- a/server/src/main/java/org/opensearch/action/ActionModule.java +++ b/server/src/main/java/org/opensearch/action/ActionModule.java @@ -42,8 +42,8 @@ import org.opensearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction; import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionAction; import org.opensearch.action.admin.cluster.decommission.awareness.get.TransportGetDecommissionAction; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionAction; -import org.opensearch.action.admin.cluster.decommission.awareness.put.TransportPutDecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.put.TransportDecommissionAction; import org.opensearch.action.admin.cluster.health.ClusterHealthAction; import org.opensearch.action.admin.cluster.health.TransportClusterHealthAction; import org.opensearch.action.admin.cluster.node.hotthreads.NodesHotThreadsAction; @@ -322,7 +322,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.RestDecommissionAction; import org.opensearch.rest.action.admin.cluster.RestPutRepositoryAction; import org.opensearch.rest.action.admin.cluster.RestPutStoredScriptAction; import org.opensearch.rest.action.admin.cluster.RestReloadSecureSettingsAction; @@ -690,7 +690,7 @@ public void reg actions.register(RestoreRemoteStoreAction.INSTANCE, TransportRestoreRemoteStoreAction.class); // Decommission actions - actions.register(PutDecommissionAction.INSTANCE, TransportPutDecommissionAction.class); + actions.register(DecommissionAction.INSTANCE, TransportDecommissionAction.class); actions.register(GetDecommissionAction.INSTANCE, TransportGetDecommissionAction.class); return unmodifiableMap(actions.getRegistry()); @@ -883,7 +883,7 @@ public void initRestHandlers(Supplier nodesInCluster) { } } registerHandler.accept(new RestCatAction(catActions)); - registerHandler.accept(new RestPutDecommissionAction()); + registerHandler.accept(new RestDecommissionAction()); registerHandler.accept(new RestGetDecommissionAction()); // Remote Store APIs diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionAction.java similarity index 64% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionAction.java index 78d6270247c97..56678650f6e35 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionAction.java @@ -15,11 +15,11 @@ * * @opensearch.internal */ -public final class PutDecommissionAction extends ActionType { - public static final PutDecommissionAction INSTANCE = new PutDecommissionAction(); +public final class DecommissionAction extends ActionType { + public static final DecommissionAction INSTANCE = new DecommissionAction(); public static final String NAME = "cluster:admin/decommission/awareness/put"; - private PutDecommissionAction() { - super(NAME, PutDecommissionResponse::new); + private DecommissionAction() { + super(NAME, DecommissionResponse::new); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java similarity index 82% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java index d92e2c002a0c8..f835f9368c41e 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java @@ -26,19 +26,19 @@ * * @opensearch.internal */ -public class PutDecommissionRequest extends ClusterManagerNodeRequest { +public class DecommissionRequest extends ClusterManagerNodeRequest { private DecommissionAttribute decommissionAttribute; private TimeValue timeout; - public PutDecommissionRequest() {} + public DecommissionRequest() {} - public PutDecommissionRequest(DecommissionAttribute decommissionAttribute, TimeValue timeout) { + public DecommissionRequest(DecommissionAttribute decommissionAttribute, TimeValue timeout) { this.decommissionAttribute = decommissionAttribute; this.timeout = timeout; } - public PutDecommissionRequest(StreamInput in) throws IOException { + public DecommissionRequest(StreamInput in) throws IOException { super(in); decommissionAttribute = new DecommissionAttribute(in); timeout = in.readTimeValue(); @@ -57,7 +57,7 @@ public void writeTo(StreamOutput out) throws IOException { * @param decommissionAttribute attribute key-value that needs to be decommissioned * @return this request */ - public PutDecommissionRequest setDecommissionAttribute(DecommissionAttribute decommissionAttribute) { + public DecommissionRequest setDecommissionAttribute(DecommissionAttribute decommissionAttribute) { this.decommissionAttribute = decommissionAttribute; return this; } @@ -68,7 +68,7 @@ public PutDecommissionRequest setDecommissionAttribute(DecommissionAttribute dec * @param timeout time out for the request * @return this request */ - public PutDecommissionRequest setTimeout(TimeValue timeout) { + public DecommissionRequest setTimeout(TimeValue timeout) { this.timeout = timeout; return this; } @@ -98,6 +98,6 @@ public ActionRequestValidationException validate() { @Override public String toString() { - return "PutDecommissionRequest{" + "decommissionAttribute=" + decommissionAttribute + ", timeout=" + timeout + '}'; + return "DecommissionRequest{" + "decommissionAttribute=" + decommissionAttribute + ", timeout=" + timeout + '}'; } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java similarity index 68% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java index 300ed202df98c..daeddf08b1684 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java @@ -19,15 +19,15 @@ * * @opensearch.internal */ -public class PutDecommissionRequestBuilder extends ClusterManagerNodeOperationRequestBuilder< - PutDecommissionRequest, - PutDecommissionResponse, - PutDecommissionRequestBuilder> { +public class DecommissionRequestBuilder extends ClusterManagerNodeOperationRequestBuilder< + DecommissionRequest, + DecommissionResponse, + DecommissionRequestBuilder> { - public PutDecommissionRequestBuilder( + public DecommissionRequestBuilder( OpenSearchClient client, - ActionType action, - PutDecommissionRequest request + ActionType action, + DecommissionRequest request ) { super(client, action, request); } @@ -36,7 +36,7 @@ public PutDecommissionRequestBuilder( * @param decommissionAttribute decommission attribute * @return current object */ - public PutDecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttribute decommissionAttribute) { + public DecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttribute decommissionAttribute) { request.setDecommissionAttribute(decommissionAttribute); return this; } @@ -45,7 +45,7 @@ public PutDecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttr * @param timeout time out for the request * @return current object */ - public PutDecommissionRequestBuilder setTimeout(TimeValue timeout) { + public DecommissionRequestBuilder setTimeout(TimeValue timeout) { request.setTimeout(timeout); return this; } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionResponse.java similarity index 77% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionResponse.java index c584c039e2d93..499f403c8cd64 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionResponse.java @@ -20,13 +20,13 @@ * * @opensearch.internal */ -public class PutDecommissionResponse extends AcknowledgedResponse implements ToXContentObject { +public class DecommissionResponse extends AcknowledgedResponse implements ToXContentObject { - public PutDecommissionResponse(StreamInput in) throws IOException { + public DecommissionResponse(StreamInput in) throws IOException { super(in); } - public PutDecommissionResponse(boolean acknowledged) { + public DecommissionResponse(boolean acknowledged) { super(acknowledged); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java similarity index 77% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java index 08769e575fa5e..f07d562f36d93 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportPutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java @@ -30,12 +30,12 @@ * * @opensearch.internal */ -public class TransportPutDecommissionAction extends TransportClusterManagerNodeAction { +public class TransportDecommissionAction extends TransportClusterManagerNodeAction { - private static final Logger logger = LogManager.getLogger(TransportPutDecommissionAction.class); + private static final Logger logger = LogManager.getLogger(TransportDecommissionAction.class); @Inject - public TransportPutDecommissionAction( + public TransportDecommissionAction( TransportService transportService, ClusterService clusterService, // DecommissionService decommissionService, @@ -44,12 +44,12 @@ public TransportPutDecommissionAction( IndexNameExpressionResolver indexNameExpressionResolver ) { super( - PutDecommissionAction.NAME, + DecommissionAction.NAME, transportService, clusterService, threadPool, actionFilters, - PutDecommissionRequest::new, + DecommissionRequest::new, indexNameExpressionResolver ); // TODO - uncomment when integrating with the service @@ -62,23 +62,23 @@ protected String executor() { } @Override - protected PutDecommissionResponse read(StreamInput in) throws IOException { - return new PutDecommissionResponse(in); + protected DecommissionResponse read(StreamInput in) throws IOException { + return new DecommissionResponse(in); } @Override - protected ClusterBlockException checkBlock(PutDecommissionRequest request, ClusterState state) { + protected ClusterBlockException checkBlock(DecommissionRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); } @Override protected void clusterManagerOperation( - PutDecommissionRequest request, + DecommissionRequest request, ClusterState state, - ActionListener listener + ActionListener listener ) throws Exception { logger.info("initiating awareness attribute [{}] decommissioning", request.getDecommissionAttribute().toString()); - listener.onResponse(new PutDecommissionResponse(true)); // TODO - remove after integration + listener.onResponse(new DecommissionResponse(true)); // TODO - remove after integration // TODO - uncomment when integrating with the service // decommissionService.initiateAttributeDecommissioning( // request.getDecommissionAttribute(), diff --git a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java index 0c5a7c2b30809..eca6b0bd8a5d9 100644 --- a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java @@ -40,9 +40,9 @@ import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequestBuilder; import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionResponse; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequestBuilder; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionResponse; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequestBuilder; import org.opensearch.action.admin.cluster.health.ClusterHealthResponse; @@ -801,17 +801,17 @@ public interface ClusterAdminClient extends OpenSearchClient { /** * Decommission a node */ - ActionFuture putDecommission(PutDecommissionRequest request); + ActionFuture decommission(DecommissionRequest request); /** * Decommission a node */ - void putDecommission(PutDecommissionRequest request, ActionListener listener); + void decommission(DecommissionRequest request, ActionListener listener); /** * Decommission a node */ - PutDecommissionRequestBuilder preparePutDecommission(PutDecommissionRequest request); + DecommissionRequestBuilder prepareDecommission(DecommissionRequest request); /** * Get Decommissioned attribute diff --git a/server/src/main/java/org/opensearch/client/Requests.java b/server/src/main/java/org/opensearch/client/Requests.java index ee97d0412a7c9..a0eac23fc9d98 100644 --- a/server/src/main/java/org/opensearch/client/Requests.java +++ b/server/src/main/java/org/opensearch/client/Requests.java @@ -33,7 +33,7 @@ package org.opensearch.client; import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; import org.opensearch.action.admin.cluster.node.stats.NodesStatsRequest; @@ -556,8 +556,8 @@ public static SnapshotsStatusRequest snapshotsStatusRequest(String repository) { * * @return returns put decommission request */ - public static PutDecommissionRequest putDecommissionRequest() { - return new PutDecommissionRequest(); + public static DecommissionRequest decommissionRequest() { + return new DecommissionRequest(); } /** diff --git a/server/src/main/java/org/opensearch/client/support/AbstractClient.java b/server/src/main/java/org/opensearch/client/support/AbstractClient.java index c120b24b1efd9..00ec2f5086b12 100644 --- a/server/src/main/java/org/opensearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/opensearch/client/support/AbstractClient.java @@ -47,10 +47,10 @@ import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequestBuilder; import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionResponse; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionAction; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequestBuilder; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionResponse; import org.opensearch.action.admin.cluster.health.ClusterHealthAction; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequestBuilder; @@ -1324,18 +1324,18 @@ public DeleteStoredScriptRequestBuilder prepareDeleteStoredScript(String id) { } @Override - public ActionFuture putDecommission(PutDecommissionRequest request) { - return execute(PutDecommissionAction.INSTANCE, request); + public ActionFuture decommission(DecommissionRequest request) { + return execute(DecommissionAction.INSTANCE, request); } @Override - public void putDecommission(PutDecommissionRequest request, ActionListener listener) { - execute(PutDecommissionAction.INSTANCE, request, listener); + public void decommission(DecommissionRequest request, ActionListener listener) { + execute(DecommissionAction.INSTANCE, request, listener); } @Override - public PutDecommissionRequestBuilder preparePutDecommission(PutDecommissionRequest request) { - return new PutDecommissionRequestBuilder(this, PutDecommissionAction.INSTANCE, request); + public DecommissionRequestBuilder prepareDecommission(DecommissionRequest request) { + return new DecommissionRequestBuilder(this, DecommissionAction.INSTANCE, request); } @Override diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java similarity index 75% rename from server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java rename to server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java index 9155634c59239..3c76b255fe138 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java @@ -8,7 +8,7 @@ package org.opensearch.rest.action.admin.cluster; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; import org.opensearch.client.Requests; import org.opensearch.client.node.NodeClient; import org.opensearch.cluster.decommission.DecommissionAttribute; @@ -28,7 +28,7 @@ * * @opensearch.api */ -public class RestPutDecommissionAction extends BaseRestHandler { +public class RestDecommissionAction extends BaseRestHandler { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(300L); @@ -44,14 +44,14 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - PutDecommissionRequest putDecommissionRequest = createRequest(request); - return channel -> client.admin().cluster().putDecommission(putDecommissionRequest, new RestToXContentListener<>(channel)); + DecommissionRequest decommissionRequest = createRequest(request); + return channel -> client.admin().cluster().decommission(decommissionRequest, new RestToXContentListener<>(channel)); } - PutDecommissionRequest createRequest(RestRequest request) throws IOException { + DecommissionRequest createRequest(RestRequest request) throws IOException { String attributeName = null; String attributeValue = null; - PutDecommissionRequest putDecommissionRequest = Requests.putDecommissionRequest(); + DecommissionRequest decommissionRequest = Requests.decommissionRequest(); if (request.hasParam("awareness_attribute_name")) { attributeName = request.param("awareness_attribute_name"); } @@ -59,7 +59,7 @@ PutDecommissionRequest createRequest(RestRequest request) throws IOException { if (request.hasParam("awareness_attribute_value")) { attributeValue = request.param("awareness_attribute_value"); } - return putDecommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)) + return decommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)) .setTimeout(TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java similarity index 78% rename from server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java rename to server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java index 606158725c955..fe03fc42d4ba4 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java @@ -15,16 +15,16 @@ import java.io.IOException; -public class PutDecommissionRequestTests extends OpenSearchTestCase { +public class DecommissionRequestTests extends OpenSearchTestCase { public void testSerialization() throws IOException { String attributeName = "zone"; String attributeValue = "zone-1"; DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest originalRequest = new PutDecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest originalRequest = new DecommissionRequest(decommissionAttribute, timeout); - final PutDecommissionRequest deserialized = copyWriteable(originalRequest, writableRegistry(), PutDecommissionRequest::new); + final DecommissionRequest deserialized = copyWriteable(originalRequest, writableRegistry(), DecommissionRequest::new); assertEquals(deserialized.getDecommissionAttribute(), originalRequest.getDecommissionAttribute()); assertEquals(deserialized.getTimeout(), originalRequest.getTimeout()); @@ -37,7 +37,7 @@ public void testValidation() { DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest request = new PutDecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest request = new DecommissionRequest(decommissionAttribute, timeout); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertTrue(e.getMessage().contains("attribute name is missing")); @@ -48,7 +48,7 @@ public void testValidation() { DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest request = new PutDecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest request = new DecommissionRequest(decommissionAttribute, timeout); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertTrue(e.getMessage().contains("attribute value is missing")); @@ -59,7 +59,7 @@ public void testValidation() { DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final PutDecommissionRequest request = new PutDecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest request = new DecommissionRequest(decommissionAttribute, timeout); ActionRequestValidationException e = request.validate(); assertNull(e); } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionResponseTests.java similarity index 66% rename from server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java rename to server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionResponseTests.java index 91f1cf3d9eb66..5ee5a5f3cf016 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/PutDecommissionResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionResponseTests.java @@ -12,10 +12,10 @@ import java.io.IOException; -public class PutDecommissionResponseTests extends OpenSearchTestCase { +public class DecommissionResponseTests extends OpenSearchTestCase { public void testSerialization() throws IOException { - final PutDecommissionResponse originalRequest = new PutDecommissionResponse(true); - copyWriteable(originalRequest, writableRegistry(), PutDecommissionResponse::new); + final DecommissionResponse originalRequest = new DecommissionResponse(true); + copyWriteable(originalRequest, writableRegistry(), DecommissionResponse::new); // there are no fields so we're just checking that this doesn't throw anything } } diff --git a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java similarity index 86% rename from server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java rename to server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java index 71be108e1637d..25b0ba0f273be 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestPutDecommissionActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java @@ -9,7 +9,7 @@ package org.opensearch.rest.action.admin.cluster; import org.junit.Before; -import org.opensearch.action.admin.cluster.decommission.awareness.put.PutDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; import org.opensearch.common.unit.TimeValue; import org.opensearch.rest.RestRequest; import org.opensearch.test.rest.FakeRestRequest; @@ -19,13 +19,13 @@ import java.util.HashMap; import java.util.Map; -public class RestPutDecommissionActionTests extends RestActionTestCase { +public class RestDecommissionActionTests extends RestActionTestCase { - private RestPutDecommissionAction action; + private RestDecommissionAction action; @Before public void setupAction() { - action = new RestPutDecommissionAction(); + action = new RestDecommissionAction(); controller().registerHandler(action); } @@ -37,7 +37,7 @@ public void testCreateRequest() throws IOException { RestRequest deprecatedRequest = buildRestRequest(params); - PutDecommissionRequest request = action.createRequest(deprecatedRequest); + DecommissionRequest request = action.createRequest(deprecatedRequest); assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(10L)); @@ -51,7 +51,7 @@ public void testCreateRequestWithDefaultTimeout() throws IOException { RestRequest deprecatedRequest = buildRestRequest(params); - PutDecommissionRequest request = action.createRequest(deprecatedRequest); + DecommissionRequest request = action.createRequest(deprecatedRequest); assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(300L)); From 0c08d980aa608b78e1ebdd56a29cfc1c6cfcbba2 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 2 Sep 2022 16:35:58 +0530 Subject: [PATCH 15/31] Refactor GetDecommissionAction to GetDecommissionStateAction Signed-off-by: Rishab Nahata --- .../org/opensearch/action/ActionModule.java | 10 ++++---- ...n.java => GetDecommissionStateAction.java} | 8 +++---- ....java => GetDecommissionStateRequest.java} | 6 ++--- ...> GetDecommissionStateRequestBuilder.java} | 12 +++++----- ...java => GetDecommissionStateResponse.java} | 12 +++++----- ... TransportGetDecommissionStateAction.java} | 24 +++++++++---------- .../opensearch/client/ClusterAdminClient.java | 12 +++++----- .../java/org/opensearch/client/Requests.java | 6 ++--- .../client/support/AbstractClient.java | 20 ++++++++-------- .../admin/cluster/RestDecommissionAction.java | 2 +- ...va => RestGetDecommissionStateAction.java} | 12 +++++----- ...=> GetDecommissionStateResponseTests.java} | 10 ++++---- 12 files changed, 67 insertions(+), 67 deletions(-) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/{GetDecommissionAction.java => GetDecommissionStateAction.java} (62%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/{GetDecommissionRequest.java => GetDecommissionStateRequest.java} (79%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/{GetDecommissionRequestBuilder.java => GetDecommissionStateRequestBuilder.java} (60%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/{GetDecommissionResponse.java => GetDecommissionStateResponse.java} (91%) rename server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/{TransportGetDecommissionAction.java => TransportGetDecommissionStateAction.java} (71%) rename server/src/main/java/org/opensearch/rest/action/admin/cluster/{RestGetDecommissionAction.java => RestGetDecommissionStateAction.java} (76%) rename server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/{GetDecommissionResponseTests.java => GetDecommissionStateResponseTests.java} (70%) diff --git a/server/src/main/java/org/opensearch/action/ActionModule.java b/server/src/main/java/org/opensearch/action/ActionModule.java index fd389cb69cc0e..1d19875267678 100644 --- a/server/src/main/java/org/opensearch/action/ActionModule.java +++ b/server/src/main/java/org/opensearch/action/ActionModule.java @@ -40,8 +40,8 @@ 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.awareness.get.GetDecommissionAction; -import org.opensearch.action.admin.cluster.decommission.awareness.get.TransportGetDecommissionAction; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateAction; +import org.opensearch.action.admin.cluster.decommission.awareness.get.TransportGetDecommissionStateAction; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionAction; import org.opensearch.action.admin.cluster.decommission.awareness.put.TransportDecommissionAction; import org.opensearch.action.admin.cluster.health.ClusterHealthAction; @@ -309,7 +309,7 @@ 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.RestGetDecommissionStateAction; import org.opensearch.rest.action.admin.cluster.RestGetRepositoriesAction; import org.opensearch.rest.action.admin.cluster.RestGetScriptContextAction; import org.opensearch.rest.action.admin.cluster.RestGetScriptLanguageAction; @@ -691,7 +691,7 @@ public void reg // Decommission actions actions.register(DecommissionAction.INSTANCE, TransportDecommissionAction.class); - actions.register(GetDecommissionAction.INSTANCE, TransportGetDecommissionAction.class); + actions.register(GetDecommissionStateAction.INSTANCE, TransportGetDecommissionStateAction.class); return unmodifiableMap(actions.getRegistry()); } @@ -884,7 +884,7 @@ public void initRestHandlers(Supplier nodesInCluster) { } registerHandler.accept(new RestCatAction(catActions)); registerHandler.accept(new RestDecommissionAction()); - registerHandler.accept(new RestGetDecommissionAction()); + registerHandler.accept(new RestGetDecommissionStateAction()); // Remote Store APIs if (FeatureFlags.isEnabled(FeatureFlags.REMOTE_STORE)) { diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateAction.java similarity index 62% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateAction.java index 72a7d5d53ce77..72fd1a26cb860 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateAction.java @@ -15,12 +15,12 @@ * * @opensearch.internal */ -public class GetDecommissionAction extends ActionType { +public class GetDecommissionStateAction extends ActionType { - public static final GetDecommissionAction INSTANCE = new GetDecommissionAction(); + public static final GetDecommissionStateAction INSTANCE = new GetDecommissionStateAction(); public static final String NAME = "cluster:admin/decommission/awareness/get"; - private GetDecommissionAction() { - super(NAME, GetDecommissionResponse::new); + private GetDecommissionStateAction() { + super(NAME, GetDecommissionStateResponse::new); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateRequest.java similarity index 79% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateRequest.java index fa979544129c2..90150c71bf3f2 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateRequest.java @@ -20,11 +20,11 @@ * * @opensearch.internal */ -public class GetDecommissionRequest extends ClusterManagerNodeReadRequest { +public class GetDecommissionStateRequest extends ClusterManagerNodeReadRequest { - public GetDecommissionRequest() {} + public GetDecommissionStateRequest() {} - public GetDecommissionRequest(StreamInput in) throws IOException { + public GetDecommissionStateRequest(StreamInput in) throws IOException { super(in); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateRequestBuilder.java similarity index 60% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateRequestBuilder.java index c6a5925d87860..2b8616d0511cd 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateRequestBuilder.java @@ -16,15 +16,15 @@ * * @opensearch.internal */ -public class GetDecommissionRequestBuilder extends ClusterManagerNodeReadOperationRequestBuilder< - GetDecommissionRequest, - GetDecommissionResponse, - GetDecommissionRequestBuilder> { +public class GetDecommissionStateRequestBuilder extends ClusterManagerNodeReadOperationRequestBuilder< + GetDecommissionStateRequest, + GetDecommissionStateResponse, + GetDecommissionStateRequestBuilder> { /** * Creates new get decommissioned attributes request builder */ - public GetDecommissionRequestBuilder(OpenSearchClient client, GetDecommissionAction action) { - super(client, action, new GetDecommissionRequest()); + public GetDecommissionStateRequestBuilder(OpenSearchClient client, GetDecommissionStateAction action) { + super(client, action, new GetDecommissionStateRequest()); } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java similarity index 91% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java index 29c307065a700..4b6c1f20db008 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java @@ -28,17 +28,17 @@ * * @opensearch.internal */ -public class GetDecommissionResponse extends ActionResponse implements ToXContentObject { +public class GetDecommissionStateResponse extends ActionResponse implements ToXContentObject { private final DecommissionAttribute decommissionedAttribute; private final DecommissionStatus status; - GetDecommissionResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { + GetDecommissionStateResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { this.decommissionedAttribute = decommissionedAttribute; this.status = status; } - GetDecommissionResponse(StreamInput in) throws IOException { + GetDecommissionStateResponse(StreamInput in) throws IOException { this.decommissionedAttribute = new DecommissionAttribute(in); this.status = DecommissionStatus.fromValue(in.readByte()); } @@ -72,7 +72,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws return builder; } - public static GetDecommissionResponse fromXContent(XContentParser parser) throws IOException { + public static GetDecommissionStateResponse fromXContent(XContentParser parser) throws IOException { ensureExpectedToken(XContentParser.Token.START_OBJECT, parser.nextToken(), parser); String attributeType = "awareness"; XContentParser.Token token; @@ -125,14 +125,14 @@ public static GetDecommissionResponse fromXContent(XContentParser parser) throws } } } - return new GetDecommissionResponse(decommissionAttribute, status); + return new GetDecommissionStateResponse(decommissionAttribute, status); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - GetDecommissionResponse that = (GetDecommissionResponse) o; + GetDecommissionStateResponse that = (GetDecommissionStateResponse) o; return decommissionedAttribute.equals(that.decommissionedAttribute) && status == that.status; } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java similarity index 71% rename from server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java rename to server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java index 28d91fd454d20..0080c6dfd41cd 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java @@ -31,10 +31,10 @@ * * @opensearch.internal */ -public class TransportGetDecommissionAction extends TransportClusterManagerNodeReadAction { +public class TransportGetDecommissionStateAction extends TransportClusterManagerNodeReadAction { @Inject - public TransportGetDecommissionAction( + public TransportGetDecommissionStateAction( TransportService transportService, ClusterService clusterService, ThreadPool threadPool, @@ -42,12 +42,12 @@ public TransportGetDecommissionAction( IndexNameExpressionResolver indexNameExpressionResolver ) { super( - GetDecommissionAction.NAME, + GetDecommissionStateAction.NAME, transportService, clusterService, threadPool, actionFilters, - GetDecommissionRequest::new, + GetDecommissionStateRequest::new, indexNameExpressionResolver ); } @@ -58,34 +58,34 @@ protected String executor() { } @Override - protected GetDecommissionResponse read(StreamInput in) throws IOException { - return new GetDecommissionResponse(in); + protected GetDecommissionStateResponse read(StreamInput in) throws IOException { + return new GetDecommissionStateResponse(in); } @Override protected void clusterManagerOperation( - GetDecommissionRequest request, + GetDecommissionStateRequest request, ClusterState state, - ActionListener listener + ActionListener listener ) throws Exception { Metadata metadata = state.metadata(); // DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); // TODO - update once service layer changes are merged // <<<<<<< HEAD - listener.onResponse(new GetDecommissionResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED)); + listener.onResponse(new GetDecommissionStateResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED)); // ======= // if (decommissionedAttributes!=null) { - // listener.onResponse(new GetDecommissionResponse(decommissionedAttributes.decommissionAttribute(), + // listener.onResponse(new GetDecommissionStateResponse(decommissionedAttributes.decommissionAttribute(), // decommissionedAttributes.status())); // } // else { - // listener.onResponse(new GetDecommissionResponse()); + // listener.onResponse(new GetDecommissionStateResponse()); // } // >>>>>>> 1025b6e3e3e (Fix GET without PUT) } @Override - protected ClusterBlockException checkBlock(GetDecommissionRequest request, ClusterState state) { + protected ClusterBlockException checkBlock(GetDecommissionStateRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ); } } diff --git a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java index eca6b0bd8a5d9..69c63017632c1 100644 --- a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java @@ -37,9 +37,9 @@ import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequestBuilder; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateResponse; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequestBuilder; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionResponse; @@ -816,15 +816,15 @@ public interface ClusterAdminClient extends OpenSearchClient { /** * Get Decommissioned attribute */ - ActionFuture getDecommission(GetDecommissionRequest request); + ActionFuture getDecommission(GetDecommissionStateRequest request); /** * Get Decommissioned attribute */ - void getDecommission(GetDecommissionRequest request, ActionListener listener); + void getDecommission(GetDecommissionStateRequest request, ActionListener listener); /** * Get Decommissioned attribute */ - GetDecommissionRequestBuilder prepareGetDecommission(); + GetDecommissionStateRequestBuilder prepareGetDecommission(); } diff --git a/server/src/main/java/org/opensearch/client/Requests.java b/server/src/main/java/org/opensearch/client/Requests.java index a0eac23fc9d98..38674f8d917cd 100644 --- a/server/src/main/java/org/opensearch/client/Requests.java +++ b/server/src/main/java/org/opensearch/client/Requests.java @@ -32,7 +32,7 @@ package org.opensearch.client; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateRequest; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; import org.opensearch.action.admin.cluster.health.ClusterHealthRequest; import org.opensearch.action.admin.cluster.node.info.NodesInfoRequest; @@ -565,7 +565,7 @@ public static DecommissionRequest decommissionRequest() { * * @return returns get decommission request */ - public static GetDecommissionRequest getDecommissionRequest() { - return new GetDecommissionRequest(); + public static GetDecommissionStateRequest getDecommissionStateRequest() { + return new GetDecommissionStateRequest(); } } diff --git a/server/src/main/java/org/opensearch/client/support/AbstractClient.java b/server/src/main/java/org/opensearch/client/support/AbstractClient.java index 00ec2f5086b12..253e20d84c410 100644 --- a/server/src/main/java/org/opensearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/opensearch/client/support/AbstractClient.java @@ -43,10 +43,10 @@ import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainRequestBuilder; import org.opensearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionAction; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequestBuilder; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionResponse; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateAction; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateRequestBuilder; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateResponse; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionAction; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequestBuilder; @@ -1339,18 +1339,18 @@ public DecommissionRequestBuilder prepareDecommission(DecommissionRequest reques } @Override - public ActionFuture getDecommission(GetDecommissionRequest request) { - return execute(GetDecommissionAction.INSTANCE, request); + public ActionFuture getDecommission(GetDecommissionStateRequest request) { + return execute(GetDecommissionStateAction.INSTANCE, request); } @Override - public void getDecommission(GetDecommissionRequest request, ActionListener listener) { - execute(GetDecommissionAction.INSTANCE, request, listener); + public void getDecommission(GetDecommissionStateRequest request, ActionListener listener) { + execute(GetDecommissionStateAction.INSTANCE, request, listener); } @Override - public GetDecommissionRequestBuilder prepareGetDecommission() { - return new GetDecommissionRequestBuilder(this, GetDecommissionAction.INSTANCE); + public GetDecommissionStateRequestBuilder prepareGetDecommission() { + return new GetDecommissionStateRequestBuilder(this, GetDecommissionStateAction.INSTANCE); } } diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java index 3c76b255fe138..f48b3a38f77e1 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java @@ -39,7 +39,7 @@ public List routes() { @Override public String getName() { - return "put_decommission_action"; + return "decommission_action"; } @Override diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java similarity index 76% rename from server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java rename to server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java index 3f962e75c2274..2caca50501914 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java @@ -8,7 +8,7 @@ package org.opensearch.rest.action.admin.cluster; -import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionRequest; +import org.opensearch.action.admin.cluster.decommission.awareness.get.GetDecommissionStateRequest; import org.opensearch.client.Requests; import org.opensearch.client.node.NodeClient; import org.opensearch.rest.BaseRestHandler; @@ -26,7 +26,7 @@ * * @opensearch.api */ -public class RestGetDecommissionAction extends BaseRestHandler { +public class RestGetDecommissionStateAction extends BaseRestHandler { @Override public List routes() { @@ -40,10 +40,10 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - GetDecommissionRequest getDecommissionRequest = Requests.getDecommissionRequest(); - getDecommissionRequest.clusterManagerNodeTimeout( - request.paramAsTime("cluster_manager_timeout", getDecommissionRequest.clusterManagerNodeTimeout()) + GetDecommissionStateRequest getDecommissionStateRequest = Requests.getDecommissionStateRequest(); + getDecommissionStateRequest.clusterManagerNodeTimeout( + request.paramAsTime("cluster_manager_timeout", getDecommissionStateRequest.clusterManagerNodeTimeout()) ); - return channel -> client.admin().cluster().getDecommission(getDecommissionRequest, new RestToXContentListener<>(channel)); + return channel -> client.admin().cluster().getDecommission(getDecommissionStateRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java similarity index 70% rename from server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java rename to server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java index be6d336128882..32f4fcf99f565 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java @@ -15,19 +15,19 @@ import java.io.IOException; -public class GetDecommissionResponseTests extends AbstractXContentTestCase { +public class GetDecommissionStateResponseTests extends AbstractXContentTestCase { @Override - protected GetDecommissionResponse createTestInstance() { + protected GetDecommissionStateResponse createTestInstance() { DecommissionStatus status = DecommissionStatus.fromValue((byte) randomIntBetween(0, 5)); String attributeName = randomAlphaOfLength(10); String attributeValue = randomAlphaOfLength(10); DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); - return new GetDecommissionResponse(decommissionAttribute, status); + return new GetDecommissionStateResponse(decommissionAttribute, status); } @Override - protected GetDecommissionResponse doParseInstance(XContentParser parser) throws IOException { - return GetDecommissionResponse.fromXContent(parser); + protected GetDecommissionStateResponse doParseInstance(XContentParser parser) throws IOException { + return GetDecommissionStateResponse.fromXContent(parser); } @Override From a1289a2f06bf40f0065457f91389e61916a48786 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 2 Sep 2022 16:44:04 +0530 Subject: [PATCH 16/31] Fix spotless check Signed-off-by: Rishab Nahata --- .../get/TransportGetDecommissionStateAction.java | 8 ++++++-- .../awareness/put/DecommissionRequestBuilder.java | 8 ++------ .../awareness/put/TransportDecommissionAction.java | 7 ++----- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java index 0080c6dfd41cd..ab3567d23cbdb 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java @@ -31,7 +31,9 @@ * * @opensearch.internal */ -public class TransportGetDecommissionStateAction extends TransportClusterManagerNodeReadAction { +public class TransportGetDecommissionStateAction extends TransportClusterManagerNodeReadAction< + GetDecommissionStateRequest, + GetDecommissionStateResponse> { @Inject public TransportGetDecommissionStateAction( @@ -72,7 +74,9 @@ protected void clusterManagerOperation( // DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); // TODO - update once service layer changes are merged // <<<<<<< HEAD - listener.onResponse(new GetDecommissionStateResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED)); + listener.onResponse( + new GetDecommissionStateResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED) + ); // ======= // if (decommissionedAttributes!=null) { // listener.onResponse(new GetDecommissionStateResponse(decommissionedAttributes.decommissionAttribute(), diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java index daeddf08b1684..2a9de91056785 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java @@ -20,15 +20,11 @@ * @opensearch.internal */ public class DecommissionRequestBuilder extends ClusterManagerNodeOperationRequestBuilder< - DecommissionRequest, + DecommissionRequest, DecommissionResponse, DecommissionRequestBuilder> { - public DecommissionRequestBuilder( - OpenSearchClient client, - ActionType action, - DecommissionRequest request - ) { + public DecommissionRequestBuilder(OpenSearchClient client, ActionType action, DecommissionRequest request) { super(client, action, request); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java index f07d562f36d93..166912c4a5e9c 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java @@ -72,11 +72,8 @@ protected ClusterBlockException checkBlock(DecommissionRequest request, ClusterS } @Override - protected void clusterManagerOperation( - DecommissionRequest request, - ClusterState state, - ActionListener listener - ) throws Exception { + protected void clusterManagerOperation(DecommissionRequest request, ClusterState state, ActionListener listener) + throws Exception { logger.info("initiating awareness attribute [{}] decommissioning", request.getDecommissionAttribute().toString()); listener.onResponse(new DecommissionResponse(true)); // TODO - remove after integration // TODO - uncomment when integrating with the service From 93ae7c23f7b26d7b9fcdf4cd7c2f28de2da65881 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 8 Sep 2022 16:18:35 +0530 Subject: [PATCH 17/31] fix empty response Signed-off-by: Rishab Nahata --- .../get/GetDecommissionStateResponse.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java index 4b6c1f20db008..9748f13642765 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java @@ -14,6 +14,7 @@ import org.opensearch.cluster.decommission.DecommissionStatus; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; @@ -39,14 +40,30 @@ public class GetDecommissionStateResponse extends ActionResponse implements ToXC } GetDecommissionStateResponse(StreamInput in) throws IOException { - this.decommissionedAttribute = new DecommissionAttribute(in); - this.status = DecommissionStatus.fromValue(in.readByte()); + if (in.readBoolean()) { + this.decommissionedAttribute = new DecommissionAttribute(in); + } else { + this.decommissionedAttribute = null; + } + if (in.readBoolean()) { + this.status = DecommissionStatus.fromString(in.readString()); + } else { + this.status = null; + } } @Override public void writeTo(StreamOutput out) throws IOException { - decommissionedAttribute.writeTo(out); - out.writeByte(status.value()); + boolean isNotNullDecommissionAttribute = this.decommissionedAttribute != null; + boolean isNotNullStatus = this.status != null; + out.writeBoolean(isNotNullDecommissionAttribute); + if (isNotNullDecommissionAttribute) { + decommissionedAttribute.writeTo(out); + } + out.writeBoolean(isNotNullStatus); + if (isNotNullStatus) { + out.writeString(status.status()); + } } public DecommissionAttribute getDecommissionedAttribute() { From c9b0b48eddc8eb8dfd7fb8b7fb9b36d8c3133c94 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Thu, 22 Sep 2022 17:18:26 +0530 Subject: [PATCH 18/31] minor fix Signed-off-by: Rishab Nahata --- .../action/admin/cluster/RestGetDecommissionStateAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java index 2caca50501914..a77164709370d 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java @@ -35,7 +35,7 @@ public List routes() { @Override public String getName() { - return "get_decommission_action"; + return "get_decommission_state_action"; } @Override From 00270f09a91cb4de1e8da41066407c0c5bd37af3 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Sun, 25 Sep 2022 12:47:34 +0530 Subject: [PATCH 19/31] Update changelog Signed-off-by: Rishab Nahata --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acb8ded704a7b..583136b4f97da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - [Remote Store] Change behaviour in replica recovery for remote translog enabled indices ([#4318](https://github.com/opensearch-project/OpenSearch/pull/4318)) - Unmute test RelocationIT.testRelocationWhileIndexingRandom ([#4580](https://github.com/opensearch-project/OpenSearch/pull/4580)) - Add DecommissionService and helper to execute awareness attribute decommissioning ([#4084](https://github.com/opensearch-project/OpenSearch/pull/4084)) - +- Add APIs (GET/PUT) to decommission awareness attribute ([#4261](https://github.com/opensearch-project/OpenSearch/pull/4261)) ### Deprecated From 71529326ff3482934144bff4622058d248e95149 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Sun, 25 Sep 2022 12:58:05 +0530 Subject: [PATCH 20/31] Fix API PR after service merge Signed-off-by: Rishab Nahata --- .../get/GetDecommissionStateResponse.java | 6 ++++- .../TransportGetDecommissionStateAction.java | 24 +++++++------------ .../put/TransportDecommissionAction.java | 17 +++++-------- .../decommission/DecommissionService.java | 7 +++--- .../DecommissionServiceTests.java | 13 +++++----- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java index 9748f13642765..92a18986736dc 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java @@ -34,6 +34,10 @@ public class GetDecommissionStateResponse extends ActionResponse implements ToXC private final DecommissionAttribute decommissionedAttribute; private final DecommissionStatus status; + GetDecommissionStateResponse() { + this(null, null); + } + GetDecommissionStateResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { this.decommissionedAttribute = decommissionedAttribute; this.status = status; @@ -120,7 +124,7 @@ public static GetDecommissionStateResponse fromXContent(XContentParser parser) t ); } decommissionAttribute = new DecommissionAttribute(fieldName, value); - token = parser.nextToken(); + parser.nextToken(); } else { throw new OpenSearchParseException("failed to parse attribute type [{}], unexpected type", attributeType); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java index ab3567d23cbdb..3980de78e297a 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java @@ -15,6 +15,7 @@ import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.cluster.decommission.DecommissionAttributeMetadata; import org.opensearch.cluster.decommission.DecommissionStatus; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.Metadata; @@ -70,22 +71,13 @@ protected void clusterManagerOperation( ClusterState state, ActionListener listener ) throws Exception { - Metadata metadata = state.metadata(); - // DecommissionAttributeMetadata decommissionedAttributes = metadata.custom(DecommissionAttributeMetadata.TYPE); - // TODO - update once service layer changes are merged - // <<<<<<< HEAD - listener.onResponse( - new GetDecommissionStateResponse(new DecommissionAttribute("zone", "zone-1"), DecommissionStatus.DECOMMISSIONED) - ); - // ======= - // if (decommissionedAttributes!=null) { - // listener.onResponse(new GetDecommissionStateResponse(decommissionedAttributes.decommissionAttribute(), - // decommissionedAttributes.status())); - // } - // else { - // listener.onResponse(new GetDecommissionStateResponse()); - // } - // >>>>>>> 1025b6e3e3e (Fix GET without PUT) + DecommissionAttributeMetadata decommissionAttributeMetadata = state.metadata().decommissionAttributeMetadata(); + if (decommissionAttributeMetadata != null) { + listener.onResponse(new GetDecommissionStateResponse(decommissionAttributeMetadata.decommissionAttribute(), + decommissionAttributeMetadata.status())); + } else { + listener.onResponse(new GetDecommissionStateResponse()); + } } @Override diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java index 166912c4a5e9c..2069c2cab21aa 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java @@ -16,6 +16,7 @@ import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; +import org.opensearch.cluster.decommission.DecommissionService; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; @@ -33,12 +34,13 @@ public class TransportDecommissionAction extends TransportClusterManagerNodeAction { private static final Logger logger = LogManager.getLogger(TransportDecommissionAction.class); + private final DecommissionService decommissionService; @Inject public TransportDecommissionAction( TransportService transportService, ClusterService clusterService, - // DecommissionService decommissionService, + DecommissionService decommissionService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver @@ -52,8 +54,7 @@ public TransportDecommissionAction( DecommissionRequest::new, indexNameExpressionResolver ); - // TODO - uncomment when integrating with the service - // this.decommissionService = decommissionService; + this.decommissionService = decommissionService; } @Override @@ -74,13 +75,7 @@ protected ClusterBlockException checkBlock(DecommissionRequest request, ClusterS @Override protected void clusterManagerOperation(DecommissionRequest request, ClusterState state, ActionListener listener) throws Exception { - logger.info("initiating awareness attribute [{}] decommissioning", request.getDecommissionAttribute().toString()); - listener.onResponse(new DecommissionResponse(true)); // TODO - remove after integration - // TODO - uncomment when integrating with the service - // decommissionService.initiateAttributeDecommissioning( - // request.getDecommissionAttribute(), - // listener, - // state - // ); + logger.info("starting awareness attribute [{}] decommissioning", request.getDecommissionAttribute().toString()); + decommissionService.startDecommissionAction(request.getDecommissionAttribute(), listener); } } diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java index 1a0704c5a4ac2..f027f8d6e902b 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java @@ -13,6 +13,7 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.opensearch.OpenSearchTimeoutException; import org.opensearch.action.ActionListener; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionResponse; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.ClusterStateObserver; import org.opensearch.cluster.ClusterStateUpdateTask; @@ -117,7 +118,7 @@ private void setForcedAwarenessAttributes(Settings forceSettings) { */ public void startDecommissionAction( final DecommissionAttribute decommissionAttribute, - final ActionListener listener + final ActionListener listener ) { // register the metadata with status as INIT as first step clusterService.submitStateUpdateTask("decommission [" + decommissionAttribute + "]", new ClusterStateUpdateTask(Priority.URGENT) { @@ -163,7 +164,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS private synchronized void decommissionClusterManagerNodes( final DecommissionAttribute decommissionAttribute, - ActionListener listener + ActionListener listener ) { ClusterState state = clusterService.getClusterApplierService().state(); // since here metadata is already registered with INIT, we can guarantee that no new node with decommission attribute can further @@ -205,7 +206,7 @@ public void onResponse(Void unused) { // we are good here to send the response now as the request is processed by an eligible active leader // and to-be-decommissioned cluster manager is no more part of Voting Configuration and no more to-be-decommission // nodes can be part of Voting Config - listener.onResponse(new ClusterStateUpdateResponse(true)); + listener.onResponse(new DecommissionResponse(true)); failDecommissionedNodes(clusterService.getClusterApplierService().state()); } } else { diff --git a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java index 71ee61ffec275..16efd914a472f 100644 --- a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java @@ -13,6 +13,7 @@ import org.junit.Before; import org.opensearch.Version; import org.opensearch.action.ActionListener; +import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionResponse; import org.opensearch.cluster.ClusterName; import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.ack.ClusterStateUpdateResponse; @@ -120,9 +121,9 @@ public void shutdownThreadPoolAndClusterService() { public void testDecommissioningNotStartedForInvalidAttributeName() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); DecommissionAttribute decommissionAttribute = new DecommissionAttribute("rack", "rack-a"); - ActionListener listener = new ActionListener() { + ActionListener listener = new ActionListener() { @Override - public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { + public void onResponse(DecommissionResponse decommissionResponse) { fail("on response shouldn't have been called"); } @@ -141,9 +142,9 @@ public void onFailure(Exception e) { public void testDecommissioningNotStartedForInvalidAttributeValue() throws InterruptedException { final CountDownLatch countDownLatch = new CountDownLatch(1); DecommissionAttribute decommissionAttribute = new DecommissionAttribute("zone", "rack-a"); - ActionListener listener = new ActionListener() { + ActionListener listener = new ActionListener() { @Override - public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { + public void onResponse(DecommissionResponse decommissionResponse) { fail("on response shouldn't have been called"); } @@ -177,9 +178,9 @@ public void testDecommissioningFailedWhenAnotherAttributeDecommissioningSuccessf clusterService, builder.metadata(Metadata.builder(clusterService.state().metadata()).decommissionAttributeMetadata(oldMetadata).build()) ); - ActionListener listener = new ActionListener() { + ActionListener listener = new ActionListener() { @Override - public void onResponse(ClusterStateUpdateResponse clusterStateUpdateResponse) { + public void onResponse(DecommissionResponse decommissionResponse) { fail("on response shouldn't have been called"); } From 9a9f5afaa47b9d6ed30e76ba2063d1d96484b9be Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Sun, 25 Sep 2022 13:06:18 +0530 Subject: [PATCH 21/31] Fix spotless check Signed-off-by: Rishab Nahata --- .../awareness/get/GetDecommissionStateResponse.java | 1 - .../get/TransportGetDecommissionStateAction.java | 11 ++++++----- .../awareness/put/TransportDecommissionAction.java | 2 +- .../cluster/decommission/DecommissionService.java | 1 - .../get/GetDecommissionStateResponseTests.java | 2 +- .../decommission/DecommissionServiceTests.java | 1 - 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java index 92a18986736dc..33e1d13f32d61 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java @@ -14,7 +14,6 @@ import org.opensearch.cluster.decommission.DecommissionStatus; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.settings.Settings; import org.opensearch.common.xcontent.ToXContentObject; import org.opensearch.common.xcontent.XContentBuilder; import org.opensearch.common.xcontent.XContentParser; diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java index 3980de78e297a..48ed13c6c0aaf 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/TransportGetDecommissionStateAction.java @@ -14,11 +14,8 @@ import org.opensearch.cluster.ClusterState; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.block.ClusterBlockLevel; -import org.opensearch.cluster.decommission.DecommissionAttribute; import org.opensearch.cluster.decommission.DecommissionAttributeMetadata; -import org.opensearch.cluster.decommission.DecommissionStatus; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; -import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.inject.Inject; import org.opensearch.common.io.stream.StreamInput; @@ -73,8 +70,12 @@ protected void clusterManagerOperation( ) throws Exception { DecommissionAttributeMetadata decommissionAttributeMetadata = state.metadata().decommissionAttributeMetadata(); if (decommissionAttributeMetadata != null) { - listener.onResponse(new GetDecommissionStateResponse(decommissionAttributeMetadata.decommissionAttribute(), - decommissionAttributeMetadata.status())); + listener.onResponse( + new GetDecommissionStateResponse( + decommissionAttributeMetadata.decommissionAttribute(), + decommissionAttributeMetadata.status() + ) + ); } else { listener.onResponse(new GetDecommissionStateResponse()); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java index 2069c2cab21aa..3a067d2f110b9 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/TransportDecommissionAction.java @@ -54,7 +54,7 @@ public TransportDecommissionAction( DecommissionRequest::new, indexNameExpressionResolver ); - this.decommissionService = decommissionService; + this.decommissionService = decommissionService; } @Override diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java index f027f8d6e902b..6550f0f3813f8 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java @@ -18,7 +18,6 @@ import org.opensearch.cluster.ClusterStateObserver; import org.opensearch.cluster.ClusterStateUpdateTask; import org.opensearch.cluster.NotClusterManagerException; -import org.opensearch.cluster.ack.ClusterStateUpdateResponse; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.routing.allocation.AllocationService; diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java index 32f4fcf99f565..97bc54d8d7b30 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponseTests.java @@ -18,7 +18,7 @@ public class GetDecommissionStateResponseTests extends AbstractXContentTestCase { @Override protected GetDecommissionStateResponse createTestInstance() { - DecommissionStatus status = DecommissionStatus.fromValue((byte) randomIntBetween(0, 5)); + DecommissionStatus status = randomFrom(DecommissionStatus.values()); String attributeName = randomAlphaOfLength(10); String attributeValue = randomAlphaOfLength(10); DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); diff --git a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java index 16efd914a472f..61a6662ef0cf3 100644 --- a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java @@ -16,7 +16,6 @@ import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionResponse; import org.opensearch.cluster.ClusterName; import org.opensearch.cluster.ClusterState; -import org.opensearch.cluster.ack.ClusterStateUpdateResponse; import org.opensearch.cluster.coordination.CoordinationMetadata; import org.opensearch.cluster.metadata.Metadata; import org.opensearch.cluster.node.DiscoveryNode; From 1c845db6d4176b7a6feedded22a749fa26dafdce Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Sun, 25 Sep 2022 20:43:03 +0530 Subject: [PATCH 22/31] Fix parsing issue Signed-off-by: Rishab Nahata --- .../awareness/get/GetDecommissionStateResponse.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java index 33e1d13f32d61..0351bf17e6d13 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java @@ -19,6 +19,7 @@ import org.opensearch.common.xcontent.XContentParser; import java.io.IOException; +import java.util.Locale; import java.util.Objects; import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; @@ -136,7 +137,7 @@ public static GetDecommissionStateResponse fromXContent(XContentParser parser) t "failed to parse status of decommissioning, expected string but found unknown type" ); } - status = DecommissionStatus.fromString(parser.text()); + status = DecommissionStatus.fromString(parser.text().toLowerCase(Locale.ROOT)); } else { throw new OpenSearchParseException( "unknown field found [{}], failed to parse the decommission attribute", From 40ffde788916841a2d35969a48f0e53c4fec700b Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 26 Sep 2022 11:50:53 +0530 Subject: [PATCH 23/31] Handle master abdication more gracefully Signed-off-by: Rishab Nahata --- .../org/opensearch/cluster/coordination/JoinTaskExecutor.java | 2 +- .../opensearch/cluster/decommission/DecommissionService.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java b/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java index 78b09dc020dfc..814aa17255931 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java @@ -484,7 +484,7 @@ public static void ensureNodeCommissioned(DiscoveryNode node, Metadata metadata) if (decommissionAttribute != null && status != null) { // We will let the node join the cluster if the current status is in FAILED state if (node.getAttributes().get(decommissionAttribute.attributeName()).equals(decommissionAttribute.attributeValue()) - && status.equals(DecommissionStatus.FAILED) == false) { + && (status.equals(DecommissionStatus.IN_PROGRESS) || status.equals(DecommissionStatus.SUCCESSFUL))) { throw new NodeDecommissionedException( "node [{}] has decommissioned attribute [{}] with current status of decommissioning [{}]", node.toString(), diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java index 6550f0f3813f8..c31ea53a5fd16 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java @@ -183,7 +183,8 @@ private synchronized void decommissionClusterManagerNodes( final Predicate allNodesRemovedAndAbdicated = clusterState -> { final Set votingConfigNodeIds = clusterState.getLastCommittedConfiguration().getNodeIds(); return nodeIdsToBeExcluded.stream().noneMatch(votingConfigNodeIds::contains) - && nodeIdsToBeExcluded.contains(clusterState.nodes().getClusterManagerNodeId()) == false; + && nodeIdsToBeExcluded.contains(clusterState.nodes().getClusterManagerNodeId()) == false + && clusterState.nodes().getClusterManagerNodeId() != null; }; ActionListener exclusionListener = new ActionListener() { From da2ea43b941aa43e8f0187acf470d6a48c622520 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 26 Sep 2022 12:42:23 +0530 Subject: [PATCH 24/31] Remove timeout and refactoring Signed-off-by: Rishab Nahata --- .../cluster.get_decommission_awareness.json | 10 -------- .../cluster.put_decommission_awareness.json | 6 ----- .../awareness/put/DecommissionRequest.java | 25 +++---------------- .../put/DecommissionRequestBuilder.java | 9 ------- .../opensearch/client/ClusterAdminClient.java | 6 ++--- .../admin/cluster/RestDecommissionAction.java | 5 +--- .../RestGetDecommissionStateAction.java | 3 --- .../put/DecommissionRequestTests.java | 13 +++------- .../cluster/RestDecommissionActionTests.java | 16 ------------ 9 files changed, 12 insertions(+), 81 deletions(-) diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json index 19cb03aaf20c4..430f96921fbc2 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.get_decommission_awareness.json @@ -14,16 +14,6 @@ ] } ] - }, - "params": { - "timeout": { - "type": "time", - "description": "Explicit operation timeout" - }, - "local": { - "type": "boolean", - "description": "Return local information, do not retrieve the state from master node (default: false)" - } } } } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json index 815964e49e7a0..bf4ffd454d9df 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cluster.put_decommission_awareness.json @@ -24,12 +24,6 @@ } } ] - }, - "params": { - "timeout": { - "type": "time", - "description": "Explicit operation timeout" - } } } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java index f835f9368c41e..de09f72f70778 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java @@ -29,26 +29,22 @@ public class DecommissionRequest extends ClusterManagerNodeRequest { private DecommissionAttribute decommissionAttribute; - private TimeValue timeout; public DecommissionRequest() {} - public DecommissionRequest(DecommissionAttribute decommissionAttribute, TimeValue timeout) { + public DecommissionRequest(DecommissionAttribute decommissionAttribute) { this.decommissionAttribute = decommissionAttribute; - this.timeout = timeout; } public DecommissionRequest(StreamInput in) throws IOException { super(in); decommissionAttribute = new DecommissionAttribute(in); - timeout = in.readTimeValue(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); decommissionAttribute.writeTo(out); - out.writeTimeValue(timeout); } /** @@ -62,17 +58,6 @@ public DecommissionRequest setDecommissionAttribute(DecommissionAttribute decomm return this; } - /** - * Sets the timeout for the request - * - * @param timeout time out for the request - * @return this request - */ - public DecommissionRequest setTimeout(TimeValue timeout) { - this.timeout = timeout; - return this; - } - /** * @return Returns the decommission attribute key-value */ @@ -80,10 +65,6 @@ public DecommissionAttribute getDecommissionAttribute() { return this.decommissionAttribute; } - public TimeValue getTimeout() { - return this.timeout; - } - @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; @@ -98,6 +79,8 @@ public ActionRequestValidationException validate() { @Override public String toString() { - return "DecommissionRequest{" + "decommissionAttribute=" + decommissionAttribute + ", timeout=" + timeout + '}'; + return "DecommissionRequest{" + + "decommissionAttribute=" + decommissionAttribute + + '}'; } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java index 2a9de91056785..81bf277a625be 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java @@ -36,13 +36,4 @@ public DecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttribu request.setDecommissionAttribute(decommissionAttribute); return this; } - - /** - * @param timeout time out for the request - * @return current object - */ - public DecommissionRequestBuilder setTimeout(TimeValue timeout) { - request.setTimeout(timeout); - return this; - } } diff --git a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java index 69c63017632c1..ca331ef84aace 100644 --- a/server/src/main/java/org/opensearch/client/ClusterAdminClient.java +++ b/server/src/main/java/org/opensearch/client/ClusterAdminClient.java @@ -799,17 +799,17 @@ public interface ClusterAdminClient extends OpenSearchClient { ActionFuture deleteDanglingIndex(DeleteDanglingIndexRequest request); /** - * Decommission a node + * Decommission awareness attribute */ ActionFuture decommission(DecommissionRequest request); /** - * Decommission a node + * Decommission awareness attribute */ void decommission(DecommissionRequest request, ActionListener listener); /** - * Decommission a node + * Decommission awareness attribute */ DecommissionRequestBuilder prepareDecommission(DecommissionRequest request); diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java index f48b3a38f77e1..9835e62153fd3 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java @@ -30,8 +30,6 @@ */ public class RestDecommissionAction extends BaseRestHandler { - private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(300L); - @Override public List routes() { return singletonList(new Route(PUT, "/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}")); @@ -59,7 +57,6 @@ DecommissionRequest createRequest(RestRequest request) throws IOException { if (request.hasParam("awareness_attribute_value")) { attributeValue = request.param("awareness_attribute_value"); } - return decommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)) - .setTimeout(TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")); + return decommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)); } } diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java index a77164709370d..8bc89ebf37960 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestGetDecommissionStateAction.java @@ -41,9 +41,6 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { GetDecommissionStateRequest getDecommissionStateRequest = Requests.getDecommissionStateRequest(); - getDecommissionStateRequest.clusterManagerNodeTimeout( - request.paramAsTime("cluster_manager_timeout", getDecommissionStateRequest.clusterManagerNodeTimeout()) - ); return channel -> client.admin().cluster().getDecommission(getDecommissionStateRequest, new RestToXContentListener<>(channel)); } } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java index fe03fc42d4ba4..c26e75c63ec49 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java @@ -21,13 +21,11 @@ public void testSerialization() throws IOException { String attributeName = "zone"; String attributeValue = "zone-1"; DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); - TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final DecommissionRequest originalRequest = new DecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest originalRequest = new DecommissionRequest(decommissionAttribute); final DecommissionRequest deserialized = copyWriteable(originalRequest, writableRegistry(), DecommissionRequest::new); assertEquals(deserialized.getDecommissionAttribute(), originalRequest.getDecommissionAttribute()); - assertEquals(deserialized.getTimeout(), originalRequest.getTimeout()); } public void testValidation() { @@ -35,9 +33,8 @@ public void testValidation() { String attributeName = null; String attributeValue = "test"; DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); - TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final DecommissionRequest request = new DecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest request = new DecommissionRequest(decommissionAttribute); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertTrue(e.getMessage().contains("attribute name is missing")); @@ -46,9 +43,8 @@ public void testValidation() { String attributeName = "zone"; String attributeValue = ""; DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); - TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final DecommissionRequest request = new DecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest request = new DecommissionRequest(decommissionAttribute); ActionRequestValidationException e = request.validate(); assertNotNull(e); assertTrue(e.getMessage().contains("attribute value is missing")); @@ -57,9 +53,8 @@ public void testValidation() { String attributeName = "zone"; String attributeValue = "test"; DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue); - TimeValue timeout = TimeValue.timeValueMillis(between(0, 30000)); - final DecommissionRequest request = new DecommissionRequest(decommissionAttribute, timeout); + final DecommissionRequest request = new DecommissionRequest(decommissionAttribute); ActionRequestValidationException e = request.validate(); assertNull(e); } diff --git a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java index 25b0ba0f273be..848c8dc26b9d4 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java @@ -33,28 +33,12 @@ public void testCreateRequest() throws IOException { Map params = new HashMap<>(); params.put("awareness_attribute_name", "zone"); params.put("awareness_attribute_value", "zone-1"); - params.put("timeout", "10s"); RestRequest deprecatedRequest = buildRestRequest(params); DecommissionRequest request = action.createRequest(deprecatedRequest); assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); - assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(10L)); - assertEquals(deprecatedRequest.getHttpRequest().method(), RestRequest.Method.PUT); - } - - public void testCreateRequestWithDefaultTimeout() throws IOException { - Map params = new HashMap<>(); - params.put("awareness_attribute_name", "zone"); - params.put("awareness_attribute_value", "zone-1"); - - RestRequest deprecatedRequest = buildRestRequest(params); - - DecommissionRequest request = action.createRequest(deprecatedRequest); - assertEquals(request.getDecommissionAttribute().attributeName(), "zone"); - assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1"); - assertEquals(request.getTimeout(), TimeValue.timeValueSeconds(300L)); assertEquals(deprecatedRequest.getHttpRequest().method(), RestRequest.Method.PUT); } From a206a08afe0b8d3534260a820493aaf376bb2334 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 26 Sep 2022 12:55:09 +0530 Subject: [PATCH 25/31] Update join executor tests Signed-off-by: Rishab Nahata --- .../opensearch/cluster/coordination/JoinTaskExecutorTests.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java index 28f1a92cc1bdc..df40d2fc43373 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java @@ -236,7 +236,6 @@ public void testPreventJoinClusterWithDecommission() { Settings.builder().build(); DecommissionAttribute decommissionAttribute = new DecommissionAttribute("zone", "zone-1"); DecommissionStatus decommissionStatus = randomFrom( - DecommissionStatus.INIT, DecommissionStatus.IN_PROGRESS, DecommissionStatus.SUCCESSFUL ); @@ -252,7 +251,7 @@ public void testPreventJoinClusterWithDecommission() { public void testJoinClusterWithDifferentDecommission() { Settings.builder().build(); DecommissionAttribute decommissionAttribute = new DecommissionAttribute("zone", "zone-1"); - DecommissionStatus decommissionStatus = randomFrom(DecommissionStatus.values()); + DecommissionStatus decommissionStatus = randomFrom(DecommissionStatus.INIT, DecommissionStatus.IN_PROGRESS, DecommissionStatus.SUCCESSFUL); DecommissionAttributeMetadata decommissionAttributeMetadata = new DecommissionAttributeMetadata( decommissionAttribute, decommissionStatus From 1873519329c30118d20e67308c49f5f2b2ee39f9 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 26 Sep 2022 13:35:56 +0530 Subject: [PATCH 26/31] Fix spotless check Signed-off-by: Rishab Nahata --- .../awareness/put/DecommissionRequest.java | 5 +---- .../awareness/put/DecommissionRequestBuilder.java | 1 - .../action/admin/cluster/RestDecommissionAction.java | 1 - .../awareness/put/DecommissionRequestTests.java | 1 - .../cluster/coordination/JoinTaskExecutorTests.java | 11 ++++++----- .../admin/cluster/RestDecommissionActionTests.java | 1 - 6 files changed, 7 insertions(+), 13 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java index de09f72f70778..9756bf96dd66d 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java @@ -13,7 +13,6 @@ import org.opensearch.cluster.decommission.DecommissionAttribute; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; -import org.opensearch.common.unit.TimeValue; import java.io.IOException; @@ -79,8 +78,6 @@ public ActionRequestValidationException validate() { @Override public String toString() { - return "DecommissionRequest{" + - "decommissionAttribute=" + decommissionAttribute + - '}'; + return "DecommissionRequest{" + "decommissionAttribute=" + decommissionAttribute + '}'; } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java index 81bf277a625be..47af3b952c895 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestBuilder.java @@ -12,7 +12,6 @@ import org.opensearch.action.support.clustermanager.ClusterManagerNodeOperationRequestBuilder; import org.opensearch.client.OpenSearchClient; import org.opensearch.cluster.decommission.DecommissionAttribute; -import org.opensearch.common.unit.TimeValue; /** * Register decommission request builder diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java index 9835e62153fd3..e236409554bba 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java @@ -12,7 +12,6 @@ import org.opensearch.client.Requests; import org.opensearch.client.node.NodeClient; import org.opensearch.cluster.decommission.DecommissionAttribute; -import org.opensearch.common.unit.TimeValue; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.RestRequest; import org.opensearch.rest.action.RestToXContentListener; diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java index c26e75c63ec49..c189b5702dea0 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequestTests.java @@ -10,7 +10,6 @@ import org.opensearch.action.ActionRequestValidationException; import org.opensearch.cluster.decommission.DecommissionAttribute; -import org.opensearch.common.unit.TimeValue; import org.opensearch.test.OpenSearchTestCase; import java.io.IOException; diff --git a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java index df40d2fc43373..5aa582a5e73f6 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java @@ -235,10 +235,7 @@ public void testJoinClusterWithNoDecommission() { public void testPreventJoinClusterWithDecommission() { Settings.builder().build(); DecommissionAttribute decommissionAttribute = new DecommissionAttribute("zone", "zone-1"); - DecommissionStatus decommissionStatus = randomFrom( - DecommissionStatus.IN_PROGRESS, - DecommissionStatus.SUCCESSFUL - ); + DecommissionStatus decommissionStatus = randomFrom(DecommissionStatus.IN_PROGRESS, DecommissionStatus.SUCCESSFUL); DecommissionAttributeMetadata decommissionAttributeMetadata = new DecommissionAttributeMetadata( decommissionAttribute, decommissionStatus @@ -251,7 +248,11 @@ public void testPreventJoinClusterWithDecommission() { public void testJoinClusterWithDifferentDecommission() { Settings.builder().build(); DecommissionAttribute decommissionAttribute = new DecommissionAttribute("zone", "zone-1"); - DecommissionStatus decommissionStatus = randomFrom(DecommissionStatus.INIT, DecommissionStatus.IN_PROGRESS, DecommissionStatus.SUCCESSFUL); + DecommissionStatus decommissionStatus = randomFrom( + DecommissionStatus.INIT, + DecommissionStatus.IN_PROGRESS, + DecommissionStatus.SUCCESSFUL + ); DecommissionAttributeMetadata decommissionAttributeMetadata = new DecommissionAttributeMetadata( decommissionAttribute, decommissionStatus diff --git a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java index 848c8dc26b9d4..b724de0bd5cc6 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestDecommissionActionTests.java @@ -10,7 +10,6 @@ import org.junit.Before; import org.opensearch.action.admin.cluster.decommission.awareness.put.DecommissionRequest; -import org.opensearch.common.unit.TimeValue; import org.opensearch.rest.RestRequest; import org.opensearch.test.rest.FakeRestRequest; import org.opensearch.test.rest.RestActionTestCase; From c0d5de787f07be047e43c4fd8e9eb54a812ecad7 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Mon, 26 Sep 2022 14:24:18 +0530 Subject: [PATCH 27/31] Empty-Commit Signed-off-by: Rishab Nahata From fbe0e7d145bba4e8c33dbed7fa8410e88f2084ae Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Wed, 28 Sep 2022 01:29:03 +0530 Subject: [PATCH 28/31] Fix create decommission request Signed-off-by: Rishab Nahata --- .../action/admin/cluster/RestDecommissionAction.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java index e236409554bba..979bf05f537b7 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestDecommissionAction.java @@ -46,16 +46,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli } DecommissionRequest createRequest(RestRequest request) throws IOException { - String attributeName = null; - String attributeValue = null; DecommissionRequest decommissionRequest = Requests.decommissionRequest(); - if (request.hasParam("awareness_attribute_name")) { - attributeName = request.param("awareness_attribute_name"); - } - - if (request.hasParam("awareness_attribute_value")) { - attributeValue = request.param("awareness_attribute_value"); - } + String attributeName = request.param("awareness_attribute_name"); + String attributeValue = request.param("awareness_attribute_value"); return decommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue)); } } From fc6dd88e624bb74c10770f97fbd4f78de52557a7 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 30 Sep 2022 00:40:50 +0530 Subject: [PATCH 29/31] Fix Response & Fix spotless check Signed-off-by: Rishab Nahata --- .../get/GetDecommissionStateResponse.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java index 0351bf17e6d13..2034cdb16e40f 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/get/GetDecommissionStateResponse.java @@ -31,8 +31,8 @@ */ public class GetDecommissionStateResponse extends ActionResponse implements ToXContentObject { - private final DecommissionAttribute decommissionedAttribute; - private final DecommissionStatus status; + private DecommissionAttribute decommissionedAttribute; + private DecommissionStatus status; GetDecommissionStateResponse() { this(null, null); @@ -44,28 +44,30 @@ public class GetDecommissionStateResponse extends ActionResponse implements ToXC } GetDecommissionStateResponse(StreamInput in) throws IOException { + // read decommissioned attribute and status only if it is present if (in.readBoolean()) { this.decommissionedAttribute = new DecommissionAttribute(in); - } else { - this.decommissionedAttribute = null; } if (in.readBoolean()) { this.status = DecommissionStatus.fromString(in.readString()); - } else { - this.status = null; } } @Override public void writeTo(StreamOutput out) throws IOException { - boolean isNotNullDecommissionAttribute = this.decommissionedAttribute != null; - boolean isNotNullStatus = this.status != null; - out.writeBoolean(isNotNullDecommissionAttribute); - if (isNotNullDecommissionAttribute) { + // if decommissioned attribute is null, mark absence of decommissioned attribute + if (decommissionedAttribute == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); decommissionedAttribute.writeTo(out); } - out.writeBoolean(isNotNullStatus); - if (isNotNullStatus) { + + // if status is null, mark absence of status + if (status == null) { + out.writeBoolean(false); + } else { + out.writeBoolean(true); out.writeString(status.status()); } } From 14f4ce092653953cd8e45c5909cce721e1332137 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 30 Sep 2022 00:45:25 +0530 Subject: [PATCH 30/31] Use String utility Signed-off-by: Rishab Nahata --- .../decommission/awareness/put/DecommissionRequest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java index 9756bf96dd66d..79a6688dc6049 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/decommission/awareness/put/DecommissionRequest.java @@ -11,6 +11,7 @@ import org.opensearch.action.ActionRequestValidationException; import org.opensearch.action.support.clustermanager.ClusterManagerNodeRequest; import org.opensearch.cluster.decommission.DecommissionAttribute; +import org.opensearch.common.Strings; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; @@ -67,10 +68,10 @@ public DecommissionAttribute getDecommissionAttribute() { @Override public ActionRequestValidationException validate() { ActionRequestValidationException validationException = null; - if (decommissionAttribute.attributeName() == null || decommissionAttribute.attributeName().isEmpty()) { + if (decommissionAttribute.attributeName() == null || Strings.isEmpty(decommissionAttribute.attributeName())) { validationException = addValidationError("attribute name is missing", validationException); } - if (decommissionAttribute.attributeValue() == null || decommissionAttribute.attributeValue().isEmpty()) { + if (decommissionAttribute.attributeValue() == null || Strings.isEmpty(decommissionAttribute.attributeValue())) { validationException = addValidationError("attribute value is missing", validationException); } return validationException; From 4aa3790cb20484323bcd61682c5144e2df4cd594 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 30 Sep 2022 09:33:47 +0530 Subject: [PATCH 31/31] Empty-Commit Signed-off-by: Rishab Nahata