Skip to content

Rename InternalTestCluster#getMasterNodeInstance #83407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected Settings nodeSettings(int nodeOrdinal, Settings otherSettings) {

public void testDeleteSingleItem() {
final String repoName = createRepository(randomRepositoryName());
final RepositoriesService repositoriesService = internalCluster().getMasterNodeInstance(RepositoriesService.class);
final RepositoriesService repositoriesService = internalCluster().getAnyMasterNodeInstance(RepositoriesService.class);
final BlobStoreRepository repository = (BlobStoreRepository) repositoriesService.repository(repoName);
PlainActionFuture.get(
f -> repository.threadPool()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public TimeValue masterNodeTimeout() {
};

PlainActionFuture<AcknowledgedResponse> future = PlainActionFuture.newFuture();
internalCluster().getMasterNodeInstance(ClusterService.class)
internalCluster().getAnyMasterNodeInstance(ClusterService.class)
.submitStateUpdateTask("get_mappings_cancellation_test", new AckedClusterStateUpdateTask(ackedRequest, future) {
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private UpdateDesiredNodesResponse updateDesiredNodes(DesiredNodes desiredNodes)
private Runnable blockClusterStateUpdateThread() throws InterruptedException {
final CountDownLatch unblockClusterStateUpdateTask = new CountDownLatch(1);
final CountDownLatch blockingClusterStateUpdateTaskExecuting = new CountDownLatch(1);
final ClusterService clusterService = internalCluster().getMasterNodeInstance(ClusterService.class);
final ClusterService clusterService = internalCluster().getAnyMasterNodeInstance(ClusterService.class);
clusterService.submitStateUpdateTask("blocking-task", new ClusterStateUpdateTask(Priority.IMMEDIATE) {
@Override
public ClusterState execute(ClusterState currentState) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void testBootstrapNoClusterState() throws IOException {
String node = internalCluster().startNode();
Settings dataPathSettings = internalCluster().dataPathSettings(node);
ensureStableCluster(1);
NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
NodeEnvironment nodeEnvironment = internalCluster().getAnyMasterNodeInstance(NodeEnvironment.class);
internalCluster().stopRandomDataNode();
Environment environment = TestEnvironment.newEnvironment(
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build()
Expand All @@ -168,7 +168,7 @@ public void testDetachNoClusterState() throws IOException {
String node = internalCluster().startNode();
Settings dataPathSettings = internalCluster().dataPathSettings(node);
ensureStableCluster(1);
NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
NodeEnvironment nodeEnvironment = internalCluster().getAnyMasterNodeInstance(NodeEnvironment.class);
internalCluster().stopRandomDataNode();
Environment environment = TestEnvironment.newEnvironment(
Settings.builder().put(internalCluster().getDefaultSettings()).put(dataPathSettings).build()
Expand Down Expand Up @@ -257,7 +257,7 @@ public void test3MasterNodes2Failed() throws Exception {
expectThrows(() -> unsafeBootstrap(environmentMaster1), UnsafeBootstrapMasterCommand.FAILED_TO_OBTAIN_NODE_LOCK_MSG);

logger.info("--> stop 1st master-eligible node and data-only node");
NodeEnvironment nodeEnvironment = internalCluster().getMasterNodeInstance(NodeEnvironment.class);
NodeEnvironment nodeEnvironment = internalCluster().getAnyMasterNodeInstance(NodeEnvironment.class);
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(masterNodes.get(0)));
assertBusy(() -> internalCluster().getInstance(GatewayMetaState.class, dataNode).allPendingAsyncStatesWritten());
internalCluster().stopRandomDataNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ public void testSnapshotRecovery() throws Exception {
logger.info("--> request recoveries");
RecoveryResponse response = client().admin().indices().prepareRecoveries(INDEX_NAME).execute().actionGet();

Repository repository = internalCluster().getMasterNodeInstance(RepositoriesService.class).repository(REPO_NAME);
Repository repository = internalCluster().getAnyMasterNodeInstance(RepositoriesService.class).repository(REPO_NAME);
final RepositoryData repositoryData = PlainActionFuture.get(repository::getRepositoryData);
for (Map.Entry<String, List<RecoveryState>> indexRecoveryStates : response.shardRecoveryStates().entrySet()) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ public void testFetchingInformationFromAnIncompatibleMasterNodeReturnsAnEmptyLis
createRepository(repositoryName, "fs", randomRepoPath(), true);
createSnapshot(repositoryName, snapshotName, indexName);

RepositoriesService repositoriesService = internalCluster().getMasterNodeInstance(RepositoriesService.class);
ThreadPool threadPool = internalCluster().getMasterNodeInstance(ThreadPool.class);
ClusterService clusterService = internalCluster().getMasterNodeInstance(ClusterService.class);
RepositoriesService repositoriesService = internalCluster().getAnyMasterNodeInstance(RepositoriesService.class);
ThreadPool threadPool = internalCluster().getAnyMasterNodeInstance(ThreadPool.class);
ClusterService clusterService = internalCluster().getAnyMasterNodeInstance(ClusterService.class);
ShardSnapshotsService shardSnapshotsService = new ShardSnapshotsService(client(), repositoriesService, threadPool, clusterService) {
@Override
protected boolean masterSupportsFetchingLatestSnapshots() {
Expand All @@ -305,9 +305,9 @@ private Optional<ShardSnapshot> getLatestShardSnapshot(ShardId shardId) throws E
}

private ShardSnapshotsService getShardSnapshotsService() {
RepositoriesService repositoriesService = internalCluster().getMasterNodeInstance(RepositoriesService.class);
ThreadPool threadPool = internalCluster().getMasterNodeInstance(ThreadPool.class);
ClusterService clusterService = internalCluster().getMasterNodeInstance(ClusterService.class);
RepositoriesService repositoriesService = internalCluster().getAnyMasterNodeInstance(RepositoriesService.class);
ThreadPool threadPool = internalCluster().getAnyMasterNodeInstance(ThreadPool.class);
ClusterService clusterService = internalCluster().getAnyMasterNodeInstance(ClusterService.class);
return new ShardSnapshotsService(client(), repositoriesService, threadPool, clusterService);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ private void runTestDefaultNumberOfReplicasTest(final boolean closeIndex) {

public void testNoopUpdate() {
internalCluster().ensureAtLeastNumDataNodes(2);
final ClusterService clusterService = internalCluster().getMasterNodeInstance(ClusterService.class);
final ClusterService clusterService = internalCluster().getAnyMasterNodeInstance(ClusterService.class);
assertAcked(
client().admin()
.indices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testPersistentTasksThatFailDuringInitializationAreRemovedFromCluster
startPersistentTaskFuture.actionGet();

assertBusy(() -> {
final ClusterService clusterService = internalCluster().getMasterNodeInstance(ClusterService.class);
final ClusterService clusterService = internalCluster().getAnyMasterNodeInstance(ClusterService.class);
final PersistentTasksCustomMetadata persistentTasks = clusterService.state()
.metadata()
.custom(PersistentTasksCustomMetadata.TYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected BlobStore newBlobStore() {
}

protected BlobStore newBlobStore(String repository) {
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) internalCluster().getMasterNodeInstance(
final BlobStoreRepository blobStoreRepository = (BlobStoreRepository) internalCluster().getAnyMasterNodeInstance(
RepositoriesService.class
).repository(repository);
return PlainActionFuture.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,9 @@ public <T> Iterable<T> getDataNodeInstances(Class<T> clazz) {
return getInstances(clazz, DATA_NODE_PREDICATE);
}

/**
* Return the instance of the given class &gt;T&lt; from the elected master node. See also {@link #getAnyMasterNodeInstance}.
*/
public synchronized <T> T getCurrentMasterNodeInstance(Class<T> clazz) {
return getInstance(clazz, new NodeNamePredicate(getMasterName()));
}
Expand Down Expand Up @@ -1590,7 +1593,11 @@ public <T> T getDataNodeInstance(Class<T> clazz) {
return getInstance(clazz, DATA_NODE_PREDICATE);
}

public <T> T getMasterNodeInstance(Class<T> clazz) {
/**
* Return the instance of the given class &gt;T&lt; from any of the master-eligible nodes (not necessarily the elected master). See
* also {@link #getCurrentMasterNodeInstance}.
*/
public <T> T getAnyMasterNodeInstance(Class<T> clazz) {
return getInstance(clazz, MASTER_NODE_PREDICATE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,27 +83,27 @@ public void testCapacityRestCancellationAndResponse() throws Exception {
PlainActionFuture<Response> successFuture2 = new PlainActionFuture<>();
Request getCapacityRequest = new Request("GET", "/_autoscaling/capacity");
Cancellable cancellable = restClient.performRequestAsync(getCapacityRequest, wrapAsRestResponseListener(cancelledFuture));
LocalStateAutoscaling.AutoscalingTestPlugin plugin = internalCluster().getMasterNodeInstance(PluginsService.class)
LocalStateAutoscaling.AutoscalingTestPlugin plugin = internalCluster().getAnyMasterNodeInstance(PluginsService.class)
.filterPlugins(LocalStateAutoscaling.class)
.get(0)
.testPlugin();
plugin.syncWithDeciderService(() -> {
putAutoscalingPolicy(Map.of(AutoscalingCountTestDeciderService.NAME, Settings.EMPTY));
assertThat(
internalCluster().getMasterNodeInstance(TransportGetAutoscalingCapacityAction.class).responseCacheQueueSize(),
internalCluster().getAnyMasterNodeInstance(TransportGetAutoscalingCapacityAction.class).responseCacheQueueSize(),
equalTo(1)
);
restClient.performRequestAsync(getCapacityRequest, wrapAsRestResponseListener(successFuture1));
assertBusy(
() -> assertThat(
internalCluster().getMasterNodeInstance(TransportGetAutoscalingCapacityAction.class).responseCacheQueueSize(),
internalCluster().getAnyMasterNodeInstance(TransportGetAutoscalingCapacityAction.class).responseCacheQueueSize(),
equalTo(2)
)
);
restClient.performRequestAsync(getCapacityRequest, wrapAsRestResponseListener(successFuture2));
assertBusy(
() -> assertThat(
internalCluster().getMasterNodeInstance(TransportGetAutoscalingCapacityAction.class).responseCacheQueueSize(),
internalCluster().getAnyMasterNodeInstance(TransportGetAutoscalingCapacityAction.class).responseCacheQueueSize(),
equalTo(3)
)
);
Expand All @@ -130,7 +130,7 @@ public void testCapacityRestCancellationAndResponse() throws Exception {

private void waitForCancelledCapacityTask() throws Exception {
assertBusy(() -> {
TransportService transportService = internalCluster().getMasterNodeInstance(TransportService.class);
TransportService transportService = internalCluster().getAnyMasterNodeInstance(TransportService.class);
final TaskManager taskManager = transportService.getTaskManager();
assertTrue(taskManager.assertCancellableTaskConsistency());
for (CancellableTask cancellableTask : taskManager.getCancellableTasks().values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void testFollowIndex() throws Exception {

private void setupRemoteCluster() throws Exception {
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest().masterNodeTimeout(TimeValue.MAX_VALUE);
String address = getLeaderCluster().getMasterNodeInstance(TransportService.class).boundAddress().publishAddress().toString();
String address = getLeaderCluster().getAnyMasterNodeInstance(TransportService.class).boundAddress().publishAddress().toString();
updateSettingsRequest.persistentSettings(Settings.builder().put("cluster.remote.leader_cluster.seeds", address));
assertAcked(followerClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
List<RemoteConnectionInfo> infos = followerClient().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();
Expand Down