-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 request parameter 'cluster_manager_timeout' as the alternative for 'master_timeout', and deprecate 'master_timeout' - in CAT Nodes API #2435
Changes from 12 commits
24cf061
67d9e1b
d1a8fb9
8da36a9
3f46f4e
aa50d4f
8e0e074
dec2597
7bf815c
c1e4297
d5ce228
2d36c8f
7195d42
02e68b5
399f2d9
ae7308c
b99c8d5
ec61416
dfd260d
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 |
---|---|---|
|
@@ -86,6 +86,8 @@ public class RestNodesAction extends AbstractCatAction { | |
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RestNodesAction.class); | ||
static final String LOCAL_DEPRECATED_MESSAGE = "Deprecated parameter [local] used. This parameter does not cause this API to act " | ||
+ "locally, and should not be used. It will be unsupported in version 8.0."; | ||
static final String MASTER_TIMEOUT_DEPRECATED_MESSAGE = | ||
"Deprecated parameter [master_timeout] used. To promote inclusive language, please use [cluster_manager_timeout] instead. It will be unsupported in a future major version."; | ||
|
||
@Override | ||
public List<Route> routes() { | ||
|
@@ -110,7 +112,8 @@ public RestChannelConsumer doCatRequest(final RestRequest request, final NodeCli | |
deprecationLogger.deprecate("cat_nodes_local_parameter", LOCAL_DEPRECATED_MESSAGE); | ||
} | ||
clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local())); | ||
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout())); | ||
clusterStateRequest.masterNodeTimeout(request.paramAsTime("cluster_manager_timeout", clusterStateRequest.masterNodeTimeout())); | ||
parseDeprecatedMasterTimeoutParameter(clusterStateRequest, request); | ||
final boolean fullId = request.paramAsBoolean("full_id", false); | ||
return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) { | ||
@Override | ||
|
@@ -525,4 +528,21 @@ Table buildTable( | |
private short calculatePercentage(long used, long max) { | ||
return max <= 0 ? 0 : (short) ((100d * used) / max); | ||
} | ||
|
||
/** | ||
* Parse the deprecated request parameter 'master_timeout', and add deprecated log if the parameter is used. | ||
* It also validates whether the value of 'master_timeout' is the same with 'cluster_manager_timeout'. | ||
* Remove the method along with MASTER_ROLE. | ||
* @deprecated As of 2.0, because promoting inclusive language. | ||
*/ | ||
@Deprecated | ||
private void parseDeprecatedMasterTimeoutParameter(ClusterStateRequest clusterStateRequest, RestRequest request) { | ||
final String deprecatedTimeoutParam = "master_timeout"; | ||
final String clusterManagerTimeoutParam = "cluster_manager_timeout"; | ||
clusterStateRequest.masterNodeTimeout(request.paramAsTime(deprecatedTimeoutParam, clusterStateRequest.masterNodeTimeout())); | ||
if (request.hasParam(deprecatedTimeoutParam)) { | ||
deprecationLogger.deprecate("cat_nodes_master_timeout_parameter", MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
request.validateParamValuesAreEqual(deprecatedTimeoutParam, clusterManagerTimeoutParam); | ||
} | ||
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. Two nitpicks here:
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. Great suggestion! Now the procedure is more reasonable 😄. I modified the code in the commit 399f2d9 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
|
||
import org.opensearch.OpenSearchParseException; | ||
import org.opensearch.common.CheckedConsumer; | ||
import org.opensearch.common.Strings; | ||
import org.opensearch.common.bytes.BytesArray; | ||
import org.opensearch.common.bytes.BytesReference; | ||
import org.opensearch.common.collect.MapBuilder; | ||
|
@@ -47,6 +48,7 @@ | |
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
|
@@ -280,6 +282,37 @@ public void testRequiredContent() { | |
assertEquals("unknown content type", e.getMessage()); | ||
} | ||
|
||
/* | ||
* The test is added in 2.0 when the request parameter "cluster_manager_timeout" is introduced. | ||
* Remove the test along with the removal of the non-inclusive terminology "master_timeout". | ||
*/ | ||
public void testValidateParamValuesAreEqual() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
List<String> valueList = new ArrayList<>(Arrays.asList(null, "", "value1", "value2")); | ||
String valueForKey1 = randomFrom(valueList); | ||
String valueForKey2 = randomFrom(valueList); | ||
request.params().put("key1", valueForKey1); | ||
request.params().put("key2", valueForKey2); | ||
try { | ||
request.validateParamValuesAreEqual("key1", "key2"); | ||
assertTrue( | ||
"Values of the 2 keys should be equal, or having a least 1 null value or empty String. Value of key1: " | ||
+ valueForKey1 | ||
+ ". Value of key2: " | ||
+ valueForKey2, | ||
Strings.isNullOrEmpty(valueForKey1) || Strings.isNullOrEmpty(valueForKey2) || valueForKey1.equals(valueForKey2) | ||
); | ||
} catch (OpenSearchParseException e) { | ||
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. Can we please split this into two tests? We should deterministically test both cases - when the two are equal and for inequality - for all test runs rather than testing either code path through a random. 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. Thanks for telling me the opinion to design test case! Updated along wit the above comment 02e68b5 |
||
assertEquals( | ||
"The values of the request parameters: [key1, key2] are required to be equal, otherwise please only assign value to one of the request parameters.", | ||
e.getMessage() | ||
); | ||
assertNotEquals(valueForKey1, valueForKey2); | ||
assertFalse(Strings.isNullOrEmpty(valueForKey1)); | ||
assertFalse(Strings.isNullOrEmpty(valueForKey2)); | ||
} | ||
} | ||
|
||
private static RestRequest contentRestRequest(String content, Map<String, String> params) { | ||
Map<String, List<String>> headers = new HashMap<>(); | ||
headers.put("Content-Type", Collections.singletonList("application/json")); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor improvement - you don't need a
Set
to check this. You can just track the last seen value and ensure that every subsequent value matches it. This would also force a break out of the loop as soon as there is a mismatch rather than attempting to parse all values of the input keys.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @kartg Thank you so much for your careful review and your valuable opinion!
I will make the changes according to your suggestion!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in the commit 02e68b5. I learnt the nice way to check if all the values are the same, thank you! 👍