diff --git a/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java b/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java index ea5c33b4300a5..35edd51a4b154 100644 --- a/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java +++ b/server/src/main/java/org/opensearch/cluster/coordination/JoinTaskExecutor.java @@ -94,14 +94,19 @@ public String toString() { } public boolean isBecomeMasterTask() { - return reason.equals(BECOME_MASTER_TASK_REASON); + return reason.equals(BECOME_MASTER_TASK_REASON) || reason.equals(BECOME_CLUSTER_MANAGER_TASK_REASON); } public boolean isFinishElectionTask() { return reason.equals(FINISH_ELECTION_TASK_REASON); } + /** + * @deprecated As of 2.0, because supporting inclusive language, replaced by {@link #BECOME_CLUSTER_MANAGER_TASK_REASON} + */ + @Deprecated private static final String BECOME_MASTER_TASK_REASON = "_BECOME_MASTER_TASK_"; + private static final String BECOME_CLUSTER_MANAGER_TASK_REASON = "_BECOME_CLUSTER_MANAGER_TASK_"; private static final String FINISH_ELECTION_TASK_REASON = "_FINISH_ELECTION_"; } @@ -328,10 +333,22 @@ public boolean runOnlyOnMaster() { return false; } + /** + * a task indicates that the current node should become master + * @deprecated As of 2.0, because supporting inclusive language, replaced by {@link #newBecomeClusterManagerTask()} + */ + @Deprecated public static Task newBecomeMasterTask() { return new Task(null, Task.BECOME_MASTER_TASK_REASON); } + /** + * a task indicates that the current node should become cluster-manager + */ + public static Task newBecomeClusterManagerTask() { + return new Task(null, Task.BECOME_CLUSTER_MANAGER_TASK_REASON); + } + /** * a task that is used to signal the election is stopped and we should process pending joins. * it may be used in combination with {@link JoinTaskExecutor#newBecomeMasterTask()} diff --git a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java index a019235c99743..c5ac3953fad6e 100644 --- a/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java +++ b/server/src/test/java/org/opensearch/cluster/coordination/JoinTaskExecutorTests.java @@ -53,6 +53,7 @@ import java.util.HashSet; import java.util.Map; +import static org.hamcrest.Matchers.is; import static org.opensearch.test.VersionUtils.maxCompatibleVersion; import static org.opensearch.test.VersionUtils.randomCompatibleVersion; import static org.opensearch.test.VersionUtils.randomVersion; @@ -272,4 +273,14 @@ public void testUpdatesNodeWithOpenSearchVersionForExistingAndNewNodes() throws // 7.9.0 node without active channel but shouldn't get removed assertEquals(LegacyESVersion.V_7_10_0, resultNodes.get(node_7).getVersion()); } + + /** + * Validate isBecomeMasterTask() can identify "become cluster manager task" properly + */ + public void testIsBecomeClusterManagerTask() { + JoinTaskExecutor.Task joinTaskOfMaster = JoinTaskExecutor.newBecomeMasterTask(); + assertThat(joinTaskOfMaster.isBecomeMasterTask(), is(true)); + JoinTaskExecutor.Task joinTaskOfClusterManager = JoinTaskExecutor.newBecomeClusterManagerTask(); + assertThat(joinTaskOfClusterManager.isBecomeMasterTask(), is(true)); + } }