Skip to content

Commit

Permalink
Add request parameter cluster_manager_timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Mar 11, 2022
1 parent c8d8009 commit 24cf061
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@
*/
public abstract class MasterNodeRequest<Request extends MasterNodeRequest<Request>> extends ActionRequest {

/**
* @deprecated As of 2.0, because promoting inclusive language, replaced by {@link #DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT}
*/
@Deprecated
public static final TimeValue DEFAULT_MASTER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30);

protected TimeValue masterNodeTimeout = DEFAULT_MASTER_NODE_TIMEOUT;
public static final TimeValue DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30);

protected TimeValue masterNodeTimeout = DEFAULT_CLUSTER_MANAGER_NODE_TIMEOUT;

protected MasterNodeRequest() {}

Expand All @@ -63,21 +69,49 @@ public void writeTo(StreamOutput out) throws IOException {

/**
* A timeout value in case the master has not been discovered yet or disconnected.
* @deprecated As of 2.0, because promoting inclusive language, replaced by {@link #clusterManagerNodeTimeout}
*/
@Deprecated
@SuppressWarnings("unchecked")
public final Request masterNodeTimeout(TimeValue timeout) {
this.masterNodeTimeout = timeout;
return (Request) this;
}

/**
* A timeout value in case the cluster manager has not been discovered yet or disconnected.
*/
@SuppressWarnings("unchecked")
public final Request clusterManagerNodeTimeout(TimeValue timeout) {
this.masterNodeTimeout = timeout;
return (Request) this;
}

/**
* A timeout value in case the master has not been discovered yet or disconnected.
* @deprecated As of 2.0, because promoting inclusive language, replaced by {@link #clusterManagerNodeTimeout}
*/
@Deprecated
public final Request masterNodeTimeout(String timeout) {
return masterNodeTimeout(TimeValue.parseTimeValue(timeout, null, getClass().getSimpleName() + ".masterNodeTimeout"));
}

/**
* A timeout value in case the cluster manager has not been discovered yet or disconnected.
*/
public final Request clusterManagerNodeTimeout(String timeout) {
return clusterManagerNodeTimeout(TimeValue.parseTimeValue(timeout, null, getClass().getSimpleName() + ".masterNodeTimeout"));
}

/**
* @deprecated As of 2.0, because promoting inclusive language, replaced by {@link #clusterManagerNodeTimeout}
*/
@Deprecated
public final TimeValue masterNodeTimeout() {
return this.masterNodeTimeout;
}

public final TimeValue clusterManagerNodeTimeout() {
return this.masterNodeTimeout;
}
}
26 changes: 26 additions & 0 deletions server/src/main/java/org/opensearch/rest/RestRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -578,6 +579,31 @@ public static XContentType parseContentType(List<String> header) {
throw new IllegalArgumentException("empty Content-Type header");
}

/**
* The method is only used to validate whether the values of the 2 request parameters "master_timeout" and "cluster_manager_timeout" is the same value or not.
* If the 2 values are not the same, throw an {@link OpenSearchParseException}.
* @param keys Keys of the request parameters.
* @deprecated The method will be removed along with the request parameter "master_timeout".
*/
@Deprecated
public void validateParamValuesAreEqual(String... keys) {
// Filter the non-null values of the parameters with the key, and get the distinct values.
Set<String> set = new HashSet<>();
for (String key : keys) {
String value = param(key);
if (value != null) {
set.add(value);
}
}
// If there are more than 1 distinct value of the request parameters, throw an exception.
if (set.size() > 1) {
throw new OpenSearchParseException(
"The values of the request parameters: {} are required to be equal, otherwise please only assign value to one of the request parameters.",
Arrays.toString(keys)
);
}
}

public static class ContentTypeHeaderException extends RuntimeException {

ContentTypeHeaderException(final IllegalArgumentException cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli
clusterStateRequest.clear().nodes(true);
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
// Add "cluster_manager_timeout" as the alternative to "master_timeout", for promoting inclusive language.
request.validateParamValuesAreEqual("master_timeout", "cluster_manager_timeout");
clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout()));

return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
@Override
Expand Down

0 comments on commit 24cf061

Please sign in to comment.