-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralize codes related to 'master_timeout' deprecation for eaiser r…
…emoval - in CAT Nodes API (#2670) (#2696) The request parameter `master_timeout` for CAT Nodes API is deprecated and alternative parameter `cluster_manager_timeout` is added in commit a87c9d4 / PR #2435. This PR refactors a previous code commit, and it's suggested by #2658 (comment). Change: This PR put the temporary code related to the 'master_timeout' deprecation in centralized places, so that it will be easier to remove when removing the deprecated parameter `master_timeout` in the future. - Move the method `parseDeprecatedMasterTimeoutParameter()` into abstract base class `BaseRestHandler`, so that every REST API handler can call it. - Put the unit tests related to the 'master_timeout' deprecation in one class. Another notable change: Prohibit using two paramters `master_timeout` and `cluster_manager_timeout` together. Reason: There are other 60 REST APIs have got request parameter `master_timeout`, and the parameter pending to be deprecated. (See issue #2511 for the full list). - Adding new codes (creating deprecation warning, validating the parameter value and unit tests) in every class for the 60 APIs will cause large duplication. - Removing the duplicate deprecated codes in the future is also a trouble. Signed-off-by: Tianli Feng <[email protected]>
- Loading branch information
1 parent
3984dff
commit e3891c7
Showing
6 changed files
with
145 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
server/src/test/java/org/opensearch/action/RenamedTimeoutRequestParameterTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* 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; | ||
|
||
import org.junit.After; | ||
import org.opensearch.OpenSearchParseException; | ||
import org.opensearch.action.support.master.MasterNodeRequest; | ||
import org.opensearch.client.node.NodeClient; | ||
import org.opensearch.common.logging.DeprecationLogger; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.rest.BaseRestHandler; | ||
import org.opensearch.rest.action.cat.RestNodesAction; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.test.rest.FakeRestRequest; | ||
import org.opensearch.threadpool.TestThreadPool; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
|
||
/** | ||
* As of 2.0, the request parameter 'master_timeout' in all applicable REST APIs is deprecated, | ||
* and alternative parameter 'cluster_manager_timeout' is added. | ||
* The tests are used to validate the behavior about the renamed request parameter. | ||
* Remove the test after removing MASTER_ROLE and 'master_timeout'. | ||
*/ | ||
public class RenamedTimeoutRequestParameterTests extends OpenSearchTestCase { | ||
private final TestThreadPool threadPool = new TestThreadPool(RenamedTimeoutRequestParameterTests.class.getName()); | ||
private final NodeClient client = new NodeClient(Settings.EMPTY, threadPool); | ||
private final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(RenamedTimeoutRequestParameterTests.class); | ||
|
||
private static final String DUPLICATE_PARAMETER_ERROR_MESSAGE = | ||
"Please only use one of the request parameters [master_timeout, cluster_manager_timeout]."; | ||
private 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."; | ||
|
||
@After | ||
public void terminateThreadPool() { | ||
terminate(threadPool); | ||
} | ||
|
||
public void testNoWarningsForNewParam() { | ||
BaseRestHandler.parseDeprecatedMasterTimeoutParameter( | ||
getMasterNodeRequest(), | ||
getRestRequestWithNewParam(), | ||
deprecationLogger, | ||
"test" | ||
); | ||
} | ||
|
||
public void testDeprecationWarningForOldParam() { | ||
BaseRestHandler.parseDeprecatedMasterTimeoutParameter( | ||
getMasterNodeRequest(), | ||
getRestRequestWithDeprecatedParam(), | ||
deprecationLogger, | ||
"test" | ||
); | ||
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
} | ||
|
||
public void testBothParamsNotValid() { | ||
Exception e = assertThrows( | ||
OpenSearchParseException.class, | ||
() -> BaseRestHandler.parseDeprecatedMasterTimeoutParameter( | ||
getMasterNodeRequest(), | ||
getRestRequestWithBothParams(), | ||
deprecationLogger, | ||
"test" | ||
) | ||
); | ||
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE)); | ||
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
} | ||
|
||
public void testCatAllocation() { | ||
RestNodesAction action = new RestNodesAction(); | ||
Exception e = assertThrows(OpenSearchParseException.class, () -> action.doCatRequest(getRestRequestWithBothParams(), client)); | ||
assertThat(e.getMessage(), containsString(DUPLICATE_PARAMETER_ERROR_MESSAGE)); | ||
assertWarnings(MASTER_TIMEOUT_DEPRECATED_MESSAGE); | ||
} | ||
|
||
private MasterNodeRequest getMasterNodeRequest() { | ||
return new MasterNodeRequest() { | ||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
private FakeRestRequest getRestRequestWithBothParams() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
request.params().put("cluster_manager_timeout", "1h"); | ||
request.params().put("master_timeout", "3s"); | ||
return request; | ||
} | ||
|
||
private FakeRestRequest getRestRequestWithDeprecatedParam() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
request.params().put("master_timeout", "3s"); | ||
return request; | ||
} | ||
|
||
private FakeRestRequest getRestRequestWithNewParam() { | ||
FakeRestRequest request = new FakeRestRequest(); | ||
request.params().put("cluster_manager_timeout", "2m"); | ||
return request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters