diff --git a/modules/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java b/modules/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java index 313cd04b84877..d2cd3dc6a2b22 100644 --- a/modules/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java +++ b/modules/repository-gcs/src/internalClusterTest/java/org/elasticsearch/repositories/gcs/GoogleCloudStorageBlobStoreRepositoryTests.java @@ -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() diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/RestGetMappingsCancellationIT.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/RestGetMappingsCancellationIT.java index 423101f6f915c..bf71e38ae0c28 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/RestGetMappingsCancellationIT.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/RestGetMappingsCancellationIT.java @@ -97,7 +97,7 @@ public TimeValue masterNodeTimeout() { }; PlainActionFuture 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 { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/desirednodes/TransportDesiredNodesActionsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/desirednodes/TransportDesiredNodesActionsIT.java index 9e77a51eca694..b4379ce4c0c89 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/desirednodes/TransportDesiredNodesActionsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/cluster/desirednodes/TransportDesiredNodesActionsIT.java @@ -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().getCurrentMasterNodeInstance(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 { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java index 1c772eedc3b67..93ec7e2ff33cb 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/UnsafeBootstrapAndDetachCommandIT.java @@ -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() @@ -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() @@ -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(); diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java index 6333c96326ecc..a04c6d32f8f95 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/IndexRecoveryIT.java @@ -714,7 +714,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> indexRecoveryStates : response.shardRecoveryStates().entrySet()) { diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java index 770c640796864..a1439c3d5fa06 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/recovery/plan/ShardSnapshotsServiceIT.java @@ -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() { @@ -305,9 +305,9 @@ private Optional 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); } diff --git a/server/src/internalClusterTest/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java b/server/src/internalClusterTest/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java index 4bbcc7e0e4867..86450cc4b541a 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/indices/settings/UpdateSettingsIT.java @@ -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() diff --git a/server/src/internalClusterTest/java/org/elasticsearch/persistent/PersistentTaskInitializationFailureIT.java b/server/src/internalClusterTest/java/org/elasticsearch/persistent/PersistentTaskInitializationFailureIT.java index 91afd101ae952..e309a5daa555f 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/persistent/PersistentTaskInitializationFailureIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/persistent/PersistentTaskInitializationFailureIT.java @@ -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); diff --git a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java index 3b3036ea0b194..09565ab448eff 100644 --- a/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/repositories/blobstore/ESBlobStoreRepositoryIntegTestCase.java @@ -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( diff --git a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java index 2e2deb0d1a2cd..aaa16f9b0d011 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -1558,6 +1558,9 @@ public Iterable getDataNodeInstances(Class clazz) { return getInstances(clazz, DATA_NODE_PREDICATE); } + /** + * Return the instance of the given class >T< from the elected master node. See also {@link #getAnyMasterNodeInstance}. + */ public synchronized T getCurrentMasterNodeInstance(Class clazz) { return getInstance(clazz, new NodeNamePredicate(getMasterName())); } @@ -1590,7 +1593,11 @@ public T getDataNodeInstance(Class clazz) { return getInstance(clazz, DATA_NODE_PREDICATE); } - public T getMasterNodeInstance(Class clazz) { + /** + * Return the instance of the given class >T< from any of the master-eligible nodes (not necessarily the elected master). See + * also {@link #getCurrentMasterNodeInstance}. + */ + public T getAnyMasterNodeInstance(Class clazz) { return getInstance(clazz, MASTER_NODE_PREDICATE); } diff --git a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityRestCancellationIT.java b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityRestCancellationIT.java index 4669a264ba87d..4d37e3a0475e9 100644 --- a/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityRestCancellationIT.java +++ b/x-pack/plugin/autoscaling/src/internalClusterTest/java/org/elasticsearch/xpack/autoscaling/action/GetAutoscalingCapacityRestCancellationIT.java @@ -83,27 +83,27 @@ public void testCapacityRestCancellationAndResponse() throws Exception { PlainActionFuture 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) ) ); @@ -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()) { diff --git a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java index dfd20345cedf5..896a072a95778 100644 --- a/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/internalClusterTest/java/org/elasticsearch/xpack/ccr/RestartIndexFollowingIT.java @@ -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 infos = followerClient().execute(RemoteInfoAction.INSTANCE, new RemoteInfoRequest()).get().getInfos();