diff --git a/modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleServiceTests.java b/modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleServiceTests.java index dd8f601a00f7f..b1679b5fa6701 100644 --- a/modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleServiceTests.java +++ b/modules/data-streams/src/test/java/org/elasticsearch/datastreams/lifecycle/DataStreamLifecycleServiceTests.java @@ -44,6 +44,7 @@ import org.elasticsearch.cluster.metadata.MetadataIndexStateService; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.cluster.routing.allocation.AllocationService; @@ -80,7 +81,6 @@ import java.time.Instant; import java.time.ZoneId; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -1294,17 +1294,12 @@ private static DiscoveryNodes.Builder buildNodes(String nodeId) { } private static DiscoveryNode getNode(String nodeId) { - return new DiscoveryNode( - nodeId, - nodeId, - nodeId, - "host", - "host_address", - buildNewFakeTransportAddress(), - Collections.emptyMap(), - Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE), - null - ); + return DiscoveryNodeUtils.builder(nodeId) + .name(nodeId) + .ephemeralId(nodeId) + .address("host", "host_address", buildNewFakeTransportAddress()) + .roles(Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.DATA_HOT_NODE_ROLE, DiscoveryNodeRole.DATA_CONTENT_NODE_ROLE)) + .build(); } /** diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java index d09a16ba07bb7..048eb24a39a66 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterChangedEventTests.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.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.UUIDs; @@ -457,17 +458,12 @@ private static DiscoveryNodes createDiscoveryNodes(final int numNodes, final boo // Create a new DiscoveryNode private static DiscoveryNode newNode(final String nodeId, Set roles) { - return new DiscoveryNode( - nodeId, - nodeId, - nodeId, - "host", - "host_address", - buildNewFakeTransportAddress(), - Collections.emptyMap(), - roles, - null - ); + return DiscoveryNodeUtils.builder(nodeId) + .name(nodeId) + .ephemeralId(nodeId) + .address("host", "host_address", buildNewFakeTransportAddress()) + .roles(roles) + .build(); } // Create the metadata for a cluster state. diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/JoinReasonServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/JoinReasonServiceTests.java index 79eb441a8318b..7fe9b1f8df51a 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/JoinReasonServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/JoinReasonServiceTests.java @@ -83,17 +83,14 @@ public void testJoinReasonService() { matchesNeedingGuidance("joining, removed [0ms] ago with reason [second test removal], [2] total removals") ); - final DiscoveryNode rebootedNode = new DiscoveryNode( - discoveryNode.getName(), - discoveryNode.getId(), - UUIDs.randomBase64UUID(random()), - discoveryNode.getHostName(), - discoveryNode.getHostAddress(), - discoveryNode.getAddress(), - discoveryNode.getAttributes(), - discoveryNode.getRoles(), - discoveryNode.getVersionInformation() - ); + final DiscoveryNode rebootedNode = DiscoveryNodeUtils.builder(discoveryNode.getId()) + .name(discoveryNode.getName()) + .ephemeralId(UUIDs.randomBase64UUID(random())) + .address(discoveryNode.getHostName(), discoveryNode.getHostAddress(), discoveryNode.getAddress()) + .attributes(discoveryNode.getAttributes()) + .roles(discoveryNode.getRoles()) + .version(discoveryNode.getVersionInformation()) + .build(); assertThat( joinReasonService.getJoinReason(rebootedNode, LEADER), 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 19aa035817a01..0d64e6ec20b7f 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinExecutorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/NodeJoinExecutorTests.java @@ -206,17 +206,14 @@ public void testUpdatesNodeWithNewRoles() throws Exception { final DiscoveryNode masterNode = DiscoveryNodeUtils.create(UUIDs.base64UUID()); final DiscoveryNode actualNode = DiscoveryNodeUtils.create(UUIDs.base64UUID()); - final DiscoveryNode bwcNode = new DiscoveryNode( - actualNode.getName(), - actualNode.getId(), - actualNode.getEphemeralId(), - actualNode.getHostName(), - actualNode.getHostAddress(), - actualNode.getAddress(), - actualNode.getAttributes(), - new HashSet<>(randomSubsetOf(actualNode.getRoles())), - actualNode.getVersionInformation() - ); + final DiscoveryNode bwcNode = DiscoveryNodeUtils.builder(actualNode.getId()) + .name(actualNode.getName()) + .ephemeralId(actualNode.getEphemeralId()) + .address(actualNode.getHostName(), actualNode.getHostAddress(), actualNode.getAddress()) + .attributes(actualNode.getAttributes()) + .roles(new HashSet<>(randomSubsetOf(actualNode.getRoles()))) + .version(actualNode.getVersionInformation()) + .build(); final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT) .nodes(DiscoveryNodes.builder().add(masterNode).localNodeId(masterNode.getId()).masterNodeId(masterNode.getId()).add(bwcNode)) .build(); @@ -395,17 +392,14 @@ public void testRemovesOlderNodeInstancesWhenBecomingMaster() throws Exception { final var masterNode = DiscoveryNodeUtils.create(UUIDs.randomBase64UUID(random())); final var otherNodeOld = DiscoveryNodeUtils.create(UUIDs.randomBase64UUID(random())); - final var otherNodeNew = new DiscoveryNode( - otherNodeOld.getName(), - otherNodeOld.getId(), - UUIDs.randomBase64UUID(random()), - otherNodeOld.getHostName(), - otherNodeOld.getHostAddress(), - otherNodeOld.getAddress(), - otherNodeOld.getAttributes(), - otherNodeOld.getRoles(), - otherNodeOld.getVersionInformation() - ); + final var otherNodeNew = DiscoveryNodeUtils.builder(otherNodeOld.getId()) + .name(otherNodeOld.getName()) + .ephemeralId(UUIDs.randomBase64UUID(random())) + .address(otherNodeOld.getHostName(), otherNodeOld.getHostAddress(), otherNodeOld.getAddress()) + .attributes(otherNodeOld.getAttributes()) + .roles(otherNodeOld.getRoles()) + .version(otherNodeOld.getVersionInformation()) + .build(); final var afterElectionClusterState = ClusterStateTaskExecutorUtils.executeAndAssertSuccessful( ClusterState.builder(ClusterName.DEFAULT) 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 858de71982400..a2e455dc28e0b 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeFiltersTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodeFiltersTests.java @@ -24,7 +24,6 @@ import java.util.List; import java.util.Map; -import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; import static java.util.Collections.singletonMap; import static org.elasticsearch.cluster.node.DiscoveryNodeFilters.OpType.AND; @@ -124,7 +123,13 @@ public void testIpBindFilteringMatchingAnd() { ); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -134,7 +139,13 @@ public void testIpBindFilteringNotMatching() { ); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(false)); } @@ -144,7 +155,13 @@ public void testIpBindFilteringNotMatchingAnd() { ); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(false)); } @@ -154,7 +171,13 @@ public void testIpBindFilteringMatchingOr() { ); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -164,7 +187,13 @@ public void testIpBindFilteringNotMatchingOr() { ); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -172,7 +201,13 @@ public void testIpPublishFilteringMatchingAnd() { Settings settings = shuffleSettings(Settings.builder().put("xxx.tag", "A").put("xxx._publish_ip", "192.1.1.54").build()); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -180,7 +215,13 @@ public void testIpPublishFilteringNotMatchingAnd() { Settings settings = shuffleSettings(Settings.builder().put("xxx.tag", "A").put("xxx._publish_ip", "8.8.8.8").build()); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(false)); } @@ -188,7 +229,13 @@ public void testIpPublishFilteringMatchingOr() { Settings settings = shuffleSettings(Settings.builder().put("xxx._publish_ip", "192.1.1.54").put("xxx.tag", "A").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -196,7 +243,12 @@ public void testHostNameFilteringMatchingAnd() { Settings settings = shuffleSettings(Settings.builder().put("xxx._host", "A").build()); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "A", "192.1.1.54", localAddress, emptyMap(), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("A", "192.1.1.54", localAddress) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -204,7 +256,12 @@ public void testHostAddressFilteringMatchingAnd() { Settings settings = shuffleSettings(Settings.builder().put("xxx._host", "192.1.1.54").build()); DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "A", "192.1.1.54", localAddress, emptyMap(), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("A", "192.1.1.54", localAddress) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -212,7 +269,13 @@ public void testIpPublishFilteringNotMatchingOr() { Settings settings = shuffleSettings(Settings.builder().put("xxx.tag", "A").put("xxx._publish_ip", "8.8.8.8").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "A"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "A")) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -221,12 +284,23 @@ public void testIpPublishFilteringMatchingWildcard() { Settings settings = shuffleSettings(Settings.builder().put("xxx._publish_ip", matches ? "192.1.*" : "192.2.*").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, emptyMap(), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(matches)); } public void testCommaSeparatedValuesTrimmed() { - DiscoveryNode node = new DiscoveryNode("", "", "", "", "192.1.1.54", localAddress, singletonMap("tag", "B"), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "B")) + .roles(emptySet()) + .build(); Settings settings = shuffleSettings( Settings.builder() @@ -246,17 +320,13 @@ public void testOnlyAttributeValueFilter() { Settings.Builder builder = Settings.builder(); keys.forEach(key -> builder.put("xxx." + key, "1.2.3.4")); DiscoveryNodeFilters discoveryNodeFilters = buildFromSettings(DiscoveryNodeFilters.OpType.AND, "xxx.", builder.build()); - DiscoveryNode node = new DiscoveryNode( - "", - "", - "", - "", - "192.1.1.54", - localAddress, - singletonMap("tag", "1.2.3.4"), - emptySet(), - null - ); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.1.1.54", localAddress) + .attributes(singletonMap("tag", "1.2.3.4")) + .roles(emptySet()) + .build(); assertThat(discoveryNodeFilters.isOnlyAttributeValueFilter(), is(discoveryNodeFilters.match(node))); } @@ -267,7 +337,12 @@ public void testNormalizesIPAddressFilters() { ); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "", "fdbd:dc00:111:222::333", localAddress, emptyMap(), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "fdbd:dc00:111:222::333", localAddress) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -275,17 +350,12 @@ public void testNormalizesIPAddressFiltersForPublishIp() { Settings settings = shuffleSettings(Settings.builder().put("xxx._publish_ip", "fdbd:dc00:111:222:0:0:0:333").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode( - "", - "", - "", - "", - "192.168.0.1", - new TransportAddress(InetAddresses.forString("fdbd:dc00:111:222::333"), 9300), - emptyMap(), - emptySet(), - null - ); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("", "192.168.0.1", new TransportAddress(InetAddresses.forString("fdbd:dc00:111:222::333"), 9300)) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } @@ -293,17 +363,12 @@ public void testHostnameWhichLooksLikeIpv6DoesNotGetMatched() { Settings settings = shuffleSettings(Settings.builder().put("xxx._name", "fdbd:dc00:111:222:0:0:0:333").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode( - "", - "", - "", - "fdbd:dc00:111:222::333", - "192.168.0.1", - localAddress, - emptyMap(), - emptySet(), - null - ); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("fdbd:dc00:111:222::333", "192.168.0.1", localAddress) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(false)); } @@ -311,7 +376,12 @@ public void testHostnameGetMatchedAndNotAffectedByNormalizing() { Settings settings = shuffleSettings(Settings.builder().put("xxx._host", "test-host").build()); DiscoveryNodeFilters filters = buildFromSettings(OR, "xxx.", settings); - DiscoveryNode node = new DiscoveryNode("", "", "", "test-host", "192.168.0.1", localAddress, emptyMap(), emptySet(), null); + DiscoveryNode node = DiscoveryNodeUtils.builder("") + .name("") + .ephemeralId("") + .address("test-host", "192.168.0.1", localAddress) + .roles(emptySet()) + .build(); assertThat(filters.match(node), equalTo(true)); } 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 fafacdcfaf143..8ef158aa277d8 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -231,17 +231,14 @@ public void testDeltas() { Map attrs = new HashMap<>(node.getAttributes()); attrs.put("new", "new"); final TransportAddress nodeAddress = node.getAddress(); - node = new DiscoveryNode( - node.getName(), - node.getId(), - node.getEphemeralId(), - nodeAddress.address().getHostString(), - nodeAddress.getAddress(), - nodeAddress, - attrs, - node.getRoles(), - node.getVersionInformation() - ); + node = DiscoveryNodeUtils.builder(node.getId()) + .name(node.getName()) + .ephemeralId(node.getEphemeralId()) + .address(nodeAddress) + .attributes(attrs) + .roles(node.getRoles()) + .version(node.getVersionInformation()) + .build(); } nodesB.add(node); } diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index 958532011b281..9e3be76cbce59 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -21,6 +21,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.AllocationId; import org.elasticsearch.cluster.routing.IndexRoutingTable; @@ -62,7 +63,6 @@ import java.util.List; import java.util.Set; -import static java.util.Collections.emptyMap; import static java.util.Collections.singleton; import static org.elasticsearch.cluster.routing.RoutingNodesHelper.shardsWithState; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; @@ -853,28 +853,18 @@ public void testMoveShardToNonDataNode() { logger.info("--> adding two nodes"); - DiscoveryNode node1 = new DiscoveryNode( - "node1", - "node1", - "node1", - "test1", - "test1", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ); - DiscoveryNode node2 = new DiscoveryNode( - "node2", - "node2", - "node2", - "test2", - "test2", - buildNewFakeTransportAddress(), - emptyMap(), - new HashSet<>(randomSubsetOf(Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.INGEST_ROLE))), - null - ); + DiscoveryNode node1 = DiscoveryNodeUtils.builder("node1") + .name("node1") + .ephemeralId("node1") + .address("test1", "test1", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build(); + DiscoveryNode node2 = DiscoveryNodeUtils.builder("node2") + .name("node2") + .ephemeralId("node2") + .address("test2", "test2", buildNewFakeTransportAddress()) + .roles(new HashSet<>(randomSubsetOf(Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.INGEST_ROLE)))) + .build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(node1).add(node2)).build(); @@ -921,28 +911,18 @@ public void testMoveShardFromNonDataNode() { logger.info("--> adding two nodes"); - DiscoveryNode node1 = new DiscoveryNode( - "node1", - "node1", - "node1", - "test1", - "test1", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ); - DiscoveryNode node2 = new DiscoveryNode( - "node2", - "node2", - "node2", - "test2", - "test2", - buildNewFakeTransportAddress(), - emptyMap(), - new HashSet<>(randomSubsetOf(Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.INGEST_ROLE))), - null - ); + DiscoveryNode node1 = DiscoveryNodeUtils.builder("node1") + .name("node1") + .ephemeralId("node1") + .address("test1", "test1", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build(); + DiscoveryNode node2 = DiscoveryNodeUtils.builder("node2") + .name("node2") + .ephemeralId("node2") + .address("test2", "test2", buildNewFakeTransportAddress()) + .roles(new HashSet<>(randomSubsetOf(Set.of(DiscoveryNodeRole.MASTER_ROLE, DiscoveryNodeRole.INGEST_ROLE)))) + .build(); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(node1).add(node2)).build(); logger.info("start primary shard"); diff --git a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java index f8e77cec78678..4413c51eb6128 100644 --- a/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/routing/allocation/SameShardRoutingTests.java @@ -18,6 +18,7 @@ import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RoutingNode; import org.elasticsearch.cluster.routing.RoutingTable; @@ -36,7 +37,6 @@ import java.util.Collections; import java.util.List; -import static java.util.Collections.emptyMap; import static java.util.Collections.singletonList; import static org.elasticsearch.cluster.routing.RoutingNodesHelper.numberOfShardsWithState; import static org.elasticsearch.cluster.routing.RoutingNodesHelper.shardsWithState; @@ -72,30 +72,20 @@ public void testSameHost() { .nodes( DiscoveryNodes.builder() .add( - new DiscoveryNode( - "node1", - "node1", - "node1", - "test1", - "test1", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ) + DiscoveryNodeUtils.builder("node1") + .name("node1") + .ephemeralId("node1") + .address("test1", "test1", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build() ) .add( - new DiscoveryNode( - "node2", - "node2", - "node2", - "test1", - "test1", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ) + DiscoveryNodeUtils.builder("node2") + .name("node2") + .ephemeralId("node2") + .address("test1", "test1", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build() ) ) .build(); @@ -114,17 +104,12 @@ public void testSameHost() { .nodes( DiscoveryNodes.builder(clusterState.nodes()) .add( - new DiscoveryNode( - "node3", - "node3", - "node3", - "test2", - "test2", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ) + DiscoveryNodeUtils.builder("node3") + .name("node3") + .ephemeralId("node3") + .address("test2", "test2", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build() ) ) .build(); @@ -164,30 +149,20 @@ public void testSameHostCheckWithExplain() { .nodes( DiscoveryNodes.builder() .add( - new DiscoveryNode( - "node1", - "node1", - "node1", - host1, - host1, - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ) + DiscoveryNodeUtils.builder("node1") + .name("node1") + .ephemeralId("node1") + .address(host1, host1, buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build() ) .add( - new DiscoveryNode( - "node2", - "node2", - "node2", - host2, - host2, - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ) + DiscoveryNodeUtils.builder("node2") + .name("node2") + .ephemeralId("node2") + .address(host2, host2, buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build() ) ) .build(); @@ -256,29 +231,19 @@ public void testSameHostCheckDisabledByAutoExpandReplicas() { ) .build(); - final DiscoveryNode node1 = new DiscoveryNode( - "node1", - "node1", - "node1", - "test1", - "test1", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ); + final DiscoveryNode node1 = DiscoveryNodeUtils.builder("node1") + .name("node1") + .ephemeralId("node1") + .address("test1", "test1", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build(); - final DiscoveryNode node2 = new DiscoveryNode( - "node2", - "node2", - "node2", - "test1", - "test1", - buildNewFakeTransportAddress(), - emptyMap(), - MASTER_DATA_ROLES, - null - ); + final DiscoveryNode node2 = DiscoveryNodeUtils.builder("node2") + .name("node2") + .ephemeralId("node2") + .address("test1", "test1", buildNewFakeTransportAddress()) + .roles(MASTER_DATA_ROLES) + .build(); final ClusterState clusterState = applyStartedShardsUntilNoChange( ClusterState.builder(ClusterName.DEFAULT) diff --git a/server/src/test/java/org/elasticsearch/transport/SniffConnectionStrategyTests.java b/server/src/test/java/org/elasticsearch/transport/SniffConnectionStrategyTests.java index 84e4249bb0ccb..ee6a960780803 100644 --- a/server/src/test/java/org/elasticsearch/transport/SniffConnectionStrategyTests.java +++ b/server/src/test/java/org/elasticsearch/transport/SniffConnectionStrategyTests.java @@ -849,17 +849,14 @@ public void testConfiguredProxyAddressModeWillReplaceNodeAddress() { DiscoveryNode discoverableNode = getLocalNode(unresponsive2); // Use the address for the node that will not respond - DiscoveryNode unaddressableSeedNode = new DiscoveryNode( - accessibleNode.getName(), - accessibleNode.getId(), - accessibleNode.getEphemeralId(), - accessibleNode.getHostName(), - accessibleNode.getHostAddress(), - getLocalNode(unresponsive1).getAddress(), - accessibleNode.getAttributes(), - accessibleNode.getRoles(), - accessibleNode.getVersionInformation() - ); + DiscoveryNode unaddressableSeedNode = DiscoveryNodeUtils.builder(accessibleNode.getId()) + .name(accessibleNode.getName()) + .ephemeralId(accessibleNode.getEphemeralId()) + .address(accessibleNode.getHostName(), accessibleNode.getHostAddress(), getLocalNode(unresponsive1).getAddress()) + .attributes(accessibleNode.getAttributes()) + .roles(accessibleNode.getRoles()) + .version(accessibleNode.getVersionInformation()) + .build(); knownNodes.add(unaddressableSeedNode); knownNodes.add(discoverableNode); diff --git a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java index 76638c5e24c19..c6a9d93942707 100644 --- a/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java +++ b/server/src/test/java/org/elasticsearch/transport/TransportHandshakerTests.java @@ -11,6 +11,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.support.PlainActionFuture; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.core.TimeValue; @@ -41,17 +42,12 @@ public void setUp() throws Exception { String nodeId = "node-id"; channel = mock(TcpChannel.class); requestSender = mock(TransportHandshaker.HandshakeRequestSender.class); - node = new DiscoveryNode( - nodeId, - nodeId, - nodeId, - "host", - "host_address", - buildNewFakeTransportAddress(), - Collections.emptyMap(), - Collections.emptySet(), - null - ); + node = DiscoveryNodeUtils.builder(nodeId) + .name(nodeId) + .ephemeralId(nodeId) + .address("host", "host_address", buildNewFakeTransportAddress()) + .roles(Collections.emptySet()) + .build(); threadPool = new TestThreadPool("thread-poll"); handshaker = new TransportHandshaker(TransportVersion.current(), threadPool, requestSender, false); } diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/CoordinationStateTestCluster.java b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/CoordinationStateTestCluster.java index 6e71b95a7ecab..3efe729fbe36a 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/CoordinationStateTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/CoordinationStateTestCluster.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.settings.Settings; @@ -147,17 +148,14 @@ void reboot() { } } - localNode = new DiscoveryNode( - localNode.getName(), - localNode.getId(), - UUIDs.randomBase64UUID(random()), - localNode.getHostName(), - localNode.getHostAddress(), - localNode.getAddress(), - localNode.getAttributes(), - roles, - localNode.getVersionInformation() - ); + localNode = DiscoveryNodeUtils.builder(localNode.getId()) + .name(localNode.getName()) + .ephemeralId(UUIDs.randomBase64UUID(random())) + .address(localNode.getHostName(), localNode.getHostAddress(), localNode.getAddress()) + .attributes(localNode.getAttributes()) + .roles(roles) + .version(localNode.getVersionInformation()) + .build(); state = new CoordinationState(localNode, persistedState, electionStrategy); } diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java index a0fe30dd2b1cf..64cc24eb8eee2 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/DeprecationInfoActionResponseTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.settings.Settings; @@ -176,28 +177,18 @@ public void testFromWithMergeableNodeIssues() throws IOException { ) .build(); - DiscoveryNode node1 = new DiscoveryNode( - "node1", - "nodeId1", - "ephemeralId1", - "hostName1", - "hostAddress1", - new TransportAddress(TransportAddress.META_ADDRESS, 9300), - Collections.emptyMap(), - Collections.emptySet(), - null - ); - DiscoveryNode node2 = new DiscoveryNode( - "node2", - "nodeId2", - "ephemeralId2", - "hostName2", - "hostAddress2", - new TransportAddress(TransportAddress.META_ADDRESS, 9500), - Collections.emptyMap(), - Collections.emptySet(), - null - ); + DiscoveryNode node1 = DiscoveryNodeUtils.builder("nodeId1") + .name("node1") + .ephemeralId("ephemeralId1") + .address("hostName1", "hostAddress1", new TransportAddress(TransportAddress.META_ADDRESS, 9300)) + .roles(Collections.emptySet()) + .build(); + DiscoveryNode node2 = DiscoveryNodeUtils.builder("nodeId2") + .name("node2") + .ephemeralId("ephemeralId2") + .address("hostName2", "hostAddress2", new TransportAddress(TransportAddress.META_ADDRESS, 9500)) + .roles(Collections.emptySet()) + .build(); ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metadata(metadata).build(); IndexNameExpressionResolver resolver = TestIndexNameExpressionResolver.newInstance(); Map metaMap1 = DeprecationIssue.createMetaMapForRemovableSettings( diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java index 504ff930a8097..0d554eb1e8bf5 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/cluster/ClusterStatsMonitoringDocTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; @@ -236,7 +237,6 @@ public void testConstructorClusterHealthStatusMustNotBeNull() { public void testNodesHash() { final int nodeCount = randomIntBetween(0, 5); - final Map emptyMap = emptyMap(); final DiscoveryNode masterNode = masterNode(); final DiscoveryNodes.Builder builder = DiscoveryNodes.builder() .add(masterNode) @@ -245,17 +245,17 @@ public void testNodesHash() { for (int i = 0; i < nodeCount; ++i) { builder.add( - new DiscoveryNode( - randomAlphaOfLength(5), - randomAlphaOfLength(2 + i), - randomAlphaOfLength(5), - randomAlphaOfLength(5), - randomAlphaOfLength(5), - new TransportAddress(TransportAddress.META_ADDRESS, 9301 + i), - randomBoolean() ? singletonMap("attr", randomAlphaOfLength(3)) : emptyMap, - singleton(randomValueOtherThan(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE, () -> randomFrom(DiscoveryNodeRole.roles()))), - null - ) + DiscoveryNodeUtils.builder(randomAlphaOfLength(2 + i)) + .name(randomAlphaOfLength(5)) + .ephemeralId(randomAlphaOfLength(5)) + .address(randomAlphaOfLength(5), randomAlphaOfLength(5), new TransportAddress(TransportAddress.META_ADDRESS, 9301 + i)) + .attributes(randomBoolean() ? singletonMap("attr", randomAlphaOfLength(3)) : emptyMap()) + .roles( + singleton( + randomValueOtherThan(DiscoveryNodeRole.VOTING_ONLY_NODE_ROLE, () -> randomFrom(DiscoveryNodeRole.roles())) + ) + ) + .build() ); } @@ -794,17 +794,13 @@ public void testToXContent() throws IOException { } private DiscoveryNode masterNode() { - return new DiscoveryNode( - "_node_name", - "_node_id", - "_ephemeral_id", - "_host_name", - "_host_address", - new TransportAddress(TransportAddress.META_ADDRESS, 9300), - singletonMap("attr", "value"), - singleton(DiscoveryNodeRole.MASTER_ROLE), - null - ); + return DiscoveryNodeUtils.builder("_node_id") + .name("_node_name") + .ephemeralId("_ephemeral_id") + .address("_host_name", "_host_address", new TransportAddress(TransportAddress.META_ADDRESS, 9300)) + .attributes(singletonMap("attr", "value")) + .roles(singleton(DiscoveryNodeRole.MASTER_ROLE)) + .build(); } } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java index e36a50233fb80..6d16c7b84a99b 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryMonitoringDocTests.java @@ -12,6 +12,7 @@ import org.elasticsearch.action.support.DefaultShardOperationFailedException; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.cluster.node.VersionInformation; import org.elasticsearch.cluster.routing.RecoverySource; import org.elasticsearch.cluster.routing.ShardRouting; @@ -82,29 +83,28 @@ public void testConstructorRecoveryResponseMustNotBeNull() { @Override public void testToXContent() throws IOException { - final DiscoveryNode discoveryNodeZero = new DiscoveryNode( - "_node_0", - "_node_id_0", - "_ephemeral_id_0", - "_host_name_0", - "_host_address_0", - new TransportAddress(TransportAddress.META_ADDRESS, 9300), - singletonMap("attr", "value_0"), - singleton(DiscoveryNodeRole.MASTER_ROLE), - null - ); - - final DiscoveryNode discoveryNodeOne = new DiscoveryNode( - "_node_1", - "_node_id_1", - "_ephemeral_id_1", - "_host_name_1", - "_host_address_1", - new TransportAddress(TransportAddress.META_ADDRESS, 9301), - singletonMap("attr", "value_1"), - singleton(DiscoveryNodeRole.DATA_ROLE), - new VersionInformation(Version.CURRENT.minimumCompatibilityVersion(), IndexVersion.MINIMUM_COMPATIBLE, IndexVersion.current()) - ); + final DiscoveryNode discoveryNodeZero = DiscoveryNodeUtils.builder("_node_id_0") + .name("_node_0") + .ephemeralId("_ephemeral_id_0") + .address("_host_name_0", "_host_address_0", new TransportAddress(TransportAddress.META_ADDRESS, 9300)) + .attributes(singletonMap("attr", "value_0")) + .roles(singleton(DiscoveryNodeRole.MASTER_ROLE)) + .build(); + + final DiscoveryNode discoveryNodeOne = DiscoveryNodeUtils.builder("_node_id_1") + .name("_node_1") + .ephemeralId("_ephemeral_id_1") + .address("_host_name_1", "_host_address_1", new TransportAddress(TransportAddress.META_ADDRESS, 9301)) + .attributes(singletonMap("attr", "value_1")) + .roles(singleton(DiscoveryNodeRole.DATA_ROLE)) + .version( + new VersionInformation( + Version.CURRENT.minimumCompatibilityVersion(), + IndexVersion.MINIMUM_COMPATIBLE, + IndexVersion.current() + ) + ) + .build(); final ShardId shardId = new ShardId("_index_a", "_uuid_a", 0); final UnassignedInfo unassignedInfo = new UnassignedInfo(UnassignedInfo.Reason.INDEX_CREATED, "_index_info_a"); diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java index bd04a7f451eb1..16b94404cd092 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/ml/JobStatsMonitoringDocTests.java @@ -8,6 +8,7 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodeRole; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.xcontent.XContentHelper; @@ -89,17 +90,13 @@ public void testToXContent() throws IOException { final Date date7 = new Date(ZonedDateTime.parse("2017-01-07T07:07:07.007+07:00").toInstant().toEpochMilli()); final Instant date8 = ZonedDateTime.parse("2017-01-07T08:08:08.007+07:00").toInstant(); - final DiscoveryNode discoveryNode = new DiscoveryNode( - "_node_name", - "_node_id", - "_ephemeral_id", - "_host_name", - "_host_address", - new TransportAddress(TransportAddress.META_ADDRESS, 9300), - singletonMap("attr", "value"), - singleton(DiscoveryNodeRole.MASTER_ROLE), - null - ); + final DiscoveryNode discoveryNode = DiscoveryNodeUtils.builder("_node_id") + .name("_node_name") + .ephemeralId("_ephemeral_id") + .address("_host_name", "_host_address", new TransportAddress(TransportAddress.META_ADDRESS, 9300)) + .attributes(singletonMap("attr", "value")) + .roles(singleton(DiscoveryNodeRole.MASTER_ROLE)) + .build(); final ModelSizeStats modelStats = new ModelSizeStats.Builder("_model").setModelBytes(100L) .setTotalByFieldCount(101L) diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java index cde619e6260d0..361f528eed922 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/node/NodeStatsMonitoringDocTests.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.admin.indices.stats.CommonStats; import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags; import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodeUtils; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.xcontent.XContentHelper; @@ -434,17 +435,12 @@ private static NodeStats mockNodeStats() { threadpools.add(new ThreadPoolStats.Stats("write", (int) ++iota, (int) ++iota, (int) no, ++iota, (int) no, no)); final ThreadPoolStats threadPool = new ThreadPoolStats(threadpools); - final DiscoveryNode discoveryNode = new DiscoveryNode( - "_node_name", - "_node_id", - "_ephemeral_id", - "_host_name", - "_host_address", - new TransportAddress(TransportAddress.META_ADDRESS, 1234), - emptyMap(), - emptySet(), - null - ); + final DiscoveryNode discoveryNode = DiscoveryNodeUtils.builder("_node_id") + .name("_node_name") + .ephemeralId("_ephemeral_id") + .address("_host_name", "_host_address", new TransportAddress(TransportAddress.META_ADDRESS, 1234)) + .roles(emptySet()) + .build(); return new NodeStats( discoveryNode,