From e53747731567ee8ff6c35609dc98540fa7c9f967 Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Thu, 4 May 2023 11:09:50 +0100 Subject: [PATCH 1/3] Fix compile after DiscoveryNode constructor refactor --- .../indices/recovery/StartRecoveryRequestTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java index 53c20f7050a19..3a2092592c22f 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/StartRecoveryRequestTests.java @@ -75,7 +75,7 @@ public void testSerialization() throws Exception { } public void testDescription() { - final var node = new DiscoveryNode("a", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + final var node = TestDiscoveryNode.create("a", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertEquals( "recovery of [index][0] to " + node.descriptionWithoutAttributes() From 7433bfdd2aa0568bd561ed8ff7376a900f555c4e Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 2 May 2023 09:58:45 +0100 Subject: [PATCH 2/3] Refactor more constructors that specify the current version --- .../routing/allocation/Allocators.java | 3 +- .../geoip/DatabaseNodeServiceTests.java | 6 +- .../discovery/StableMasterDisruptionIT.java | 15 +- ...AddVotingConfigExclusionsRequestTests.java | 92 +++++------- ...tAddVotingConfigExclusionsActionTests.java | 13 +- ...learVotingConfigExclusionsActionTests.java | 5 +- .../CoordinationDiagnosticsActionTests.java | 22 +-- .../remote/RemoteClusterNodesActionTests.java | 3 +- .../nodes/TransportNodesActionTests.java | 4 +- ...ReplicationAllPermitsAcquisitionTests.java | 5 +- .../cluster/NodeConnectionsServiceTests.java | 4 +- .../ClusterBootstrapServiceTests.java | 35 ++--- .../CoordinationDiagnosticsServiceTests.java | 34 +---- .../coordination/CoordinatorTests.java | 7 +- .../coordination/FollowersCheckerTests.java | 2 +- .../coordination/NodeJoinExecutorTests.java | 5 +- .../cluster/coordination/NodeJoinTests.java | 9 +- .../coordination/PublicationTests.java | 4 +- ...ableMasterHealthIndicatorServiceTests.java | 30 +--- .../metadata/DesiredNodesTestCase.java | 12 +- .../metadata/TemplateUpgradeServiceTests.java | 6 +- .../node/DiscoveryNodeFiltersTests.java | 26 ++-- .../cluster/node/DiscoveryNodeTests.java | 18 +-- .../cluster/node/DiscoveryNodesTests.java | 2 +- .../cluster/routing/RoutingNodeTests.java | 4 +- .../routing/allocation/DataTierTests.java | 4 +- .../ClusterAllocationSimulationTests.java | 8 +- .../DesiredBalanceReconcilerTests.java | 5 +- .../node/DiskHealthIndicatorServiceTests.java | 17 +-- .../health/node/LocalHealthMonitorTests.java | 26 ++-- ...dsCapacityHealthIndicatorServiceTests.java | 11 +- .../elasticsearch/index/IndexModuleTests.java | 18 +-- ...ClusterStateServiceRandomUpdatesTests.java | 4 +- .../readiness/ReadinessServiceTests.java | 7 +- .../action/cat/RestPluginsActionTests.java | 3 +- .../snapshots/SnapshotResiliencyTests.java | 9 +- .../TransportServiceLifecycleTests.java | 8 +- .../cluster/node/TestDiscoveryNode.java | 21 +++ .../ESIndexLevelReplicationTestCase.java | 6 +- .../index/shard/IndexShardTestCase.java | 11 +- .../test/ClusterServiceUtils.java | 12 +- .../AutoscalingNodesInfoServiceTests.java | 3 +- .../ReactiveStorageDeciderServiceTests.java | 12 +- .../ilm/SetSingleNodeAllocateStepTests.java | 16 +-- .../core/ilm/WaitForDataTierStepTests.java | 8 +- .../GetDatafeedStatsActionResponseTests.java | 3 +- .../NodesDeprecationCheckResponseTests.java | 7 +- .../xpack/ml/MlLifeCycleServiceTests.java | 32 ++--- .../MlProcessorAutoscalingDeciderTests.java | 7 +- .../datafeed/DatafeedNodeSelectorTests.java | 11 +- .../ml/datafeed/DatafeedRunnerTests.java | 7 +- ...rainedModelAssignmentNodeServiceTests.java | 46 +----- ...TrainedModelAssignmentRebalancerTests.java | 7 +- .../planning/AllocationReducerTests.java | 5 +- .../ModelLoadingServiceTests.java | 8 +- .../xpack/ml/job/JobNodeSelectorTests.java | 131 ++++++++---------- .../xpack/ml/job/NodeLoadDetectorTests.java | 23 ++- .../ml/utils/NativeMemoryCalculatorTests.java | 13 +- .../TransportNodeEnrollmentActionTests.java | 3 +- ...InternalEnrollmentTokenGeneratorTests.java | 6 +- 60 files changed, 309 insertions(+), 575 deletions(-) diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java index f933957c74868..a2b7e3ff39f26 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java @@ -7,7 +7,6 @@ */ package org.elasticsearch.benchmark.routing.allocation; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.EmptyClusterInfoService; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -100,7 +99,7 @@ public static DiscoveryNode newNode(String nodeId, Map attribute new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()), attributes, Sets.newHashSet(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE), - Version.CURRENT + null ); } } diff --git a/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java b/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java index 1ae4789ade8ed..fb5d3efa6aa8c 100644 --- a/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java +++ b/modules/ingest-geoip/src/test/java/org/elasticsearch/ingest/geoip/DatabaseNodeServiceTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.node.TestDiscoveryNode; @@ -192,13 +191,12 @@ public void testCheckDatabases_dontCheckDatabaseOnNonIngestNode() throws Excepti ClusterState state = ClusterState.builder(createClusterState(tasksCustomMetadata)) .nodes( new DiscoveryNodes.Builder().add( - new DiscoveryNode( + TestDiscoveryNode.create( "_name1", "_id1", buildNewFakeTransportAddress(), Map.of(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ) ).localNodeId("_id1") ) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/discovery/StableMasterDisruptionIT.java b/server/src/internalClusterTest/java/org/elasticsearch/discovery/StableMasterDisruptionIT.java index ad550de9a1d4f..3d2cc287b4b85 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/discovery/StableMasterDisruptionIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/discovery/StableMasterDisruptionIT.java @@ -8,7 +8,6 @@ package org.elasticsearch.discovery; -import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterChangedEvent; @@ -21,8 +20,8 @@ import org.elasticsearch.cluster.coordination.LeaderChecker; import org.elasticsearch.cluster.coordination.MasterHistoryService; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; @@ -549,17 +548,7 @@ public void testCannotJoinLeader() throws Exception { new DiscoveryNodes.Builder().masterNodeId(null) ).build(); ClusterState previousState = new ClusterState.Builder(new ClusterName(internalCluster().getClusterName())).nodes( - new DiscoveryNodes.Builder().masterNodeId("test") - .add( - new DiscoveryNode( - "test", - "test", - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ) - ) + new DiscoveryNodes.Builder().masterNodeId("test").add(TestDiscoveryNode.create("test", "test")) ).build(); ClusterChangedEvent clusterChangedEvent = new ClusterChangedEvent("test", state, previousState); masterHistoryService.getLocalMasterHistory().clusterChanged(clusterChangedEvent); diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java index 5529c52044624..8b8cc43c7fbe9 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/AddVotingConfigExclusionsRequestTests.java @@ -7,7 +7,6 @@ */ package org.elasticsearch.action.admin.cluster.configuration; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.coordination.CoordinationMetadata; @@ -16,6 +15,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes.Builder; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.Strings; import org.elasticsearch.core.TimeValue; import org.elasticsearch.test.ESTestCase; @@ -59,40 +59,36 @@ public void testSerializationForNodeIdOrNodeName() throws IOException { } public void testResolve() { - final DiscoveryNode localNode = new DiscoveryNode( + final DiscoveryNode localNode = TestDiscoveryNode.create( "local", "local", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode); - final DiscoveryNode otherNode1 = new DiscoveryNode( + final DiscoveryNode otherNode1 = TestDiscoveryNode.create( "other1", "other1", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1); - final DiscoveryNode otherNode2 = new DiscoveryNode( + final DiscoveryNode otherNode2 = TestDiscoveryNode.create( "other2", "other2", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion otherNode2Exclusion = new VotingConfigExclusion(otherNode2); - final DiscoveryNode otherDataNode = new DiscoveryNode( + final DiscoveryNode otherDataNode = TestDiscoveryNode.create( "data", "data", buildNewFakeTransportAddress(), emptyMap(), - emptySet(), - Version.CURRENT + emptySet() ); final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")) @@ -136,33 +132,30 @@ public void testResolveMoreThanOneNodeIdentifiersSet() { } public void testResolveByNodeIds() { - final DiscoveryNode node1 = new DiscoveryNode( + final DiscoveryNode node1 = TestDiscoveryNode.create( "nodeName1", "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1); - final DiscoveryNode node2 = new DiscoveryNode( + final DiscoveryNode node2 = TestDiscoveryNode.create( "nodeName2", "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); - final DiscoveryNode node3 = new DiscoveryNode( + final DiscoveryNode node3 = TestDiscoveryNode.create( "nodeName3", "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion unresolvableVotingConfigExclusion = new VotingConfigExclusion( @@ -188,33 +181,30 @@ public void testResolveByNodeIds() { } public void testResolveByNodeNames() { - final DiscoveryNode node1 = new DiscoveryNode( + final DiscoveryNode node1 = TestDiscoveryNode.create( "nodeName1", "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion node1Exclusion = new VotingConfigExclusion(node1); - final DiscoveryNode node2 = new DiscoveryNode( + final DiscoveryNode node2 = TestDiscoveryNode.create( "nodeName2", "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); - final DiscoveryNode node3 = new DiscoveryNode( + final DiscoveryNode node3 = TestDiscoveryNode.create( "nodeName3", "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion unresolvableVotingConfigExclusion = new VotingConfigExclusion( @@ -238,22 +228,20 @@ public void testResolveByNodeNames() { } public void testResolveAmbiguousName() { - final DiscoveryNode node1 = new DiscoveryNode( + final DiscoveryNode node1 = TestDiscoveryNode.create( "ambiguous-name", "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); - final DiscoveryNode node2 = new DiscoveryNode( + final DiscoveryNode node2 = TestDiscoveryNode.create( "ambiguous-name", "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final ClusterState clusterState = ClusterState.builder(new ClusterName("cluster")) @@ -272,32 +260,29 @@ public void testResolveAmbiguousName() { } public void testResolveRemoveExistingVotingConfigExclusions() { - final DiscoveryNode node1 = new DiscoveryNode( + final DiscoveryNode node1 = TestDiscoveryNode.create( "nodeName1", "nodeId1", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); - final DiscoveryNode node2 = new DiscoveryNode( + final DiscoveryNode node2 = TestDiscoveryNode.create( "nodeName2", "nodeId2", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion node2Exclusion = new VotingConfigExclusion(node2); - final DiscoveryNode node3 = new DiscoveryNode( + final DiscoveryNode node3 = TestDiscoveryNode.create( "nodeName3", "nodeId3", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion existingVotingConfigExclusion = new VotingConfigExclusion(node1); @@ -319,31 +304,28 @@ public void testResolveRemoveExistingVotingConfigExclusions() { } public void testResolveAndCheckMaximum() { - final DiscoveryNode localNode = new DiscoveryNode( + final DiscoveryNode localNode = TestDiscoveryNode.create( "local", "local", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion localNodeExclusion = new VotingConfigExclusion(localNode); - final DiscoveryNode otherNode1 = new DiscoveryNode( + final DiscoveryNode otherNode1 = TestDiscoveryNode.create( "other1", "other1", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final VotingConfigExclusion otherNode1Exclusion = new VotingConfigExclusion(otherNode1); - final DiscoveryNode otherNode2 = new DiscoveryNode( + final DiscoveryNode otherNode2 = TestDiscoveryNode.create( "other2", "other2", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); final ClusterState.Builder builder = ClusterState.builder(new ClusterName("cluster")) diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java index 6f5561dffaa53..84c9174bb0f4e 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportAddVotingConfigExclusionsActionTests.java @@ -9,7 +9,6 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.ElasticsearchTimeoutException; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterName; @@ -24,6 +23,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes.Builder; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -82,19 +82,12 @@ public static void createThreadPoolAndClusterService() { otherNode1Exclusion = new VotingConfigExclusion(otherNode1); otherNode2 = makeDiscoveryNode("other2"); otherNode2Exclusion = new VotingConfigExclusion(otherNode2); - otherDataNode = new DiscoveryNode("data", "data", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + otherDataNode = TestDiscoveryNode.create("data", "data", buildNewFakeTransportAddress(), emptyMap(), emptySet()); clusterService = createClusterService(threadPool, localNode); } private static DiscoveryNode makeDiscoveryNode(String name) { - return new DiscoveryNode( - name, - name, - buildNewFakeTransportAddress(), - emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT - ); + return TestDiscoveryNode.create(name, name, buildNewFakeTransportAddress(), emptyMap(), Set.of(DiscoveryNodeRole.MASTER_ROLE)); } @AfterClass diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java index 7a7c1989fde26..600df636f4c00 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/configuration/TransportClearVotingConfigExclusionsActionTests.java @@ -9,7 +9,6 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.ElasticsearchTimeoutException; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.cluster.ClusterName; @@ -64,9 +63,9 @@ public class TransportClearVotingConfigExclusionsActionTests extends ESTestCase public static void createThreadPoolAndClusterService() { threadPool = new TestThreadPool("test", Settings.EMPTY); localNode = TestDiscoveryNode.create("local"); - otherNode1 = new DiscoveryNode("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + otherNode1 = TestDiscoveryNode.create("other1", "other1", buildNewFakeTransportAddress(), emptyMap(), emptySet()); otherNode1Exclusion = new VotingConfigExclusion(otherNode1); - otherNode2 = new DiscoveryNode("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + otherNode2 = TestDiscoveryNode.create("other2", "other2", buildNewFakeTransportAddress(), emptyMap(), emptySet()); otherNode2Exclusion = new VotingConfigExclusion(otherNode2); clusterService = createClusterService(threadPool, localNode); } diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/coordination/CoordinationDiagnosticsActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/coordination/CoordinationDiagnosticsActionTests.java index 1832bcdb2fb4b..96c08c0b8918c 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/coordination/CoordinationDiagnosticsActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/coordination/CoordinationDiagnosticsActionTests.java @@ -8,13 +8,11 @@ package org.elasticsearch.action.admin.cluster.coordination; -import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.EqualsHashCodeTestUtils; -import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; @@ -26,22 +24,8 @@ public class CoordinationDiagnosticsActionTests extends ESTestCase { public void testSerialization() { - DiscoveryNode node1 = new DiscoveryNode( - "node1", - UUID.randomUUID().toString(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); - DiscoveryNode node2 = new DiscoveryNode( - "node2", - UUID.randomUUID().toString(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); + DiscoveryNode node1 = TestDiscoveryNode.create("node1", UUID.randomUUID().toString()); + DiscoveryNode node2 = TestDiscoveryNode.create("node2", UUID.randomUUID().toString()); CoordinationDiagnosticsDetails details = new CoordinationDiagnosticsDetails( node1, List.of(node1, node2), diff --git a/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java index b6ba94bfcefe8..80e4c97af3d9c 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/cluster/remote/RemoteClusterNodesActionTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.transport.TransportAddress; @@ -133,7 +134,7 @@ public void testDoExecute() { } private DiscoveryNode randomNode(final int id) { - return new DiscoveryNode("node-" + id, Integer.toString(id), buildNewFakeTransportAddress(), Map.of(), Set.of(), Version.CURRENT); + return TestDiscoveryNode.create("node-" + id, Integer.toString(id), buildNewFakeTransportAddress(), Map.of(), Set.of()); } } diff --git a/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java b/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java index 65a75ec5a3d51..572ca720055db 100644 --- a/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/nodes/TransportNodesActionTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.action.support.nodes; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.PlainActionFuture; @@ -19,6 +18,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.io.stream.StreamInput; @@ -284,7 +284,7 @@ public DataNodesOnlyTransportNodesAction getDataNodesOnlyTransportNodesAction(Tr private static DiscoveryNode newNode(int nodeId, Map attributes, Set roles) { String node = "node_" + nodeId; - return new DiscoveryNode(node, node, buildNewFakeTransportAddress(), attributes, roles, Version.CURRENT); + return TestDiscoveryNode.create(node, node, buildNewFakeTransportAddress(), attributes, roles); } private static class TestTransportNodesAction extends TransportNodesAction< diff --git a/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java b/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java index ba8e500ceb9e3..f7c322bf75b1a 100644 --- a/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java +++ b/server/src/test/java/org/elasticsearch/action/support/replication/TransportReplicationAllPermitsAcquisitionTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RecoverySource; @@ -113,8 +114,8 @@ public void setUp() throws Exception { final ClusterState.Builder state = ClusterState.builder(clusterService.state()); Set roles = new HashSet<>(DiscoveryNodeRole.roles()); - DiscoveryNode node1 = new DiscoveryNode("_name1", "_node1", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT); - DiscoveryNode node2 = new DiscoveryNode("_name2", "_node2", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT); + DiscoveryNode node1 = TestDiscoveryNode.create("_name1", "_node1", buildNewFakeTransportAddress(), emptyMap(), roles); + DiscoveryNode node2 = TestDiscoveryNode.create("_name2", "_node2", buildNewFakeTransportAddress(), emptyMap(), roles); state.nodes(DiscoveryNodes.builder().add(node1).add(node2).localNodeId(node1.getId()).masterNodeId(node1.getId())); shardId = new ShardId("index", UUID.randomUUID().toString(), 0); diff --git a/server/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java index f87ff2f4c7ed8..a4df38162574d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/NodeConnectionsServiceTests.java @@ -78,9 +78,7 @@ private List generateNodes() { List nodes = new ArrayList<>(); for (int i = randomIntBetween(20, 50); i > 0; i--) { Set roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.roles())); - nodes.add( - new DiscoveryNode("node_" + i, "" + i, buildNewFakeTransportAddress(), Collections.emptyMap(), roles, Version.CURRENT) - ); + nodes.add(TestDiscoveryNode.create("node_" + i, "" + i, buildNewFakeTransportAddress(), Collections.emptyMap(), roles)); } return nodes; } diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java index 7777e0f549576..129b8e1bee93c 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/ClusterBootstrapServiceTests.java @@ -9,10 +9,10 @@ import org.apache.logging.log4j.Level; import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.DeterministicTaskQueue; @@ -89,13 +89,12 @@ protected void onSendRequest(long requestId, String action, TransportRequest req } private DiscoveryNode newDiscoveryNode(String nodeName) { - return new DiscoveryNode( + return TestDiscoveryNode.create( nodeName, randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); } @@ -153,14 +152,7 @@ public void testDoesNothingByDefaultIfMasterNodesConfigured() { } public void testDoesNothingByDefaultOnMasterIneligibleNodes() { - localNode = new DiscoveryNode( - "local", - randomAlphaOfLength(10), - buildNewFakeTransportAddress(), - emptyMap(), - emptySet(), - Version.CURRENT - ); + localNode = TestDiscoveryNode.create("local", randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), emptySet()); testDoesNothingWithSettings(Settings.builder()); } @@ -387,14 +379,7 @@ public void testDoesNotBootstrapIfAlreadyBootstrapped() { } public void testDoesNotBootstrapsOnNonMasterNode() { - localNode = new DiscoveryNode( - "local", - randomAlphaOfLength(10), - buildNewFakeTransportAddress(), - emptyMap(), - emptySet(), - Version.CURRENT - ); + localNode = TestDiscoveryNode.create("local", randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), emptySet()); ClusterBootstrapService clusterBootstrapService = new ClusterBootstrapService( Settings.builder() .putList(INITIAL_MASTER_NODES_SETTING.getKey(), localNode.getName(), otherNode1.getName(), otherNode2.getName()) @@ -507,21 +492,19 @@ public void testCancelsBootstrapIfNodeMatchesMultipleRequirements() { discoveredNodes.set( Stream.of( - new DiscoveryNode( + TestDiscoveryNode.create( otherNode1.getName(), randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ), - new DiscoveryNode( + TestDiscoveryNode.create( "yet-another-node", randomAlphaOfLength(10), otherNode1.getAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ) ).toList() ); diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinationDiagnosticsServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinationDiagnosticsServiceTests.java index 452f285ec6843..b4778f4b58636 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinationDiagnosticsServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinationDiagnosticsServiceTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.coordination; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -16,6 +15,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; @@ -74,30 +74,9 @@ public class CoordinationDiagnosticsServiceTests extends AbstractCoordinatorTest @Before public void setup() throws Exception { - node1 = new DiscoveryNode( - "node1", - randomNodeId(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); - node2 = new DiscoveryNode( - "node2", - randomNodeId(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); - node3 = new DiscoveryNode( - "node3", - randomNodeId(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); + node1 = TestDiscoveryNode.create("node1", randomNodeId()); + node2 = TestDiscoveryNode.create("node2", randomNodeId()); + node3 = TestDiscoveryNode.create("node3", randomNodeId()); nullMasterClusterState = createClusterState(null); node1MasterClusterState = createClusterState(node1); node2MasterClusterState = createClusterState(node2); @@ -1062,13 +1041,12 @@ public void testBeginPollingRemoteMasterStabilityDiagnostic() throws Exception { var clusterService = mock(ClusterService.class); when(clusterService.getSettings()).thenReturn(Settings.EMPTY); when(clusterService.state()).thenReturn(nullMasterClusterState); - DiscoveryNode localNode = new DiscoveryNode( + DiscoveryNode localNode = TestDiscoveryNode.create( "node4", randomNodeId(), buildNewFakeTransportAddress(), Collections.emptyMap(), - Set.of(DiscoveryNodeRole.DATA_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.DATA_ROLE) ); when(clusterService.localNode()).thenReturn(localNode); Coordinator coordinator = mock(Coordinator.class); diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java index d176f355c22b8..4f48858570b36 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -11,7 +11,6 @@ import org.apache.logging.log4j.core.LogEvent; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.cluster.AbstractNamedDiffable; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.SimpleDiffable; @@ -23,6 +22,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterStateUpdateStats; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -1930,13 +1930,12 @@ private ClusterState buildNewClusterStateWithVotingConfigExclusion( ) { DiscoveryNodes newNodes = DiscoveryNodes.builder(currentState.nodes()) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "resolvableNodeName", "resolvableNodeId", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ) ) .build(); diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/FollowersCheckerTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/FollowersCheckerTests.java index 69fd6ef2758ef..cfabd20baf674 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/FollowersCheckerTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/FollowersCheckerTests.java @@ -785,7 +785,7 @@ private static List randomNodes(final int numNodes) { } private static DiscoveryNode newNode(int nodeId, Map attributes, Set roles) { - return new DiscoveryNode("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles, Version.CURRENT); + return TestDiscoveryNode.create("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles); } private static Settings randomSettings() { diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinExecutorTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinExecutorTests.java index 0f7f1d827be89..807b865b107f0 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinExecutorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinExecutorTests.java @@ -443,13 +443,12 @@ public void testUpdatesVotingConfigExclusionsIfNeeded() throws Exception { final var executor = new NodeJoinExecutor(allocationService, rerouteService); final var masterNode = TestDiscoveryNode.create(UUIDs.randomBase64UUID(random())); - final var otherNode = new DiscoveryNode( + final var otherNode = TestDiscoveryNode.create( UUIDs.randomBase64UUID(random()), UUIDs.randomBase64UUID(random()), buildNewFakeTransportAddress(), Map.of(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); var clusterState = ClusterState.builder(ClusterName.DEFAULT) diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java index 6bd421c4414cb..1999fcd9ec1bb 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.Build; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.ClusterName; @@ -21,6 +20,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.FakeThreadPoolMasterService; import org.elasticsearch.cluster.service.MasterService; import org.elasticsearch.cluster.service.MasterServiceTests; @@ -251,7 +251,7 @@ protected DiscoveryNode newNode(int i, boolean master) { roles = Set.of(); } final String prefix = master ? "master_" : "data_"; - return new DiscoveryNode(prefix + i, i + "", buildNewFakeTransportAddress(), emptyMap(), roles, Version.CURRENT); + return TestDiscoveryNode.create(prefix + i, i + "", buildNewFakeTransportAddress(), emptyMap(), roles); } private Future joinNodeAsync(final JoinRequest joinRequest) { @@ -528,13 +528,12 @@ public void testJoinUpdateVotingConfigExclusion() throws Exception { () -> new StatusInfo(HEALTHY, "healthy-info") ); - DiscoveryNode knownJoiningNode = new DiscoveryNode( + DiscoveryNode knownJoiningNode = TestDiscoveryNode.create( "knownNodeName", "newNodeId", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); long newTerm = initialTerm + randomLongBetween(1, 10); long newerTerm = newTerm + randomLongBetween(1, 10); diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java index dd81751bbd27e..f48c9e5947533 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/PublicationTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.coordination; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.SubscribableListener; import org.elasticsearch.cluster.ClusterState; @@ -16,6 +15,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.Nullable; @@ -534,7 +534,7 @@ private static List randomNodes(final int numNodes) { } private static DiscoveryNode newNode(int nodeId, Map attributes, Set roles) { - return new DiscoveryNode("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles, Version.CURRENT); + return TestDiscoveryNode.create("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles); } public static Collector> shuffle() { diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/StableMasterHealthIndicatorServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/StableMasterHealthIndicatorServiceTests.java index 17b19b5d89894..4d646327bfe77 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/StableMasterHealthIndicatorServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/StableMasterHealthIndicatorServiceTests.java @@ -8,14 +8,13 @@ package org.elasticsearch.cluster.coordination; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesReference; @@ -63,30 +62,9 @@ public class StableMasterHealthIndicatorServiceTests extends AbstractCoordinator @Before public void setup() throws Exception { - node1 = new DiscoveryNode( - "node1", - randomNodeId(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); - node2 = new DiscoveryNode( - "node2", - randomNodeId(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); - node3 = new DiscoveryNode( - "node3", - randomNodeId(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); + node1 = TestDiscoveryNode.create("node1", randomNodeId()); + node2 = TestDiscoveryNode.create("node2", randomNodeId()); + node3 = TestDiscoveryNode.create("node3", randomNodeId()); nullMasterClusterState = createClusterState(null); node1MasterClusterState = createClusterState(node1); node2MasterClusterState = createClusterState(node2); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/DesiredNodesTestCase.java b/server/src/test/java/org/elasticsearch/cluster/metadata/DesiredNodesTestCase.java index 69dc49bb0dd0f..a1977e9fe65ef 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/DesiredNodesTestCase.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/DesiredNodesTestCase.java @@ -13,14 +13,13 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.test.ESTestCase; -import java.util.Collections; import java.util.List; import java.util.Set; @@ -175,14 +174,7 @@ public static ClusterState createClusterStateWithDiscoveryNodesAndDesiredNodes( } public static DiscoveryNode newDiscoveryNode(String nodeName) { - return new DiscoveryNode( - nodeName, - UUIDs.randomBase64UUID(random()), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); + return TestDiscoveryNode.create(nodeName, UUIDs.randomBase64UUID(random())); } public static double randomNumberOfProcessors() { diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceTests.java index 200fd596b4cbf..45430a8800d6a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/TemplateUpgradeServiceTests.java @@ -18,9 +18,9 @@ import org.elasticsearch.client.internal.IndicesAdminClient; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; @@ -334,9 +334,7 @@ public void clusterChanged(ClusterChangedEvent event) { ClusterState state = ClusterState.builder(prevState) .nodes( DiscoveryNodes.builder() - .add( - new DiscoveryNode("node1", "node1", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES, Version.CURRENT) - ) + .add(TestDiscoveryNode.create("node1", "node1", buildNewFakeTransportAddress(), emptyMap(), MASTER_DATA_ROLES)) .localNodeId("node1") .masterNodeId("node1") .build() diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeFiltersTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeFiltersTests.java index f10c4e75d02d9..22f2871568631 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeFiltersTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeFiltersTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.node; -import org.elasticsearch.Version; import org.elasticsearch.common.network.InetAddresses; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -51,10 +50,10 @@ public void testNameMatch() { Settings settings = Settings.builder().put("xxx.name", "name1").build(); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertThat(filters.match(node), equalTo(true)); - node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + node = TestDiscoveryNode.create("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertThat(filters.match(node), equalTo(false)); } @@ -62,10 +61,10 @@ public void testIdMatch() { Settings settings = Settings.builder().put("xxx._id", "id1").build(); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertThat(filters.match(node), equalTo(true)); - node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + node = TestDiscoveryNode.create("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertThat(filters.match(node), equalTo(false)); } @@ -73,14 +72,13 @@ public void testIdOrNameMatch() { Settings settings = shuffleSettings(Settings.builder().put("xxx._id", "id1,blah").put("xxx.name", "blah,name2").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - final Version version = Version.CURRENT; - DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version); + DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), null); assertThat(filters.match(node), equalTo(true)); - node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version); + node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), emptyMap(), emptySet(), null); assertThat(filters.match(node), equalTo(true)); - node = new DiscoveryNode("name3", "id3", buildNewFakeTransportAddress(), emptyMap(), emptySet(), version); + node = new DiscoveryNode("name3", "id3", buildNewFakeTransportAddress(), emptyMap(), emptySet(), null); assertThat(filters.match(node), equalTo(false)); } @@ -91,24 +89,24 @@ public void testTagAndGroupMatch() { Map attributes = new HashMap<>(); attributes.put("tag", "A"); attributes.put("group", "B"); - DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), attributes, emptySet(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", buildNewFakeTransportAddress(), attributes, emptySet()); assertThat(filters.match(node), equalTo(true)); attributes = new HashMap<>(); attributes.put("tag", "A"); attributes.put("group", "B"); attributes.put("name", "X"); - node = new DiscoveryNode("name2", "id2", buildNewFakeTransportAddress(), attributes, emptySet(), Version.CURRENT); + node = TestDiscoveryNode.create("name2", "id2", buildNewFakeTransportAddress(), attributes, emptySet()); assertThat(filters.match(node), equalTo(true)); attributes = new HashMap<>(); attributes.put("tag", "A"); attributes.put("group", "F"); attributes.put("name", "X"); - node = new DiscoveryNode("name3", "id3", buildNewFakeTransportAddress(), attributes, emptySet(), Version.CURRENT); + node = TestDiscoveryNode.create("name3", "id3", buildNewFakeTransportAddress(), attributes, emptySet()); assertThat(filters.match(node), equalTo(false)); - node = new DiscoveryNode("name4", "id4", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + node = TestDiscoveryNode.create("name4", "id4", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertThat(filters.match(node), equalTo(false)); } @@ -116,7 +114,7 @@ public void testStarMatch() { Settings settings = Settings.builder().put("xxx.name", "*").build(); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", buildNewFakeTransportAddress(), emptyMap(), emptySet()); assertThat(filters.match(node), equalTo(true)); } diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java index ba8994fe93aa5..154302ae79166 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeTests.java @@ -40,13 +40,12 @@ public class DiscoveryNodeTests extends ESTestCase { public void testRolesAreSorted() { final Set roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.roles())); - final DiscoveryNode node = new DiscoveryNode( + final DiscoveryNode node = TestDiscoveryNode.create( "name", "id", new TransportAddress(TransportAddress.META_ADDRESS, 9200), emptyMap(), - roles, - Version.CURRENT + roles ); DiscoveryNodeRole previous = null; for (final DiscoveryNodeRole current : node.getRoles()) { @@ -63,7 +62,7 @@ public void testDiscoveryNodeIsCreatedWithHostFromInetAddress() throws Exception ? InetAddress.getByName("192.0.2.1") : InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1 }); TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535)); - DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", transportAddress, emptyMap(), emptySet()); assertEquals(transportAddress.address().getHostString(), node.getHostName()); assertEquals(transportAddress.getAddress(), node.getHostAddress()); } @@ -71,7 +70,7 @@ public void testDiscoveryNodeIsCreatedWithHostFromInetAddress() throws Exception public void testDiscoveryNodeSerializationKeepsHost() throws Exception { InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1 }); TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535)); - DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", transportAddress, emptyMap(), emptySet()); BytesStreamOutput streamOutput = new BytesStreamOutput(); streamOutput.setTransportVersion(TransportVersion.CURRENT); @@ -92,14 +91,7 @@ public void testDiscoveryNodeRoleWithOldVersion() throws Exception { DiscoveryNodeRole customRole = new DiscoveryNodeRole("data_custom_role", "z", true); - DiscoveryNode node = new DiscoveryNode( - "name1", - "id1", - transportAddress, - emptyMap(), - Collections.singleton(customRole), - Version.CURRENT - ); + DiscoveryNode node = TestDiscoveryNode.create("name1", "id1", transportAddress, emptyMap(), Collections.singleton(customRole)); { BytesStreamOutput streamOutput = new BytesStreamOutput(); diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index e69614983a15d..d18af5b97c83d 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -322,7 +322,7 @@ private static DiscoveryNodes buildDiscoveryNodes() { } private static DiscoveryNode newNode(int nodeId, Map attributes, Set roles) { - return new DiscoveryNode("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles, Version.CURRENT); + return TestDiscoveryNode.create("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles); } private enum NodeSelector { diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/RoutingNodeTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/RoutingNodeTests.java index 15bd91d9a561e..65a740ad3319f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/RoutingNodeTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/RoutingNodeTests.java @@ -8,9 +8,9 @@ package org.elasticsearch.cluster.routing; -import org.elasticsearch.Version; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.index.Index; import org.elasticsearch.index.shard.ShardId; @@ -45,7 +45,7 @@ public void setUp() throws Exception { super.setUp(); InetAddress inetAddress = InetAddress.getByAddress("name1", new byte[] { (byte) 192, (byte) 168, (byte) 0, (byte) 1 }); TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535)); - DiscoveryNode discoveryNode = new DiscoveryNode("name1", "node-1", transportAddress, emptyMap(), emptySet(), Version.CURRENT); + DiscoveryNode discoveryNode = TestDiscoveryNode.create("name1", "node-1", transportAddress, emptyMap(), emptySet()); routingNode = RoutingNodesHelper.routingNode("node1", discoveryNode, unassignedShard0, initializingShard0, relocatingShard0); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java index b716dd1c83243..2fdac9bbef279 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/DataTierTests.java @@ -8,10 +8,10 @@ package org.elasticsearch.cluster.routing.allocation; -import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.allocation.DataTier.DataTierSettingValidator; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; @@ -137,7 +137,7 @@ private static DiscoveryNodes buildDiscoveryNodes() { } private static DiscoveryNode newNode(int nodeId, Map attributes, Set roles) { - return new DiscoveryNode("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles, Version.CURRENT); + return TestDiscoveryNode.create("name_" + nodeId, "node_" + nodeId, buildNewFakeTransportAddress(), attributes, roles); } private static List randomNodes(final int numNodes) { diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java index 2fe8e008edca1..612f8ca6ba5d3 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/ClusterAllocationSimulationTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingTable; @@ -187,7 +188,7 @@ public void testBalanceQuality() throws IOException { final var discoveryNodesBuilder = new DiscoveryNodes.Builder(); discoveryNodesBuilder.add( - new DiscoveryNode("master", "master", buildNewFakeTransportAddress(), Map.of(), Set.of(MASTER_ROLE), Version.CURRENT) + TestDiscoveryNode.create("master", "master", buildNewFakeTransportAddress(), Map.of(), Set.of(MASTER_ROLE)) ).localNodeId("master").masterNodeId("master"); for (var nodeIndex = 0; nodeIndex < nodeCountByTier.get(DataTier.DATA_HOT) + nodeCountByTier.get(DataTier.DATA_WARM) + nodeCountByTier.get(DataTier.DATA_COLD); nodeIndex++) { @@ -197,13 +198,12 @@ public void testBalanceQuality() throws IOException { final var nodeId = Strings.format("node-%s-%03d", tierRole.roleNameAbbreviation(), nodeIndex); discoveryNodesBuilder.add( - new DiscoveryNode( + TestDiscoveryNode.create( nodeId, nodeId, buildNewFakeTransportAddress(), Map.of("fake_tier", tierRole.roleName()), - Set.of(tierRole), - Version.CURRENT + Set.of(tierRole) ) ); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java index 02a516fb06fbd..665c3598e757e 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/allocator/DesiredBalanceReconcilerTests.java @@ -1147,13 +1147,12 @@ private static DiscoveryNodes discoveryNodes(int nodeCount) { final var discoveryNodes = DiscoveryNodes.builder(); for (var i = 0; i < nodeCount; i++) { discoveryNodes.add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-" + i, "node-" + i, buildNewFakeTransportAddress(), Map.of(), - Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE) ) ); } diff --git a/server/src/test/java/org/elasticsearch/health/node/DiskHealthIndicatorServiceTests.java b/server/src/test/java/org/elasticsearch/health/node/DiskHealthIndicatorServiceTests.java index 7e61045f806e4..e918dfe087ae7 100644 --- a/server/src/test/java/org/elasticsearch/health/node/DiskHealthIndicatorServiceTests.java +++ b/server/src/test/java/org/elasticsearch/health/node/DiskHealthIndicatorServiceTests.java @@ -17,6 +17,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; @@ -510,16 +511,7 @@ public void testRedNodesWithoutAnyBlockedIndices() throws IOException { public void testMissingHealthInfo() { Set discoveryNodes = createNodesWithAllRoles(); Set discoveryNodesInClusterState = new HashSet<>(discoveryNodes); - discoveryNodesInClusterState.add( - new DiscoveryNode( - randomAlphaOfLength(30), - UUID.randomUUID().toString(), - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ) - ); + discoveryNodesInClusterState.add(TestDiscoveryNode.create(randomAlphaOfLength(30), UUID.randomUUID().toString())); ClusterService clusterService = createClusterService(discoveryNodesInClusterState, false); DiskHealthIndicatorService diskHealthIndicatorService = new DiskHealthIndicatorService(clusterService); { @@ -1000,13 +992,12 @@ private Set createNodes(int numberOfNodes, Set Set discoveryNodes = new HashSet<>(); for (int i = 0; i < numberOfNodes; i++) { discoveryNodes.add( - new DiscoveryNode( + TestDiscoveryNode.create( randomAlphaOfLength(30), UUID.randomUUID().toString(), buildNewFakeTransportAddress(), Collections.emptyMap(), - roles, - Version.CURRENT + roles ) ); } diff --git a/server/src/test/java/org/elasticsearch/health/node/LocalHealthMonitorTests.java b/server/src/test/java/org/elasticsearch/health/node/LocalHealthMonitorTests.java index b3fed1ad2326d..a22d4cfb45b42 100644 --- a/server/src/test/java/org/elasticsearch/health/node/LocalHealthMonitorTests.java +++ b/server/src/test/java/org/elasticsearch/health/node/LocalHealthMonitorTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.health.node; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.node.stats.NodeStats; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; @@ -20,6 +19,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.ShardRoutingState; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.ClusterSettings; @@ -89,21 +89,13 @@ public void setUp() throws Exception { .build(), HealthMetadata.ShardLimits.newBuilder().maxShardsPerNode(999).maxShardsPerNodeFrozen(100).build() ); - node = new DiscoveryNode( - "node", - "node", - ESTestCase.buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); - frozenNode = new DiscoveryNode( + node = TestDiscoveryNode.create("node", "node"); + frozenNode = TestDiscoveryNode.create( "frozen-node", "frozen-node", ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), - Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE) ); clusterState = ClusterStateCreationUtils.state(node, node, node, new DiscoveryNode[] { node, frozenNode }) .copyAndUpdate(b -> b.putCustom(HealthMetadata.TYPE, healthMetadata)); @@ -311,13 +303,12 @@ public void testFrozenRedDiskStatus() { } public void testYellowStatusForNonDataNode() { - DiscoveryNode dedicatedMasterNode = new DiscoveryNode( + DiscoveryNode dedicatedMasterNode = TestDiscoveryNode.create( "master-node", "master-node-1", ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); clusterState = ClusterStateCreationUtils.state( dedicatedMasterNode, @@ -339,13 +330,12 @@ public void testHasRelocatingShards() { DiscoveryNode localNode = state.nodes().getLocalNode(); assertThat(LocalHealthMonitor.DiskCheck.hasRelocatingShards(state, localNode), is(true)); - DiscoveryNode dedicatedMasterNode = new DiscoveryNode( + DiscoveryNode dedicatedMasterNode = TestDiscoveryNode.create( "master-node", "master-node-1", ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); ClusterState newState = ClusterState.builder(state) .nodes(new DiscoveryNodes.Builder(state.nodes()).add(dedicatedMasterNode)) diff --git a/server/src/test/java/org/elasticsearch/health/node/ShardsCapacityHealthIndicatorServiceTests.java b/server/src/test/java/org/elasticsearch/health/node/ShardsCapacityHealthIndicatorServiceTests.java index f55fede31659d..b1a849413c374 100644 --- a/server/src/test/java/org/elasticsearch/health/node/ShardsCapacityHealthIndicatorServiceTests.java +++ b/server/src/test/java/org/elasticsearch/health/node/ShardsCapacityHealthIndicatorServiceTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -74,22 +75,20 @@ public class ShardsCapacityHealthIndicatorServiceTests extends ESTestCase { public void setUp() throws Exception { super.setUp(); - dataNode = new DiscoveryNode( + dataNode = TestDiscoveryNode.create( "data_node", "data_node", ESTestCase.buildNewFakeTransportAddress(), Map.of(), - Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE) ); - frozenNode = new DiscoveryNode( + frozenNode = TestDiscoveryNode.create( "frozen_node", "frozen_node", ESTestCase.buildNewFakeTransportAddress(), Map.of(), - Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.DATA_FROZEN_NODE_ROLE) ); clusterService = ClusterServiceUtils.createClusterService(threadPool); diff --git a/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java b/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java index 6678e71405127..efdae20923f03 100644 --- a/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java +++ b/server/src/test/java/org/elasticsearch/index/IndexModuleTests.java @@ -31,7 +31,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; @@ -706,21 +706,7 @@ public void onIndexCommitDelete(ShardId shardId, IndexCommit deletedCommit) { IndexShard indexShard = indexService.createShard(shardRouting, s -> {}, RetentionLeaseSyncer.EMPTY); closeables.add(() -> indexShard.close("close shard at end of test", true)); - indexShard.markAsRecovering( - "test", - new RecoveryState( - shardRouting, - new DiscoveryNode( - "_node_id", - "_node_id", - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ), - null - ) - ); + indexShard.markAsRecovering("test", new RecoveryState(shardRouting, TestDiscoveryNode.create("_node_id", "_node_id"), null)); final PlainActionFuture recoveryFuture = PlainActionFuture.newFuture(); indexShard.recoverFromStore(recoveryFuture); diff --git a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java index 3bb08696ca2e5..da2b51ae96d17 100644 --- a/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java +++ b/server/src/test/java/org/elasticsearch/indices/cluster/IndicesClusterStateServiceRandomUpdatesTests.java @@ -9,7 +9,6 @@ package org.elasticsearch.indices.cluster; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.action.admin.cluster.reroute.ClusterRerouteRequest; import org.elasticsearch.action.admin.indices.close.CloseIndexRequest; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; @@ -30,6 +29,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; import org.elasticsearch.cluster.routing.ShardRoutingState; @@ -500,7 +500,7 @@ protected DiscoveryNode createNode(DiscoveryNodeRole... mustHaveRoles) { Set roles = new HashSet<>(randomSubsetOf(DiscoveryNodeRole.roles())); Collections.addAll(roles, mustHaveRoles); final String id = format("node_%03d", nodeIdGenerator.incrementAndGet()); - return new DiscoveryNode(id, id, buildNewFakeTransportAddress(), Collections.emptyMap(), roles, Version.CURRENT); + return TestDiscoveryNode.create(id, id, buildNewFakeTransportAddress(), Collections.emptyMap(), roles); } private static ClusterState adaptClusterStateToLocalNode(ClusterState state, DiscoveryNode node) { diff --git a/server/src/test/java/org/elasticsearch/readiness/ReadinessServiceTests.java b/server/src/test/java/org/elasticsearch/readiness/ReadinessServiceTests.java index 85f6ac236e289..df6acb4352d35 100644 --- a/server/src/test/java/org/elasticsearch/readiness/ReadinessServiceTests.java +++ b/server/src/test/java/org/elasticsearch/readiness/ReadinessServiceTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.readiness; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterChangedEvent; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; @@ -18,6 +17,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.settings.ClusterSettings; @@ -55,13 +55,12 @@ static class FakeHttpTransport extends AbstractLifecycleComponent implements Htt final DiscoveryNode node; FakeHttpTransport() { - node = new DiscoveryNode( + node = TestDiscoveryNode.create( "local", "local", buildNewFakeTransportAddress(), emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE) ); } diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestPluginsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestPluginsActionTests.java index 39b5ffb51860c..7c82edca96339 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestPluginsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestPluginsActionTests.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.Table; import org.elasticsearch.plugins.PluginDescriptor; import org.elasticsearch.plugins.PluginRuntimeInfo; @@ -88,6 +89,6 @@ private Table buildTable(List pluginDescriptor) { } private DiscoveryNode node(final int id) { - return new DiscoveryNode("node-" + id, Integer.toString(id), buildNewFakeTransportAddress(), Map.of(), Set.of(), Version.CURRENT); + return TestDiscoveryNode.create("node-" + id, Integer.toString(id), buildNewFakeTransportAddress(), Map.of(), Set.of()); } } diff --git a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java index 06360a0516b8e..22438f46b61fa 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java +++ b/server/src/test/java/org/elasticsearch/snapshots/SnapshotResiliencyTests.java @@ -12,7 +12,6 @@ import org.apache.logging.log4j.Logger; import org.apache.lucene.util.SetOnce; import org.elasticsearch.ExceptionsHelper; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; @@ -111,6 +110,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.BatchedRerouteService; import org.elasticsearch.cluster.routing.RerouteService; import org.elasticsearch.cluster.routing.ShardRouting; @@ -1464,13 +1464,12 @@ private TestClusterNode newDataNode(String nodeName) throws IOException { private TestClusterNode newNode(String nodeName, DiscoveryNodeRole role) throws IOException { return new TestClusterNode( - new DiscoveryNode( + TestDiscoveryNode.create( nodeName, randomAlphaOfLength(10), buildNewFakeTransportAddress(), emptyMap(), - Collections.singleton(role), - Version.CURRENT + Collections.singleton(role) ) ); } @@ -2150,7 +2149,7 @@ public void restart() { scheduleSoon(() -> { try { final TestClusterNode restartedNode = new TestClusterNode( - new DiscoveryNode(node.getName(), node.getId(), node.getAddress(), emptyMap(), node.getRoles(), Version.CURRENT) + TestDiscoveryNode.create(node.getName(), node.getId(), node.getAddress(), emptyMap(), node.getRoles()) ); nodes.put(node.getName(), restartedNode); restartedNode.start(oldState); diff --git a/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java b/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java index d7e2044010761..9f6473da8ad01 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportServiceLifecycleTests.java @@ -10,9 +10,8 @@ import org.elasticsearch.ElasticsearchException; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; -import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.core.Releasable; @@ -142,13 +141,12 @@ public ExecutorService executor(String name) { tcpTransport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, - boundTransportAddress -> new DiscoveryNode( + boundTransportAddress -> TestDiscoveryNode.create( nodeName, nodeName, tcpTransport.boundAddress().publishAddress(), emptyMap(), - emptySet(), - Version.CURRENT + emptySet() ), null, emptySet() diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java b/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java index c5081c2cae645..e9cf8a0c98db6 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java @@ -29,6 +29,17 @@ public static DiscoveryNode create(String id) { ); } + public static DiscoveryNode create(String name, String id) { + return new DiscoveryNode( + name, + id, + ESTestCase.buildNewFakeTransportAddress(), + Collections.emptyMap(), + DiscoveryNodeRole.roles(), + null + ); + } + public static DiscoveryNode create(String id, TransportAddress address) { return new DiscoveryNode("", id, address, Collections.emptyMap(), DiscoveryNodeRole.roles(), null); } @@ -50,4 +61,14 @@ public static DiscoveryNode create( ) { return new DiscoveryNode("", id, address, attributes, roles, version); } + + public static DiscoveryNode create( + String nodeName, + String nodeId, + TransportAddress address, + Map attributes, + Set roles + ) { + return new DiscoveryNode(nodeName, nodeId, address, attributes, roles, null); + } } diff --git a/test/framework/src/main/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java index b4d0ed73c4c17..9470027a7963e 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/replication/ESIndexLevelReplicationTestCase.java @@ -41,6 +41,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.AllocationId; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RecoverySource; @@ -149,13 +150,12 @@ IndexRequest copyIndexRequest(IndexRequest inRequest) throws IOException { } protected DiscoveryNode getDiscoveryNode(String id) { - return new DiscoveryNode( + return TestDiscoveryNode.create( id, id, buildNewFakeTransportAddress(), Collections.emptyMap(), - Collections.singleton(DiscoveryNodeRole.DATA_ROLE), - Version.CURRENT + Collections.singleton(DiscoveryNodeRole.DATA_ROLE) ); } diff --git a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java index b7701625f6fc4..d82673ba1f56b 100644 --- a/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/index/shard/IndexShardTestCase.java @@ -17,7 +17,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.MappingMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; @@ -703,14 +703,7 @@ protected void recoveryEmptyReplica(IndexShard replica, boolean startReplica) th } protected DiscoveryNode getFakeDiscoNode(String id) { - return new DiscoveryNode( - id, - id, - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); + return TestDiscoveryNode.create(id, id); } /** recovers a replica from the given primary **/ diff --git a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java index 9ecbc485c2b25..e46e35aad11a0 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ClusterServiceUtils.java @@ -11,7 +11,6 @@ import org.apache.logging.log4j.core.util.Throwables; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.TransportVersion; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.ClusterName; @@ -23,8 +22,8 @@ import org.elasticsearch.cluster.block.ClusterBlocks; import org.elasticsearch.cluster.coordination.ClusterStatePublisher; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterApplier; import org.elasticsearch.cluster.service.ClusterApplierService; import org.elasticsearch.cluster.service.ClusterService; @@ -112,14 +111,7 @@ public static ClusterService createClusterService(ThreadPool threadPool, Discove } public static ClusterService createClusterService(ThreadPool threadPool, ClusterSettings clusterSettings) { - DiscoveryNode discoveryNode = new DiscoveryNode( - "node", - "node", - ESTestCase.buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ); + DiscoveryNode discoveryNode = TestDiscoveryNode.create("node", "node"); return createClusterService(threadPool, discoveryNode, clusterSettings); } diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodesInfoServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodesInfoServiceTests.java index 97286b42d9e2e..3adefc0fd86ae 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodesInfoServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/capacity/nodeinfo/AutoscalingNodesInfoServiceTests.java @@ -29,6 +29,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.ClusterSettings; @@ -564,7 +565,7 @@ private DiscoveryNode newNode(String nodeName) { } private DiscoveryNode newNode(String nodeName, Set roles) { - return new DiscoveryNode(nodeName, UUIDs.randomBase64UUID(), buildNewFakeTransportAddress(), Map.of(), roles, Version.CURRENT); + return TestDiscoveryNode.create(nodeName, UUIDs.randomBase64UUID(), buildNewFakeTransportAddress(), Map.of(), roles); } private DiscoveryNode restartNode(DiscoveryNode node) { diff --git a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java index 0bc93bba3c793..92c8298a62e7b 100644 --- a/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java +++ b/x-pack/plugin/autoscaling/src/test/java/org/elasticsearch/xpack/autoscaling/storage/ReactiveStorageDeciderServiceTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.cluster.node.DiscoveryNodeFilters; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.RoutingNode; @@ -486,16 +487,7 @@ static void addNode(ClusterState.Builder stateBuilder) { static void addNode(ClusterState.Builder stateBuilder, DiscoveryNodeRole role) { stateBuilder.nodes( DiscoveryNodes.builder(stateBuilder.nodes()) - .add( - new DiscoveryNode( - "test", - UUIDs.randomBase64UUID(), - buildNewFakeTransportAddress(), - Map.of(), - Set.of(role), - Version.CURRENT - ) - ) + .add(TestDiscoveryNode.create("test", UUIDs.randomBase64UUID(), buildNewFakeTransportAddress(), Map.of(), Set.of(role))) ); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java index 54b9c33f1b625..9a7335171ac41 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/SetSingleNodeAllocateStepTests.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.ShardRoutingState; @@ -392,13 +393,12 @@ public void testPerformActionSomeShardsOnlyOnNewNodes() throws Exception { Settings nodeSettings = Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), nodeName).build(); newNodeIds.add(nodeId); nodes.add( - new DiscoveryNode( + TestDiscoveryNode.create( Node.NODE_NAME_SETTING.get(nodeSettings), nodeId, new TransportAddress(TransportAddress.META_ADDRESS, nodePort), Node.NODE_ATTRIBUTES.getAsMap(nodeSettings), - DiscoveryNode.getRolesFromSettings(nodeSettings), - Version.CURRENT + DiscoveryNode.getRolesFromSettings(nodeSettings) ) ); } @@ -462,13 +462,12 @@ public void testPerformActionSomeShardsOnlyOnNewNodesButNewNodesInvalidAttrs() { .build(); newNodeIds.add(nodeId); nodes.add( - new DiscoveryNode( + TestDiscoveryNode.create( Node.NODE_NAME_SETTING.get(nodeSettings), nodeId, new TransportAddress(TransportAddress.META_ADDRESS, nodePort), Node.NODE_ATTRIBUTES.getAsMap(nodeSettings), - DiscoveryNode.getRolesFromSettings(nodeSettings), - Version.CURRENT + DiscoveryNode.getRolesFromSettings(nodeSettings) ) ); } @@ -533,13 +532,12 @@ public void testPerformActionNewShardsExistButWithInvalidAttributes() throws Exc .build(); newNodeIds.add(nodeId); nodes.add( - new DiscoveryNode( + TestDiscoveryNode.create( Node.NODE_NAME_SETTING.get(nodeSettings), nodeId, new TransportAddress(TransportAddress.META_ADDRESS, nodePort), Node.NODE_ATTRIBUTES.getAsMap(nodeSettings), - DiscoveryNode.getRolesFromSettings(nodeSettings), - Version.CURRENT + DiscoveryNode.getRolesFromSettings(nodeSettings) ) ); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForDataTierStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForDataTierStepTests.java index c0fb29be28aec..edd4dba7f5a33 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForDataTierStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/WaitForDataTierStepTests.java @@ -7,12 +7,11 @@ package org.elasticsearch.xpack.core.ilm; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.allocation.DataTier; import org.elasticsearch.common.Strings; import org.elasticsearch.common.UUIDs; @@ -93,15 +92,14 @@ private ClusterState state(Collection roles) { DiscoveryNodes.Builder builder = DiscoveryNodes.builder(); IntStream.range(0, between(1, 5)) .mapToObj( - i -> new DiscoveryNode( + i -> TestDiscoveryNode.create( "node_" + i, UUIDs.randomBase64UUID(), buildNewFakeTransportAddress(), Map.of(), randomSubsetOf(between(1, roles.size()), roles).stream() .map(DiscoveryNodeRole::getRoleFromRoleName) - .collect(Collectors.toSet()), - Version.CURRENT + .collect(Collectors.toSet()) ) ) .forEach(builder::add); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java index 7f7c30dc81b2c..99251b7d251c1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/action/GetDatafeedStatsActionResponseTests.java @@ -6,7 +6,6 @@ */ package org.elasticsearch.xpack.core.ml.action; -import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.bytes.BytesReference; @@ -89,7 +88,7 @@ public void testDatafeedStatsToXContent() throws IOException { attributes.put("non-ml-attribute", "should be filtered out"); TransportAddress transportAddress = new TransportAddress(TransportAddress.META_ADDRESS, 9000); - DiscoveryNode node = new DiscoveryNode("df-node-name", "df-node-id", transportAddress, attributes, Set.of(), Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("df-node-name", "df-node-id", transportAddress, attributes, Set.of()); DatafeedTimingStats timingStats = new DatafeedTimingStats( "my-job-id", diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java index 04e9c8efe75d1..9321e367a49fb 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodesDeprecationCheckResponseTests.java @@ -7,10 +7,10 @@ package org.elasticsearch.xpack.deprecation; -import org.elasticsearch.Version; import org.elasticsearch.action.FailedNodeException; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.core.Tuple; @@ -69,13 +69,12 @@ private static DiscoveryNode randomDiscoveryNode() throws Exception { ); TransportAddress transportAddress = new TransportAddress(inetAddress, randomIntBetween(0, 65535)); - return new DiscoveryNode( + return TestDiscoveryNode.create( randomAlphaOfLength(5), randomAlphaOfLength(5), transportAddress, Collections.emptyMap(), - Collections.emptySet(), - Version.CURRENT + Collections.emptySet() ); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlLifeCycleServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlLifeCycleServiceTests.java index 99e34cacbe8fe..9f373ea67a4ff 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlLifeCycleServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlLifeCycleServiceTests.java @@ -10,9 +10,9 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; @@ -189,33 +189,30 @@ public void testSignalGracefulShutdownIncludingLocalNode() { // Local node is node-2 here DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-1-name", "node-1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-2-name", "node-2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-3-name", "node-3", new TransportAddress(InetAddress.getLoopbackAddress(), 9302), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ) .masterNodeId("node-1") @@ -254,33 +251,30 @@ public void testSignalGracefulShutdownExcludingLocalNode() { // Local node is node-2 here DiscoveryNodes.Builder nodesBuilder = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-1-name", "node-1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-2-name", "node-2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node-3-name", "node-3", new TransportAddress(InetAddress.getLoopbackAddress(), 9302), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ) .masterNodeId("node-1") diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/autoscaling/MlProcessorAutoscalingDeciderTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/autoscaling/MlProcessorAutoscalingDeciderTests.java index 5711599a596da..80789280ba302 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/autoscaling/MlProcessorAutoscalingDeciderTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/autoscaling/MlProcessorAutoscalingDeciderTests.java @@ -7,13 +7,13 @@ package org.elasticsearch.xpack.ml.autoscaling; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; @@ -537,7 +537,7 @@ public void testScale_GivenLowPriorityDeploymentsOnly() { } private static DiscoveryNode buildNode(String name, boolean isML, double allocatedProcessors) { - return new DiscoveryNode( + return TestDiscoveryNode.create( name, name, buildNewFakeTransportAddress(), @@ -545,8 +545,7 @@ private static DiscoveryNode buildNode(String name, boolean isML, double allocat .put(MachineLearning.MAX_JVM_SIZE_NODE_ATTR, String.valueOf(10)) .put(MachineLearning.ALLOCATED_PROCESSORS_NODE_ATTR, String.valueOf(allocatedProcessors)) .map(), - isML ? DiscoveryNodeRole.roles() : Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE), - Version.CURRENT + isML ? DiscoveryNodeRole.roles() : Set.of(DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.MASTER_ROLE) ); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java index 0a4bc016ed18b..e55b9d6369a78 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedNodeSelectorTests.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.RecoverySource; @@ -70,13 +71,12 @@ public void init() { resolver = TestIndexNameExpressionResolver.newInstance(); nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node_name", "node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - Collections.emptySet(), - Version.CURRENT + Collections.emptySet() ) ) .build(); @@ -740,13 +740,12 @@ Collection makeCandidateNodes(String... nodeIds) { int port = 9300; for (String nodeId : nodeIds) { candidateNodes.add( - new DiscoveryNode( + TestDiscoveryNode.create( nodeId + "-name", nodeId, new TransportAddress(InetAddress.getLoopbackAddress(), port++), Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ) ); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedRunnerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedRunnerTests.java index 1d2773397d802..76b177b67c161 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedRunnerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/datafeed/DatafeedRunnerTests.java @@ -6,7 +6,6 @@ */ package org.elasticsearch.xpack.ml.datafeed; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterChangedEvent; @@ -16,6 +15,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; @@ -94,13 +94,12 @@ public void setUpTests() { PersistentTasksCustomMetadata tasks = tasksBuilder.build(); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node_name", "node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - Collections.emptySet(), - Version.CURRENT + Collections.emptySet() ) ) .build(); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentNodeServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentNodeServiceTests.java index 67fb90475f6b0..66ef229de6f43 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentNodeServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentNodeServiceTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.ml.inference.assignment; import org.elasticsearch.ResourceNotFoundException; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.search.SearchPhaseExecutionException; import org.elasticsearch.action.search.ShardSearchFailure; @@ -17,9 +16,8 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; @@ -311,19 +309,7 @@ public void testLoadQueuedModelsWhenOneFails() throws InterruptedException { public void testClusterChangedWithResetMode() { final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); - final DiscoveryNodes nodes = DiscoveryNodes.builder() - .localNodeId(NODE_ID) - .add( - new DiscoveryNode( - NODE_ID, - NODE_ID, - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ) - ) - .build(); + final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(TestDiscoveryNode.create(NODE_ID, NODE_ID)).build(); String modelOne = "model-1"; String modelTwo = "model-2"; String notUsedModel = "model-3"; @@ -371,19 +357,7 @@ public void testClusterChangedWithResetMode() { public void testClusterChanged() throws Exception { final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); - final DiscoveryNodes nodes = DiscoveryNodes.builder() - .localNodeId(NODE_ID) - .add( - new DiscoveryNode( - NODE_ID, - NODE_ID, - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ) - ) - .build(); + final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(TestDiscoveryNode.create(NODE_ID, NODE_ID)).build(); String modelOne = "model-1"; String modelTwo = "model-2"; String notUsedModel = "model-3"; @@ -536,19 +510,7 @@ public void testClusterChanged() throws Exception { public void testClusterChanged_GivenAllStartedAssignments_AndNonMatchingTargetAllocations() throws Exception { final TrainedModelAssignmentNodeService trainedModelAssignmentNodeService = createService(); - final DiscoveryNodes nodes = DiscoveryNodes.builder() - .localNodeId(NODE_ID) - .add( - new DiscoveryNode( - NODE_ID, - NODE_ID, - buildNewFakeTransportAddress(), - Collections.emptyMap(), - DiscoveryNodeRole.roles(), - Version.CURRENT - ) - ) - .build(); + final DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId(NODE_ID).add(TestDiscoveryNode.create(NODE_ID, NODE_ID)).build(); String modelOne = "model-1"; String modelTwo = "model-2"; String deploymentOne = "deployment-1"; diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentRebalancerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentRebalancerTests.java index a00fc38d75640..83e794f546dc3 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentRebalancerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/TrainedModelAssignmentRebalancerTests.java @@ -8,9 +8,9 @@ package org.elasticsearch.xpack.ml.inference.assignment; import org.elasticsearch.ResourceAlreadyExistsException; -import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.test.ESTestCase; @@ -1087,7 +1087,7 @@ private static StartTrainedModelDeploymentAction.TaskParams normalPriorityParams } private static DiscoveryNode buildNode(String name, long nativeMemory, int allocatedProcessors) { - return new DiscoveryNode( + return TestDiscoveryNode.create( name, name, buildNewFakeTransportAddress(), @@ -1096,8 +1096,7 @@ private static DiscoveryNode buildNode(String name, long nativeMemory, int alloc .put(MachineLearning.MAX_JVM_SIZE_NODE_ATTR, String.valueOf(10)) .put(MachineLearning.ALLOCATED_PROCESSORS_NODE_ATTR, String.valueOf(allocatedProcessors)) .map(), - DiscoveryNodeRole.roles(), - Version.CURRENT + DiscoveryNodeRole.roles() ); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AllocationReducerTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AllocationReducerTests.java index 20188d12f0598..a516fef49b7de 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AllocationReducerTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/assignment/planning/AllocationReducerTests.java @@ -7,9 +7,8 @@ package org.elasticsearch.xpack.ml.inference.assignment.planning; -import org.elasticsearch.Version; import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.ml.action.StartTrainedModelDeploymentAction; import org.elasticsearch.xpack.core.ml.inference.assignment.Priority; @@ -194,6 +193,6 @@ private static TrainedModelAssignment createAssignment( } private static DiscoveryNode buildNode(String nodeId) { - return new DiscoveryNode(nodeId, nodeId, buildNewFakeTransportAddress(), Map.of(), DiscoveryNodeRole.roles(), Version.CURRENT); + return TestDiscoveryNode.create(nodeId, nodeId); } } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/loadingservice/ModelLoadingServiceTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/loadingservice/ModelLoadingServiceTests.java index 565ebf4a1ccfe..f9e1f7294d3fe 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/loadingservice/ModelLoadingServiceTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/inference/loadingservice/ModelLoadingServiceTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.ml.inference.loadingservice; import org.elasticsearch.ResourceNotFoundException; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.ClusterChangedEvent; @@ -15,9 +14,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.breaker.CircuitBreaker; import org.elasticsearch.common.breaker.CircuitBreakingException; @@ -758,13 +757,12 @@ private static ClusterState.Builder builder(boolean isIngestNode) { .nodes( DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "node_name", "node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - isIngestNode ? Collections.singleton(DiscoveryNodeRole.INGEST_ROLE) : Collections.emptySet(), - Version.CURRENT + isIngestNode ? Collections.singleton(DiscoveryNodeRole.INGEST_ROLE) : Collections.emptySet() ) ) .localNodeId("node_id") diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java index dce64fadf0061..f91385ab9322c 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/JobNodeSelectorTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.Randomness; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.transport.TransportAddress; @@ -83,7 +84,7 @@ public void testNodeNameAndVersion() { TransportAddress ta = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); Map attributes = new HashMap<>(); attributes.put("unrelated", "attribute"); - DiscoveryNode node = new DiscoveryNode("_node_name1", "_node_id1", ta, attributes, ROLES_WITHOUT_ML, Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("_node_name1", "_node_id1", ta, attributes, ROLES_WITHOUT_ML); assertEquals("{_node_name1}{version=" + node.getVersion() + "}", JobNodeSelector.nodeNameAndVersion(node)); } @@ -91,14 +92,14 @@ public void testNodeNameAndMlAttributes() { TransportAddress ta = new TransportAddress(InetAddress.getLoopbackAddress(), 9300); SortedMap attributes = new TreeMap<>(); attributes.put("unrelated", "attribute"); - DiscoveryNode node = new DiscoveryNode("_node_name1", "_node_id1", ta, attributes, ROLES_WITHOUT_ML, Version.CURRENT); + DiscoveryNode node = TestDiscoveryNode.create("_node_name1", "_node_id1", ta, attributes, ROLES_WITHOUT_ML); assertEquals("{_node_name1}", JobNodeSelector.nodeNameAndMlAttributes(node)); attributes.put("ml.machine_memory", "5"); - node = new DiscoveryNode("_node_name1", "_node_id1", ta, attributes, ROLES_WITH_ML, Version.CURRENT); + node = TestDiscoveryNode.create("_node_name1", "_node_id1", ta, attributes, ROLES_WITH_ML); assertEquals("{_node_name1}{ml.machine_memory=5}", JobNodeSelector.nodeNameAndMlAttributes(node)); - node = new DiscoveryNode(null, "_node_id1", ta, attributes, ROLES_WITH_ML, Version.CURRENT); + node = TestDiscoveryNode.create(null, "_node_id1", ta, attributes, ROLES_WITH_ML); assertEquals("{_node_id1}{ml.machine_memory=5}", JobNodeSelector.nodeNameAndMlAttributes(node)); } @@ -458,23 +459,21 @@ public void testSelectLeastLoadedMlNodeForDataFrameAnalyticsJob_firstJobTooBigMe public void testSelectLeastLoadedMlNode_noMlNodes() { DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .build(); @@ -514,33 +513,30 @@ public void testSelectLeastLoadedMlNode_maxConcurrentOpeningJobs() { ); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name3", "_node_id3", new TransportAddress(InetAddress.getLoopbackAddress(), 9302), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -649,33 +645,30 @@ public void testSelectLeastLoadedMlNode_concurrentOpeningJobsAndStaleFailedJob() ); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name3", "_node_id3", new TransportAddress(InetAddress.getLoopbackAddress(), 9302), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -747,23 +740,21 @@ public void testSelectLeastLoadedMlNode_noCompatibleJobTypeNodes() { ); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -807,23 +798,21 @@ public void testSelectLeastLoadedMlNode_reasonsAreInDeterministicOrder() { ); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -991,23 +980,21 @@ public void testSelectMlNodeOnlyOutOfCandidates() { ); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), nodeAttr, - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -1042,23 +1029,21 @@ public void testSelectMlNodeOnlyOutOfCandidates() { public void testConsiderLazyAssignmentWithNoLazyNodes() { DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .build(); @@ -1087,23 +1072,21 @@ public void testConsiderLazyAssignmentWithNoLazyNodes() { public void testConsiderLazyAssignmentWithLazyNodes() { DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .build(); @@ -1132,7 +1115,7 @@ public void testConsiderLazyAssignmentWithLazyNodes() { public void testConsiderLazyAssignmentWithFilledLazyNodesAndVerticalScale() { DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), @@ -1142,12 +1125,11 @@ public void testConsiderLazyAssignmentWithFilledLazyNodesAndVerticalScale() { MachineLearning.MAX_JVM_SIZE_NODE_ATTR, Long.toString(ByteSizeValue.ofMb(400).getBytes()) ), - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), @@ -1157,8 +1139,7 @@ public void testConsiderLazyAssignmentWithFilledLazyNodesAndVerticalScale() { MachineLearning.MAX_JVM_SIZE_NODE_ATTR, Long.toString(ByteSizeValue.ofMb(400).getBytes()) ), - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -1231,17 +1212,16 @@ public void testMaximumPossibleNodeMemoryTooSmall() { public void testPerceivedCapacityAndMaxFreeMemory() { DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "not_ml_node_name", "_node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), Collections.emptyMap(), - ROLES_WITHOUT_ML, - Version.CURRENT + ROLES_WITHOUT_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "filled_ml_node_name", "filled_ml_node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), @@ -1249,12 +1229,11 @@ public void testPerceivedCapacityAndMaxFreeMemory() { .put(MachineLearning.MAX_JVM_SIZE_NODE_ATTR, "10") .put(MachineLearning.MACHINE_MEMORY_NODE_ATTR, Long.toString(ByteSizeValue.ofGb(30).getBytes())) .map(), - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "not_filled_ml_node", "not_filled_ml_node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9302), @@ -1262,12 +1241,11 @@ public void testPerceivedCapacityAndMaxFreeMemory() { .put(MachineLearning.MAX_JVM_SIZE_NODE_ATTR, "10") .put(MachineLearning.MACHINE_MEMORY_NODE_ATTR, Long.toString(ByteSizeValue.ofGb(30).getBytes())) .map(), - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "not_filled_smaller_ml_node", "not_filled_smaller_ml_node_id", new TransportAddress(InetAddress.getLoopbackAddress(), 9303), @@ -1275,8 +1253,7 @@ public void testPerceivedCapacityAndMaxFreeMemory() { .put(MachineLearning.MAX_JVM_SIZE_NODE_ATTR, "10") .put(MachineLearning.MACHINE_MEMORY_NODE_ATTR, Long.toString(ByteSizeValue.ofGb(10).getBytes())) .map(), - ROLES_WITH_ML, - Version.CURRENT + ROLES_WITH_ML ) ) .build(); @@ -1335,7 +1312,7 @@ private ClusterState.Builder fillNodesWithRunningJobs( for (int i = 0; i < numNodes; i++) { String nodeId = "_node_id" + i; TransportAddress address = new TransportAddress(InetAddress.getLoopbackAddress(), 9300 + i); - nodes.add(new DiscoveryNode("_node_name" + i, nodeId, address, nodeAttr, ROLES_WITH_ML, Version.CURRENT)); + nodes.add(TestDiscoveryNode.create("_node_name" + i, nodeId, address, nodeAttr, ROLES_WITH_ML)); for (int j = 0; j < numRunningJobsPerNode; j++) { int id = j + (numRunningJobsPerNode * i); // Both anomaly detector jobs and data frame analytics jobs should count towards the limit diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/NodeLoadDetectorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/NodeLoadDetectorTests.java index d5874200d465d..b44d3126be598 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/NodeLoadDetectorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/job/NodeLoadDetectorTests.java @@ -6,13 +6,12 @@ */ package org.elasticsearch.xpack.ml.job; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.Metadata; -import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.persistent.PersistentTasksCustomMetadata; @@ -68,43 +67,39 @@ public void testNodeLoadDetection() { ); DiscoveryNodes nodes = DiscoveryNodes.builder() .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name1", "_node_id1", new TransportAddress(InetAddress.getLoopbackAddress(), 9300), nodeAttr, - Set.of(DiscoveryNodeRole.ML_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.ML_ROLE) ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name2", "_node_id2", new TransportAddress(InetAddress.getLoopbackAddress(), 9301), nodeAttr, - Set.of(DiscoveryNodeRole.ML_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.ML_ROLE) ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name3", "_node_id3", new TransportAddress(InetAddress.getLoopbackAddress(), 9302), nodeAttr, - Set.of(DiscoveryNodeRole.ML_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.ML_ROLE) ) ) .add( - new DiscoveryNode( + TestDiscoveryNode.create( "_node_name4", "_node_id4", new TransportAddress(InetAddress.getLoopbackAddress(), 9303), nodeAttr, - Set.of(DiscoveryNodeRole.ML_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.ML_ROLE) ) ) .build(); diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/NativeMemoryCalculatorTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/NativeMemoryCalculatorTests.java index ae5674da408b5..93151f08415d1 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/NativeMemoryCalculatorTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/utils/NativeMemoryCalculatorTests.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.ml.utils; -import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -532,30 +531,28 @@ DiscoveryNodes randomNodes(int numMlNodes, int numNonMlNodes, long mlMachineMemo if (i < numMlNodes) { // ML node builder.add( - new DiscoveryNode( + TestDiscoveryNode.create( nodeName, nodeId, ta, Map.of( - MachineLearning.MACHINE_MEMORY_NODE_ATTR, + MACHINE_MEMORY_NODE_ATTR, String.valueOf(mlMachineMemory), MAX_JVM_SIZE_NODE_ATTR, String.valueOf(mlMachineMemory / 20) ), - Set.of(DiscoveryNodeRole.ML_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.ML_ROLE) ) ); } else { // Not an ML node builder.add( - new DiscoveryNode( + TestDiscoveryNode.create( nodeName, nodeId, ta, Collections.emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.INGEST_ROLE), - Version.CURRENT + Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_ROLE, DiscoveryNodeRole.INGEST_ROLE) ) ); } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentActionTests.java index 9a9e02bc489b4..c771b082c2eb3 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/action/enrollment/TransportNodeEnrollmentActionTests.java @@ -19,6 +19,7 @@ import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.settings.MockSecureSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.ssl.SslConfiguration; @@ -170,6 +171,6 @@ private void assertSameCertificate(String cert, Path original, char[] originalPa } private DiscoveryNode node(final int id) { - return new DiscoveryNode("node-" + id, Integer.toString(id), buildNewFakeTransportAddress(), Map.of(), Set.of(), Version.CURRENT); + return TestDiscoveryNode.create("node-" + id, Integer.toString(id), buildNewFakeTransportAddress(), Map.of(), Set.of()); } } diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGeneratorTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGeneratorTests.java index 5dd80b77441ed..f2be63531cd3b 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGeneratorTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/enrollment/InternalEnrollmentTokenGeneratorTests.java @@ -17,7 +17,7 @@ import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.client.internal.Client; import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.TestDiscoveryNode; import org.elasticsearch.common.settings.MockSecureSettings; import org.elasticsearch.common.settings.SecureString; import org.elasticsearch.common.settings.Settings; @@ -225,7 +225,7 @@ public Answer answerNullHttpInfo(InvocationOnMock invocationO Version.CURRENT, TransportVersion.CURRENT, null, - new DiscoveryNode("node-name", "1", buildNewFakeTransportAddress(), Map.of(), Set.of(), Version.CURRENT), + TestDiscoveryNode.create("node-name", "1", buildNewFakeTransportAddress(), Map.of(), Set.of()), null, null, null, @@ -258,7 +258,7 @@ private Answer answerWithInfo(InvocationOnMock invocationOnMo Version.CURRENT, TransportVersion.CURRENT, null, - new DiscoveryNode("node-name", "1", buildNewFakeTransportAddress(), Map.of(), Set.of(), Version.CURRENT), + TestDiscoveryNode.create("node-name", "1", buildNewFakeTransportAddress(), Map.of(), Set.of()), null, null, null, From fc127f70ac26ec96770a75b2f131c28c0edd9e3e Mon Sep 17 00:00:00 2001 From: Simon Cooper Date: Tue, 2 May 2023 10:06:07 +0100 Subject: [PATCH 3/3] Use null rather than empty string --- .../benchmark/routing/allocation/Allocators.java | 2 +- .../transport/ProxyConnectionStrategy.java | 2 +- .../transport/SniffConnectionStrategy.java | 4 ++-- .../elasticsearch/cluster/node/TestDiscoveryNode.java | 10 +++++----- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java index a2b7e3ff39f26..951b0c6fe0949 100644 --- a/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java +++ b/benchmarks/src/main/java/org/elasticsearch/benchmark/routing/allocation/Allocators.java @@ -94,7 +94,7 @@ public static AllocationDeciders defaultAllocationDeciders(Settings settings, Cl public static DiscoveryNode newNode(String nodeId, Map attributes) { return new DiscoveryNode( - "", + null, nodeId, new TransportAddress(TransportAddress.META_ADDRESS, portGenerator.incrementAndGet()), attributes, diff --git a/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java b/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java index c6c47dd820264..fcddf42bb0815 100644 --- a/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java +++ b/server/src/main/java/org/elasticsearch/transport/ProxyConnectionStrategy.java @@ -292,7 +292,7 @@ public void onFailure(Exception e) { attributes = Collections.singletonMap("server_name", configuredServerName); } DiscoveryNode node = new DiscoveryNode( - "", + null, id, resolved, attributes, diff --git a/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java b/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java index f9691cfc7fe0f..01c759288cdac 100644 --- a/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java +++ b/server/src/main/java/org/elasticsearch/transport/SniffConnectionStrategy.java @@ -498,7 +498,7 @@ private static DiscoveryNode resolveSeedNode(String clusterAlias, String address if (proxyAddress == null || proxyAddress.isEmpty()) { TransportAddress transportAddress = new TransportAddress(parseConfiguredAddress(address)); return new DiscoveryNode( - "", + null, clusterAlias + "#" + transportAddress, transportAddress, Collections.emptyMap(), @@ -509,7 +509,7 @@ private static DiscoveryNode resolveSeedNode(String clusterAlias, String address TransportAddress transportAddress = new TransportAddress(parseConfiguredAddress(proxyAddress)); String hostName = RemoteConnectionStrategy.parseHost(proxyAddress); return new DiscoveryNode( - "", + null, clusterAlias + "#" + address, UUIDs.randomBase64UUID(), hostName, diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java b/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java index e9cf8a0c98db6..d97451f5aff6d 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/node/TestDiscoveryNode.java @@ -20,7 +20,7 @@ public class TestDiscoveryNode { public static DiscoveryNode create(String id) { return new DiscoveryNode( - "", + null, id, ESTestCase.buildNewFakeTransportAddress(), Collections.emptyMap(), @@ -41,15 +41,15 @@ public static DiscoveryNode create(String name, String id) { } public static DiscoveryNode create(String id, TransportAddress address) { - return new DiscoveryNode("", id, address, Collections.emptyMap(), DiscoveryNodeRole.roles(), null); + return new DiscoveryNode(null, id, address, Collections.emptyMap(), DiscoveryNodeRole.roles(), null); } public static DiscoveryNode create(String id, TransportAddress address, Version version) { - return new DiscoveryNode("", id, address, Collections.emptyMap(), DiscoveryNodeRole.roles(), version); + return new DiscoveryNode(null, id, address, Collections.emptyMap(), DiscoveryNodeRole.roles(), version); } public static DiscoveryNode create(String id, TransportAddress address, Map attributes, Set roles) { - return new DiscoveryNode("", id, address, attributes, roles, null); + return new DiscoveryNode(null, id, address, attributes, roles, null); } public static DiscoveryNode create( @@ -59,7 +59,7 @@ public static DiscoveryNode create( Set roles, Version version ) { - return new DiscoveryNode("", id, address, attributes, roles, version); + return new DiscoveryNode(null, id, address, attributes, roles, version); } public static DiscoveryNode create(