Skip to content

Commit

Permalink
Restore method getMasterService() to return MasterService
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Jul 14, 2022
1 parent 951af92 commit 694d876
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

import java.util.Collections;
import java.util.Map;
import java.util.Objects;

/**
* Main Cluster Service
Expand All @@ -63,6 +64,8 @@
*/
public class ClusterService extends AbstractLifecycleComponent {
private final ClusterManagerService clusterManagerService;
@Deprecated
private MasterService masterService = null;

private final ClusterApplierService clusterApplierService;

Expand Down Expand Up @@ -114,6 +117,20 @@ public ClusterService(
this.clusterApplierService = clusterApplierService;
}

/**
* @deprecated As of 2.2, because supporting inclusive language.
*/
@Deprecated
public ClusterService(
Settings settings,
ClusterSettings clusterSettings,
MasterService masterService,
ClusterApplierService clusterApplierService
) {
this(settings, clusterSettings, (ClusterManagerService) masterService, clusterApplierService);
this.masterService = masterService;
}

public synchronized void setNodeConnectionsService(NodeConnectionsService nodeConnectionsService) {
clusterApplierService.setNodeConnectionsService(nodeConnectionsService);
}
Expand Down Expand Up @@ -218,10 +235,21 @@ public void addLocalNodeMasterListener(LocalNodeClusterManagerListener listener)
clusterApplierService.addLocalNodeMasterListener(listener);
}

public ClusterManagerService getMasterService() {
public ClusterManagerService getClusterManagerService() {
return clusterManagerService;
}

/**
* @deprecated As of 2.2, because supporting inclusive language, replaced by {@link #getClusterManagerService()}
*/
@Deprecated
public MasterService getMasterService() {
return Objects.requireNonNullElseGet(
masterService,
() -> new MasterService(settings, clusterSettings, clusterManagerService.threadPool)
);
}

/**
* Getter and Setter for IndexingPressureService, This method exposes IndexingPressureService stats to other plugins for usage.
* Although Indexing Pressure instances can be accessed via Node and NodeService class but none of them are
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.cluster.service;

import org.hamcrest.Matchers;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.Settings;
import org.opensearch.test.OpenSearchTestCase;

public class ClusterServiceTests extends OpenSearchTestCase {
public void testDeprecatedGetMasterServiceWhenUsingMasterServiceToInitializeClusterService() {
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
MasterService masterService = new MasterService(Settings.EMPTY, clusterSettings, null);
ClusterService clusterServiceWithMasterService = new ClusterService(Settings.EMPTY, clusterSettings, masterService, null);
assertThat(clusterServiceWithMasterService.getMasterService(), Matchers.equalTo(masterService));
}

public void testDeprecatedGetMasterServiceWithoutAssigningMasterService() {
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
ClusterService clusterService = new ClusterService(Settings.EMPTY, clusterSettings, null);
assertThat(clusterService.getMasterService(), Matchers.instanceOf(MasterService.class));
}
}

0 comments on commit 694d876

Please sign in to comment.