diff --git a/src/main/java/org/opensearch/ad/cluster/ClusterManagerEventListener.java b/src/main/java/org/opensearch/ad/cluster/ClusterManagerEventListener.java index d85ef8271..99e175193 100644 --- a/src/main/java/org/opensearch/ad/cluster/ClusterManagerEventListener.java +++ b/src/main/java/org/opensearch/ad/cluster/ClusterManagerEventListener.java @@ -20,7 +20,7 @@ import org.opensearch.ad.util.DateUtils; import org.opensearch.ad.util.DiscoveryNodeFilterer; import org.opensearch.client.Client; -import org.opensearch.cluster.LocalNodeMasterListener; +import org.opensearch.cluster.LocalNodeClusterManagerListener; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.component.LifecycleListener; import org.opensearch.common.settings.Setting; @@ -31,7 +31,7 @@ import com.google.common.annotations.VisibleForTesting; -public class ClusterManagerEventListener implements LocalNodeMasterListener { +public class ClusterManagerEventListener implements LocalNodeClusterManagerListener { private Cancellable checkpointIndexRetentionCron; private Cancellable hourlyCron; @@ -56,7 +56,7 @@ public ClusterManagerEventListener( this.clusterService = clusterService; this.threadPool = threadPool; this.client = client; - this.clusterService.addLocalNodeMasterListener(this); + this.clusterService.addLocalNodeClusterManagerListener(this); this.clock = clock; this.clientUtil = clientUtil; this.nodeFilter = nodeFilter; @@ -77,7 +77,7 @@ public ClusterManagerEventListener( } @Override - public void onMaster() { + public void onClusterManager() { if (hourlyCron == null) { hourlyCron = threadPool.scheduleWithFixedDelay(new HourlyCron(client, nodeFilter), TimeValue.timeValueHours(1), executorName()); clusterService.addLifecycleListener(new LifecycleListener() { @@ -108,7 +108,7 @@ public void beforeStop() { } @Override - public void offMaster() { + public void offClusterManager() { cancel(hourlyCron); cancel(checkpointIndexRetentionCron); hourlyCron = null; diff --git a/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java b/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java index 266a5ece4..d20672ff6 100644 --- a/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java +++ b/src/main/java/org/opensearch/ad/indices/AnomalyDetectionIndices.java @@ -70,7 +70,7 @@ import org.opensearch.ad.util.DiscoveryNodeFilterer; import org.opensearch.client.AdminClient; import org.opensearch.client.Client; -import org.opensearch.cluster.LocalNodeMasterListener; +import org.opensearch.cluster.LocalNodeClusterManagerListener; import org.opensearch.cluster.metadata.AliasMetadata; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.service.ClusterService; @@ -99,7 +99,7 @@ /** * This class provides utility methods for various anomaly detection indices. */ -public class AnomalyDetectionIndices implements LocalNodeMasterListener { +public class AnomalyDetectionIndices implements LocalNodeClusterManagerListener { private static final Logger logger = LogManager.getLogger(AnomalyDetectionIndices.class); // The index name pattern to query all the AD result history indices @@ -185,7 +185,7 @@ public AnomalyDetectionIndices( this.adminClient = client.admin(); this.clusterService = clusterService; this.threadPool = threadPool; - this.clusterService.addLocalNodeMasterListener(this); + this.clusterService.addLocalNodeClusterManagerListener(this); this.historyRolloverPeriod = AD_RESULT_HISTORY_ROLLOVER_PERIOD.get(settings); this.historyMaxDocs = AD_RESULT_HISTORY_MAX_DOCS_PER_SHARD.get(settings); this.historyRetentionPeriod = AD_RESULT_HISTORY_RETENTION_PERIOD.get(settings); @@ -677,7 +677,7 @@ public void initCheckpointIndex(ActionListener actionListen } @Override - public void onMaster() { + public void onClusterManager() { try { // try to rollover immediately as we might be restarting the cluster rolloverAndDeleteHistoryIndex(); @@ -692,7 +692,7 @@ public void onMaster() { } @Override - public void offMaster() { + public void offClusterManager() { if (scheduledRollover != null) { scheduledRollover.cancel(); } @@ -703,7 +703,7 @@ private String executorName() { } private void rescheduleRollover() { - if (clusterService.state().getNodes().isLocalNodeElectedMaster()) { + if (clusterService.state().getNodes().isLocalNodeElectedClusterManager()) { if (scheduledRollover != null) { scheduledRollover.cancel(); } diff --git a/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java b/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java index b95d89d14..268133bfc 100644 --- a/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java +++ b/src/test/java/org/opensearch/ad/cluster/ADClusterEventListenerTests.java @@ -81,14 +81,17 @@ public void setUp() throws Exception { oldClusterState = ClusterState .builder(new ClusterName(clusterName)) .nodes( - new DiscoveryNodes.Builder().masterNodeId(clusterManagerNodeId).localNodeId(clusterManagerNodeId).add(clusterManagerNode) + new DiscoveryNodes.Builder() + .clusterManagerNodeId(clusterManagerNodeId) + .localNodeId(clusterManagerNodeId) + .add(clusterManagerNode) ) .build(); newClusterState = ClusterState .builder(new ClusterName(clusterName)) .nodes( new DiscoveryNodes.Builder() - .masterNodeId(clusterManagerNodeId) + .clusterManagerNodeId(clusterManagerNodeId) .localNodeId(dataNode1Id) .add(clusterManagerNode) .add(dataNode1) @@ -123,7 +126,7 @@ public void testIsWarmNode() { .builder(new ClusterName(clusterName)) .nodes( new DiscoveryNodes.Builder() - .masterNodeId(clusterManagerNodeId) + .clusterManagerNodeId(clusterManagerNodeId) .localNodeId(dataNode1Id) .add(clusterManagerNode) .add(dataNode1) @@ -139,7 +142,7 @@ public void testNotRecovered() { .builder(new ClusterName(clusterName)) .nodes( new DiscoveryNodes.Builder() - .masterNodeId(clusterManagerNodeId) + .clusterManagerNodeId(clusterManagerNodeId) .localNodeId(dataNode1Id) .add(clusterManagerNode) .add(dataNode1) @@ -191,7 +194,7 @@ public void testNodeRemoved() { .builder(new ClusterName(clusterName)) .nodes( new DiscoveryNodes.Builder() - .masterNodeId(clusterManagerNodeId) + .clusterManagerNodeId(clusterManagerNodeId) .localNodeId(dataNode1Id) .add(new DiscoveryNode(clusterManagerNodeId, buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT)) .add(dataNode1) diff --git a/src/test/java/org/opensearch/ad/cluster/ClusterManagerEventListenerTests.java b/src/test/java/org/opensearch/ad/cluster/ClusterManagerEventListenerTests.java index 147feb8f0..8a3d45302 100644 --- a/src/test/java/org/opensearch/ad/cluster/ClusterManagerEventListenerTests.java +++ b/src/test/java/org/opensearch/ad/cluster/ClusterManagerEventListenerTests.java @@ -90,13 +90,13 @@ public void setUp() throws Exception { ); } - public void testOnOffMaster() { - clusterManagerService.onMaster(); + public void testOnOffClusterManager() { + clusterManagerService.onClusterManager(); assertThat(hourlyCancellable, is(notNullValue())); assertThat(checkpointIndexRetentionCancellable, is(notNullValue())); assertTrue(!clusterManagerService.getHourlyCron().isCancelled()); assertTrue(!clusterManagerService.getCheckpointIndexRetentionCron().isCancelled()); - clusterManagerService.offMaster(); + clusterManagerService.offClusterManager(); assertThat(clusterManagerService.getCheckpointIndexRetentionCron(), is(nullValue())); assertThat(clusterManagerService.getHourlyCron(), is(nullValue())); } @@ -120,10 +120,10 @@ public void testBeforeStop() { return null; }).when(clusterService).addLifecycleListener(any()); - clusterManagerService.onMaster(); + clusterManagerService.onClusterManager(); assertThat(clusterManagerService.getCheckpointIndexRetentionCron(), is(nullValue())); assertThat(clusterManagerService.getHourlyCron(), is(nullValue())); - clusterManagerService.offMaster(); + clusterManagerService.offClusterManager(); assertThat(clusterManagerService.getCheckpointIndexRetentionCron(), is(nullValue())); assertThat(clusterManagerService.getHourlyCron(), is(nullValue())); } diff --git a/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java b/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java index 2061e42fc..d9928b623 100644 --- a/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java +++ b/src/test/java/test/org/opensearch/ad/util/ClusterCreation.java @@ -49,7 +49,7 @@ public static ClusterState state( discoBuilder.add(node); } if (clusterManagerNode != null) { - discoBuilder.masterNodeId(clusterManagerNode.getId()); + discoBuilder.clusterManagerNodeId(clusterManagerNode.getId()); } discoBuilder.localNodeId(localNode.getId());