From ea3148312622cd1362593e3623d498e57913ae45 Mon Sep 17 00:00:00 2001 From: Tianli Feng Date: Fri, 18 Mar 2022 15:06:06 -0700 Subject: [PATCH] Add a new node role 'cluster_manager' as the alternative for 'master' role and deprecate 'master' role (#2424) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../routing/allocation/Allocators.java | 2 +- .../main/java/org/opensearch/client/Node.java | 8 +-- .../test/cluster.stats/10_basic.yml | 19 +++++ .../test/nodes.info/10_basic.yml | 32 ++++++++- .../admin/cluster/stats/ClusterStatsIT.java | 4 +- .../org/opensearch/env/NodeEnvironmentIT.java | 2 +- .../cluster/stats/ClusterStatsNodes.java | 9 ++- .../cluster/node/DiscoveryNode.java | 20 +++--- .../cluster/node/DiscoveryNodeRole.java | 70 ++++++++++++++++++- .../cluster/node/DiscoveryNodes.java | 19 ++++- .../org/opensearch/env/NodeEnvironment.java | 2 +- .../org/opensearch/node/NodeRoleSettings.java | 6 +- .../repositories/RepositoriesService.java | 3 +- ...AddVotingConfigExclusionsRequestTests.java | 30 ++++---- ...tAddVotingConfigExclusionsActionTests.java | 2 +- .../shrink/TransportResizeActionTests.java | 2 +- .../TransportMultiSearchActionTests.java | 2 +- .../TransportMasterNodeActionTests.java | 4 +- .../nodes/TransportNodesActionTests.java | 2 + .../cluster/ClusterChangedEventTests.java | 6 +- .../ClusterBootstrapServiceTests.java | 6 +- .../ClusterFormationFailureHelperTests.java | 4 +- .../coordination/CoordinatorTests.java | 2 +- .../cluster/coordination/NodeJoinTests.java | 4 +- .../health/ClusterHealthAllocationTests.java | 4 +- .../metadata/AutoExpandReplicasTests.java | 14 ++-- .../MetadataCreateIndexServiceTests.java | 2 +- .../metadata/TemplateUpgradeServiceTests.java | 2 +- .../node/DiscoveryNodeRoleSettingTests.java | 6 ++ .../cluster/node/DiscoveryNodeRoleTests.java | 10 +++ .../cluster/node/DiscoveryNodeTests.java | 6 ++ .../cluster/node/DiscoveryNodesTests.java | 9 +++ .../DelayedAllocationServiceTests.java | 2 +- .../routing/OperationRoutingTests.java | 2 +- .../allocation/AllocationCommandsTests.java | 10 ++- .../allocation/FailedNodeRoutingTests.java | 2 +- .../decider/DiskThresholdDeciderTests.java | 4 +- ...storeInProgressAllocationDeciderTests.java | 2 +- .../opensearch/env/NodeEnvironmentTests.java | 2 +- .../env/NodeRepurposeCommandTests.java | 2 +- .../gateway/ClusterStateUpdatersTests.java | 4 +- .../GatewayMetaStatePersistedStateTests.java | 2 +- ...ClusterStateServiceRandomUpdatesTests.java | 2 +- .../node/NodeRoleSettingsTests.java | 57 +++++++++++++++ .../PersistentTasksClusterServiceTests.java | 2 +- .../snapshots/SnapshotResiliencyTests.java | 2 +- .../SniffConnectionStrategyTests.java | 8 +-- .../cluster/OpenSearchAllocationTestCase.java | 2 +- .../CoordinationStateTestCluster.java | 6 +- .../opensearch/test/InternalTestCluster.java | 8 +-- .../java/org/opensearch/test/NodeRoles.java | 13 +++- .../test/test/InternalTestClusterTests.java | 16 +++-- 52 files changed, 356 insertions(+), 105 deletions(-) create mode 100644 server/src/test/java/org/opensearch/node/NodeRoleSettingsTests.java 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 7c00fa5abb53f..d700b9dab2cf3 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 static DiscoveryNode newNode(String nodeId, Map attribute 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 41c2926a7d54d..c982ae8eb931f 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 Roles(final Set roles) { } /** - * 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 a0432fa7aa558..6e149b297d843 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 2a4bbfe0a20ba..c779cb80d13b3 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 72f34133067ee..5b48268dfa89f 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 void testNodeCounts() { 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 void testNodeCounts() { 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 void testNodeCounts() { } 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 0bebcce27f975..83c103bd82738 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 Settings onNodeStopped(String nodeName) { }) ); 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 0ae7ebd17aaa5..fbca94780f827 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 @@ private Counts(final List nodeInfos) { 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 9fa49ec93d307..6bd943c5e1d0d 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 static boolean hasRole(final Settings settings, final DiscoveryNodeRole r } 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 DiscoveryNode(StreamInput in) throws IOException { 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 void writeTo(StreamOutput out) throws IOException { .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 boolean isDataNode() { * 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 static void setAdditionalRoles(final Set additionalRol + "], 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 static Set getPossibleRoleNames() { } /** - * 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 fb1cfb24166c4..cff1a77f4cdb7 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 @@ 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 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 @@ */ 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 DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) { 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 Setting legacySetting() { /** * 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 Setting legacySetting() { * 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 Setting legacySetting() { } + /** + * 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 d6e2f129f0ed8..1097f3bc245ac 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 DiscoveryNode resolveNode(String 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: * - * - _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 String[] resolveNodes(String... nodes) { 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 String[] resolveNodes(String... nodes) { } 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 boolean isLocalNodeElectedMaster() { 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 06109e7fcdc5b..555ca990b736d 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 @@ private void ensureNoIndexMetadata(final NodePath[] nodePaths) throws IOExceptio 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 1e29f22b140f9..d690cfa4caa69 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 ec5cb02c32379..e7c5804f458a0 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 @@ protected void doRun() { }); } + // 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 a1aa38017a808..8da65ba13b9cb 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 void testResolve() { "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 void testResolve() { "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 void testResolve() { "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 void testResolveByNodeIds() { "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 void testResolveByNodeIds() { "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 void testResolveByNodeIds() { "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -298,7 +298,7 @@ public void testResolveByNodeNames() { "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 void testResolveByNodeNames() { "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 void testResolveByNodeNames() { "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -348,7 +348,7 @@ public void testResolveRemoveExistingVotingConfigExclusions() { "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -357,7 +357,7 @@ public void testResolveRemoveExistingVotingConfigExclusions() { "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 void testResolveRemoveExistingVotingConfigExclusions() { "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -399,7 +399,7 @@ public void testResolveAndCheckMaximum() { "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 void testResolveAndCheckMaximum() { "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 void testResolveAndCheckMaximum() { "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 b4540a66c9264..a570db040a805 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 @@ private static DiscoveryNode makeDiscoveryNode(String name) { 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 37cdda6c365b8..e4b79ac54f8fd 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 void testShrinkIndexSettings() { 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 05f9ef8baed29..09ab2438bd106 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 void testDefaultMaxConcurrentSearches() { "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 60dcbc15b96c8..a8ad356e947b5 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 void setUp() throws Exception { "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 a8755df6b5daa..53ebceb25510a 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 @@ private List mockList(Supplier supplier, int size) { 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 4f68358b15b3d..49d4a8baf0a1c 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 @@ private static DiscoveryNodes createDiscoveryNodes(final int numNodes, final boo 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 d8007933c2559..079b31f31f599 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 @@ private DiscoveryNode newDiscoveryNode(String nodeName) { randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); } @@ -522,7 +522,7 @@ public void testCancelsBootstrapIfNodeMatchesMultipleRequirements() { randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Collections.singleton(DiscoveryNodeRole.MASTER_ROLE), + Collections.singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ), new DiscoveryNode( @@ -530,7 +530,7 @@ public void testCancelsBootstrapIfNodeMatchesMultipleRequirements() { 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 4288d4eb5d53b..13cdc640008cb 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 void testDescriptionOnUnhealthyNodes() { "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 void testDescriptionAfterBootstrapping() { 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 33d522e196d9b..1cdea588564c4 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 @@ private ClusterState buildNewClusterStateWithVotingConfigExclusion( "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 bccd94e2c40bf..3b309908a1df0 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 @@ protected DiscoveryNode newNode(int i) { 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 void testJoinUpdateVotingConfigExclusion() throws Exception { "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 2e4bba0ff1c7b..2f05297146f8e 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 void testClusterHealth() { 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 13bc108591f7f..d6c62e4bb0903 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 void testAutoExpandWhenNodeLeavesAndPossiblyRejoins() throws InterruptedE 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 void testOnlyAutoExpandAllocationFilteringAfterAllNodesUpgraded() { 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 void testOnlyAutoExpandAllocationFilteringAfterAllNodesUpgraded() { 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 19f6a516ca83a..5bea69c5bbd66 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 @@ private void runPrepareResizeIndexSettingsTest( 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 e4692fe7d21f7..1e52fa380793e 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 void testUpdateTemplates() { } 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 006968a2f2ac2..55c518c62973e 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 void testIsIngestNode() { } 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 76f9843e386b8..d1acec2832b7c 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 void testUnknownRoleIsDistinctFromKnownRoles() { 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 39a3381bede26..933d9d5f825e9 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 void testDiscoveryNodeIsRemoteClusterClientUnset() { 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 69cecade5b745..aff9e1cfe7a8c 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 @@ Set matchingNodeIds(DiscoveryNodes nodes) { 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 @@ Set matchingNodeIds(DiscoveryNodes nodes) { 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 1f79d52d84d74..1f45c5c1dfce4 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 void testDelayedUnassignedScheduleRerouteAfterDelayedReroute() throws Exc .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 7a5e24a7eeca2..d42c3e80c60c9 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 @@ private DiscoveryNode[] setupNodes() { "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 28599ea0b9baa..cda0f1afaf62c 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 void testAllocateCommand() { .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 void testMoveShardToNonDataNode() { "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 void testMoveShardFromNonDataNode() { "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 f871d74d3d1a5..f60497b4108b7 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 @@ private static Version getNodeVersion(ShardRouting shardRouting, ClusterState st 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 038dd2713bbf9..a2fcf14638d45 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 void testForSingleDataNode() { "node1", buildNewFakeTransportAddress(), emptyMap(), - singleton(DiscoveryNodeRole.MASTER_ROLE), + singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); DiscoveryNode discoveryNode2 = new DiscoveryNode( @@ -1227,7 +1227,7 @@ public void testWatermarksEnabledForSingleDataNode() { "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 8917b9793e621..5b05cb3afd83e 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 @@ private ClusterState createInitialClusterState() { 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 e6f0f2824b7d3..6f07d0de1e31d 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 @@ private void verifyFailsOnMetadata(Settings settings, Path indexPath) { ); 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 45ec6d8ebf75a..9897ad1a3650b 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 void createNodePaths() throws IOException { 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 f6a8f1515002d..1f63dff04b3df 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 void testSetLocalNode() { "node1", buildNewFakeTransportAddress(), Collections.emptyMap(), - Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE), + Sets.newHashSet(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE), Version.CURRENT ); @@ -354,7 +354,7 @@ public void testHideStateIfNotRecovered() { "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 4ab5d7c44f356..339b04f45c830 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 void setUp() throws Exception { "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 5574e3c911213..7789054cfdc16 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 ClusterState randomInitialClusterState( 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 0000000000000..c875fec1979d1 --- /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 de9dbdc2d5793..bb8f0405ecf7e 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 @@ private String addTask(PersistentTasksCustomMetadata.Builder tasks, String param 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 5e7def04fe8c8..7855f7f2b0e59 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 TestClusterNode nodeById(final String nodeId) { } 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 7e456fa86754f..1714f154036a5 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 void testGetNodePredicateNodeRoles() { "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 void testGetNodePredicateNodeRoles() { "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 void testGetNodePredicateNodeRoles() { "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 void testGetNodePredicatesCombination() { 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 e806548cee088..e42dd42b18da5 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 static AllocationDeciders randomAllocationDeciders(Settings settings, Clu } 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 0e308e64617fe..291eee501c4df 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 @@ void reboot() { 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 7461ebb9c8713..3a28ec2efdd4b 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 @@ private static String getRoleSuffix(Settings settings) { 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 List startMasterOnlyNodes(int numNodes) { } 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 ed5f505e02304..64fd6b22e9805 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 static Settings removeRoles(final Settings settings, final Set 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 static Settings masterNode() { } 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 static Settings masterOnlyNode() { } 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 static Settings nonMasterNode() { } 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 7ffd96fb68911..f1aee04d92a19 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 Path nodeConfigPath(int nodeOrdinal) { 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 Path nodeConfigPath(int nodeOrdinal) { 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 Path nodeConfigPath(int nodeOrdinal) { 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 {