Search in sources :

Example 91 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class ClusterFormationFailureHelperTests method testDescriptionBeforeBootstrapping.

public void testDescriptionBeforeBootstrapping() {
    final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
    final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).version(7L).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().term(4L).build())).nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())).build();
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), emptyList(), 1L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet, this node has not previously joined a bootstrapped cluster, and " + "[cluster.initial_master_nodes] is empty on this node: have discovered []; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 1, last-accepted version 7 in term 4"));
    final TransportAddress otherAddress = buildNewFakeTransportAddress();
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, singletonList(otherAddress), emptyList(), 2L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet, this node has not previously joined a bootstrapped cluster, and " + "[cluster.initial_master_nodes] is empty on this node: have discovered []; " + "discovery will continue using [" + otherAddress + "] from hosts providers and [" + localNode + "] from last-known cluster state; node term 2, last-accepted version 7 in term 4"));
    final DiscoveryNode otherNode = new DiscoveryNode("other", buildNewFakeTransportAddress(), Version.CURRENT);
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), singletonList(otherNode), 3L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet, this node has not previously joined a bootstrapped cluster, and " + "[cluster.initial_master_nodes] is empty on this node: have discovered [" + otherNode + "]; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 3, last-accepted version 7 in term 4"));
    assertThat(new ClusterFormationState(Settings.builder().putList(INITIAL_MASTER_NODES_SETTING.getKey(), "other").build(), clusterState, emptyList(), emptyList(), 4L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet, this node has not previously joined a bootstrapped cluster, and " + "this node must discover master-eligible nodes [other] to bootstrap a cluster: have discovered []; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 4, last-accepted version 7 in term 4"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) StatusInfo(org.opensearch.monitor.StatusInfo) TransportAddress(org.opensearch.common.transport.TransportAddress) ClusterFormationState(org.opensearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState)

Example 92 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class ClusterFormationFailureHelperTests method testDescriptionAfterBootstrapping.

public void testDescriptionAfterBootstrapping() {
    final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), Version.CURRENT);
    final ClusterState clusterState = state(localNode, "otherNode");
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [otherNode], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    final TransportAddress otherAddress = buildNewFakeTransportAddress();
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, singletonList(otherAddress), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [otherNode], " + "have discovered [] which is not a quorum; " + "discovery will continue using [" + otherAddress + "] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    final DiscoveryNode otherNode = new DiscoveryNode("otherNode", buildNewFakeTransportAddress(), Version.CURRENT);
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), singletonList(otherNode), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [otherNode], " + "have discovered [" + otherNode + "] which is a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    final DiscoveryNode yetAnotherNode = new DiscoveryNode("yetAnotherNode", buildNewFakeTransportAddress(), Version.CURRENT);
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), singletonList(yetAnotherNode), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [otherNode], " + "have discovered [" + yetAnotherNode + "] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires two nodes with ids [n1, n2], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2", "n3"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires at least 2 nodes with ids from [n1, n2, n3], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2", BOOTSTRAP_PLACEHOLDER_PREFIX + "n3"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires 2 nodes with ids [n1, n2], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2", "n3", "n4"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires at least 3 nodes with ids from [n1, n2, n3, n4], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2", "n3", "n4", "n5"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires at least 3 nodes with ids from [n1, n2, n3, n4, n5], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2", "n3", "n4", BOOTSTRAP_PLACEHOLDER_PREFIX + "n5"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires at least 3 nodes with ids from [n1, n2, n3, n4], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, "n1", "n2", "n3", BOOTSTRAP_PLACEHOLDER_PREFIX + "n4", BOOTSTRAP_PLACEHOLDER_PREFIX + "n5"), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires 3 nodes with ids [n1, n2, n3], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, new String[] { "n1" }, new String[] { "n1" }), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [n1], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, new String[] { "n1" }, new String[] { "n2" }), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [n1] and a node with id [n2], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, new String[] { "n1" }, new String[] { "n2", "n3" }), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [n1] and two nodes with ids [n2, n3], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, new String[] { "n1" }, new String[] { "n2", "n3", "n4" }), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires a node with id [n1] and " + "at least 2 nodes with ids from [n2, n3, n4], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
    final DiscoveryNode otherMasterNode = new DiscoveryNode("other-master", buildNewFakeTransportAddress(), Version.CURRENT);
    final DiscoveryNode otherNonMasterNode = new DiscoveryNode("other-non-master", buildNewFakeTransportAddress(), emptyMap(), new HashSet<>(randomSubsetOf(DiscoveryNodeRole.BUILT_IN_ROLES).stream().filter(r -> r != DiscoveryNodeRole.MASTER_ROLE).collect(Collectors.toList())), Version.CURRENT);
    String[] configNodeIds = new String[] { "n1", "n2" };
    final ClusterState stateWithOtherNodes = ClusterState.builder(ClusterName.DEFAULT).nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId()).add(otherMasterNode).add(otherNonMasterNode)).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().lastAcceptedConfiguration(config(configNodeIds)).lastCommittedConfiguration(config(configNodeIds)).build())).build();
    assertThat(new ClusterFormationState(Settings.EMPTY, stateWithOtherNodes, emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), // nodes from last-known cluster state could be in either order
    is(oneOf("master not discovered or elected yet, an election requires two nodes with ids [n1, n2], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + ", " + otherMasterNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0", "master not discovered or elected yet, an election requires two nodes with ids [n1, n2], " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + otherMasterNode + ", " + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0")));
    assertThat(new ClusterFormationState(Settings.EMPTY, state(localNode, GatewayMetaState.STALE_STATE_CONFIG_NODE_ID), emptyList(), emptyList(), 0L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered or elected yet, an election requires one or more nodes that have already participated as " + "master-eligible nodes in the cluster but this node was not master-eligible the last time it joined the cluster, " + "have discovered [] which is not a quorum; " + "discovery will continue using [] from hosts providers and [" + localNode + "] from last-known cluster state; node term 0, last-accepted version 0 in term 0"));
}
Also used : DiscoveryNodes(org.opensearch.cluster.node.DiscoveryNodes) Arrays(java.util.Arrays) Metadata(org.opensearch.cluster.metadata.Metadata) Version(org.opensearch.Version) Collections.singletonList(java.util.Collections.singletonList) HashSet(java.util.HashSet) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) BOOTSTRAP_PLACEHOLDER_PREFIX(org.opensearch.cluster.coordination.ClusterBootstrapService.BOOTSTRAP_PLACEHOLDER_PREFIX) UNHEALTHY(org.opensearch.monitor.StatusInfo.Status.UNHEALTHY) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.oneOf(org.hamcrest.Matchers.oneOf) ClusterFormationState(org.opensearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState) VotingConfiguration(org.opensearch.cluster.coordination.CoordinationMetadata.VotingConfiguration) Collections.emptySet(java.util.Collections.emptySet) Collections.emptyList(java.util.Collections.emptyList) INITIAL_MASTER_NODES_SETTING(org.opensearch.cluster.coordination.ClusterBootstrapService.INITIAL_MASTER_NODES_SETTING) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) HEALTHY(org.opensearch.monitor.StatusInfo.Status.HEALTHY) Settings(org.opensearch.common.settings.Settings) DiscoveryNodeRole(org.opensearch.cluster.node.DiscoveryNodeRole) Collectors(java.util.stream.Collectors) TransportAddress(org.opensearch.common.transport.TransportAddress) AtomicLong(java.util.concurrent.atomic.AtomicLong) GatewayMetaState(org.opensearch.gateway.GatewayMetaState) NODE_NAME_SETTING(org.opensearch.node.Node.NODE_NAME_SETTING) Matchers.equalTo(org.hamcrest.Matchers.equalTo) ClusterName(org.opensearch.cluster.ClusterName) StatusInfo(org.opensearch.monitor.StatusInfo) Matchers.is(org.hamcrest.Matchers.is) ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) StatusInfo(org.opensearch.monitor.StatusInfo) TransportAddress(org.opensearch.common.transport.TransportAddress) ClusterFormationState(org.opensearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState)

Example 93 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class ReplicationOperationTests method testRetryTransientReplicationFailure.

public void testRetryTransientReplicationFailure() throws Exception {
    final String index = "test";
    final ShardId shardId = new ShardId(index, "_na_", 0);
    ClusterState initialState = stateWithActivePrimary(index, true, randomInt(5));
    IndexMetadata indexMetadata = initialState.getMetadata().index(index);
    final long primaryTerm = indexMetadata.primaryTerm(0);
    final IndexShardRoutingTable indexShardRoutingTable = initialState.getRoutingTable().shardRoutingTable(shardId);
    ShardRouting primaryShard = indexShardRoutingTable.primaryShard();
    if (primaryShard.relocating() && randomBoolean()) {
        // simulate execution of the replication phase on the relocation target node after relocation source was marked as relocated
        initialState = ClusterState.builder(initialState).nodes(DiscoveryNodes.builder(initialState.nodes()).localNodeId(primaryShard.relocatingNodeId())).build();
        primaryShard = primaryShard.getTargetRelocatingShard();
    }
    // add a few in-sync allocation ids that don't have corresponding routing entries
    final Set<String> staleAllocationIds = Sets.newHashSet(generateRandomStringArray(4, 10, false));
    final Set<String> inSyncAllocationIds = Sets.union(indexMetadata.inSyncAllocationIds(0), staleAllocationIds);
    final Set<String> trackedShards = new HashSet<>();
    final Set<String> untrackedShards = new HashSet<>();
    addTrackingInfo(indexShardRoutingTable, primaryShard, trackedShards, untrackedShards);
    trackedShards.addAll(staleAllocationIds);
    final ReplicationGroup replicationGroup = new ReplicationGroup(indexShardRoutingTable, inSyncAllocationIds, trackedShards, 0);
    final Set<ShardRouting> expectedReplicas = getExpectedReplicas(shardId, initialState, trackedShards);
    final Map<ShardRouting, Exception> simulatedFailures = new HashMap<>();
    for (ShardRouting replica : expectedReplicas) {
        Exception cause;
        Exception exception;
        if (randomBoolean()) {
            if (randomBoolean()) {
                cause = new CircuitBreakingException("broken", CircuitBreaker.Durability.PERMANENT);
            } else {
                cause = new OpenSearchRejectedExecutionException("rejected");
            }
            exception = new RemoteTransportException("remote", cause);
        } else {
            TransportAddress address = new TransportAddress(InetAddress.getLoopbackAddress(), 9300);
            DiscoveryNode node = new DiscoveryNode("replica", address, Version.CURRENT);
            cause = new ConnectTransportException(node, "broken");
            exception = cause;
        }
        logger.debug("--> simulating failure on {} with [{}]", replica, exception.getClass().getSimpleName());
        simulatedFailures.put(replica, exception);
    }
    Request request = new Request(shardId);
    PlainActionFuture<TestPrimary.Result> listener = new PlainActionFuture<>();
    final TestReplicaProxy replicasProxy = new TestReplicaProxy(simulatedFailures, true);
    final TestPrimary primary = new TestPrimary(primaryShard, () -> replicationGroup, threadPool);
    final TestReplicationOperation op = new TestReplicationOperation(request, primary, listener, replicasProxy, primaryTerm, TimeValue.timeValueMillis(20), TimeValue.timeValueSeconds(60));
    op.execute();
    assertThat("request was not processed on primary", request.processedOnPrimary.get(), equalTo(true));
    assertThat(request.processedOnReplicas, equalTo(expectedReplicas));
    assertThat(replicasProxy.failedReplicas.size(), equalTo(0));
    assertThat(replicasProxy.markedAsStaleCopies, equalTo(staleAllocationIds));
    assertThat("post replication operations not run on primary", request.runPostReplicationActionsOnPrimary.get(), equalTo(true));
    ShardInfo shardInfo = listener.actionGet().getShardInfo();
    assertThat(shardInfo.getSuccessful(), equalTo(1 + expectedReplicas.size()));
    final List<ShardRouting> unassignedShards = indexShardRoutingTable.shardsWithState(ShardRoutingState.UNASSIGNED);
    final int totalShards = 1 + expectedReplicas.size() + unassignedShards.size() + untrackedShards.size();
    assertThat(replicationGroup.toString(), shardInfo.getTotal(), equalTo(totalShards));
    assertThat(primary.knownLocalCheckpoints.remove(primaryShard.allocationId().getId()), equalTo(primary.localCheckpoint));
    assertThat(primary.knownLocalCheckpoints, equalTo(replicasProxy.generatedLocalCheckpoints));
    assertThat(primary.knownGlobalCheckpoints.remove(primaryShard.allocationId().getId()), equalTo(primary.globalCheckpoint));
    assertThat(primary.knownGlobalCheckpoints, equalTo(replicasProxy.generatedGlobalCheckpoints));
}
Also used : IndexShardRoutingTable(org.opensearch.cluster.routing.IndexShardRoutingTable) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) HashMap(java.util.HashMap) TransportAddress(org.opensearch.common.transport.TransportAddress) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) ReplicationGroup(org.opensearch.index.shard.ReplicationGroup) ShardId(org.opensearch.index.shard.ShardId) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata) HashSet(java.util.HashSet) ShardInfo(org.opensearch.action.support.replication.ReplicationResponse.ShardInfo) ClusterState(org.opensearch.cluster.ClusterState) RemoteTransportException(org.opensearch.transport.RemoteTransportException) OpenSearchRejectedExecutionException(org.opensearch.common.util.concurrent.OpenSearchRejectedExecutionException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) CorruptIndexException(org.apache.lucene.index.CorruptIndexException) NodeClosedException(org.opensearch.node.NodeClosedException) UnavailableShardsException(org.opensearch.action.UnavailableShardsException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) IndexShardNotStartedException(org.opensearch.index.shard.IndexShardNotStartedException) SendRequestTransportException(org.opensearch.transport.SendRequestTransportException) ExecutionException(java.util.concurrent.ExecutionException) ConnectTransportException(org.opensearch.transport.ConnectTransportException) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException) ShardRouting(org.opensearch.cluster.routing.ShardRouting)

Example 94 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class DiscoveryNodeTests method testDiscoveryNodeRoleWithOldVersion.

public void testDiscoveryNodeRoleWithOldVersion() 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));
    DiscoveryNodeRole customRole = new DiscoveryNodeRole("custom_role", "z", true) {

        @Override
        public Setting<Boolean> legacySetting() {
            return null;
        }

        @Override
        public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
            if (nodeVersion.equals(Version.CURRENT)) {
                return this;
            } else {
                return DiscoveryNodeRole.DATA_ROLE;
            }
        }
    };
    DiscoveryNode node = new DiscoveryNode("name1", "id1", transportAddress, emptyMap(), Collections.singleton(customRole), Version.CURRENT);
    {
        BytesStreamOutput streamOutput = new BytesStreamOutput();
        streamOutput.setVersion(Version.CURRENT);
        node.writeTo(streamOutput);
        StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
        in.setVersion(Version.CURRENT);
        DiscoveryNode serialized = new DiscoveryNode(in);
        assertThat(serialized.getRoles().stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining()), equalTo("custom_role"));
    }
    {
        BytesStreamOutput streamOutput = new BytesStreamOutput();
        streamOutput.setVersion(LegacyESVersion.V_7_9_0);
        node.writeTo(streamOutput);
        StreamInput in = StreamInput.wrap(streamOutput.bytes().toBytesRef().bytes);
        in.setVersion(LegacyESVersion.V_7_9_0);
        DiscoveryNode serialized = new DiscoveryNode(in);
        assertThat(serialized.getRoles().stream().map(DiscoveryNodeRole::roleName).collect(Collectors.joining()), equalTo("data"));
    }
}
Also used : Version(org.opensearch.Version) LegacyESVersion(org.opensearch.LegacyESVersion) TransportAddress(org.opensearch.common.transport.TransportAddress) StreamInput(org.opensearch.common.io.stream.StreamInput) InetAddress(java.net.InetAddress) BytesStreamOutput(org.opensearch.common.io.stream.BytesStreamOutput)

Example 95 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class DiscoveryNodeTests method runTestDiscoveryNodeIsRemoteClusterClient.

private void runTestDiscoveryNodeIsRemoteClusterClient(final Settings settings, final boolean expected) {
    final DiscoveryNode node = DiscoveryNode.createLocal(settings, new TransportAddress(TransportAddress.META_ADDRESS, 9200), "node");
    assertThat(node.isRemoteClusterClient(), equalTo(expected));
    if (expected) {
        assertThat(node.getRoles(), hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE));
    } else {
        assertThat(node.getRoles(), not(hasItem(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE)));
    }
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress)

Aggregations

TransportAddress (org.opensearch.common.transport.TransportAddress)129 Settings (org.opensearch.common.settings.Settings)51 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)43 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)31 Version (org.opensearch.Version)26 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)22 List (java.util.List)21 InetAddress (java.net.InetAddress)20 HashSet (java.util.HashSet)20 CountDownLatch (java.util.concurrent.CountDownLatch)20 ClusterSettings (org.opensearch.common.settings.ClusterSettings)20 ThreadPool (org.opensearch.threadpool.ThreadPool)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 HttpServerTransport (org.opensearch.http.HttpServerTransport)16 Set (java.util.Set)15 TimeUnit (java.util.concurrent.TimeUnit)15 AtomicReference (java.util.concurrent.atomic.AtomicReference)15 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)15 MockTransportService (org.opensearch.test.transport.MockTransportService)15