-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add APIs (GET/PUT) to decommission awareness attribute #4261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e3dcf4a
1dfc3cd
f5f676a
4c8b65b
8c2ddbc
c7e4bcc
e2b38cb
1c9fe9f
17f2548
f9bfff9
6ba62c2
6f2f3d3
81748c1
f4ec908
0c08d98
a1289a2
93ae7c2
c9b0b48
00270f0
7152932
9a9f5af
1c845db
40ffde7
da2ea43
a206a08
1873519
c0d5de7
fbe0e7d
ef33115
908fe08
fc6dd88
14f4ce0
4aa3790
534a3de
80449a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"cluster.get_decommission_awareness": { | ||
"documentation": { | ||
"url": "https://opensearch.org/docs/latest/opensearch/rest-api/decommission/", | ||
"description": "Get details and status of decommissioned attribute" | ||
}, | ||
"stability": "experimental", | ||
imRishN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_cluster/decommission/awareness/_status", | ||
"methods": [ | ||
"GET" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"cluster.put_decommission_awareness": { | ||
"documentation": { | ||
"url": "https://opensearch.org/docs/latest/opensearch/rest-api/decommission/", | ||
"description": "Decommissions an awareness attribute" | ||
}, | ||
"stability": "experimental", | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decommissioning is only supported on awareness attributes, what about decommissioning by nodeId, nodeName etc.? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For now, we are supporting decommissioning an awareness attribute. Incrementally, we can have this feature for decommissioning a node There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we just keep the API generic and pass awareness as query param instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we make There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could do two GET APIs
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opened issue to add another route - #4640 |
||
"methods": [ | ||
"PUT" | ||
], | ||
"parts": { | ||
"awareness_attribute_name": { | ||
"type": "string", | ||
"description": "Awareness attribute name" | ||
}, | ||
"awareness_attribute_value": { | ||
"type": "string", | ||
"description": "Awareness attribute value" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Get decommission action | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetDecommissionStateAction extends ActionType<GetDecommissionStateResponse> { | ||
|
||
public static final GetDecommissionStateAction INSTANCE = new GetDecommissionStateAction(); | ||
public static final String NAME = "cluster:admin/decommission/awareness/get"; | ||
|
||
private GetDecommissionStateAction() { | ||
super(NAME, GetDecommissionStateResponse::new); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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 GetDecommissionStateRequest extends ClusterManagerNodeReadRequest<GetDecommissionStateRequest> { | ||
|
||
public GetDecommissionStateRequest() {} | ||
|
||
public GetDecommissionStateRequest(StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
} | ||
imRishN marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Get decommission request builder | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetDecommissionStateRequestBuilder extends ClusterManagerNodeReadOperationRequestBuilder< | ||
GetDecommissionStateRequest, | ||
GetDecommissionStateResponse, | ||
GetDecommissionStateRequestBuilder> { | ||
|
||
/** | ||
* Creates new get decommissioned attributes request builder | ||
*/ | ||
public GetDecommissionStateRequestBuilder(OpenSearchClient client, GetDecommissionStateAction action) { | ||
super(client, action, new GetDecommissionStateRequest()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/* | ||
* 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 java.util.Locale; | ||
import java.util.Objects; | ||
|
||
import static org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken; | ||
|
||
/** | ||
* Response for decommission status | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public class GetDecommissionStateResponse extends ActionResponse implements ToXContentObject { | ||
|
||
private DecommissionAttribute decommissionedAttribute; | ||
private DecommissionStatus status; | ||
|
||
GetDecommissionStateResponse() { | ||
this(null, null); | ||
} | ||
|
||
GetDecommissionStateResponse(DecommissionAttribute decommissionedAttribute, DecommissionStatus status) { | ||
this.decommissionedAttribute = decommissionedAttribute; | ||
this.status = status; | ||
} | ||
|
||
GetDecommissionStateResponse(StreamInput in) throws IOException { | ||
// read decommissioned attribute and status only if it is present | ||
if (in.readBoolean()) { | ||
this.decommissionedAttribute = new DecommissionAttribute(in); | ||
} | ||
if (in.readBoolean()) { | ||
this.status = DecommissionStatus.fromString(in.readString()); | ||
} | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
// if decommissioned attribute is null, mark absence of decommissioned attribute | ||
if (decommissionedAttribute == null) { | ||
out.writeBoolean(false); | ||
} else { | ||
out.writeBoolean(true); | ||
decommissionedAttribute.writeTo(out); | ||
} | ||
|
||
// if status is null, mark absence of status | ||
if (status == null) { | ||
out.writeBoolean(false); | ||
} else { | ||
out.writeBoolean(true); | ||
out.writeString(status.status()); | ||
} | ||
} | ||
|
||
public DecommissionAttribute getDecommissionedAttribute() { | ||
return decommissionedAttribute; | ||
} | ||
|
||
public DecommissionStatus getDecommissionStatus() { | ||
return status; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startObject("awareness"); | ||
if (decommissionedAttribute != null) { | ||
builder.field(decommissionedAttribute.attributeName(), decommissionedAttribute.attributeValue()); | ||
} | ||
builder.endObject(); | ||
if (status != null) { | ||
builder.field("status", status); | ||
} | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
public static GetDecommissionStateResponse 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; | ||
while ((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); | ||
parser.nextToken(); | ||
} 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().toLowerCase(Locale.ROOT)); | ||
} else { | ||
throw new OpenSearchParseException( | ||
"unknown field found [{}], failed to parse the decommission attribute", | ||
currentFieldName | ||
); | ||
} | ||
} | ||
} | ||
return new GetDecommissionStateResponse(decommissionAttribute, status); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
GetDecommissionStateResponse that = (GetDecommissionStateResponse) o; | ||
return decommissionedAttribute.equals(that.decommissionedAttribute) && status == that.status; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(decommissionedAttribute, status); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.