Add a new node role 'cluster_manager' as the alternative for 'master' role and deprecate 'master' role (#2424)

Add a new node role `cluster_manager`, as the replacement for `master` role, that used in setting `node.roles: [ master ]`. 
They have got the same functionality, but can NOT be assigned to `node.roles` together.
* Add `CLUSTER_MANAGER_ROLE` in `DiscoveryNodeRole` class, and deprecate `MASTER_ROLE`
* Remove `MASTER_ROLE` from the `DiscoveryNodeRole.BUILT_IN_ROLES`, and temporarily load the role by the existing method `DiscoveryNode.setAdditionalRoles`
* Add a method `validateRole()` in `DiscoveryNodeRole` class, it's used to validate a specific role is compatible with the other roles to be assigned to a node together.
* Add deprecation message when assigning `master` role in setting `node.roles`
* Replace most `MASTER_ROLE` with `CLUSTER_MANAGER_ROLE` in current unit and integration tests
* Add new unit and integration tests to validate `CLUSTER_MANAGER_ROLE` and `MASTER_ROLE` can be treated as the same.

More explanation:
* New node will have "cluster_manager", "data", and "ingest" roles by default. Which means the default value of setting "node.roles" will be `["cluster_manager","data","ingest"]`, instead of `["master","data","ingest"]`
* "cluster_manager" role will be treated as "master" role in the OpenSearch node of previous versions.
* "cluster_manager” role and "master" role have got the same abbreviation name: "m"

Signed-off-by: Tianli Feng <ftianli@amazon.com>
This commit is contained in:
Tianli Feng 2022-03-18 15:06:06 -07:00 committed by GitHub
parent 641350b0b6
commit ea31483126
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 356 additions and 105 deletions

View File

@ -111,7 +111,7 @@ public final class Allocators {
nodeId, nodeId,
new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()), new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()),
attributes, attributes,
Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE), Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE),
Version.CURRENT Version.CURRENT
); );
} }

View File

@ -210,21 +210,21 @@ public class Node {
} }
/** /**
* Teturns whether or not the node <strong>could</strong> be elected master. * Returns whether or not the node <strong>could</strong> be elected master.
*/ */
public boolean isMasterEligible() { public boolean isMasterEligible() {
return roles.contains("master"); return roles.contains("master") || roles.contains("cluster_manager");
} }
/** /**
* Teturns whether or not the node stores data. * Returns whether or not the node stores data.
*/ */
public boolean isData() { public boolean isData() {
return roles.contains("data"); return roles.contains("data");
} }
/** /**
* Teturns whether or not the node runs ingest pipelines. * Returns whether or not the node runs ingest pipelines.
*/ */
public boolean isIngest() { public boolean isIngest() {
return roles.contains("ingest"); return roles.contains("ingest");

View File

@ -91,3 +91,22 @@
cluster.stats: {} cluster.stats: {}
- is_true: nodes.packaging_types - is_true: nodes.packaging_types
---
"get cluster stats nodes count with both master and cluster_manager":
- skip:
version: " - 1.4.99"
reason: "node role cluster_manager is added in 2.0.0"
- do:
cluster.stats: {}
- set:
nodes.count.cluster_manager: cluster_manager_count
- gte: { nodes.count.total: 1}
- match: { nodes.count.cluster_manager: $cluster_manager_count }
- match: { nodes.count.master: $cluster_manager_count }
- gte: { nodes.count.data: 1}
- gte: { nodes.count.ingest: 0}
- gte: { nodes.count.coordinating_only: 0}

View File

@ -12,14 +12,24 @@ setup:
- is_true: cluster_name - is_true: cluster_name
--- ---
"node_info role test": "node_info role test - before 2.0.0":
- skip: - skip:
version: " - 7.7.99" version: " - 7.7.99 , 2.0.0 - "
reason: "node roles were not sorted before 7.8.0" reason: "node roles were not sorted before 7.8.0"
features: node_selector
- do: - do:
nodes.info: {} nodes.info: {}
node_selector:
# Only send request to nodes in <2.0 versions, especially during ':qa:mixed-cluster:v1.x.x#mixedClusterTest'.
# Because YAML REST test takes the minimum OpenSearch version in the cluster to apply the filter in 'skip' section,
# see OpenSearchClientYamlSuiteTestCase#initAndResetContext() for detail.
# During 'mixedClusterTest', the cluster can be mixed with nodes in 1.x and 2.x versions,
# so node_selector is required, and only filtering version in 'skip' is not enough.
version: "1.0.0 - 1.4.99"
- set: - set:
# Note: It will only stash the first node_id in the api response.
nodes._arbitrary_key_: node_id nodes._arbitrary_key_: node_id
- is_true: nodes.$node_id.roles - is_true: nodes.$node_id.roles
@ -29,3 +39,21 @@ setup:
- match: { nodes.$node_id.roles.2: "master" } - match: { nodes.$node_id.roles.2: "master" }
- match: { nodes.$node_id.roles.3: "remote_cluster_client" } - match: { nodes.$node_id.roles.3: "remote_cluster_client" }
---
"node_info role test":
- skip:
version: " - 1.4.99"
reason: "node role cluster_manager is added in 2.0.0"
- do:
nodes.info: {}
- set:
nodes._arbitrary_key_: node_id
- is_true: nodes.$node_id.roles
# the roles output is sorted
- match: { nodes.$node_id.roles.0: "cluster_manager" }
- match: { nodes.$node_id.roles.1: "data" }
- match: { nodes.$node_id.roles.2: "ingest" }
- match: { nodes.$node_id.roles.3: "remote_cluster_client" }

View File

@ -85,6 +85,7 @@ public class ClusterStatsIT extends OpenSearchIntegTestCase {
Map<String, Integer> expectedCounts = new HashMap<>(); Map<String, Integer> expectedCounts = new HashMap<>();
expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.DATA_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1); expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1);
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0); expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
@ -106,7 +107,7 @@ public class ClusterStatsIT extends OpenSearchIntegTestCase {
roles.add(DiscoveryNodeRole.INGEST_ROLE); roles.add(DiscoveryNodeRole.INGEST_ROLE);
} }
if (isMasterNode) { if (isMasterNode) {
roles.add(DiscoveryNodeRole.MASTER_ROLE); roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
if (isRemoteClusterClientNode) { if (isRemoteClusterClientNode) {
roles.add(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); roles.add(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE);
@ -129,6 +130,7 @@ public class ClusterStatsIT extends OpenSearchIntegTestCase {
} }
if (isMasterNode) { if (isMasterNode) {
incrementCountForRole(DiscoveryNodeRole.MASTER_ROLE.roleName(), expectedCounts); incrementCountForRole(DiscoveryNodeRole.MASTER_ROLE.roleName(), expectedCounts);
incrementCountForRole(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), expectedCounts);
} }
if (isRemoteClusterClientNode) { if (isRemoteClusterClientNode) {
incrementCountForRole(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), expectedCounts); incrementCountForRole(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), expectedCounts);

View File

@ -95,7 +95,7 @@ public class NodeEnvironmentIT extends OpenSearchIntegTestCase {
}) })
); );
if (writeDanglingIndices) { if (writeDanglingIndices) {
assertThat(ex.getMessage(), startsWith("node does not have the data and master roles but has index metadata")); assertThat(ex.getMessage(), startsWith("node does not have the data and cluster_manager roles but has index metadata"));
} else { } else {
assertThat(ex.getMessage(), startsWith("node does not have the data role but has shard data")); assertThat(ex.getMessage(), startsWith("node does not have the data role but has shard data"));
} }

View File

@ -223,7 +223,14 @@ public class ClusterStatsNodes implements ToXContentFragment {
roles.merge(COORDINATING_ONLY, 1, Integer::sum); roles.merge(COORDINATING_ONLY, 1, Integer::sum);
} else { } else {
for (DiscoveryNodeRole role : nodeInfo.getNode().getRoles()) { for (DiscoveryNodeRole role : nodeInfo.getNode().getRoles()) {
roles.merge(role.roleName(), 1, Integer::sum); // TODO: Remove the 'if' condition and only keep the statement in 'else' after removing MASTER_ROLE.
// As of 2.0, CLUSTER_MANAGER_ROLE is added, and it should be taken as MASTER_ROLE
if (role.isClusterManager()) {
roles.merge(DiscoveryNodeRole.MASTER_ROLE.roleName(), 1, Integer::sum);
roles.merge(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1, Integer::sum);
} else {
roles.merge(role.roleName(), 1, Integer::sum);
}
} }
} }
} }

View File

@ -94,7 +94,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
} }
public static boolean isMasterNode(Settings settings) { public static boolean isMasterNode(Settings settings) {
return hasRole(settings, DiscoveryNodeRole.MASTER_ROLE); return hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) || hasRole(settings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
/** /**
@ -343,7 +343,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
final LegacyRole legacyRole = in.readEnum(LegacyRole.class); final LegacyRole legacyRole = in.readEnum(LegacyRole.class);
switch (legacyRole) { switch (legacyRole) {
case MASTER: case MASTER:
roles.add(DiscoveryNodeRole.MASTER_ROLE); roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
break; break;
case DATA: case DATA:
roles.add(DiscoveryNodeRole.DATA_ROLE); roles.add(DiscoveryNodeRole.DATA_ROLE);
@ -390,11 +390,11 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
.collect(Collectors.toList()); .collect(Collectors.toList());
out.writeVInt(rolesToWrite.size()); out.writeVInt(rolesToWrite.size());
for (final DiscoveryNodeRole role : rolesToWrite) { for (final DiscoveryNodeRole role : rolesToWrite) {
if (role == DiscoveryNodeRole.MASTER_ROLE) { if (role.isClusterManager()) {
out.writeEnum(LegacyRole.MASTER); out.writeEnum(LegacyRole.MASTER);
} else if (role == DiscoveryNodeRole.DATA_ROLE) { } else if (role.equals(DiscoveryNodeRole.DATA_ROLE)) {
out.writeEnum(LegacyRole.DATA); out.writeEnum(LegacyRole.DATA);
} else if (role == DiscoveryNodeRole.INGEST_ROLE) { } else if (role.equals(DiscoveryNodeRole.INGEST_ROLE)) {
out.writeEnum(LegacyRole.INGEST); out.writeEnum(LegacyRole.INGEST);
} }
} }
@ -456,7 +456,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
* Can this node become master or not. * Can this node become master or not.
*/ */
public boolean isMasterNode() { public boolean isMasterNode() {
return roles.contains(DiscoveryNodeRole.MASTER_ROLE); return roles.contains(DiscoveryNodeRole.MASTER_ROLE) || roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
/** /**
@ -591,7 +591,11 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
+ "], roles by name abbreviation [" + "], roles by name abbreviation ["
+ roleNameAbbreviationToPossibleRoles + roleNameAbbreviationToPossibleRoles
+ "]"; + "]";
roleMap = roleNameToPossibleRoles; // TODO: Remove the Map 'roleNameToPossibleRolesWithMaster' and let 'roleMap = roleNameToPossibleRoles', after removing MASTER_ROLE.
// It's used to allow CLUSTER_MANAGER_ROLE that introduced in 2.0, having the same abbreviation name with MASTER_ROLE.
final Map<String, DiscoveryNodeRole> roleNameToPossibleRolesWithMaster = new HashMap<>(roleNameToPossibleRoles);
roleNameToPossibleRolesWithMaster.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE);
roleMap = Collections.unmodifiableMap(roleNameToPossibleRolesWithMaster);
} }
public static Set<String> getPossibleRoleNames() { public static Set<String> getPossibleRoleNames() {
@ -599,7 +603,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment {
} }
/** /**
* Enum that holds all the possible roles that that a node can fulfill in a cluster. * Enum that holds all the possible roles that a node can fulfill in a cluster.
* Each role has its name and a corresponding abbreviation used by cat apis. * Each role has its name and a corresponding abbreviation used by cat apis.
*/ */
private enum LegacyRole { private enum LegacyRole {

View File

@ -34,6 +34,7 @@ package org.opensearch.cluster.node;
import org.opensearch.LegacyESVersion; import org.opensearch.LegacyESVersion;
import org.opensearch.Version; import org.opensearch.Version;
import org.opensearch.common.logging.DeprecationLogger;
import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Setting.Property;
import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.Settings;
@ -41,6 +42,8 @@ import org.opensearch.transport.RemoteClusterService;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
@ -50,6 +53,10 @@ import java.util.TreeSet;
*/ */
public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole> { public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole> {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(DiscoveryNodeRole.class);
public static final String MASTER_ROLE_DEPRECATION_MESSAGE =
"Assigning [master] role in setting [node.roles] is deprecated. To promote inclusive language, please use [cluster_manager] role instead.";
private final String roleName; private final String roleName;
/** /**
@ -129,6 +136,13 @@ public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole>
return this; return this;
} }
/**
* Validate the role is compatible with the other roles in the list, when assigning the list of roles to a node.
* An {@link IllegalArgumentException} is expected to be thrown, if the role can't coexist with the other roles.
* @param roles a {@link List} of {@link DiscoveryNodeRole} that a node is going to have
*/
public void validateRole(List<DiscoveryNodeRole> roles) {};
@Override @Override
public final boolean equals(Object o) { public final boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -193,15 +207,60 @@ public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole>
/** /**
* Represents the role for a master-eligible node. * Represents the role for a master-eligible node.
* @deprecated As of 2.0, because promoting inclusive language, replaced by {@link #CLUSTER_MANAGER_ROLE}
*/ */
@Deprecated
public static final DiscoveryNodeRole MASTER_ROLE = new DiscoveryNodeRole("master", "m") { public static final DiscoveryNodeRole MASTER_ROLE = new DiscoveryNodeRole("master", "m") {
@Override
public Setting<Boolean> legacySetting() {
// copy the setting here so we can mark it private in org.opensearch.node.Node
// As of 2.0, set the default value to 'false', so that MASTER_ROLE isn't added as a default value of NODE_ROLES_SETTING
return Setting.boolSetting("node.master", false, Property.Deprecated, Property.NodeScope);
}
@Override
public void validateRole(List<DiscoveryNodeRole> roles) {
deprecationLogger.deprecate("node_role_master", MASTER_ROLE_DEPRECATION_MESSAGE);
}
};
/**
* Represents the role for a cluster-manager-eligible node.
*/
public static final DiscoveryNodeRole CLUSTER_MANAGER_ROLE = new DiscoveryNodeRole("cluster_manager", "m") {
@Override @Override
public Setting<Boolean> legacySetting() { public Setting<Boolean> legacySetting() {
// copy the setting here so we can mark it private in org.opensearch.node.Node // copy the setting here so we can mark it private in org.opensearch.node.Node
return Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope); return Setting.boolSetting("node.master", true, Property.Deprecated, Property.NodeScope);
} }
@Override
public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
if (nodeVersion.onOrAfter(Version.V_2_0_0)) {
return this;
} else {
return DiscoveryNodeRole.MASTER_ROLE;
}
}
@Override
public void validateRole(List<DiscoveryNodeRole> roles) {
if (roles.contains(DiscoveryNodeRole.MASTER_ROLE)) {
throw new IllegalArgumentException(
String.format(
Locale.ROOT,
"The two roles [%s, %s] can not be assigned together to a node. %s",
DiscoveryNodeRole.MASTER_ROLE.roleName(),
DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(),
MASTER_ROLE_DEPRECATION_MESSAGE
)
);
}
}
}; };
public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") { public static final DiscoveryNodeRole REMOTE_CLUSTER_CLIENT_ROLE = new DiscoveryNodeRole("remote_cluster_client", "r") {
@ -223,7 +282,7 @@ public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole>
* The built-in node roles. * The built-in node roles.
*/ */
public static SortedSet<DiscoveryNodeRole> BUILT_IN_ROLES = Collections.unmodifiableSortedSet( public static SortedSet<DiscoveryNodeRole> BUILT_IN_ROLES = Collections.unmodifiableSortedSet(
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, MASTER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE)) new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE))
); );
/** /**
@ -262,4 +321,13 @@ public abstract class DiscoveryNodeRole implements Comparable<DiscoveryNodeRole>
} }
/**
* Check if the role is {@link #CLUSTER_MANAGER_ROLE} or {@link #MASTER_ROLE}.
* @deprecated As of 2.0, because promoting inclusive language. MASTER_ROLE is deprecated.
* @return true if the node role is{@link #CLUSTER_MANAGER_ROLE} or {@link #MASTER_ROLE}
*/
@Deprecated
public boolean isClusterManager() {
return this.equals(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE) || this.equals(DiscoveryNodeRole.MASTER_ROLE);
}
} }

View File

@ -370,7 +370,7 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
* Works by tracking the current set of nodes and applying each node specification in sequence. The set starts out empty and each node * Works by tracking the current set of nodes and applying each node specification in sequence. The set starts out empty and each node
* specification may either add or remove nodes. For instance: * specification may either add or remove nodes. For instance:
* *
* - _local, _master and _all respectively add to the subset the local node, the currently-elected master, and all the nodes * - _local, _cluster_manager (_master) and _all respectively add to the subset the local node, the currently-elected cluster_manager, and all the nodes
* - node IDs, names, hostnames and IP addresses all add to the subset any nodes which match * - node IDs, names, hostnames and IP addresses all add to the subset any nodes which match
* - a wildcard-based pattern of the form "attr*:value*" adds to the subset all nodes with a matching attribute with a matching value * - a wildcard-based pattern of the form "attr*:value*" adds to the subset all nodes with a matching attribute with a matching value
* - role:true adds to the subset all nodes with a matching role * - role:true adds to the subset all nodes with a matching role
@ -393,7 +393,7 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
if (localNodeId != null) { if (localNodeId != null) {
resolvedNodesIds.add(localNodeId); resolvedNodesIds.add(localNodeId);
} }
} else if (nodeId.equals("_master")) { } else if (nodeId.equals("_master") || nodeId.equals("_cluster_manager")) {
String masterNodeId = getMasterNodeId(); String masterNodeId = getMasterNodeId();
if (masterNodeId != null) { if (masterNodeId != null) {
resolvedNodesIds.add(masterNodeId); resolvedNodesIds.add(masterNodeId);
@ -419,7 +419,7 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
} else { } else {
resolvedNodesIds.removeAll(dataNodes.keys()); resolvedNodesIds.removeAll(dataNodes.keys());
} }
} else if (DiscoveryNodeRole.MASTER_ROLE.roleName().equals(matchAttrName)) { } else if (roleNameIsClusterManager(matchAttrName)) {
if (Booleans.parseBoolean(matchAttrValue, true)) { if (Booleans.parseBoolean(matchAttrValue, true)) {
resolvedNodesIds.addAll(masterNodes.keys()); resolvedNodesIds.addAll(masterNodes.keys());
} else { } else {
@ -797,4 +797,17 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
return masterNodeId != null && masterNodeId.equals(localNodeId); return masterNodeId != null && masterNodeId.equals(localNodeId);
} }
} }
/**
* Check if the given name of the node role is 'cluster_manger' or 'master'.
* The method is added for {@link #resolveNodes} to keep the code clear, when support the both above roles.
* @deprecated As of 2.0, because promoting inclusive language. MASTER_ROLE is deprecated.
* @param matchAttrName a given String for a name of the node role.
* @return true if the given roleName is 'cluster_manger' or 'master'
*/
@Deprecated
private boolean roleNameIsClusterManager(String matchAttrName) {
return DiscoveryNodeRole.MASTER_ROLE.roleName().equals(matchAttrName)
|| DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName().equals(matchAttrName);
}
} }

View File

@ -1138,7 +1138,7 @@ public final class NodeEnvironment implements Closeable {
Locale.ROOT, Locale.ROOT,
"node does not have the %s and %s roles but has index metadata: %s. Use 'opensearch-node repurpose' tool to clean up", "node does not have the %s and %s roles but has index metadata: %s. Use 'opensearch-node repurpose' tool to clean up",
DiscoveryNodeRole.DATA_ROLE.roleName(), DiscoveryNodeRole.DATA_ROLE.roleName(),
DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(),
indexMetadataPaths indexMetadataPaths
); );
throw new IllegalStateException(message); throw new IllegalStateException(message);

View File

@ -51,7 +51,11 @@ public class NodeRoleSettings {
.filter(role -> role.isEnabledByDefault(settings)) .filter(role -> role.isEnabledByDefault(settings))
.map(DiscoveryNodeRole::roleName) .map(DiscoveryNodeRole::roleName)
.collect(Collectors.toList()), .collect(Collectors.toList()),
roles -> {}, roles -> {
for (DiscoveryNodeRole role : roles) {
role.validateRole(roles);
}
},
Property.NodeScope Property.NodeScope
); );

View File

@ -346,8 +346,9 @@ public class RepositoriesService extends AbstractLifecycleComponent implements C
}); });
} }
// Note: "voting_only" role has not been implemented yet, so the method always returns false.
static boolean isDedicatedVotingOnlyNode(Set<DiscoveryNodeRole> roles) { static boolean isDedicatedVotingOnlyNode(Set<DiscoveryNodeRole> roles) {
return roles.contains(DiscoveryNodeRole.MASTER_ROLE) return roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)
&& roles.contains(DiscoveryNodeRole.DATA_ROLE) == false && roles.contains(DiscoveryNodeRole.DATA_ROLE) == false
&& roles.stream().anyMatch(role -> role.roleName().equals("voting_only")); && roles.stream().anyMatch(role -> role.roleName().equals("voting_only"));
} }

View File

@ -113,7 +113,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"local", "local",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode); final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
@ -122,7 +122,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"other1", "other1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1); final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
@ -131,7 +131,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"other2", "other2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2); final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2);
@ -238,7 +238,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId1", "nodeId1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1); final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1);
@ -248,7 +248,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId2", "nodeId2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2);
@ -258,7 +258,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId3", "nodeId3",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
@ -298,7 +298,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId1", "nodeId1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1); final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1);
@ -308,7 +308,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId2", "nodeId2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2);
@ -318,7 +318,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId3", "nodeId3",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
@ -348,7 +348,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId1", "nodeId1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
@ -357,7 +357,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId2", "nodeId2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2);
@ -367,7 +367,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"nodeId3", "nodeId3",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
@ -399,7 +399,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"local", "local",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode); final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode);
@ -408,7 +408,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"other1", "other1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1); final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1);
@ -417,7 +417,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase {
"other2", "other2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2); final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2);

View File

@ -119,7 +119,7 @@ public class TransportAddVotingConfigExclusionsActionTests extends OpenSearchTes
name, name,
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
} }

View File

@ -278,7 +278,7 @@ public class TransportResizeActionTests extends OpenSearchTestCase {
private DiscoveryNode newNode(String nodeId) { private DiscoveryNode newNode(String nodeId) {
final Set<DiscoveryNodeRole> roles = Collections.unmodifiableSet( final Set<DiscoveryNodeRole> roles = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE)) new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE))
); );
return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT); return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
} }

View File

@ -263,7 +263,7 @@ public class TransportMultiSearchActionTests extends OpenSearchTestCase {
"master", "master",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
) )
); );

View File

@ -121,14 +121,14 @@ public class TransportMasterNodeActionTests extends OpenSearchTestCase {
"local_node", "local_node",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
remoteNode = new DiscoveryNode( remoteNode = new DiscoveryNode(
"remote_node", "remote_node",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
allNodes = new DiscoveryNode[] { localNode, remoteNode }; allNodes = new DiscoveryNode[] { localNode, remoteNode };

View File

@ -172,7 +172,9 @@ public class TransportNodesActionTests extends OpenSearchTestCase {
private enum NodeSelector { private enum NodeSelector {
LOCAL("_local"), LOCAL("_local"),
ELECTED_MASTER("_master"), ELECTED_MASTER("_master"),
// TODO: Remove this element after removing DiscoveryNodeRole.MASTER_ROLE
MASTER_ELIGIBLE("master:true"), MASTER_ELIGIBLE("master:true"),
CLUSTER_MANAGER_ELIGIBLE("cluster_manager:true"),
DATA("data:true"), DATA("data:true"),
CUSTOM_ATTRIBUTE("attr:value"); CUSTOM_ATTRIBUTE("attr:value");

View File

@ -447,17 +447,17 @@ public class ClusterChangedEventTests extends OpenSearchTestCase {
if (i == 0) { if (i == 0) {
// the master node // the master node
builder.masterNodeId(nodeId); builder.masterNodeId(nodeId);
roles.add(DiscoveryNodeRole.MASTER_ROLE); roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} else if (i == 1) { } else if (i == 1) {
// the alternate master node // the alternate master node
roles.add(DiscoveryNodeRole.MASTER_ROLE); roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} else if (i == 2) { } else if (i == 2) {
// we need at least one data node // we need at least one data node
roles.add(DiscoveryNodeRole.DATA_ROLE); roles.add(DiscoveryNodeRole.DATA_ROLE);
} else { } else {
// remaining nodes can be anything (except for master) // remaining nodes can be anything (except for master)
if (randomBoolean()) { if (randomBoolean()) {
roles.add(DiscoveryNodeRole.MASTER_ROLE); roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
if (randomBoolean()) { if (randomBoolean()) {
roles.add(DiscoveryNodeRole.DATA_ROLE); roles.add(DiscoveryNodeRole.DATA_ROLE);

View File

@ -112,7 +112,7 @@ public class ClusterBootstrapServiceTests extends OpenSearchTestCase {
randomAlphaOfLength(10), randomAlphaOfLength(10),
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
} }
@ -522,7 +522,7 @@ public class ClusterBootstrapServiceTests extends OpenSearchTestCase {
randomAlphaOfLength(10), randomAlphaOfLength(10),
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
), ),
new DiscoveryNode( new DiscoveryNode(
@ -530,7 +530,7 @@ public class ClusterBootstrapServiceTests extends OpenSearchTestCase {
randomAlphaOfLength(10), randomAlphaOfLength(10),
otherNode1.getAddress(), otherNode1.getAddress(),
emptyMap(), emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
) )
).collect(Collectors.toList()) ).collect(Collectors.toList())

View File

@ -287,7 +287,7 @@ public class ClusterFormationFailureHelperTests extends OpenSearchTestCase {
"local", "local",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
org.opensearch.common.collect.Set.of(DiscoveryNodeRole.MASTER_ROLE), org.opensearch.common.collect.Set.of(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
clusterState = ClusterState.builder(ClusterName.DEFAULT) clusterState = ClusterState.builder(ClusterName.DEFAULT)
@ -825,7 +825,7 @@ public class ClusterFormationFailureHelperTests extends OpenSearchTestCase {
emptyMap(), emptyMap(),
new HashSet<>( new HashSet<>(
randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES).stream() randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES).stream()
.filter(r -> r != DiscoveryNodeRole.MASTER_ROLE) .filter(r -> r != DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)
.collect(Collectors.toList()) .collect(Collectors.toList())
), ),
Version.CURRENT Version.CURRENT

View File

@ -1789,7 +1789,7 @@ public class CoordinatorTests extends AbstractCoordinatorTestCase {
"resolvableNodeId", "resolvableNodeId",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
) )
) )

View File

@ -248,7 +248,7 @@ public class NodeJoinTests extends OpenSearchTestCase {
protected DiscoveryNode newNode(int i, boolean master) { protected DiscoveryNode newNode(int i, boolean master) {
final Set<DiscoveryNodeRole> roles; final Set<DiscoveryNodeRole> roles;
if (master) { if (master) {
roles = singleton(DiscoveryNodeRole.MASTER_ROLE); roles = singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} else { } else {
roles = Collections.emptySet(); roles = Collections.emptySet();
} }
@ -492,7 +492,7 @@ public class NodeJoinTests extends OpenSearchTestCase {
"newNodeId", "newNodeId",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
long newTerm = initialTerm + randomLongBetween(1, 10); long newTerm = initialTerm + randomLongBetween(1, 10);

View File

@ -87,7 +87,9 @@ public class ClusterHealthAllocationTests extends OpenSearchAllocationTestCase {
private ClusterState addNode(ClusterState clusterState, String nodeName, boolean isMaster) { private ClusterState addNode(ClusterState clusterState, String nodeName, boolean isMaster) {
DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder(clusterState.getNodes()); DiscoveryNodes.Builder nodeBuilder = DiscoveryNodes.builder(clusterState.getNodes());
nodeBuilder.add(newNode(nodeName, Collections.singleton(isMaster ? DiscoveryNodeRole.MASTER_ROLE : DiscoveryNodeRole.DATA_ROLE))); nodeBuilder.add(
newNode(nodeName, Collections.singleton(isMaster ? DiscoveryNodeRole.CLUSTER_MANAGER_ROLE : DiscoveryNodeRole.DATA_ROLE))
);
return ClusterState.builder(clusterState).nodes(nodeBuilder).build(); return ClusterState.builder(clusterState).nodes(nodeBuilder).build();
} }

View File

@ -146,7 +146,7 @@ public class AutoExpandReplicasTests extends OpenSearchTestCase {
try { try {
List<DiscoveryNode> allNodes = new ArrayList<>(); List<DiscoveryNode> allNodes = new ArrayList<>();
DiscoveryNode localNode = createNode(DiscoveryNodeRole.MASTER_ROLE); // local node is the master DiscoveryNode localNode = createNode(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); // local node is the master
allNodes.add(localNode); allNodes.add(localNode);
int numDataNodes = randomIntBetween(3, 5); int numDataNodes = randomIntBetween(3, 5);
List<DiscoveryNode> dataNodes = new ArrayList<>(numDataNodes); List<DiscoveryNode> dataNodes = new ArrayList<>(numDataNodes);
@ -245,7 +245,7 @@ public class AutoExpandReplicasTests extends OpenSearchTestCase {
List<DiscoveryNode> allNodes = new ArrayList<>(); List<DiscoveryNode> allNodes = new ArrayList<>();
DiscoveryNode oldNode = createNode( DiscoveryNode oldNode = createNode(
VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_1), VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_1),
DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE,
DiscoveryNodeRole.DATA_ROLE DiscoveryNodeRole.DATA_ROLE
); // local node is the master ); // local node is the master
allNodes.add(oldNode); allNodes.add(oldNode);
@ -266,11 +266,11 @@ public class AutoExpandReplicasTests extends OpenSearchTestCase {
state = cluster.reroute(state, new ClusterRerouteRequest()); state = cluster.reroute(state, new ClusterRerouteRequest());
} }
DiscoveryNode newNode = createNode(LegacyESVersion.V_7_6_0, DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE); // local DiscoveryNode newNode = createNode(
// node LegacyESVersion.V_7_6_0,
// is DiscoveryNodeRole.CLUSTER_MANAGER_ROLE,
// the DiscoveryNodeRole.DATA_ROLE
// master ); // local node is the cluster_manager
state = cluster.addNodes(state, Collections.singletonList(newNode)); state = cluster.addNodes(state, Collections.singletonList(newNode));

View File

@ -582,7 +582,7 @@ public class MetadataCreateIndexServiceTests extends OpenSearchTestCase {
private DiscoveryNode newNode(String nodeId) { private DiscoveryNode newNode(String nodeId) {
final Set<DiscoveryNodeRole> roles = Collections.unmodifiableSet( final Set<DiscoveryNodeRole> roles = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE)) new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE))
); );
return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT); return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
} }

View File

@ -261,7 +261,7 @@ public class TemplateUpgradeServiceTests extends OpenSearchTestCase {
} }
private static final Set<DiscoveryNodeRole> MASTER_DATA_ROLES = Collections.unmodifiableSet( private static final Set<DiscoveryNodeRole> MASTER_DATA_ROLES = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE)) new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE))
); );
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")

View File

@ -56,9 +56,15 @@ public class DiscoveryNodeRoleSettingTests extends OpenSearchTestCase {
} }
public void testIsMasterNode() { public void testIsMasterNode() {
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
runRoleTest(DiscoveryNode::isMasterNode, DiscoveryNodeRole.MASTER_ROLE); runRoleTest(DiscoveryNode::isMasterNode, DiscoveryNodeRole.MASTER_ROLE);
} }
public void testIsClusterManagerNode() {
runRoleTest(DiscoveryNode::isMasterNode, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
}
public void testIsRemoteClusterClient() { public void testIsRemoteClusterClient() {
runRoleTest(DiscoveryNode::isRemoteClusterClient, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); runRoleTest(DiscoveryNode::isRemoteClusterClient, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE);
} }

View File

@ -128,4 +128,14 @@ public class DiscoveryNodeRoleTests extends OpenSearchTestCase {
assertNotEquals(buildInRole.toString(), unknownDataRole.toString()); assertNotEquals(buildInRole.toString(), unknownDataRole.toString());
} }
} }
/**
* Validate the method can identify the role as cluster-manager.
* Remove along with MASTER_ROLE.
*/
public void testIsClusterManager() {
assertTrue(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.isClusterManager());
assertTrue(DiscoveryNodeRole.MASTER_ROLE.isClusterManager());
assertFalse(randomFrom(DiscoveryNodeRole.DATA_ROLE.isClusterManager(), DiscoveryNodeRole.INGEST_ROLE.isClusterManager()));
}
} }

View File

@ -174,6 +174,12 @@ public class DiscoveryNodeTests extends OpenSearchTestCase {
runTestDiscoveryNodeIsRemoteClusterClient(nonRemoteClusterClientNode(), false); runTestDiscoveryNodeIsRemoteClusterClient(nonRemoteClusterClientNode(), false);
} }
// TODO: Remove the test along with MASTER_ROLE. It is added in 2.0, along with the introduction of CLUSTER_MANAGER_ROLE.
public void testSetAdditionalRolesCanAddDeprecatedMasterRole() {
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
assertTrue(DiscoveryNode.getPossibleRoleNames().contains(DiscoveryNodeRole.MASTER_ROLE.roleName()));
}
private void runTestDiscoveryNodeIsRemoteClusterClient(final Settings settings, final boolean expected) { private void runTestDiscoveryNodeIsRemoteClusterClient(final Settings settings, final boolean expected) {
final DiscoveryNode node = DiscoveryNode.createLocal(settings, new TransportAddress(TransportAddress.META_ADDRESS, 9200), "node"); final DiscoveryNode node = DiscoveryNode.createLocal(settings, new TransportAddress(TransportAddress.META_ADDRESS, 9200), "node");
assertThat(node.isRemoteClusterClient(), equalTo(expected)); assertThat(node.isRemoteClusterClient(), equalTo(expected));

View File

@ -361,6 +361,7 @@ public class DiscoveryNodesTests extends OpenSearchTestCase {
return Collections.singleton(nodes.getMasterNodeId()); return Collections.singleton(nodes.getMasterNodeId());
} }
}, },
// TODO: Remove this element after removing DiscoveryNodeRole.MASTER_ROLE
MASTER_ELIGIBLE(DiscoveryNodeRole.MASTER_ROLE.roleName() + ":true") { MASTER_ELIGIBLE(DiscoveryNodeRole.MASTER_ROLE.roleName() + ":true") {
@Override @Override
Set<String> matchingNodeIds(DiscoveryNodes nodes) { Set<String> matchingNodeIds(DiscoveryNodes nodes) {
@ -369,6 +370,14 @@ public class DiscoveryNodesTests extends OpenSearchTestCase {
return ids; return ids;
} }
}, },
CLUSTER_MANAGER_ELIGIBLE(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName() + ":true") {
@Override
Set<String> matchingNodeIds(DiscoveryNodes nodes) {
Set<String> ids = new HashSet<>();
nodes.getMasterNodes().keysIt().forEachRemaining(ids::add);
return ids;
}
},
DATA(DiscoveryNodeRole.DATA_ROLE.roleName() + ":true") { DATA(DiscoveryNodeRole.DATA_ROLE.roleName() + ":true") {
@Override @Override
Set<String> matchingNodeIds(DiscoveryNodes nodes) { Set<String> matchingNodeIds(DiscoveryNodes nodes) {

View File

@ -262,7 +262,7 @@ public class DelayedAllocationServiceTests extends OpenSearchAllocationTestCase
.routingTable(RoutingTable.builder().addAsNew(metadata.index("short_delay")).addAsNew(metadata.index("long_delay")).build()) .routingTable(RoutingTable.builder().addAsNew(metadata.index("short_delay")).addAsNew(metadata.index("long_delay")).build())
.nodes( .nodes(
DiscoveryNodes.builder() DiscoveryNodes.builder()
.add(newNode("node0", singleton(DiscoveryNodeRole.MASTER_ROLE))) .add(newNode("node0", singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)))
.localNodeId("node0") .localNodeId("node0")
.masterNodeId("node0") .masterNodeId("node0")
.add(newNode("node1")) .add(newNode("node1"))

View File

@ -778,7 +778,7 @@ public class OperationRoutingTests extends OpenSearchTestCase {
"master", "master",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
allNodes[i] = master; allNodes[i] = master;

View File

@ -188,7 +188,7 @@ public class AllocationCommandsTests extends OpenSearchAllocationTestCase {
.add(newNode("node1")) .add(newNode("node1"))
.add(newNode("node2")) .add(newNode("node2"))
.add(newNode("node3")) .add(newNode("node3"))
.add(newNode("node4", singleton(DiscoveryNodeRole.MASTER_ROLE))) .add(newNode("node4", singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)))
) )
.build(); .build();
clusterState = allocation.reroute(clusterState, "reroute"); clusterState = allocation.reroute(clusterState, "reroute");
@ -748,7 +748,9 @@ public class AllocationCommandsTests extends OpenSearchAllocationTestCase {
"test2", "test2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
new HashSet<>(randomSubsetOf(new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.INGEST_ROLE)))), new HashSet<>(
randomSubsetOf(new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.INGEST_ROLE)))
),
Version.CURRENT Version.CURRENT
); );
@ -817,7 +819,9 @@ public class AllocationCommandsTests extends OpenSearchAllocationTestCase {
"test2", "test2",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
new HashSet<>(randomSubsetOf(new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.INGEST_ROLE)))), new HashSet<>(
randomSubsetOf(new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.INGEST_ROLE)))
),
Version.CURRENT Version.CURRENT
); );

View File

@ -230,7 +230,7 @@ public class FailedNodeRoutingTests extends OpenSearchAllocationTestCase {
public ClusterState randomInitialClusterState() { public ClusterState randomInitialClusterState() {
List<DiscoveryNode> allNodes = new ArrayList<>(); List<DiscoveryNode> allNodes = new ArrayList<>();
DiscoveryNode localNode = createNode(DiscoveryNodeRole.MASTER_ROLE); // local node is the master DiscoveryNode localNode = createNode(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); // local node is the master
allNodes.add(localNode); allNodes.add(localNode);
// at least two nodes that have the data role so that we can allocate shards // at least two nodes that have the data role so that we can allocate shards
allNodes.add(createNode(DiscoveryNodeRole.DATA_ROLE)); allNodes.add(createNode(DiscoveryNodeRole.DATA_ROLE));

View File

@ -1078,7 +1078,7 @@ public class DiskThresholdDeciderTests extends OpenSearchAllocationTestCase {
"node1", "node1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
DiscoveryNode discoveryNode2 = new DiscoveryNode( DiscoveryNode discoveryNode2 = new DiscoveryNode(
@ -1227,7 +1227,7 @@ public class DiskThresholdDeciderTests extends OpenSearchAllocationTestCase {
"master", "master",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
emptyMap(), emptyMap(),
singleton(DiscoveryNodeRole.MASTER_ROLE), singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
DiscoveryNode dataNode = new DiscoveryNode( DiscoveryNode dataNode = new DiscoveryNode(

View File

@ -199,7 +199,7 @@ public class RestoreInProgressAllocationDeciderTests extends OpenSearchAllocatio
RoutingTable routingTable = RoutingTable.builder().addAsNew(metadata.index("test")).build(); RoutingTable routingTable = RoutingTable.builder().addAsNew(metadata.index("test")).build();
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder() DiscoveryNodes discoveryNodes = DiscoveryNodes.builder()
.add(newNode("master", Collections.singleton(DiscoveryNodeRole.MASTER_ROLE))) .add(newNode("master", Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)))
.localNodeId("master") .localNodeId("master")
.masterNodeId("master") .masterNodeId("master")
.build(); .build();

View File

@ -602,7 +602,7 @@ public class NodeEnvironmentTests extends OpenSearchTestCase {
); );
assertThat(ex.getMessage(), containsString(indexPath.resolve(MetadataStateFormat.STATE_DIR_NAME).toAbsolutePath().toString())); assertThat(ex.getMessage(), containsString(indexPath.resolve(MetadataStateFormat.STATE_DIR_NAME).toAbsolutePath().toString()));
assertThat(ex.getMessage(), startsWith("node does not have the data and master roles but has index metadata")); assertThat(ex.getMessage(), startsWith("node does not have the data and cluster_manager roles but has index metadata"));
} }
/** Converts an array of Strings to an array of Paths, adding an additional child if specified */ /** Converts an array of Strings to an array of Paths, adding an additional child if specified */

View File

@ -105,7 +105,7 @@ public class NodeRepurposeCommandTests extends OpenSearchTestCase {
dataNoMasterSettings = nonMasterNode(dataMasterSettings); dataNoMasterSettings = nonMasterNode(dataMasterSettings);
noDataNoMasterSettings = removeRoles( noDataNoMasterSettings = removeRoles(
dataMasterSettings, dataMasterSettings,
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE))) Collections.unmodifiableSet(new HashSet<>(Arrays.asList(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)))
); );
noDataMasterSettings = masterNode(nonDataNode(dataMasterSettings)); noDataMasterSettings = masterNode(nonDataNode(dataMasterSettings));

View File

@ -304,7 +304,7 @@ public class ClusterStateUpdatersTests extends OpenSearchTestCase {
"node1", "node1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
@ -354,7 +354,7 @@ public class ClusterStateUpdatersTests extends OpenSearchTestCase {
"node1", "node1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
final ClusterState updatedState = Function.<ClusterState>identity() final ClusterState updatedState = Function.<ClusterState>identity()

View File

@ -97,7 +97,7 @@ public class GatewayMetaStatePersistedStateTests extends OpenSearchTestCase {
"node1", "node1",
buildNewFakeTransportAddress(), buildNewFakeTransportAddress(),
Collections.emptyMap(), Collections.emptyMap(),
Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
Version.CURRENT Version.CURRENT
); );
clusterName = new ClusterName(randomAlphaOfLength(10)); clusterName = new ClusterName(randomAlphaOfLength(10));

View File

@ -327,7 +327,7 @@ public class IndicesClusterStateServiceRandomUpdatesTests extends AbstractIndice
Supplier<MockIndicesService> indicesServiceSupplier Supplier<MockIndicesService> indicesServiceSupplier
) { ) {
List<DiscoveryNode> allNodes = new ArrayList<>(); List<DiscoveryNode> allNodes = new ArrayList<>();
DiscoveryNode localNode = createNode(DiscoveryNodeRole.MASTER_ROLE); // local node is the master DiscoveryNode localNode = createNode(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); // local node is the master
allNodes.add(localNode); allNodes.add(localNode);
// at least two nodes that have the data role so that we can allocate shards // at least two nodes that have the data role so that we can allocate shards
allNodes.add(createNode(DiscoveryNodeRole.DATA_ROLE)); allNodes.add(createNode(DiscoveryNodeRole.DATA_ROLE));

View File

@ -0,0 +1,57 @@
/*
* 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.node;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.node.DiscoveryNodeRole;
import org.opensearch.common.settings.Settings;
import org.opensearch.test.OpenSearchTestCase;
import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.Matchers.containsString;
public class NodeRoleSettingsTests extends OpenSearchTestCase {
/**
* Validate cluster_manager role and master role can not coexist in a node.
* Remove the test after removing MASTER_ROLE.
*/
public void testClusterManagerAndMasterRoleCanNotCoexist() {
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "cluster_manager, master").build();
Exception exception = expectThrows(IllegalArgumentException.class, () -> NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings));
assertThat(exception.getMessage(), containsString("[master, cluster_manager] can not be assigned together to a node"));
}
/**
* Validate cluster_manager role and data role can coexist in a node. The test is added along with validateRole().
*/
public void testClusterManagerAndDataNodeRoles() {
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "cluster_manager, data").build();
assertEquals(
Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE),
NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings)
);
}
/**
* Validate setting master role will result a deprecation message.
* Remove the test after removing MASTER_ROLE.
*/
public void testMasterRoleDeprecationMessage() {
// It's used to add MASTER_ROLE into 'roleMap', because MASTER_ROLE is removed from DiscoveryNodeRole.BUILT_IN_ROLES in 2.0.
DiscoveryNode.setAdditionalRoles(Collections.emptySet());
Settings roleSettings = Settings.builder().put(NodeRoleSettings.NODE_ROLES_SETTING.getKey(), "master").build();
assertEquals(Collections.singletonList(DiscoveryNodeRole.MASTER_ROLE), NodeRoleSettings.NODE_ROLES_SETTING.get(roleSettings));
assertWarnings(DiscoveryNodeRole.MASTER_ROLE_DEPRECATION_MESSAGE);
}
}

View File

@ -886,7 +886,7 @@ public class PersistentTasksClusterServiceTests extends OpenSearchTestCase {
private DiscoveryNode newNode(String nodeId) { private DiscoveryNode newNode(String nodeId) {
final Set<DiscoveryNodeRole> roles = Collections.unmodifiableSet( final Set<DiscoveryNodeRole> roles = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE)) new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE))
); );
return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT); return new DiscoveryNode(nodeId, buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT);
} }

View File

@ -1500,7 +1500,7 @@ public class SnapshotResiliencyTests extends OpenSearchTestCase {
} }
private TestClusterNode newMasterNode(String nodeName) throws IOException { private TestClusterNode newMasterNode(String nodeName) throws IOException {
return newNode(nodeName, DiscoveryNodeRole.MASTER_ROLE); return newNode(nodeName, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
private TestClusterNode newDataNode(String nodeName) throws IOException { private TestClusterNode newDataNode(String nodeName) throws IOException {

View File

@ -747,7 +747,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase {
"id", "id",
address, address,
Collections.emptyMap(), Collections.emptyMap(),
new HashSet<>(Arrays.asList(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE)), new HashSet<>(Arrays.asList(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)),
Version.CURRENT Version.CURRENT
); );
assertTrue(nodePredicate.test(dataMaster)); assertTrue(nodePredicate.test(dataMaster));
@ -757,7 +757,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase {
"id", "id",
address, address,
Collections.emptyMap(), Collections.emptyMap(),
new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE)), new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)),
Version.CURRENT Version.CURRENT
); );
assertFalse(nodePredicate.test(dedicatedMaster)); assertFalse(nodePredicate.test(dedicatedMaster));
@ -777,7 +777,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase {
"id", "id",
address, address,
Collections.emptyMap(), Collections.emptyMap(),
new HashSet<>(Arrays.asList(DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.MASTER_ROLE)), new HashSet<>(Arrays.asList(DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)),
Version.CURRENT Version.CURRENT
); );
assertTrue(nodePredicate.test(masterIngest)); assertTrue(nodePredicate.test(masterIngest));
@ -855,7 +855,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase {
TransportAddress address = new TransportAddress(TransportAddress.META_ADDRESS, 0); TransportAddress address = new TransportAddress(TransportAddress.META_ADDRESS, 0);
Settings settings = Settings.builder().put("cluster.remote.node.attr", "gateway").build(); Settings settings = Settings.builder().put("cluster.remote.node.attr", "gateway").build();
Predicate<DiscoveryNode> nodePredicate = SniffConnectionStrategy.getNodePredicate(settings); Predicate<DiscoveryNode> nodePredicate = SniffConnectionStrategy.getNodePredicate(settings);
Set<DiscoveryNodeRole> dedicatedMasterRoles = new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE)); Set<DiscoveryNodeRole> dedicatedMasterRoles = new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE));
Set<DiscoveryNodeRole> allRoles = DiscoveryNodeRole.BUILT_IN_ROLES; Set<DiscoveryNodeRole> allRoles = DiscoveryNodeRole.BUILT_IN_ROLES;
{ {
DiscoveryNode node = new DiscoveryNode( DiscoveryNode node = new DiscoveryNode(

View File

@ -149,7 +149,7 @@ public abstract class OpenSearchAllocationTestCase extends OpenSearchTestCase {
} }
protected static Set<DiscoveryNodeRole> MASTER_DATA_ROLES = Collections.unmodifiableSet( protected static Set<DiscoveryNodeRole> MASTER_DATA_ROLES = Collections.unmodifiableSet(
new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE)) new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE))
); );
protected static DiscoveryNode newNode(String nodeId) { protected static DiscoveryNode newNode(String nodeId) {

View File

@ -164,10 +164,10 @@ public class CoordinationStateTestCluster {
final Set<DiscoveryNodeRole> roles = new HashSet<>(localNode.getRoles()); final Set<DiscoveryNodeRole> roles = new HashSet<>(localNode.getRoles());
if (randomBoolean()) { if (randomBoolean()) {
if (roles.contains(DiscoveryNodeRole.MASTER_ROLE)) { if (roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)) {
roles.remove(DiscoveryNodeRole.MASTER_ROLE); roles.remove(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} else { } else {
roles.add(DiscoveryNodeRole.MASTER_ROLE); roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
} }

View File

@ -787,13 +787,13 @@ public final class InternalTestCluster extends TestCluster {
String suffix = ""; String suffix = "";
// only add the suffixes if roles are explicitly defined // only add the suffixes if roles are explicitly defined
if (settings.hasValue("nodes.roles")) { if (settings.hasValue("nodes.roles")) {
if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE)) { if (DiscoveryNode.isMasterNode(settings)) {
suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); suffix = suffix + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleNameAbbreviation();
} }
if (DiscoveryNode.isDataNode(settings)) { if (DiscoveryNode.isDataNode(settings)) {
suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation(); suffix = suffix + DiscoveryNodeRole.DATA_ROLE.roleNameAbbreviation();
} }
if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE) == false && DiscoveryNode.isDataNode(settings) == false) { if (!DiscoveryNode.isMasterNode(settings) && !DiscoveryNode.isDataNode(settings)) {
suffix = suffix + "c"; suffix = suffix + "c";
} }
} }
@ -2150,7 +2150,7 @@ public final class InternalTestCluster extends TestCluster {
} }
public List<String> startMasterOnlyNodes(int numNodes, Settings settings) { public List<String> startMasterOnlyNodes(int numNodes, Settings settings) {
return startNodes(numNodes, Settings.builder().put(onlyRole(settings, DiscoveryNodeRole.MASTER_ROLE)).build()); return startNodes(numNodes, Settings.builder().put(onlyRole(settings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)).build());
} }
public List<String> startDataOnlyNodes(int numNodes) { public List<String> startDataOnlyNodes(int numNodes) {

View File

@ -80,6 +80,13 @@ public class NodeRoles {
NodeRoleSettings.NODE_ROLES_SETTING.get(settings) NodeRoleSettings.NODE_ROLES_SETTING.get(settings)
.stream() .stream()
.filter(r -> roles.contains(r) == false) .filter(r -> roles.contains(r) == false)
// TODO: Remove the below filter after removing MASTER_ROLE.
// It's used to remove both CLUSTER_MANAGER_ROLE and MASTER_ROLE, when requested to remove either.
.filter(
roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE) || roles.contains(DiscoveryNodeRole.MASTER_ROLE)
? r -> !r.isClusterManager()
: r -> true
)
.map(DiscoveryNodeRole::roleName) .map(DiscoveryNodeRole::roleName)
.collect(Collectors.toList()) .collect(Collectors.toList())
) )
@ -166,7 +173,7 @@ public class NodeRoles {
} }
public static Settings masterNode(final Settings settings) { public static Settings masterNode(final Settings settings) {
return addRoles(settings, Collections.singleton(DiscoveryNodeRole.MASTER_ROLE)); return addRoles(settings, Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE));
} }
public static Settings masterOnlyNode() { public static Settings masterOnlyNode() {
@ -174,7 +181,7 @@ public class NodeRoles {
} }
public static Settings masterOnlyNode(final Settings settings) { public static Settings masterOnlyNode(final Settings settings) {
return onlyRole(settings, DiscoveryNodeRole.MASTER_ROLE); return onlyRole(settings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE);
} }
public static Settings nonMasterNode() { public static Settings nonMasterNode() {
@ -182,7 +189,7 @@ public class NodeRoles {
} }
public static Settings nonMasterNode(final Settings settings) { public static Settings nonMasterNode(final Settings settings) {
return removeRoles(settings, Collections.singleton(DiscoveryNodeRole.MASTER_ROLE)); return removeRoles(settings, Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE));
} }
public static Settings remoteClusterClientNode() { public static Settings remoteClusterClientNode() {

View File

@ -398,17 +398,19 @@ public class InternalTestClusterTests extends OpenSearchTestCase {
Function.identity() Function.identity()
); );
cluster.beforeTest(random()); cluster.beforeTest(random());
// TODO: Remove this line, and replace 'clusterManagerRole' with CLUSTER_MANAGER_ROLE, after MASTER_ROLE is removed.
// It is added in 2.0, along with the introduction of CLUSTER_MANAGER_ROLE, aims to test the 2 roles have the same effect.
DiscoveryNodeRole clusterManagerRole = randomFrom(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.MASTER_ROLE);
List<DiscoveryNodeRole> roles = new ArrayList<>(); List<DiscoveryNodeRole> roles = new ArrayList<>();
for (int i = 0; i < numNodes; i++) { for (int i = 0; i < numNodes; i++) {
final DiscoveryNodeRole role = i == numNodes - 1 && roles.contains(DiscoveryNodeRole.MASTER_ROLE) == false final DiscoveryNodeRole role = i == numNodes - 1 && roles.contains(clusterManagerRole) == false
? DiscoveryNodeRole.MASTER_ROLE ? clusterManagerRole // last node and still no master
: // last node and still no master : randomFrom(clusterManagerRole, DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.INGEST_ROLE);
randomFrom(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.INGEST_ROLE);
roles.add(role); roles.add(role);
} }
cluster.setBootstrapMasterNodeIndex( cluster.setBootstrapMasterNodeIndex(
randomIntBetween(0, (int) roles.stream().filter(role -> role.equals(DiscoveryNodeRole.MASTER_ROLE)).count() - 1) randomIntBetween(0, (int) roles.stream().filter(role -> role.equals(clusterManagerRole)).count() - 1)
); );
try { try {
@ -416,7 +418,7 @@ public class InternalTestClusterTests extends OpenSearchTestCase {
for (int i = 0; i < numNodes; i++) { for (int i = 0; i < numNodes; i++) {
final DiscoveryNodeRole role = roles.get(i); final DiscoveryNodeRole role = roles.get(i);
final String node; final String node;
if (role == DiscoveryNodeRole.MASTER_ROLE) { if (role == clusterManagerRole) {
node = cluster.startMasterOnlyNode(); node = cluster.startMasterOnlyNode();
} else if (role == DiscoveryNodeRole.DATA_ROLE) { } else if (role == DiscoveryNodeRole.DATA_ROLE) {
node = cluster.startDataOnlyNode(); node = cluster.startDataOnlyNode();
@ -438,7 +440,7 @@ public class InternalTestClusterTests extends OpenSearchTestCase {
DiscoveryNode node = cluster.getInstance(ClusterService.class, name).localNode(); DiscoveryNode node = cluster.getInstance(ClusterService.class, name).localNode();
List<String> paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList()); List<String> paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList());
if (node.isMasterNode()) { if (node.isMasterNode()) {
result.computeIfAbsent(DiscoveryNodeRole.MASTER_ROLE, k -> new HashSet<>()).addAll(paths); result.computeIfAbsent(clusterManagerRole, k -> new HashSet<>()).addAll(paths);
} else if (node.isDataNode()) { } else if (node.isDataNode()) {
result.computeIfAbsent(DiscoveryNodeRole.DATA_ROLE, k -> new HashSet<>()).addAll(paths); result.computeIfAbsent(DiscoveryNodeRole.DATA_ROLE, k -> new HashSet<>()).addAll(paths);
} else { } else {