Skip to content

Commit

Permalink
Replace internal usages of 'master' term in 'client' directory (#3088) (
Browse files Browse the repository at this point in the history
#3284)

* 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>
  • Loading branch information
Tianli Feng committed May 11, 2022
1 parent 0cecf81 commit bdefab0
Show file tree
Hide file tree
Showing 14 changed files with 92 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public abstract class TimedRequest implements Validatable {
public static final TimeValue DEFAULT_MASTER_NODE_TIMEOUT = TimeValue.timeValueSeconds(30);

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
Expand All @@ -58,11 +58,11 @@ public void setTimeout(TimeValue timeout) {
}

/**
* Sets the timeout to connect to the master node
* @param masterTimeout timeout as a {@link TimeValue}
* Sets the timeout to connect to the cluster-manager node
* @param clusterManagerTimeout timeout as a {@link TimeValue}
*/
public void setMasterTimeout(TimeValue masterTimeout) {
this.masterTimeout = masterTimeout;
public void setMasterTimeout(TimeValue clusterManagerTimeout) {
this.clusterManagerTimeout = clusterManagerTimeout;
}

/**
Expand All @@ -73,9 +73,9 @@ public TimeValue timeout() {
}

/**
* 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() {
return masterTimeout;
return clusterManagerTimeout;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GetComponentTemplatesRequest implements Validatable {

private final String name;

private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private TimeValue clusterManagerNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private boolean local = false;

/**
Expand All @@ -65,23 +65,23 @@ public String name() {
}

/**
* @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() {
return masterNodeTimeout;
return clusterManagerNodeTimeout;
}

public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout;
public void setMasterNodeTimeout(@Nullable TimeValue clusterManagerNodeTimeout) {
this.clusterManagerNodeTimeout = clusterManagerNodeTimeout;
}

public void setMasterNodeTimeout(String masterNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
public void setMasterNodeTimeout(String clusterManagerNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(clusterManagerNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
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() {
return local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class GetComposableIndexTemplateRequest implements Validatable {

private final String name;

private TimeValue masterNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private TimeValue clusterManagerNodeTimeout = TimedRequest.DEFAULT_MASTER_NODE_TIMEOUT;
private boolean local = false;

/**
Expand All @@ -65,23 +65,23 @@ public String name() {
}

/**
* @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() {
return masterNodeTimeout;
return clusterManagerNodeTimeout;
}

public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout;
public void setMasterNodeTimeout(@Nullable TimeValue clusterManagerNodeTimeout) {
this.clusterManagerNodeTimeout = clusterManagerNodeTimeout;
}

public void setMasterNodeTimeout(String masterNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
public void setMasterNodeTimeout(String clusterManagerNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(clusterManagerNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
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() {
return local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public final GetIndexRequest local(boolean local) {
}

/**
* 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;
* <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() {
return local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class GetIndexTemplatesRequest implements Validatable {

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;

/**
Expand Down Expand Up @@ -84,23 +84,23 @@ public List<String> names() {
}

/**
* @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() {
return masterNodeTimeout;
return clusterManagerNodeTimeout;
}

public void setMasterNodeTimeout(@Nullable TimeValue masterNodeTimeout) {
this.masterNodeTimeout = masterNodeTimeout;
public void setMasterNodeTimeout(@Nullable TimeValue clusterManagerNodeTimeout) {
this.clusterManagerNodeTimeout = clusterManagerNodeTimeout;
}

public void setMasterNodeTimeout(String masterNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(masterNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
public void setMasterNodeTimeout(String clusterManagerNodeTimeout) {
final TimeValue timeValue = TimeValue.parseTimeValue(clusterManagerNodeTimeout, getClass().getSimpleName() + ".masterNodeTimeout");
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() {
return local;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testClusterHealth() {
RequestConvertersTests.setRandomLocal(healthRequest::local, expectedParams);
String timeoutType = OpenSearchTestCase.randomFrom("timeout", "masterTimeout", "both", "none");
String timeout = OpenSearchTestCase.randomTimeValue();
String masterTimeout = OpenSearchTestCase.randomTimeValue();
String clusterManagerTimeout = OpenSearchTestCase.randomTimeValue();
switch (timeoutType) {
case "timeout":
healthRequest.timeout(timeout);
Expand All @@ -101,8 +101,8 @@ public void testClusterHealth() {
break;
case "masterTimeout":
expectedParams.put("timeout", "30s");
healthRequest.masterNodeTimeout(masterTimeout);
expectedParams.put("master_timeout", masterTimeout);
healthRequest.masterNodeTimeout(clusterManagerTimeout);
expectedParams.put("master_timeout", clusterManagerTimeout);
break;
case "both":
healthRequest.timeout(timeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public void testNonDefaults() {
TimedRequest timedRequest = new TimedRequest() {
};
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.setMasterTimeout(masterTimeout);
timedRequest.setMasterTimeout(clusterManagerTimeout);
assertEquals(timedRequest.timeout(), timeout);
assertEquals(timedRequest.masterNodeTimeout(), masterTimeout);
assertEquals(timedRequest.masterNodeTimeout(), clusterManagerTimeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ public void testTimeout() {
final TimeValue timeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
request.setTimeout(timeout);

final TimeValue masterTimeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
request.setMasterTimeout(masterTimeout);
final TimeValue clusterManagerTimeout = TimeValue.timeValueSeconds(randomIntBetween(0, 1000));
request.setMasterTimeout(clusterManagerTimeout);

assertEquals(request.timeout(), timeout);
assertEquals(request.masterNodeTimeout(), masterTimeout);
assertEquals(request.masterNodeTimeout(), clusterManagerTimeout);
}
}
2 changes: 1 addition & 1 deletion client/rest/src/main/java/org/opensearch/client/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public Roles(final Set<String> roles) {
}

/**
* 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() {
return roles.contains("master") || roles.contains("cluster_manager");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

/**
* 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)}.
*/
public interface NodeSelector {
Expand Down Expand Up @@ -80,10 +80,10 @@ public String toString() {

/**
* 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.
*/
NodeSelector SKIP_DEDICATED_MASTERS = new NodeSelector() {
NodeSelector SKIP_DEDICATED_CLUSTER_MANAGERS = new NodeSelector() {
@Override
public void select(Iterable<Node> nodes) {
for (Iterator<Node> itr = nodes.iterator(); itr.hasNext();) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,33 @@ public void testAny() {
assertEquals(expected, nodes);
}

public void testNotMasterOnly() {
Node masterOnly = dummyNode(true, false, false);
public void testNotClusterManagerOnly() {
Node clusterManagerOnly = dummyNode(true, false, false);
Node all = dummyNode(true, true, true);
Node masterAndData = dummyNode(true, true, false);
Node masterAndIngest = dummyNode(true, false, true);
Node clusterManagerAndData = dummyNode(true, true, false);
Node clusterManagerAndIngest = dummyNode(true, false, true);
Node coordinatingOnly = dummyNode(false, false, false);
Node ingestOnly = dummyNode(false, false, true);
Node data = dummyNode(false, true, randomBoolean());
List<Node> nodes = new ArrayList<>();
nodes.add(masterOnly);
nodes.add(clusterManagerOnly);
nodes.add(all);
nodes.add(masterAndData);
nodes.add(masterAndIngest);
nodes.add(clusterManagerAndData);
nodes.add(clusterManagerAndIngest);
nodes.add(coordinatingOnly);
nodes.add(ingestOnly);
nodes.add(data);
Collections.shuffle(nodes, getRandom());
List<Node> expected = new ArrayList<>(nodes);
expected.remove(masterOnly);
NodeSelector.SKIP_DEDICATED_MASTERS.select(nodes);
expected.remove(clusterManagerOnly);
NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS.select(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<>();
if (master) {
roles.add("master");
if (clusterManager) {
roles.add("cluster_manager");
}
if (data) {
roles.add("data");
Expand All @@ -98,4 +98,33 @@ private static Node dummyNode(boolean master, boolean data, boolean ingest) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void testNodeSelector() 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());
for (int i = 0; i < nodes.size(); i++) {
Node.Roles roles = i == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void usage() throws IOException, InterruptedException {
//tag::rest-client-init-node-selector
RestClientBuilder builder = RestClient.builder(
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
}
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ public void testAddingDoWithNodeSelectorWithoutSkipNodeSelector() {
int lineNumber = between(1, 10000);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS);
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
doSection.setApiCallSection(apiCall);
ClientYamlTestSuite testSuite = createTestSuite(SkipSection.EMPTY, doSection);
Exception e = expectThrows(IllegalArgumentException.class, testSuite::validate);
Expand Down Expand Up @@ -553,7 +553,7 @@ public void testMultipleValidationErrors() {
{
DoSection doSection = new DoSection(new XContentLocation(thirdLineNumber, 0));
ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS);
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
doSection.setApiCallSection(apiCall);
doSections.add(doSection);
}
Expand Down Expand Up @@ -593,7 +593,7 @@ public void testAddingDoWithNodeSelectorWithSkip() {
SkipSection skipSection = new SkipSection(null, singletonList("node_selector"), null);
DoSection doSection = new DoSection(new XContentLocation(lineNumber, 0));
ApiCallSection apiCall = new ApiCallSection("test");
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_MASTERS);
apiCall.setNodeSelector(NodeSelector.SKIP_DEDICATED_CLUSTER_MANAGERS);
doSection.setApiCallSection(apiCall);
createTestSuite(skipSection, doSection).validate();
}
Expand Down

0 comments on commit bdefab0

Please sign in to comment.