diff --git a/benchmarks/src/main/java/org/opensearch/benchmark/routing/allocation/Allocators.java b/benchmarks/src/main/java/org/opensearch/benchmark/routing/allocation/Allocators.java index 7c00fa5abb5..d700b9dab2c 100644 --- a/benchmarks/src/main/java/org/opensearch/benchmark/routing/allocation/Allocators.java +++ b/benchmarks/src/main/java/org/opensearch/benchmark/routing/allocation/Allocators.java @@ -111,7 +111,7 @@ public final class Allocators { nodeId, new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()), attributes, - Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE), + Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE), Version.CURRENT ); } diff --git a/client/rest/src/main/java/org/opensearch/client/Node.java b/client/rest/src/main/java/org/opensearch/client/Node.java index 41c2926a7d5..c982ae8eb93 100644 --- a/client/rest/src/main/java/org/opensearch/client/Node.java +++ b/client/rest/src/main/java/org/opensearch/client/Node.java @@ -210,21 +210,21 @@ public class Node { } /** - * Teturns whether or not the node could be elected master. + * Returns whether or not the node could be elected master. */ 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() { 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() { return roles.contains("ingest"); diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml index a0432fa7aa5..6e149b297d8 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cluster.stats/10_basic.yml @@ -91,3 +91,22 @@ cluster.stats: {} - 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} diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.info/10_basic.yml b/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.info/10_basic.yml index 2a4bbfe0a20..c779cb80d13 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.info/10_basic.yml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/nodes.info/10_basic.yml @@ -12,14 +12,24 @@ setup: - is_true: cluster_name --- -"node_info role test": +"node_info role test - before 2.0.0": - skip: - version: " - 7.7.99" + version: " - 7.7.99 , 2.0.0 - " reason: "node roles were not sorted before 7.8.0" + features: node_selector - do: 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: + # Note: It will only stash the first node_id in the api response. nodes._arbitrary_key_: node_id - is_true: nodes.$node_id.roles @@ -29,3 +39,21 @@ setup: - match: { nodes.$node_id.roles.2: "master" } - 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" } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java index 72f34133067..5b48268dfa8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java @@ -85,6 +85,7 @@ public class ClusterStatsIT extends OpenSearchIntegTestCase { Map expectedCounts = new HashMap<>(); expectedCounts.put(DiscoveryNodeRole.DATA_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.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1); expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0); @@ -106,7 +107,7 @@ public class ClusterStatsIT extends OpenSearchIntegTestCase { roles.add(DiscoveryNodeRole.INGEST_ROLE); } if (isMasterNode) { - roles.add(DiscoveryNodeRole.MASTER_ROLE); + roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } if (isRemoteClusterClientNode) { roles.add(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); @@ -129,6 +130,7 @@ public class ClusterStatsIT extends OpenSearchIntegTestCase { } if (isMasterNode) { incrementCountForRole(DiscoveryNodeRole.MASTER_ROLE.roleName(), expectedCounts); + incrementCountForRole(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), expectedCounts); } if (isRemoteClusterClientNode) { incrementCountForRole(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), expectedCounts); diff --git a/server/src/internalClusterTest/java/org/opensearch/env/NodeEnvironmentIT.java b/server/src/internalClusterTest/java/org/opensearch/env/NodeEnvironmentIT.java index 0bebcce27f9..83c103bd827 100644 --- a/server/src/internalClusterTest/java/org/opensearch/env/NodeEnvironmentIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/env/NodeEnvironmentIT.java @@ -95,7 +95,7 @@ public class NodeEnvironmentIT extends OpenSearchIntegTestCase { }) ); 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 { assertThat(ex.getMessage(), startsWith("node does not have the data role but has shard data")); } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java b/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java index 0ae7ebd17aa..fbca94780f8 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodes.java @@ -223,7 +223,14 @@ public class ClusterStatsNodes implements ToXContentFragment { roles.merge(COORDINATING_ONLY, 1, Integer::sum); } else { 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); + } } } } diff --git a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java index 9fa49ec93d3..6bd943c5e1d 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java @@ -94,7 +94,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { } 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); switch (legacyRole) { case MASTER: - roles.add(DiscoveryNodeRole.MASTER_ROLE); + roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); break; case DATA: roles.add(DiscoveryNodeRole.DATA_ROLE); @@ -390,11 +390,11 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { .collect(Collectors.toList()); out.writeVInt(rolesToWrite.size()); for (final DiscoveryNodeRole role : rolesToWrite) { - if (role == DiscoveryNodeRole.MASTER_ROLE) { + if (role.isClusterManager()) { out.writeEnum(LegacyRole.MASTER); - } else if (role == DiscoveryNodeRole.DATA_ROLE) { + } else if (role.equals(DiscoveryNodeRole.DATA_ROLE)) { out.writeEnum(LegacyRole.DATA); - } else if (role == DiscoveryNodeRole.INGEST_ROLE) { + } else if (role.equals(DiscoveryNodeRole.INGEST_ROLE)) { out.writeEnum(LegacyRole.INGEST); } } @@ -456,7 +456,7 @@ public class DiscoveryNode implements Writeable, ToXContentFragment { * Can this node become master or not. */ 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 [" + 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 roleNameToPossibleRolesWithMaster = new HashMap<>(roleNameToPossibleRoles); + roleNameToPossibleRolesWithMaster.put(DiscoveryNodeRole.MASTER_ROLE.roleName(), DiscoveryNodeRole.MASTER_ROLE); + roleMap = Collections.unmodifiableMap(roleNameToPossibleRolesWithMaster); } public static Set 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. */ private enum LegacyRole { diff --git a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java index fb1cfb24166..cff1a77f4cd 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java @@ -34,6 +34,7 @@ package org.opensearch.cluster.node; import org.opensearch.LegacyESVersion; import org.opensearch.Version; +import org.opensearch.common.logging.DeprecationLogger; import org.opensearch.common.settings.Setting; import org.opensearch.common.settings.Setting.Property; import org.opensearch.common.settings.Settings; @@ -41,6 +42,8 @@ import org.opensearch.transport.RemoteClusterService; import java.util.Arrays; import java.util.Collections; +import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.SortedSet; import java.util.TreeSet; @@ -50,6 +53,10 @@ import java.util.TreeSet; */ public abstract class DiscoveryNodeRole implements Comparable { + 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; /** @@ -129,6 +136,13 @@ public abstract class DiscoveryNodeRole implements Comparable 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 roles) {}; + @Override public final boolean equals(Object o) { if (this == o) return true; @@ -193,15 +207,60 @@ public abstract class DiscoveryNodeRole implements Comparable /** * 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") { + @Override + public Setting 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 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 public Setting legacySetting() { // 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); } + @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 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") { @@ -223,7 +282,7 @@ public abstract class DiscoveryNodeRole implements Comparable * The built-in node roles. */ public static SortedSet 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 } + /** + * 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); + } } diff --git a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java index d6e2f129f0e..1097f3bc245 100644 --- a/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/opensearch/cluster/node/DiscoveryNodes.java @@ -370,7 +370,7 @@ public class DiscoveryNodes extends AbstractDiffable implements * 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: * - * - _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 * - 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 @@ -393,7 +393,7 @@ public class DiscoveryNodes extends AbstractDiffable implements if (localNodeId != null) { resolvedNodesIds.add(localNodeId); } - } else if (nodeId.equals("_master")) { + } else if (nodeId.equals("_master") || nodeId.equals("_cluster_manager")) { String masterNodeId = getMasterNodeId(); if (masterNodeId != null) { resolvedNodesIds.add(masterNodeId); @@ -419,7 +419,7 @@ public class DiscoveryNodes extends AbstractDiffable implements } else { resolvedNodesIds.removeAll(dataNodes.keys()); } - } else if (DiscoveryNodeRole.MASTER_ROLE.roleName().equals(matchAttrName)) { + } else if (roleNameIsClusterManager(matchAttrName)) { if (Booleans.parseBoolean(matchAttrValue, true)) { resolvedNodesIds.addAll(masterNodes.keys()); } else { @@ -797,4 +797,17 @@ public class DiscoveryNodes extends AbstractDiffable implements 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); + } } diff --git a/server/src/main/java/org/opensearch/env/NodeEnvironment.java b/server/src/main/java/org/opensearch/env/NodeEnvironment.java index 06109e7fcdc..555ca990b73 100644 --- a/server/src/main/java/org/opensearch/env/NodeEnvironment.java +++ b/server/src/main/java/org/opensearch/env/NodeEnvironment.java @@ -1138,7 +1138,7 @@ public final class NodeEnvironment implements Closeable { Locale.ROOT, "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.MASTER_ROLE.roleName(), + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), indexMetadataPaths ); throw new IllegalStateException(message); diff --git a/server/src/main/java/org/opensearch/node/NodeRoleSettings.java b/server/src/main/java/org/opensearch/node/NodeRoleSettings.java index 1e29f22b140..d690cfa4caa 100644 --- a/server/src/main/java/org/opensearch/node/NodeRoleSettings.java +++ b/server/src/main/java/org/opensearch/node/NodeRoleSettings.java @@ -51,7 +51,11 @@ public class NodeRoleSettings { .filter(role -> role.isEnabledByDefault(settings)) .map(DiscoveryNodeRole::roleName) .collect(Collectors.toList()), - roles -> {}, + roles -> { + for (DiscoveryNodeRole role : roles) { + role.validateRole(roles); + } + }, Property.NodeScope ); diff --git a/server/src/main/java/org/opensearch/repositories/RepositoriesService.java b/server/src/main/java/org/opensearch/repositories/RepositoriesService.java index ec5cb02c323..e7c5804f458 100644 --- a/server/src/main/java/org/opensearch/repositories/RepositoriesService.java +++ b/server/src/main/java/org/opensearch/repositories/RepositoriesService.java @@ -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 roles) { - return roles.contains(DiscoveryNodeRole.MASTER_ROLE) + return roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE) && roles.contains(DiscoveryNodeRole.DATA_ROLE) == false && roles.stream().anyMatch(role -> role.roleName().equals("voting_only")); } diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java index a1aa38017a8..8da65ba13b9 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java @@ -113,7 +113,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "local", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode); @@ -122,7 +122,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "other1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1); @@ -131,7 +131,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "other2", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2); @@ -238,7 +238,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1); @@ -248,7 +248,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); @@ -258,7 +258,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -298,7 +298,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1); @@ -308,7 +308,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); @@ -318,7 +318,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -348,7 +348,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -357,7 +357,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); @@ -367,7 +367,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -399,7 +399,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "local", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode); @@ -408,7 +408,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "other1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1); @@ -417,7 +417,7 @@ public class AddVotingConfigExclusionsRequestTests extends OpenSearchTestCase { "other2", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java index b4540a66c92..a570db040a8 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java @@ -119,7 +119,7 @@ public class TransportAddVotingConfigExclusionsActionTests extends OpenSearchTes name, buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java index 37cdda6c365..e4b79ac54f8 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java @@ -278,7 +278,7 @@ public class TransportResizeActionTests extends OpenSearchTestCase { private DiscoveryNode newNode(String nodeId) { final Set 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); } diff --git a/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java b/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java index 05f9ef8baed..09ab2438bd1 100644 --- a/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java +++ b/server/src/test/java/org/opensearch/action/search/TransportMultiSearchActionTests.java @@ -263,7 +263,7 @@ public class TransportMultiSearchActionTests extends OpenSearchTestCase { "master", buildNewFakeTransportAddress(), Collections.emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ) ); diff --git a/server/src/test/java/org/opensearch/action/support/master/TransportMasterNodeActionTests.java b/server/src/test/java/org/opensearch/action/support/master/TransportMasterNodeActionTests.java index 60dcbc15b96..a8ad356e947 100644 --- a/server/src/test/java/org/opensearch/action/support/master/TransportMasterNodeActionTests.java +++ b/server/src/test/java/org/opensearch/action/support/master/TransportMasterNodeActionTests.java @@ -121,14 +121,14 @@ public class TransportMasterNodeActionTests extends OpenSearchTestCase { "local_node", buildNewFakeTransportAddress(), Collections.emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); remoteNode = new DiscoveryNode( "remote_node", buildNewFakeTransportAddress(), Collections.emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); allNodes = new DiscoveryNode[] { localNode, remoteNode }; diff --git a/server/src/test/java/org/opensearch/action/support/nodes/TransportNodesActionTests.java b/server/src/test/java/org/opensearch/action/support/nodes/TransportNodesActionTests.java index a8755df6b5d..53ebceb2551 100644 --- a/server/src/test/java/org/opensearch/action/support/nodes/TransportNodesActionTests.java +++ b/server/src/test/java/org/opensearch/action/support/nodes/TransportNodesActionTests.java @@ -172,7 +172,9 @@ public class TransportNodesActionTests extends OpenSearchTestCase { private enum NodeSelector { LOCAL("_local"), ELECTED_MASTER("_master"), + // TODO: Remove this element after removing DiscoveryNodeRole.MASTER_ROLE MASTER_ELIGIBLE("master:true"), + CLUSTER_MANAGER_ELIGIBLE("cluster_manager:true"), DATA("data:true"), CUSTOM_ATTRIBUTE("attr:value"); diff --git a/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java b/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java index 4f68358b15b..49d4a8baf0a 100644 --- a/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java +++ b/server/src/test/java/org/opensearch/cluster/ClusterChangedEventTests.java @@ -447,17 +447,17 @@ public class ClusterChangedEventTests extends OpenSearchTestCase { if (i == 0) { // the master node builder.masterNodeId(nodeId); - roles.add(DiscoveryNodeRole.MASTER_ROLE); + roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } else if (i == 1) { // the alternate master node - roles.add(DiscoveryNodeRole.MASTER_ROLE); + roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } else if (i == 2) { // we need at least one data node roles.add(DiscoveryNodeRole.DATA_ROLE); } else { // remaining nodes can be anything (except for master) if (randomBoolean()) { - roles.add(DiscoveryNodeRole.MASTER_ROLE); + roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } if (randomBoolean()) { roles.add(DiscoveryNodeRole.DATA_ROLE); diff --git a/server/src/test/java/org/opensearch/cluster/coordination/ClusterBootstrapServiceTests.java b/server/src/test/java/org/opensearch/cluster/coordination/ClusterBootstrapServiceTests.java index d8007933c25..079b31f31f5 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/ClusterBootstrapServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/ClusterBootstrapServiceTests.java @@ -112,7 +112,7 @@ public class ClusterBootstrapServiceTests extends OpenSearchTestCase { randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); } @@ -522,7 +522,7 @@ public class ClusterBootstrapServiceTests extends OpenSearchTestCase { randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ), new DiscoveryNode( @@ -530,7 +530,7 @@ public class ClusterBootstrapServiceTests extends OpenSearchTestCase { randomAlphaOfLength(10), otherNode1.getAddress(), emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ) ).collect(Collectors.toList()) diff --git a/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java b/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java index 4288d4eb5d5..13cdc640008 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/ClusterFormationFailureHelperTests.java @@ -287,7 +287,7 @@ public class ClusterFormationFailureHelperTests extends OpenSearchTestCase { "local", buildNewFakeTransportAddress(), emptyMap(), - org.opensearch.common.collect.Set.of(DiscoveryNodeRole.MASTER_ROLE), + org.opensearch.common.collect.Set.of(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); clusterState = ClusterState.builder(ClusterName.DEFAULT) @@ -825,7 +825,7 @@ public class ClusterFormationFailureHelperTests extends OpenSearchTestCase { emptyMap(), new HashSet<>( randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES).stream() - .filter(r -> r != DiscoveryNodeRole.MASTER_ROLE) + .filter(r -> r != DiscoveryNodeRole.CLUSTER_MANAGER_ROLE) .collect(Collectors.toList()) ), Version.CURRENT diff --git a/server/src/test/java/org/opensearch/cluster/coordination/CoordinatorTests.java b/server/src/test/java/org/opensearch/cluster/coordination/CoordinatorTests.java index 33d522e196d..1cdea588564 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/CoordinatorTests.java @@ -1789,7 +1789,7 @@ public class CoordinatorTests extends AbstractCoordinatorTestCase { "resolvableNodeId", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ) ) diff --git a/server/src/test/java/org/opensearch/cluster/coordination/NodeJoinTests.java b/server/src/test/java/org/opensearch/cluster/coordination/NodeJoinTests.java index bccd94e2c40..3b309908a1d 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/NodeJoinTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/NodeJoinTests.java @@ -248,7 +248,7 @@ public class NodeJoinTests extends OpenSearchTestCase { protected DiscoveryNode newNode(int i, boolean master) { final Set roles; if (master) { - roles = singleton(DiscoveryNodeRole.MASTER_ROLE); + roles = singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } else { roles = Collections.emptySet(); } @@ -492,7 +492,7 @@ public class NodeJoinTests extends OpenSearchTestCase { "newNodeId", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); long newTerm = initialTerm + randomLongBetween(1, 10); diff --git a/server/src/test/java/org/opensearch/cluster/health/ClusterHealthAllocationTests.java b/server/src/test/java/org/opensearch/cluster/health/ClusterHealthAllocationTests.java index 2e4bba0ff1c..2f05297146f 100644 --- a/server/src/test/java/org/opensearch/cluster/health/ClusterHealthAllocationTests.java +++ b/server/src/test/java/org/opensearch/cluster/health/ClusterHealthAllocationTests.java @@ -87,7 +87,9 @@ public class ClusterHealthAllocationTests extends OpenSearchAllocationTestCase { private ClusterState addNode(ClusterState clusterState, String nodeName, boolean isMaster) { 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(); } diff --git a/server/src/test/java/org/opensearch/cluster/metadata/AutoExpandReplicasTests.java b/server/src/test/java/org/opensearch/cluster/metadata/AutoExpandReplicasTests.java index 13bc108591f..d6c62e4bb09 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/AutoExpandReplicasTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/AutoExpandReplicasTests.java @@ -146,7 +146,7 @@ public class AutoExpandReplicasTests extends OpenSearchTestCase { try { List 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); int numDataNodes = randomIntBetween(3, 5); List dataNodes = new ArrayList<>(numDataNodes); @@ -245,7 +245,7 @@ public class AutoExpandReplicasTests extends OpenSearchTestCase { List allNodes = new ArrayList<>(); DiscoveryNode oldNode = createNode( VersionUtils.randomVersionBetween(random(), LegacyESVersion.V_7_0_0, LegacyESVersion.V_7_5_1), - DiscoveryNodeRole.MASTER_ROLE, + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, DiscoveryNodeRole.DATA_ROLE ); // local node is the master allNodes.add(oldNode); @@ -266,11 +266,11 @@ public class AutoExpandReplicasTests extends OpenSearchTestCase { state = cluster.reroute(state, new ClusterRerouteRequest()); } - DiscoveryNode newNode = createNode(LegacyESVersion.V_7_6_0, DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE); // local - // node - // is - // the - // master + DiscoveryNode newNode = createNode( + LegacyESVersion.V_7_6_0, + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE, + DiscoveryNodeRole.DATA_ROLE + ); // local node is the cluster_manager state = cluster.addNodes(state, Collections.singletonList(newNode)); diff --git a/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java index 19f6a516ca8..5bea69c5bbd 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java @@ -582,7 +582,7 @@ public class MetadataCreateIndexServiceTests extends OpenSearchTestCase { private DiscoveryNode newNode(String nodeId) { final Set 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); } diff --git a/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java b/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java index e4692fe7d21..1e52fa38079 100644 --- a/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/metadata/TemplateUpgradeServiceTests.java @@ -261,7 +261,7 @@ public class TemplateUpgradeServiceTests extends OpenSearchTestCase { } private static final Set 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") diff --git a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleSettingTests.java b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleSettingTests.java index 006968a2f2a..55c518c6297 100644 --- a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleSettingTests.java +++ b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleSettingTests.java @@ -56,9 +56,15 @@ public class DiscoveryNodeRoleSettingTests extends OpenSearchTestCase { } 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); } + public void testIsClusterManagerNode() { + runRoleTest(DiscoveryNode::isMasterNode, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); + } + public void testIsRemoteClusterClient() { runRoleTest(DiscoveryNode::isRemoteClusterClient, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE); } diff --git a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleTests.java b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleTests.java index 76f9843e386..d1acec2832b 100644 --- a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleTests.java +++ b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeRoleTests.java @@ -128,4 +128,14 @@ public class DiscoveryNodeRoleTests extends OpenSearchTestCase { 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())); + } } diff --git a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeTests.java b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeTests.java index 39a3381bede..933d9d5f825 100644 --- a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeTests.java +++ b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeTests.java @@ -174,6 +174,12 @@ public class DiscoveryNodeTests extends OpenSearchTestCase { 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) { final DiscoveryNode node = DiscoveryNode.createLocal(settings, new TransportAddress(TransportAddress.META_ADDRESS, 9200), "node"); assertThat(node.isRemoteClusterClient(), equalTo(expected)); diff --git a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java index 69cecade5b7..aff9e1cfe7a 100644 --- a/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/opensearch/cluster/node/DiscoveryNodesTests.java @@ -361,6 +361,7 @@ public class DiscoveryNodesTests extends OpenSearchTestCase { return Collections.singleton(nodes.getMasterNodeId()); } }, + // TODO: Remove this element after removing DiscoveryNodeRole.MASTER_ROLE MASTER_ELIGIBLE(DiscoveryNodeRole.MASTER_ROLE.roleName() + ":true") { @Override Set matchingNodeIds(DiscoveryNodes nodes) { @@ -369,6 +370,14 @@ public class DiscoveryNodesTests extends OpenSearchTestCase { return ids; } }, + CLUSTER_MANAGER_ELIGIBLE(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName() + ":true") { + @Override + Set matchingNodeIds(DiscoveryNodes nodes) { + Set ids = new HashSet<>(); + nodes.getMasterNodes().keysIt().forEachRemaining(ids::add); + return ids; + } + }, DATA(DiscoveryNodeRole.DATA_ROLE.roleName() + ":true") { @Override Set matchingNodeIds(DiscoveryNodes nodes) { diff --git a/server/src/test/java/org/opensearch/cluster/routing/DelayedAllocationServiceTests.java b/server/src/test/java/org/opensearch/cluster/routing/DelayedAllocationServiceTests.java index 1f79d52d84d..1f45c5c1dfc 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/DelayedAllocationServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/DelayedAllocationServiceTests.java @@ -262,7 +262,7 @@ public class DelayedAllocationServiceTests extends OpenSearchAllocationTestCase .routingTable(RoutingTable.builder().addAsNew(metadata.index("short_delay")).addAsNew(metadata.index("long_delay")).build()) .nodes( DiscoveryNodes.builder() - .add(newNode("node0", singleton(DiscoveryNodeRole.MASTER_ROLE))) + .add(newNode("node0", singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE))) .localNodeId("node0") .masterNodeId("node0") .add(newNode("node1")) diff --git a/server/src/test/java/org/opensearch/cluster/routing/OperationRoutingTests.java b/server/src/test/java/org/opensearch/cluster/routing/OperationRoutingTests.java index 7a5e24a7eec..d42c3e80c60 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/OperationRoutingTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/OperationRoutingTests.java @@ -778,7 +778,7 @@ public class OperationRoutingTests extends OpenSearchTestCase { "master", buildNewFakeTransportAddress(), Collections.emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); allNodes[i] = master; diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/AllocationCommandsTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/AllocationCommandsTests.java index 28599ea0b9b..cda0f1afaf6 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -188,7 +188,7 @@ public class AllocationCommandsTests extends OpenSearchAllocationTestCase { .add(newNode("node1")) .add(newNode("node2")) .add(newNode("node3")) - .add(newNode("node4", singleton(DiscoveryNodeRole.MASTER_ROLE))) + .add(newNode("node4", singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE))) ) .build(); clusterState = allocation.reroute(clusterState, "reroute"); @@ -748,7 +748,9 @@ public class AllocationCommandsTests extends OpenSearchAllocationTestCase { "test2", buildNewFakeTransportAddress(), 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 ); @@ -817,7 +819,9 @@ public class AllocationCommandsTests extends OpenSearchAllocationTestCase { "test2", buildNewFakeTransportAddress(), 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 ); diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/FailedNodeRoutingTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/FailedNodeRoutingTests.java index f871d74d3d1..f60497b4108 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/FailedNodeRoutingTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/FailedNodeRoutingTests.java @@ -230,7 +230,7 @@ public class FailedNodeRoutingTests extends OpenSearchAllocationTestCase { public ClusterState randomInitialClusterState() { List 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); // at least two nodes that have the data role so that we can allocate shards allNodes.add(createNode(DiscoveryNodeRole.DATA_ROLE)); diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java index 038dd2713bb..a2fcf14638d 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/DiskThresholdDeciderTests.java @@ -1078,7 +1078,7 @@ public class DiskThresholdDeciderTests extends OpenSearchAllocationTestCase { "node1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); DiscoveryNode discoveryNode2 = new DiscoveryNode( @@ -1227,7 +1227,7 @@ public class DiskThresholdDeciderTests extends OpenSearchAllocationTestCase { "master", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); DiscoveryNode dataNode = new DiscoveryNode( diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java index 8917b9793e6..5b05cb3afd8 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/decider/RestoreInProgressAllocationDeciderTests.java @@ -199,7 +199,7 @@ public class RestoreInProgressAllocationDeciderTests extends OpenSearchAllocatio RoutingTable routingTable = RoutingTable.builder().addAsNew(metadata.index("test")).build(); DiscoveryNodes discoveryNodes = DiscoveryNodes.builder() - .add(newNode("master", Collections.singleton(DiscoveryNodeRole.MASTER_ROLE))) + .add(newNode("master", Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE))) .localNodeId("master") .masterNodeId("master") .build(); diff --git a/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java b/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java index e6f0f2824b7..6f07d0de1e3 100644 --- a/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java +++ b/server/src/test/java/org/opensearch/env/NodeEnvironmentTests.java @@ -602,7 +602,7 @@ public class NodeEnvironmentTests extends OpenSearchTestCase { ); 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 */ diff --git a/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java b/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java index 45ec6d8ebf7..9897ad1a365 100644 --- a/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java +++ b/server/src/test/java/org/opensearch/env/NodeRepurposeCommandTests.java @@ -105,7 +105,7 @@ public class NodeRepurposeCommandTests extends OpenSearchTestCase { dataNoMasterSettings = nonMasterNode(dataMasterSettings); noDataNoMasterSettings = removeRoles( 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)); diff --git a/server/src/test/java/org/opensearch/gateway/ClusterStateUpdatersTests.java b/server/src/test/java/org/opensearch/gateway/ClusterStateUpdatersTests.java index f6a8f151500..1f63dff04b3 100644 --- a/server/src/test/java/org/opensearch/gateway/ClusterStateUpdatersTests.java +++ b/server/src/test/java/org/opensearch/gateway/ClusterStateUpdatersTests.java @@ -304,7 +304,7 @@ public class ClusterStateUpdatersTests extends OpenSearchTestCase { "node1", buildNewFakeTransportAddress(), Collections.emptyMap(), - Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), + Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -354,7 +354,7 @@ public class ClusterStateUpdatersTests extends OpenSearchTestCase { "node1", buildNewFakeTransportAddress(), Collections.emptyMap(), - Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), + Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); final ClusterState updatedState = Function.identity() diff --git a/server/src/test/java/org/opensearch/gateway/GatewayMetaStatePersistedStateTests.java b/server/src/test/java/org/opensearch/gateway/GatewayMetaStatePersistedStateTests.java index 4ab5d7c44f3..339b04f45c8 100644 --- a/server/src/test/java/org/opensearch/gateway/GatewayMetaStatePersistedStateTests.java +++ b/server/src/test/java/org/opensearch/gateway/GatewayMetaStatePersistedStateTests.java @@ -97,7 +97,7 @@ public class GatewayMetaStatePersistedStateTests extends OpenSearchTestCase { "node1", buildNewFakeTransportAddress(), Collections.emptyMap(), - Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), + Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); clusterName = new ClusterName(randomAlphaOfLength(10)); diff --git a/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index 5574e3c9112..7789054cfdc 100644 --- a/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/server/src/test/java/org/opensearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -327,7 +327,7 @@ public class IndicesClusterStateServiceRandomUpdatesTests extends AbstractIndice Supplier indicesServiceSupplier ) { List 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); // at least two nodes that have the data role so that we can allocate shards allNodes.add(createNode(DiscoveryNodeRole.DATA_ROLE)); diff --git a/server/src/test/java/org/opensearch/node/NodeRoleSettingsTests.java b/server/src/test/java/org/opensearch/node/NodeRoleSettingsTests.java new file mode 100644 index 00000000000..c875fec1979 --- /dev/null +++ b/server/src/test/java/org/opensearch/node/NodeRoleSettingsTests.java @@ -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); + } +} diff --git a/server/src/test/java/org/opensearch/persistent/PersistentTasksClusterServiceTests.java b/server/src/test/java/org/opensearch/persistent/PersistentTasksClusterServiceTests.java index de9dbdc2d57..bb8f0405ecf 100644 --- a/server/src/test/java/org/opensearch/persistent/PersistentTasksClusterServiceTests.java +++ b/server/src/test/java/org/opensearch/persistent/PersistentTasksClusterServiceTests.java @@ -886,7 +886,7 @@ public class PersistentTasksClusterServiceTests extends OpenSearchTestCase { private DiscoveryNode newNode(String nodeId) { final Set 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); } diff --git a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java index 5e7def04fe8..7855f7f2b0e 100644 --- a/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/opensearch/snapshots/SnapshotResiliencyTests.java @@ -1500,7 +1500,7 @@ public class SnapshotResiliencyTests extends OpenSearchTestCase { } 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 { diff --git a/server/src/test/java/org/opensearch/transport/SniffConnectionStrategyTests.java b/server/src/test/java/org/opensearch/transport/SniffConnectionStrategyTests.java index 7e456fa8675..1714f154036 100644 --- a/server/src/test/java/org/opensearch/transport/SniffConnectionStrategyTests.java +++ b/server/src/test/java/org/opensearch/transport/SniffConnectionStrategyTests.java @@ -747,7 +747,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase { "id", address, 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 ); assertTrue(nodePredicate.test(dataMaster)); @@ -757,7 +757,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase { "id", address, Collections.emptyMap(), - new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE)), + new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)), Version.CURRENT ); assertFalse(nodePredicate.test(dedicatedMaster)); @@ -777,7 +777,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase { "id", address, 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 ); assertTrue(nodePredicate.test(masterIngest)); @@ -855,7 +855,7 @@ public class SniffConnectionStrategyTests extends OpenSearchTestCase { TransportAddress address = new TransportAddress(TransportAddress.META_ADDRESS, 0); Settings settings = Settings.builder().put("cluster.remote.node.attr", "gateway").build(); Predicate nodePredicate = SniffConnectionStrategy.getNodePredicate(settings); - Set dedicatedMasterRoles = new HashSet<>(Arrays.asList(DiscoveryNodeRole.MASTER_ROLE)); + Set dedicatedMasterRoles = new HashSet<>(Arrays.asList(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)); Set allRoles = DiscoveryNodeRole.BUILT_IN_ROLES; { DiscoveryNode node = new DiscoveryNode( diff --git a/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java b/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java index e806548cee0..e42dd42b18d 100644 --- a/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java +++ b/test/framework/src/main/java/org/opensearch/cluster/OpenSearchAllocationTestCase.java @@ -149,7 +149,7 @@ public abstract class OpenSearchAllocationTestCase extends OpenSearchTestCase { } protected static Set 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) { diff --git a/test/framework/src/main/java/org/opensearch/cluster/coordination/CoordinationStateTestCluster.java b/test/framework/src/main/java/org/opensearch/cluster/coordination/CoordinationStateTestCluster.java index 0e308e64617..291eee501c4 100644 --- a/test/framework/src/main/java/org/opensearch/cluster/coordination/CoordinationStateTestCluster.java +++ b/test/framework/src/main/java/org/opensearch/cluster/coordination/CoordinationStateTestCluster.java @@ -164,10 +164,10 @@ public class CoordinationStateTestCluster { final Set roles = new HashSet<>(localNode.getRoles()); if (randomBoolean()) { - if (roles.contains(DiscoveryNodeRole.MASTER_ROLE)) { - roles.remove(DiscoveryNodeRole.MASTER_ROLE); + if (roles.contains(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)) { + roles.remove(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } else { - roles.add(DiscoveryNodeRole.MASTER_ROLE); + roles.add(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } } diff --git a/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java index 7461ebb9c87..3a28ec2efdd 100644 --- a/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/opensearch/test/InternalTestCluster.java @@ -787,13 +787,13 @@ public final class InternalTestCluster extends TestCluster { String suffix = ""; // only add the suffixes if roles are explicitly defined if (settings.hasValue("nodes.roles")) { - if (DiscoveryNode.hasRole(settings, DiscoveryNodeRole.MASTER_ROLE)) { - suffix = suffix + DiscoveryNodeRole.MASTER_ROLE.roleNameAbbreviation(); + if (DiscoveryNode.isMasterNode(settings)) { + suffix = suffix + DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleNameAbbreviation(); } if (DiscoveryNode.isDataNode(settings)) { 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"; } } @@ -2150,7 +2150,7 @@ public final class InternalTestCluster extends TestCluster { } public List 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 startDataOnlyNodes(int numNodes) { diff --git a/test/framework/src/main/java/org/opensearch/test/NodeRoles.java b/test/framework/src/main/java/org/opensearch/test/NodeRoles.java index ed5f505e023..64fd6b22e98 100644 --- a/test/framework/src/main/java/org/opensearch/test/NodeRoles.java +++ b/test/framework/src/main/java/org/opensearch/test/NodeRoles.java @@ -80,6 +80,13 @@ public class NodeRoles { NodeRoleSettings.NODE_ROLES_SETTING.get(settings) .stream() .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) .collect(Collectors.toList()) ) @@ -166,7 +173,7 @@ public class NodeRoles { } 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() { @@ -174,7 +181,7 @@ public class NodeRoles { } public static Settings masterOnlyNode(final Settings settings) { - return onlyRole(settings, DiscoveryNodeRole.MASTER_ROLE); + return onlyRole(settings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE); } public static Settings nonMasterNode() { @@ -182,7 +189,7 @@ public class NodeRoles { } 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() { diff --git a/test/framework/src/test/java/org/opensearch/test/test/InternalTestClusterTests.java b/test/framework/src/test/java/org/opensearch/test/test/InternalTestClusterTests.java index 7ffd96fb689..f1aee04d92a 100644 --- a/test/framework/src/test/java/org/opensearch/test/test/InternalTestClusterTests.java +++ b/test/framework/src/test/java/org/opensearch/test/test/InternalTestClusterTests.java @@ -398,17 +398,19 @@ public class InternalTestClusterTests extends OpenSearchTestCase { Function.identity() ); 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 roles = new ArrayList<>(); for (int i = 0; i < numNodes; i++) { - final DiscoveryNodeRole role = i == numNodes - 1 && roles.contains(DiscoveryNodeRole.MASTER_ROLE) == false - ? DiscoveryNodeRole.MASTER_ROLE - : // last node and still no master - randomFrom(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.INGEST_ROLE); + final DiscoveryNodeRole role = i == numNodes - 1 && roles.contains(clusterManagerRole) == false + ? clusterManagerRole // last node and still no master + : randomFrom(clusterManagerRole, DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.INGEST_ROLE); roles.add(role); } 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 { @@ -416,7 +418,7 @@ public class InternalTestClusterTests extends OpenSearchTestCase { for (int i = 0; i < numNodes; i++) { final DiscoveryNodeRole role = roles.get(i); final String node; - if (role == DiscoveryNodeRole.MASTER_ROLE) { + if (role == clusterManagerRole) { node = cluster.startMasterOnlyNode(); } else if (role == DiscoveryNodeRole.DATA_ROLE) { node = cluster.startDataOnlyNode(); @@ -438,7 +440,7 @@ public class InternalTestClusterTests extends OpenSearchTestCase { DiscoveryNode node = cluster.getInstance(ClusterService.class, name).localNode(); List paths = Arrays.stream(getNodePaths(cluster, name)).map(Path::toString).collect(Collectors.toList()); 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()) { result.computeIfAbsent(DiscoveryNodeRole.DATA_ROLE, k -> new HashSet<>()).addAll(paths); } else {