Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add delay timeout for decommission request #4931

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [BUG]: flaky test index/80_geo_point/Single point test([#4860](https://github.com/opensearch-project/OpenSearch/pull/4860))
- Fix bug in SlicedInputStream with zero length ([#4863](https://github.com/opensearch-project/OpenSearch/pull/4863))
- Fix a bug on handling an invalid array value for point type field #4900([#4900](https://github.com/opensearch-project/OpenSearch/pull/4900))

- [BUG]: Allow decommission to support delay timeout [#4930](https://github.com/opensearch-project/OpenSearch/pull/4930))
### Security
- CVE-2022-25857 org.yaml:snakeyaml DOS vulnerability ([#4341](https://github.com/opensearch-project/OpenSearch/pull/4341))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public DecommissionRequest(StreamInput in) throws IOException {
super(in);
decommissionAttribute = new DecommissionAttribute(in);
this.delayTimeout = in.readTimeValue();
this.noDelay = in.readBoolean();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
decommissionAttribute.writeTo(out);
out.writeTimeValue(delayTimeout);
out.writeBoolean(noDelay);
}

/**
Expand All @@ -75,12 +77,18 @@ public DecommissionAttribute getDecommissionAttribute() {
return this.decommissionAttribute;
}

public void setDelayTimeout(TimeValue delayTimeout) {
this.delayTimeout = delayTimeout;
}

public TimeValue getDelayTimeout() {
return this.delayTimeout;
}

public void setNoDelay(boolean noDelay) {
this.delayTimeout = TimeValue.ZERO;
if (noDelay) {
this.delayTimeout = TimeValue.ZERO;
}
this.noDelay = noDelay;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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
Expand All @@ -35,4 +36,14 @@ public DecommissionRequestBuilder setDecommissionedAttribute(DecommissionAttribu
request.setDecommissionAttribute(decommissionAttribute);
return this;
}

public DecommissionRequestBuilder setDelayTimeOut(TimeValue delayTimeOut) {
request.setDelayTimeout(delayTimeOut);
return this;
}

public DecommissionRequestBuilder setNoDelay(boolean noDelay) {
request.setNoDelay(noDelay);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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;
Expand Down Expand Up @@ -51,8 +52,11 @@ DecommissionRequest createRequest(RestRequest request) throws IOException {
String attributeValue = request.param("awareness_attribute_value");
// Check if we have no delay set.
boolean noDelay = request.paramAsBoolean("no_delay", false);
if (noDelay) {
decommissionRequest.setNoDelay(noDelay);
decommissionRequest.setNoDelay(noDelay);

if (request.hasParam("delay_timeout")) {
TimeValue delayTimeout = request.paramAsTime("delay_timeout", DecommissionRequest.DEFAULT_NODE_DRAINING_TIMEOUT);
decommissionRequest.setDelayTimeout(delayTimeout);
}
return decommissionRequest.setDecommissionAttribute(new DecommissionAttribute(attributeName, attributeValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,17 @@ public void testValidation() {
assertNull(e);
assertEquals(DecommissionRequest.DEFAULT_NODE_DRAINING_TIMEOUT, request.getDelayTimeout());
}
{
String attributeName = "zone";
String attributeValue = "test";
DecommissionAttribute decommissionAttribute = new DecommissionAttribute(attributeName, attributeValue);

final DecommissionRequest request = new DecommissionRequest(decommissionAttribute);
request.setNoDelay(true);
request.setDelayTimeout(TimeValue.timeValueSeconds(30));
ActionRequestValidationException e = request.validate();
assertNotNull(e);
assertTrue(e.getMessage().contains("Invalid decommission request"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ public void testCreateRequestWithNoDelay() throws IOException {
assertEquals(deprecatedRequest.getHttpRequest().method(), RestRequest.Method.PUT);
}

public void testCreateRequestWithDelayTimeout() throws IOException {
Map<String, String> params = new HashMap<>();
params.put("awareness_attribute_name", "zone");
params.put("awareness_attribute_value", "zone-1");
params.put("delay_timeout", "300s");

RestRequest deprecatedRequest = buildRestRequest(params);

DecommissionRequest request = action.createRequest(deprecatedRequest);
assertEquals(request.getDecommissionAttribute().attributeName(), "zone");
assertEquals(request.getDecommissionAttribute().attributeValue(), "zone-1");
assertEquals(request.getDelayTimeout().getSeconds(), 300);
assertEquals(deprecatedRequest.getHttpRequest().method(), RestRequest.Method.PUT);
}

private FakeRestRequest buildRestRequest(Map<String, String> params) {
return new FakeRestRequest.Builder(xContentRegistry()).withMethod(RestRequest.Method.PUT)
.withPath("/_cluster/decommission/awareness/{awareness_attribute_name}/{awareness_attribute_value}")
Expand Down