From 62ac7d219f821d8ba295e023e272cceeac4cecbf Mon Sep 17 00:00:00 2001 From: javanna Date: Wed, 30 Mar 2016 15:19:28 +0200 Subject: [PATCH] Remove DiscoveryNodes#masterNode in favour of existing DiscoveryNodes#getMasterNode --- .../master/TransportMasterNodeAction.java | 8 +++--- .../action/index/NodeIndexDeletedAction.java | 4 +-- .../index/NodeMappingRefreshAction.java | 4 +-- .../action/shard/ShardStateAction.java | 2 +- .../cluster/node/DiscoveryNodes.java | 17 +++--------- .../cluster/service/ClusterService.java | 2 +- .../discovery/local/LocalDiscovery.java | 2 +- .../discovery/zen/NodeJoinController.java | 4 +-- .../discovery/zen/ZenDiscovery.java | 26 +++++++++---------- .../zen/ping/unicast/UnicastZenPing.java | 2 +- .../publish/PendingClusterStatesQueue.java | 4 +-- .../publish/PublishClusterStateAction.java | 6 ++--- .../gateway/LocalAllocateDangledIndices.java | 2 +- .../cluster/IndicesClusterStateService.java | 16 ++++++------ .../snapshots/RestoreService.java | 4 +-- .../snapshots/SnapshotShardsService.java | 2 +- .../TransportBroadcastByNodeActionTests.java | 4 +-- .../BasicBackwardsCompatibilityIT.java | 2 +- .../cluster/MinimumMasterNodesIT.java | 2 +- .../cluster/SpecificMasterNodesIT.java | 22 ++++++++-------- .../action/shard/ShardStateActionTests.java | 2 +- .../cluster/service/ClusterServiceIT.java | 8 +++--- .../DiscoveryWithServiceDisruptionsIT.java | 12 ++++----- .../discovery/ZenUnicastDiscoveryIT.java | 4 +-- .../PublishClusterStateActionTests.java | 2 +- .../indices/state/RareClusterStateIT.java | 4 +-- .../test/InternalTestCluster.java | 2 +- 27 files changed, 80 insertions(+), 89 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeAction.java b/core/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeAction.java index 1a7092c3a97..cd07b87cdc9 100644 --- a/core/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeAction.java +++ b/core/src/main/java/org/elasticsearch/action/support/master/TransportMasterNodeAction.java @@ -168,12 +168,12 @@ public abstract class TransportMasterNodeAction(listener) { + taskManager.registerChildTask(task, nodes.getMasterNode().getId()); + transportService.sendRequest(nodes.getMasterNode(), actionName, request, new ActionListenerResponseHandler(listener) { @Override public Response newInstance() { return newResponse(); @@ -185,7 +185,7 @@ public abstract class TransportMasterNodeAction { diff --git a/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java b/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java index 68926368ddb..6b9079cb363 100644 --- a/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java +++ b/core/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java @@ -92,7 +92,7 @@ public class ShardStateAction extends AbstractComponent { } private void sendShardAction(final String actionName, final ClusterStateObserver observer, final ShardRoutingEntry shardRoutingEntry, final Listener listener) { - DiscoveryNode masterNode = observer.observedState().nodes().masterNode(); + DiscoveryNode masterNode = observer.observedState().nodes().getMasterNode(); if (masterNode == null) { logger.warn("{} no master known for action [{}] for shard [{}]", shardRoutingEntry.getShardRouting().shardId(), actionName, shardRoutingEntry.getShardRouting()); waitForNewMasterAndRetry(actionName, observer, shardRoutingEntry, listener); diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 45ac4a6b971..e24098ea8ab 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -197,22 +197,13 @@ public class DiscoveryNodes extends AbstractDiffable implements return nodes.get(localNodeId); } - /** - * Get the master node - * - * @return master node - */ - public DiscoveryNode masterNode() { - return nodes.get(masterNodeId); - } - /** * Get the master node * * @return master node */ public DiscoveryNode getMasterNode() { - return masterNode(); + return nodes.get(masterNodeId); } /** @@ -383,8 +374,8 @@ public class DiscoveryNodes extends AbstractDiffable implements DiscoveryNode newMasterNode = null; if (masterNodeId != null) { if (other.masterNodeId == null || !other.masterNodeId.equals(masterNodeId)) { - previousMasterNode = other.masterNode(); - newMasterNode = masterNode(); + previousMasterNode = other.getMasterNode(); + newMasterNode = getMasterNode(); } } return new Delta(previousMasterNode, newMasterNode, localNodeId, Collections.unmodifiableList(removed), Collections.unmodifiableList(added)); @@ -409,7 +400,7 @@ public class DiscoveryNodes extends AbstractDiffable implements if (node == getLocalNode()) { sb.append(", local"); } - if (node == masterNode()) { + if (node == getMasterNode()) { sb.append(", master"); } sb.append("\n"); diff --git a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java index d280ec591e3..ca350ea0a05 100644 --- a/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java +++ b/core/src/main/java/org/elasticsearch/cluster/service/ClusterService.java @@ -973,7 +973,7 @@ public class ClusterService extends AbstractLifecycleComponent { public void onNodeAck(DiscoveryNode node, @Nullable Throwable t) { if (!ackedTaskListener.mustAck(node)) { //we always wait for the master ack anyway - if (!node.equals(nodes.masterNode())) { + if (!node.equals(nodes.getMasterNode())) { return; } } diff --git a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java index 97ecf00b1fc..03f27d093e8 100644 --- a/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/local/LocalDiscovery.java @@ -340,7 +340,7 @@ public class LocalDiscovery extends AbstractLifecycleComponent implem nodeSpecificClusterState.status(ClusterState.ClusterStateStatus.RECEIVED); // ignore cluster state messages that do not include "me", not in the game yet... if (nodeSpecificClusterState.nodes().getLocalNode() != null) { - assert nodeSpecificClusterState.nodes().masterNode() != null : "received a cluster state without a master"; + assert nodeSpecificClusterState.nodes().getMasterNode() != null : "received a cluster state without a master"; assert !nodeSpecificClusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock()) : "received a cluster state with a master block"; discovery.clusterService.submitStateUpdateTask("local-disco-receive(from master)", new ClusterStateUpdateTask() { diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java b/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java index 5afc81c484a..ddfb49340a4 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/NodeJoinController.java @@ -240,9 +240,9 @@ public class NodeJoinController extends AbstractComponent { // Take into account the previous known nodes, if they happen not to be available // then fault detection will remove these nodes. - if (currentState.nodes().masterNode() != null) { + if (currentState.nodes().getMasterNode() != null) { // TODO can we tie break here? we don't have a remote master cluster state version to decide on - logger.trace("join thread elected local node as master, but there is already a master in place: {}", currentState.nodes().masterNode()); + logger.trace("join thread elected local node as master, but there is already a master in place: {}", currentState.nodes().getMasterNode()); throw new NotMasterException("Node [" + clusterService.localNode() + "] not master for join request"); } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java index 353880a39cb..40487170837 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java @@ -242,13 +242,13 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen nodesFD.stop(); DiscoveryNodes nodes = nodes(); if (sendLeaveRequest) { - if (nodes.masterNode() == null) { + if (nodes.getMasterNode() == null) { // if we don't know who the master is, nothing to do here } else if (!nodes.localNodeMaster()) { try { - membership.sendLeaveRequestBlocking(nodes.masterNode(), nodes.getLocalNode(), TimeValue.timeValueSeconds(1)); + membership.sendLeaveRequestBlocking(nodes.getMasterNode(), nodes.getLocalNode(), TimeValue.timeValueSeconds(1)); } catch (Exception e) { - logger.debug("failed to send leave request to master [{}]", e, nodes.masterNode()); + logger.debug("failed to send leave request to master [{}]", e, nodes.getMasterNode()); } } else { // we're master -> let other potential master we left and start a master election now rather then wait for masterFD @@ -260,7 +260,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen try { membership.sendLeaveRequest(nodes.getLocalNode(), possibleMaster); } catch (Exception e) { - logger.debug("failed to send leave request from master [{}] to possible master [{}]", e, nodes.masterNode(), possibleMaster); + logger.debug("failed to send leave request from master [{}] to possible master [{}]", e, nodes.getMasterNode(), possibleMaster); } } } @@ -419,7 +419,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen return currentState; } - if (currentState.getNodes().masterNode() == null) { + if (currentState.getNodes().getMasterNode() == null) { // Post 1.3.0, the master should publish a new cluster state before acking our join request. we now should have // a valid master. logger.debug("no master node is set, despite of join request completing. retrying pings."); @@ -427,7 +427,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen return currentState; } - if (!currentState.getNodes().masterNode().equals(finalMasterNode)) { + if (!currentState.getNodes().getMasterNode().equals(finalMasterNode)) { return joinThreadControl.stopRunningThreadAndRejoin(currentState, "master_switched_while_finalizing_join"); } @@ -524,7 +524,7 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen logger.error("unexpected failure during [{}]", t, source); } }); - } else if (node.equals(nodes().masterNode())) { + } else if (node.equals(nodes().getMasterNode())) { handleMasterGone(node, null, "shut_down"); } } @@ -680,11 +680,11 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen return currentState; } - assert newClusterState.nodes().masterNode() != null : "received a cluster state without a master"; + assert newClusterState.nodes().getMasterNode() != null : "received a cluster state without a master"; assert !newClusterState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock()) : "received a cluster state with a master block"; if (currentState.nodes().localNodeMaster()) { - return handleAnotherMaster(currentState, newClusterState.nodes().masterNode(), newClusterState.version(), "via a new cluster state"); + return handleAnotherMaster(currentState, newClusterState.nodes().getMasterNode(), newClusterState.version(), "via a new cluster state"); } if (shouldIgnoreOrRejectNewClusterState(logger, currentState, newClusterState)) { @@ -692,8 +692,8 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen } // check to see that we monitor the correct master of the cluster - if (masterFD.masterNode() == null || !masterFD.masterNode().equals(newClusterState.nodes().masterNode())) { - masterFD.restart(newClusterState.nodes().masterNode(), "new cluster state received and we are monitoring the wrong master [" + masterFD.masterNode() + "]"); + if (masterFD.masterNode() == null || !masterFD.masterNode().equals(newClusterState.nodes().getMasterNode())) { + masterFD.restart(newClusterState.nodes().getMasterNode(), "new cluster state received and we are monitoring the wrong master [" + masterFD.masterNode() + "]"); } if (currentState.blocks().hasGlobalBlock(discoverySettings.getNoMasterBlock())) { @@ -787,8 +787,8 @@ public class ZenDiscovery extends AbstractLifecycleComponent implemen return; } if (!currentNodes.getMasterNodeId().equals(newClusterState.nodes().getMasterNodeId())) { - logger.warn("received a cluster state from a different master than the current one, rejecting (received {}, current {})", newClusterState.nodes().masterNode(), currentNodes.masterNode()); - throw new IllegalStateException("cluster state from a different master than the current one, rejecting (received " + newClusterState.nodes().masterNode() + ", current " + currentNodes.masterNode() + ")"); + logger.warn("received a cluster state from a different master than the current one, rejecting (received {}, current {})", newClusterState.nodes().getMasterNode(), currentNodes.getMasterNode()); + throw new IllegalStateException("cluster state from a different master than the current one, rejecting (received " + newClusterState.nodes().getMasterNode() + ", current " + currentNodes.getMasterNode() + ")"); } } diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java index 0d4d4a9b004..d04a216fd31 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPing.java @@ -565,7 +565,7 @@ public class UnicastZenPing extends AbstractLifecycleComponent implemen } private PingResponse createPingResponse(DiscoveryNodes discoNodes) { - return new PingResponse(discoNodes.getLocalNode(), discoNodes.masterNode(), clusterName, contextProvider.nodeHasJoinedClusterOnce()); + return new PingResponse(discoNodes.getLocalNode(), discoNodes.getMasterNode(), clusterName, contextProvider.nodeHasJoinedClusterOnce()); } static class UnicastPingResponse extends TransportResponse { diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueue.java b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueue.java index 5638f877967..b3ad7329d99 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueue.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStatesQueue.java @@ -138,7 +138,7 @@ public class PendingClusterStatesQueue { if (findState(state.stateUUID()) == null) { throw new IllegalStateException("can't resolve processed cluster state with uuid [" + state.stateUUID() + "], version [" + state.version() + "]"); } - final DiscoveryNode currentMaster = state.nodes().masterNode(); + final DiscoveryNode currentMaster = state.nodes().getMasterNode(); assert currentMaster != null : "processed cluster state mast have a master. " + state; // fail or remove any incoming state from a different master @@ -147,7 +147,7 @@ public class PendingClusterStatesQueue { for (int index = 0; index < pendingStates.size(); index++) { final ClusterStateContext pendingContext = pendingStates.get(index); final ClusterState pendingState = pendingContext.state; - final DiscoveryNode pendingMasterNode = pendingState.nodes().masterNode(); + final DiscoveryNode pendingMasterNode = pendingState.nodes().getMasterNode(); if (Objects.equals(currentMaster, pendingMasterNode) == false) { contextsToRemove.add(pendingContext); if (pendingContext.committed()) { diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java index 1f5eb882f77..d7c4ac1568d 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateAction.java @@ -391,13 +391,13 @@ public class PublishClusterStateAction extends AbstractComponent { void validateIncomingState(ClusterState incomingState, ClusterState lastSeenClusterState) { final ClusterName incomingClusterName = incomingState.getClusterName(); if (!incomingClusterName.equals(this.clusterName)) { - logger.warn("received cluster state from [{}] which is also master but with a different cluster name [{}]", incomingState.nodes().masterNode(), incomingClusterName); + logger.warn("received cluster state from [{}] which is also master but with a different cluster name [{}]", incomingState.nodes().getMasterNode(), incomingClusterName); throw new IllegalStateException("received state from a node that is not part of the cluster"); } final DiscoveryNodes currentNodes = nodesProvider.nodes(); if (currentNodes.getLocalNode().equals(incomingState.nodes().getLocalNode()) == false) { - logger.warn("received a cluster state from [{}] and not part of the cluster, should not happen", incomingState.nodes().masterNode()); + logger.warn("received a cluster state from [{}] and not part of the cluster, should not happen", incomingState.nodes().getMasterNode()); throw new IllegalStateException("received state from a node that is not part of the cluster"); } @@ -427,7 +427,7 @@ public class PublishClusterStateAction extends AbstractComponent { } }); if (state != null) { - newPendingClusterStatelistener.onNewClusterState("master " + state.nodes().masterNode() + " committed version [" + state.version() + "]"); + newPendingClusterStatelistener.onNewClusterState("master " + state.nodes().getMasterNode() + " committed version [" + state.version() + "]"); } } diff --git a/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java b/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java index face4c62ca7..3ee6851f8a5 100644 --- a/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java +++ b/core/src/main/java/org/elasticsearch/gateway/LocalAllocateDangledIndices.java @@ -76,7 +76,7 @@ public class LocalAllocateDangledIndices extends AbstractComponent { public void allocateDangled(Collection indices, final Listener listener) { ClusterState clusterState = clusterService.state(); - DiscoveryNode masterNode = clusterState.nodes().masterNode(); + DiscoveryNode masterNode = clusterState.nodes().getMasterNode(); if (masterNode == null) { listener.onFailure(new MasterNotDiscoveredException("no master to send allocate dangled request")); return; diff --git a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java index 255d6fb2e6a..7b1c03218b1 100644 --- a/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java +++ b/core/src/main/java/org/elasticsearch/indices/cluster/IndicesClusterStateService.java @@ -483,14 +483,14 @@ public class IndicesClusterStateService extends AbstractLifecycleComponent listener = new PlainActionFuture<>(); - DiscoveryNode masterNode = clusterService.state().nodes().masterNode(); + DiscoveryNode masterNode = clusterService.state().nodes().getMasterNode(); DiscoveryNodes.Builder builder = DiscoveryNodes.builder(clusterService.state().getNodes()); builder.remove(masterNode.getId()); @@ -403,7 +403,7 @@ public class TransportBroadcastByNodeActionTests extends ESTestCase { final boolean simulateFailedMasterNode = rarely(); DiscoveryNode failedMasterNode = null; if (simulateFailedMasterNode) { - failedMasterNode = clusterService.state().nodes().masterNode(); + failedMasterNode = clusterService.state().nodes().getMasterNode(); DiscoveryNodes.Builder builder = DiscoveryNodes.builder(clusterService.state().getNodes()); builder.remove(failedMasterNode.getId()); builder.masterNodeId(null); diff --git a/core/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityIT.java b/core/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityIT.java index 9d74ef66319..6ea530d1de5 100644 --- a/core/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityIT.java +++ b/core/src/test/java/org/elasticsearch/bwcompat/BasicBackwardsCompatibilityIT.java @@ -449,7 +449,7 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase { public Version getMasterVersion() { - return client().admin().cluster().prepareState().get().getState().nodes().masterNode().getVersion(); + return client().admin().cluster().prepareState().get().getState().nodes().getMasterNode().getVersion(); } public void testDeleteRoutingRequired() throws ExecutionException, InterruptedException, IOException { diff --git a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java index b97b973a728..991ed9ee883 100644 --- a/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/MinimumMasterNodesIT.java @@ -409,7 +409,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase { assertBusy(new Runnable() { @Override public void run() { - assertThat(masterClusterService.state().nodes().masterNode(), nullValue()); + assertThat(masterClusterService.state().nodes().getMasterNode(), nullValue()); } }); diff --git a/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java b/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java index 625428d09e9..792c28680e3 100644 --- a/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/SpecificMasterNodesIT.java @@ -53,8 +53,8 @@ public class SpecificMasterNodesIT extends ESIntegTestCase { } logger.info("--> start master node"); final String masterNodeName = internalCluster().startNode(settingsBuilder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); - assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); - assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); logger.info("--> stop master node"); internalCluster().stopCurrentMasterNode(); @@ -68,8 +68,8 @@ public class SpecificMasterNodesIT extends ESIntegTestCase { logger.info("--> start master node"); final String nextMasterEligibleNodeName = internalCluster().startNode(settingsBuilder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); - assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(nextMasterEligibleNodeName)); - assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(nextMasterEligibleNodeName)); + assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligibleNodeName)); + assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligibleNodeName)); } public void testElectOnlyBetweenMasterNodes() throws IOException { @@ -83,19 +83,19 @@ public class SpecificMasterNodesIT extends ESIntegTestCase { } logger.info("--> start master node (1)"); final String masterNodeName = internalCluster().startNode(settingsBuilder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); - assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); - assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); logger.info("--> start master node (2)"); final String nextMasterEligableNodeName = internalCluster().startNode(settingsBuilder().put(Node.NODE_DATA_SETTING.getKey(), false).put(Node.NODE_MASTER_SETTING.getKey(), true)); - assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); - assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); - assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); + assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(masterNodeName)); logger.info("--> closing master node (1)"); internalCluster().stopCurrentMasterNode(); - assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(nextMasterEligableNodeName)); - assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().masterNode().getName(), equalTo(nextMasterEligableNodeName)); + assertThat(internalCluster().nonMasterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName)); + assertThat(internalCluster().masterClient().admin().cluster().prepareState().execute().actionGet().getState().nodes().getMasterNode().getName(), equalTo(nextMasterEligableNodeName)); } /** diff --git a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java index 0915ede3eea..c79d198d350 100644 --- a/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/action/shard/ShardStateActionTests.java @@ -162,7 +162,7 @@ public class ShardStateActionTests extends ESTestCase { // for the right shard assertEquals(shardRouting, shardRoutingEntry.getShardRouting()); // sent to the master - assertEquals(clusterService.state().nodes().masterNode().getId(), capturedRequests[0].node.getId()); + assertEquals(clusterService.state().nodes().getMasterNode().getId(), capturedRequests[0].node.getId()); transport.handleResponse(capturedRequests[0].requestId, TransportResponse.Empty.INSTANCE); diff --git a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceIT.java b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceIT.java index bf55968df9f..b21f019e3b7 100644 --- a/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/service/ClusterServiceIT.java @@ -518,7 +518,7 @@ public class ClusterServiceIT extends ESIntegTestCase { assertThat(clusterHealth.isTimedOut(), equalTo(false)); // the first node should be a master as the minimum required is 1 - assertThat(clusterService.state().nodes().masterNode(), notNullValue()); + assertThat(clusterService.state().nodes().getMasterNode(), notNullValue()); assertThat(clusterService.state().nodes().localNodeMaster(), is(true)); assertThat(testService.master(), is(true)); @@ -554,7 +554,7 @@ public class ClusterServiceIT extends ESIntegTestCase { internalCluster().stopRandomNonMasterNode(); // there should not be any master as the minimum number of required eligible masters is not met - awaitBusy(() -> clusterService1.state().nodes().masterNode() == null && + awaitBusy(() -> clusterService1.state().nodes().getMasterNode() == null && clusterService1.state().status() == ClusterState.ClusterStateStatus.APPLIED); assertThat(testService1.master(), is(false)); @@ -571,8 +571,8 @@ public class ClusterServiceIT extends ESIntegTestCase { .setWaitForNodes("2").get().isTimedOut(), is(false)); // now that we started node1 again, a new master should be elected - assertThat(clusterService2.state().nodes().masterNode(), is(notNullValue())); - if (node_2.equals(clusterService2.state().nodes().masterNode().getName())) { + assertThat(clusterService2.state().nodes().getMasterNode(), is(notNullValue())); + if (node_2.equals(clusterService2.state().nodes().getMasterNode().getName())) { assertThat(testService1.master(), is(false)); assertThat(testService2.master(), is(true)); } else { diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java index ab76924e685..0c0bc05a2ad 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java @@ -846,7 +846,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { DiscoveryNodes discoveryNodes = internalCluster().getInstance(ClusterService.class, nonMasterNode).state().nodes(); - TransportService masterTranspotService = internalCluster().getInstance(TransportService.class, discoveryNodes.masterNode().getName()); + TransportService masterTranspotService = internalCluster().getInstance(TransportService.class, discoveryNodes.getMasterNode().getName()); logger.info("blocking requests from non master [{}] to master [{}]", nonMasterNode, masterNode); MockTransportService nonMasterTransportService = (MockTransportService) internalCluster().getInstance(TransportService.class, nonMasterNode); @@ -1175,7 +1175,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { @Override public void run() { ClusterState state = getNodeClusterState(node); - assertNull("node [" + node + "] still has [" + state.nodes().masterNode() + "] as master", state.nodes().masterNode()); + assertNull("node [" + node + "] still has [" + state.nodes().getMasterNode() + "] as master", state.nodes().getMasterNode()); if (expectedBlocks != null) { for (ClusterBlockLevel level : expectedBlocks.levels()) { assertTrue("node [" + node + "] does have level [" + level + "] in it's blocks", state.getBlocks().hasGlobalBlock(level)); @@ -1191,10 +1191,10 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { public void run() { ClusterState state = getNodeClusterState(node); String masterNode = null; - if (state.nodes().masterNode() != null) { - masterNode = state.nodes().masterNode().getName(); + if (state.nodes().getMasterNode() != null) { + masterNode = state.nodes().getMasterNode().getName(); } - logger.trace("[{}] master is [{}]", node, state.nodes().masterNode()); + logger.trace("[{}] master is [{}]", node, state.nodes().getMasterNode()); assertThat("node [" + node + "] still has [" + masterNode + "] as master", oldMasterNode, not(equalTo(masterNode))); } @@ -1206,7 +1206,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { ClusterState state = getNodeClusterState(node); String failMsgSuffix = "cluster_state:\n" + state.prettyPrint(); assertThat("wrong node count on [" + node + "]. " + failMsgSuffix, state.nodes().getSize(), equalTo(nodes.size())); - String otherMasterNodeName = state.nodes().masterNode() != null ? state.nodes().masterNode().getName() : null; + String otherMasterNodeName = state.nodes().getMasterNode() != null ? state.nodes().getMasterNode().getName() : null; assertThat("wrong master on node [" + node + "]. " + failMsgSuffix, otherMasterNodeName, equalTo(masterNode)); } } diff --git a/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java b/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java index 6bc0301cd08..e3c11a6e322 100644 --- a/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryIT.java @@ -94,9 +94,9 @@ public class ZenUnicastDiscoveryIT extends ESIntegTestCase { ClusterState state = internalCluster().client(node).admin().cluster().prepareState().setLocal(true).execute().actionGet().getState(); assertThat(state.nodes().getSize(), equalTo(currentNumNodes)); if (masterDiscoNode == null) { - masterDiscoNode = state.nodes().masterNode(); + masterDiscoNode = state.nodes().getMasterNode(); } else { - assertThat(masterDiscoNode.equals(state.nodes().masterNode()), equalTo(true)); + assertThat(masterDiscoNode.equals(state.nodes().getMasterNode()), equalTo(true)); } } } diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java index a94a03fb671..b32581e0e2b 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/publish/PublishClusterStateActionTests.java @@ -123,7 +123,7 @@ public class PublishClusterStateActionTests extends ESTestCase { ClusterChangedEvent event = new ClusterChangedEvent("", newClusterState, clusterState); listener.clusterChanged(event); } - if (clusterState.nodes().masterNode() == null || newClusterState.supersedes(clusterState)) { + if (clusterState.nodes().getMasterNode() == null || newClusterState.supersedes(clusterState)) { clusterState = newClusterState; } action.pendingStatesQueue().markAsProcessed(newClusterState); diff --git a/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java b/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java index 920fb2ba442..87e317be734 100644 --- a/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java +++ b/core/src/test/java/org/elasticsearch/indices/state/RareClusterStateIT.java @@ -234,7 +234,7 @@ public class RareClusterStateIT extends ESIntegTestCase { // Check routing tables ClusterState state = client().admin().cluster().prepareState().get().getState(); - assertEquals(master, state.nodes().masterNode().getName()); + assertEquals(master, state.nodes().getMasterNode().getName()); List shards = state.routingTable().allShards("index"); assertThat(shards, hasSize(1)); for (ShardRouting shard : shards) { @@ -352,7 +352,7 @@ public class RareClusterStateIT extends ESIntegTestCase { // Check routing tables ClusterState state = client().admin().cluster().prepareState().get().getState(); - assertEquals(master, state.nodes().masterNode().getName()); + assertEquals(master, state.nodes().getMasterNode().getName()); List shards = state.routingTable().allShards("index"); assertThat(shards, hasSize(2)); for (ShardRouting shard : shards) { 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 dca508852a0..0db133ba0cf 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/InternalTestCluster.java @@ -1363,7 +1363,7 @@ public final class InternalTestCluster extends TestCluster { try { Client client = viaNode != null ? client(viaNode) : client(); ClusterState state = client.admin().cluster().prepareState().execute().actionGet().getState(); - return state.nodes().masterNode().getName(); + return state.nodes().getMasterNode().getName(); } catch (Throwable e) { logger.warn("Can't fetch cluster state", e); throw new RuntimeException("Can't get master node " + e.getMessage(), e);