Replace internal usages of 'master' term in 'client' directory (#3088)

* Replace internal usages of 'master' term in 'client' directory

Signed-off-by: Tianli Feng <ftianli@amazon.com>

* Add a uni test for NodeSelector to test deprecated master role

Signed-off-by: Tianli Feng <ftianli@amazon.com>
This commit is contained in:
Tianli Feng 2022-04-27 06:09:08 -07:00 committed by GitHub
parent 79eb3b0492
commit dd7add2568
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 96 additions and 67 deletions

View File

@ -895,8 +895,8 @@ final class RequestConverters {
* @deprecated As of 2.0, because supporting inclusive language, replaced by {@link #withClusterManagerTimeout(TimeValue)} * @deprecated As of 2.0, because supporting inclusive language, replaced by {@link #withClusterManagerTimeout(TimeValue)}
*/ */
@Deprecated @Deprecated
Params withMasterTimeout(TimeValue masterTimeout) { Params withMasterTimeout(TimeValue clusterManagerTimeout) {
return putParam("master_timeout", masterTimeout); return putParam("master_timeout", clusterManagerTimeout);
} }
Params withClusterManagerTimeout(TimeValue clusterManagerTimeout) { Params withClusterManagerTimeout(TimeValue clusterManagerTimeout) {

View File

@ -47,7 +47,7 @@ public abstract class TimedRequest implements Validatable {
public static final TimeValue DEFAULT_MASTER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30); public static final TimeValue DEFAULT_MASTER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30);
private TimeValue timeout = DEFAULT_ACK_TIMEOUT; private TimeValue timeout = DEFAULT_ACK_TIMEOUT;
private TimeValue masterTimeout = DEFAULT_MASTER_NODE_TIMEOUT; private TimeValue clusterManagerTimeout = DEFAULT_MASTER_NODE_TIMEOUT;
/** /**
* Sets the timeout to wait for the all the nodes to acknowledge * Sets the timeout to wait for the all the nodes to acknowledge
@ -58,11 +58,11 @@ public abstract class TimedRequest implements Validatable {
} }
/** /**
* Sets the timeout to connect to the master node * Sets the timeout to connect to the cluster-manager node
* @param masterTimeout timeout as a {@link TimeValue} * @param clusterManagerTimeout timeout as a {@link TimeValue}
*/ */
public void setMasterTimeout(TimeValue masterTimeout) { public void setMasterTimeout(TimeValue clusterManagerTimeout) {
this.masterTimeout = masterTimeout; this.clusterManagerTimeout = clusterManagerTimeout;
} }
/** /**
@ -73,9 +73,9 @@ public abstract class TimedRequest implements Validatable {
} }
/** /**
* Returns the timeout for the request to be completed on the master node * Returns the timeout for the request to be completed on the cluster-manager node
*/ */
public TimeValue masterNodeTimeout() { public TimeValue masterNodeTimeout() {
return masterTimeout; return clusterManagerTimeout;
} }
} }

View File

@ -44,7 +44,7 @@ public class GetComponentTemplatesRequest implements Validatable {
private final String name; private final String name;
private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT; private TimeValue clusterManagerNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private boolean local = false; private boolean local = false;
/** /**
@ -65,23 +65,23 @@ public class GetComponentTemplatesRequest implements Validatable {
} }
/** /**
* @return the timeout for waiting for the master node to respond * @return the timeout for waiting for the cluster-manager node to respond
*/ */
public TimeValue getMasterNodeTimeout() { public TimeValue getMasterNodeTimeout() {
return masterNodeTimeout; return clusterManagerNodeTimeout;
} }
public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) { public void setMasterNodeTimeout(@Nullable TimeValue clusterManagerNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout; this.clusterManagerNodeTimeout = clusterManagerNodeTimeout;
} }
public void setMasterNodeTimeout(String masterNodeTimeout) { public void setMasterNodeTimeout(String clusterManagerNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout"); final TimeValue timeValue = TimeValue.parseTimeValue(clusterManagerNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
setMasterNodeTimeout(timeValue); setMasterNodeTimeout(timeValue);
} }
/** /**
* @return true if this request is to read from the local cluster state, rather than the master node - false otherwise * @return true if this request is to read from the local cluster state, rather than the cluster-manager node - false otherwise
*/ */
public boolean isLocal() { public boolean isLocal() {
return local; return local;

View File

@ -44,7 +44,7 @@ public class GetComposableIndexTemplateRequest implements Validatable {
private final String name; private final String name;
private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT; private TimeValue clusterManagerNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private boolean local = false; private boolean local = false;
/** /**
@ -65,23 +65,23 @@ public class GetComposableIndexTemplateRequest implements Validatable {
} }
/** /**
* @return the timeout for waiting for the master node to respond * @return the timeout for waiting for the cluster-manager node to respond
*/ */
public TimeValue getMasterNodeTimeout() { public TimeValue getMasterNodeTimeout() {
return masterNodeTimeout; return clusterManagerNodeTimeout;
} }
public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) { public void setMasterNodeTimeout(@Nullable TimeValue clusterManagerNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout; this.clusterManagerNodeTimeout = clusterManagerNodeTimeout;
} }
public void setMasterNodeTimeout(String masterNodeTimeout) { public void setMasterNodeTimeout(String clusterManagerNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout"); final TimeValue timeValue = TimeValue.parseTimeValue(clusterManagerNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
setMasterNodeTimeout(timeValue); setMasterNodeTimeout(timeValue);
} }
/** /**
* @return true if this request is to read from the local cluster state, rather than the master node - false otherwise * @return true if this request is to read from the local cluster state, rather than the cluster-manager node - false otherwise
*/ */
public boolean isLocal() { public boolean isLocal() {
return local; return local;

View File

@ -82,9 +82,9 @@ public class GetIndexRequest extends TimedRequest {
} }
/** /**
* Return local information, do not retrieve the state from master node (default: false). * Return local information, do not retrieve the state from cluster-manager node (default: false).
* @return <code>true</code> if local information is to be returned; * @return <code>true</code> if local information is to be returned;
* <code>false</code> if information is to be retrieved from master node (default). * <code>false</code> if information is to be retrieved from cluster-manager node (default).
*/ */
public final boolean local() { public final boolean local() {
return local; return local;

View File

@ -51,7 +51,7 @@ public class GetIndexTemplatesRequest implements Validatable {
private final List<String> names; private final List<String> names;
private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT; private TimeValue clusterManagerNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private boolean local = false; private boolean local = false;
/** /**
@ -84,23 +84,23 @@ public class GetIndexTemplatesRequest implements Validatable {
} }
/** /**
* @return the timeout for waiting for the master node to respond * @return the timeout for waiting for the cluster-manager node to respond
*/ */
public TimeValue getMasterNodeTimeout() { public TimeValue getMasterNodeTimeout() {
return masterNodeTimeout; return clusterManagerNodeTimeout;
} }
public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) { public void setMasterNodeTimeout(@Nullable TimeValue clusterManagerNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout; this.clusterManagerNodeTimeout = clusterManagerNodeTimeout;
} }
public void setMasterNodeTimeout(String masterNodeTimeout) { public void setMasterNodeTimeout(String clusterManagerNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout"); final TimeValue timeValue = TimeValue.parseTimeValue(clusterManagerNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
setMasterNodeTimeout(timeValue); setMasterNodeTimeout(timeValue);
} }
/** /**
* @return true if this request is to read from the local cluster state, rather than the master node - false otherwise * @return true if this request is to read from the local cluster state, rather than the cluster-manager node - false otherwise
*/ */
public boolean isLocal() { public boolean isLocal() {
return local; return local;

View File

@ -89,9 +89,9 @@ public class ClusterRequestConvertersTests extends OpenSearchTestCase {
ClusterHealthRequest healthRequest = new ClusterHealthRequest(); ClusterHealthRequest healthRequest = new ClusterHealthRequest();
Map<String, String> expectedParams = new HashMap<>(); Map<String, String> expectedParams = new HashMap<>();
RequestConvertersTests.setRandomLocal(healthRequest::local, expectedParams); RequestConvertersTests.setRandomLocal(healthRequest::local, expectedParams);
String timeoutType = OpenSearchTestCase.randomFrom("timeout", "masterTimeout", "both", "none"); String timeoutType = OpenSearchTestCase.randomFrom("timeout", "clusterManagerTimeout", "both", "none");
String timeout = OpenSearchTestCase.randomTimeValue(); String timeout = OpenSearchTestCase.randomTimeValue();
String masterTimeout = OpenSearchTestCase.randomTimeValue(); String clusterManagerTimeout = OpenSearchTestCase.randomTimeValue();
switch (timeoutType) { switch (timeoutType) {
case "timeout": case "timeout":
healthRequest.timeout(timeout); healthRequest.timeout(timeout);
@ -99,10 +99,10 @@ public class ClusterRequestConvertersTests extends OpenSearchTestCase {
// If Cluster Manager Timeout wasn't set it uses the same value as Timeout // If Cluster Manager Timeout wasn't set it uses the same value as Timeout
expectedParams.put("cluster_manager_timeout", timeout); expectedParams.put("cluster_manager_timeout", timeout);
break; break;
case "masterTimeout": case "clusterManagerTimeout":
expectedParams.put("timeout", "30s"); expectedParams.put("timeout", "30s");
healthRequest.masterNodeTimeout(masterTimeout); healthRequest.masterNodeTimeout(clusterManagerTimeout);
expectedParams.put("cluster_manager_timeout", masterTimeout); expectedParams.put("cluster_manager_timeout", clusterManagerTimeout);
break; break;
case "both": case "both":
healthRequest.timeout(timeout); healthRequest.timeout(timeout);

View File

@ -48,10 +48,10 @@ public class TimedRequestTests extends OpenSearchTestCase {
TimedRequest timedRequest = new TimedRequest() { TimedRequest timedRequest = new TimedRequest() {
}; };
TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000)); TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
TimeValue masterTimeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000)); TimeValue clusterManagerTimeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
timedRequest.setTimeout(timeout); timedRequest.setTimeout(timeout);
timedRequest.setMasterTimeout(masterTimeout); timedRequest.setMasterTimeout(clusterManagerTimeout);
assertEquals(timedRequest.timeout(), timeout); assertEquals(timedRequest.timeout(), timeout);
assertEquals(timedRequest.masterNodeTimeout(), masterTimeout); assertEquals(timedRequest.masterNodeTimeout(), clusterManagerTimeout);
} }
} }

View File

@ -80,10 +80,10 @@ public class CloseIndexRequestTests extends OpenSearchTestCase {
final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000)); final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
request.setTimeout(timeout); request.setTimeout(timeout);
final TimeValue masterTimeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000)); final TimeValue clusterManagerTimeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
request.setMasterTimeout(masterTimeout); request.setMasterTimeout(clusterManagerTimeout);
assertEquals(request.timeout(), timeout); assertEquals(request.timeout(), timeout);
assertEquals(request.masterNodeTimeout(), masterTimeout); assertEquals(request.masterNodeTimeout(), clusterManagerTimeout);
} }
} }

View File

@ -210,7 +210,7 @@ public class Node {
} }
/** /**
* Returns whether or not the node <strong>could</strong> be elected master. * Returns whether or not the node <strong>could</strong> be elected cluster-manager.
*/ */
public boolean isMasterEligible() { public boolean isMasterEligible() {
return roles.contains("master") || roles.contains("cluster_manager"); return roles.contains("master") || roles.contains("cluster_manager");

View File

@ -36,7 +36,7 @@ import java.util.Iterator;
/** /**
* Selects nodes that can receive requests. Used to keep requests away * Selects nodes that can receive requests. Used to keep requests away
* from master nodes or to send them to nodes with a particular attribute. * from cluster-manager nodes or to send them to nodes with a particular attribute.
* Use with {@link RestClientBuilder#setNodeSelector(NodeSelector)}. * Use with {@link RestClientBuilder#setNodeSelector(NodeSelector)}.
*/ */
public interface NodeSelector { public interface NodeSelector {
@ -80,10 +80,10 @@ public interface NodeSelector {
/** /**
* Selector that matches any node that has metadata and doesn't * Selector that matches any node that has metadata and doesn't
* have the {@code master} role OR it has the data {@code data} * have the {@code cluster_manager} role OR it has the data {@code data}
* role. * role.
*/ */
NodeSelector SKIP_DEDICATED_MASTERS = new NodeSelector() { NodeSelector SKIP_DEDICATED_CLUSTER_MANAGERS = new NodeSelector() {
@Override @Override
public void select(Iterable<Node> nodes) { public void select(Iterable<Node> nodes) {
for (Iterator<Node> itr = nodes.iterator(); itr.hasNext();) { for (Iterator<Node> itr = nodes.iterator(); itr.hasNext();) {

View File

@ -55,33 +55,33 @@ public class NodeSelectorTests extends RestClientTestCase {
assertEquals(expected, nodes); assertEquals(expected, nodes);
} }
public void testNotMasterOnly() { public void testNotClusterManagerOnly() {
Node masterOnly = dummyNode(true, false, false); Node clusterManagerOnly = dummyNode(true, false, false);
Node all = dummyNode(true, true, true); Node all = dummyNode(true, true, true);
Node masterAndData = dummyNode(true, true, false); Node clusterManagerAndData = dummyNode(true, true, false);
Node masterAndIngest = dummyNode(true, false, true); Node clusterManagerAndIngest = dummyNode(true, false, true);
Node coordinatingOnly = dummyNode(false, false, false); Node coordinatingOnly = dummyNode(false, false, false);
Node ingestOnly = dummyNode(false, false, true); Node ingestOnly = dummyNode(false, false, true);
Node data = dummyNode(false, true, randomBoolean()); Node data = dummyNode(false, true, randomBoolean());
List<Node> nodes = new ArrayList<>(); List<Node> nodes = new ArrayList<>();
nodes.add(masterOnly); nodes.add(clusterManagerOnly);
nodes.add(all); nodes.add(all);
nodes.add(masterAndData); nodes.add(clusterManagerAndData);
nodes.add(masterAndIngest); nodes.add(clusterManagerAndIngest);
nodes.add(coordinatingOnly); nodes.add(coordinatingOnly);
nodes.add(ingestOnly); nodes.add(ingestOnly);
nodes.add(data); nodes.add(data);
Collections.shuffle(nodes, getRandom()); Collections.shuffle(nodes, getRandom());
List<Node> expected = new ArrayList<>(nodes); List<Node> expected = new ArrayList<>(nodes);
expected.remove(masterOnly); expected.remove(clusterManagerOnly);
NodeSelector.SKIP_DEDICATED_MASTERS.select(nodes); NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS.select(nodes);
assertEquals(expected, nodes); assertEquals(expected, nodes);
} }
private static Node dummyNode(boolean master, boolean data, boolean ingest) { private static Node dummyNode(boolean clusterManager, boolean data, boolean ingest) {
final Set<String> roles = new TreeSet<>(); final Set<String> roles = new TreeSet<>();
if (master) { if (clusterManager) {
roles.add("master"); roles.add("cluster_manager");
} }
if (data) { if (data) {
roles.add("data"); roles.add("data");
@ -98,4 +98,33 @@ public class NodeSelectorTests extends RestClientTestCase {
Collections.<String, List<String>>emptyMap() Collections.<String, List<String>>emptyMap()
); );
} }
/*
* Validate SKIP_DEDICATED_CLUSTER_MANAGERS can filter both the deprecated "master" role and the new "cluster_manager" role.
* The test is a modified copy of the above testNotClusterManagerOnly().
*/
public void testDeprecatedNotMasterOnly() {
Node clusterManagerOnly = dummyNode(true, false, false);
Node all = dummyNode(true, true, true);
Node data = dummyNode(false, true, randomBoolean());
Node deprecatedMasterOnly = new Node(
new HttpHost("dummy"),
Collections.emptySet(),
randomAsciiAlphanumOfLength(5),
randomAsciiAlphanumOfLength(5),
new Roles(Collections.singleton("master")),
Collections.emptyMap()
);
List<Node> nodes = new ArrayList<>();
nodes.add(clusterManagerOnly);
nodes.add(all);
nodes.add(data);
nodes.add(deprecatedMasterOnly);
Collections.shuffle(nodes, getRandom());
List<Node> expected = new ArrayList<>(nodes);
expected.remove(clusterManagerOnly);
expected.remove(deprecatedMasterOnly);
NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS.select(nodes);
assertEquals(expected, nodes);
}
} }

View File

@ -297,7 +297,7 @@ public class RestClientMultipleHostsTests extends RestClientTestCase {
} }
public void testSetNodes() throws Exception { public void testSetNodes() throws Exception {
RestClient restClient = createRestClient(NodeSelector.SKIP_DEDICATED_MASTERS); RestClient restClient = createRestClient(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
List<Node> newNodes = new ArrayList<>(nodes.size()); List<Node> newNodes = new ArrayList<>(nodes.size());
for (int i = 0; i < nodes.size(); i++) { for (int i = 0; i < nodes.size(); i++) {
Node.Roles roles = i == 0 Node.Roles roles = i == 0

View File

@ -133,7 +133,7 @@ public class RestClientDocumentation {
//tag::rest-client-init-node-selector //tag::rest-client-init-node-selector
RestClientBuilder builder = RestClient.builder( RestClientBuilder builder = RestClient.builder(
new HttpHost("localhost", 9200, "http")); new HttpHost("localhost", 9200, "http"));
builder.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS); // <1> builder.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS); // <1>
//end::rest-client-init-node-selector //end::rest-client-init-node-selector
} }
{ {

View File

@ -486,7 +486,7 @@ public class ClientYamlTestSuiteTests extends AbstractClientYamlTestFragmentPars
int lineNumber = between(1, 10000); int lineNumber = between(1, 10000);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0)); DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
ApiCallSection apiCall = new ApiCallSection("test"); ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS); apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
doSection.setApiCallSection(apiCall); doSection.setApiCallSection(apiCall);
ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection); ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection);
Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate); Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
@ -553,7 +553,7 @@ public class ClientYamlTestSuiteTests extends AbstractClientYamlTestFragmentPars
{ {
DoSection doSection = new DoSection(new XContentLocation(thirdLineNumber, 0)); DoSection doSection = new DoSection(new XContentLocation(thirdLineNumber, 0));
ApiCallSection apiCall = new ApiCallSection("test"); ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS); apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
doSection.setApiCallSection(apiCall); doSection.setApiCallSection(apiCall);
doSections.add(doSection); doSections.add(doSection);
} }
@ -593,7 +593,7 @@ public class ClientYamlTestSuiteTests extends AbstractClientYamlTestFragmentPars
SkipSection skipSection = new SkipSection(null, singletonList("node_selector"), null); SkipSection skipSection = new SkipSection(null, singletonList("node_selector"), null);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0)); DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
ApiCallSection apiCall = new ApiCallSection("test"); ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS); apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
doSection.setApiCallSection(apiCall); doSection.setApiCallSection(apiCall);
createTestSuite(skipSection, doSection).validate(); createTestSuite(skipSection, doSection).validate();
} }