Search in sources :

Example 96 with TransportAddress

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

the class DiscoveryNodeTests method testDiscoveryNodeIsCreatedWithHostFromInetAddress.

public void testDiscoveryNodeIsCreatedWithHostFromInetAddress() throws Exception {
    InetAddress inetAddress = randomBoolean() ? 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);
    assertEquals(transportAddress.address().getHostString(), node.getHostName());
    assertEquals(transportAddress.getAddress(), node.getHostAddress());
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) InetAddress(java.net.InetAddress)

Example 97 with TransportAddress

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

the class RoutingNodeTests method setUp.

@Override
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);
    routingNode = new RoutingNode("node1", discoveryNode, unassignedShard0, initializingShard0, relocatingShard0);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportAddress(org.opensearch.common.transport.TransportAddress) InetAddress(java.net.InetAddress)

Example 98 with TransportAddress

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

the class DiscoveryNodesTests method testDeltas.

public void testDeltas() {
    Set<DiscoveryNode> nodesA = new HashSet<>();
    nodesA.addAll(randomNodes(1 + randomInt(10)));
    Set<DiscoveryNode> nodesB = new HashSet<>();
    nodesB.addAll(randomNodes(1 + randomInt(5)));
    for (DiscoveryNode node : randomSubsetOf(nodesA)) {
        if (randomBoolean()) {
            // change an attribute
            Map<String, String> 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.getVersion());
        }
        nodesB.add(node);
    }
    DiscoveryNode masterA = randomBoolean() ? null : RandomPicks.randomFrom(random(), nodesA);
    DiscoveryNode masterB = randomBoolean() ? null : RandomPicks.randomFrom(random(), nodesB);
    DiscoveryNodes.Builder builderA = DiscoveryNodes.builder();
    nodesA.stream().forEach(builderA::add);
    final String masterAId = masterA == null ? null : masterA.getId();
    builderA.masterNodeId(masterAId);
    builderA.localNodeId(RandomPicks.randomFrom(random(), nodesA).getId());
    DiscoveryNodes.Builder builderB = DiscoveryNodes.builder();
    nodesB.stream().forEach(builderB::add);
    final String masterBId = masterB == null ? null : masterB.getId();
    builderB.masterNodeId(masterBId);
    builderB.localNodeId(RandomPicks.randomFrom(random(), nodesB).getId());
    final DiscoveryNodes discoNodesA = builderA.build();
    final DiscoveryNodes discoNodesB = builderB.build();
    logger.info("nodes A: {}", discoNodesA);
    logger.info("nodes B: {}", discoNodesB);
    DiscoveryNodes.Delta delta = discoNodesB.delta(discoNodesA);
    if (masterA == null) {
        assertThat(delta.previousMasterNode(), nullValue());
    } else {
        assertThat(delta.previousMasterNode().getId(), equalTo(masterAId));
    }
    if (masterB == null) {
        assertThat(delta.newMasterNode(), nullValue());
    } else {
        assertThat(delta.newMasterNode().getId(), equalTo(masterBId));
    }
    if (Objects.equals(masterAId, masterBId)) {
        assertFalse(delta.masterNodeChanged());
    } else {
        assertTrue(delta.masterNodeChanged());
    }
    Set<DiscoveryNode> newNodes = new HashSet<>(nodesB);
    newNodes.removeAll(nodesA);
    assertThat(delta.added(), equalTo(newNodes.isEmpty() == false));
    assertThat(delta.addedNodes(), containsInAnyOrder(newNodes.stream().collect(Collectors.toList()).toArray()));
    assertThat(delta.addedNodes().size(), equalTo(newNodes.size()));
    Set<DiscoveryNode> removedNodes = new HashSet<>(nodesA);
    removedNodes.removeAll(nodesB);
    assertThat(delta.removed(), equalTo(removedNodes.isEmpty() == false));
    assertThat(delta.removedNodes(), containsInAnyOrder(removedNodes.stream().collect(Collectors.toList()).toArray()));
    assertThat(delta.removedNodes().size(), equalTo(removedNodes.size()));
}
Also used : HashMap(java.util.HashMap) TransportAddress(org.opensearch.common.transport.TransportAddress) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) HashSet(java.util.HashSet)

Example 99 with TransportAddress

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

the class HttpInfo method toXContent.

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject(Fields.HTTP);
    builder.array(Fields.BOUND_ADDRESS, (Object[]) address.boundAddresses());
    TransportAddress publishAddress = address.publishAddress();
    String publishAddressString = publishAddress.toString();
    String hostString = publishAddress.address().getHostString();
    if (CNAME_IN_PUBLISH_HOST) {
        deprecationLogger.deprecate("cname_in_publish_address", "opensearch.http.cname_in_publish_address system property is deprecated and no longer affects http.publish_address " + "formatting. Remove this property to get rid of this deprecation warning.");
    }
    if (InetAddresses.isInetAddress(hostString) == false) {
        publishAddressString = hostString + '/' + publishAddress.toString();
    }
    builder.field(Fields.PUBLISH_ADDRESS, publishAddressString);
    builder.humanReadableField(Fields.MAX_CONTENT_LENGTH_IN_BYTES, Fields.MAX_CONTENT_LENGTH, maxContentLength());
    builder.endObject();
    return builder;
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress)

Example 100 with TransportAddress

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

the class BootstrapChecksTests method testEnforceLimitsWhenPublishingToNonLocalAddress.

public void testEnforceLimitsWhenPublishingToNonLocalAddress() {
    final List<TransportAddress> transportAddresses = new ArrayList<>();
    for (int i = 0; i < randomIntBetween(1, 8); i++) {
        final TransportAddress randomTransportAddress = buildNewFakeTransportAddress();
        transportAddresses.add(randomTransportAddress);
    }
    final TransportAddress publishAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0);
    final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
    when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
    when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
    final String discoveryType = randomFrom(ZEN2_DISCOVERY_TYPE, "single-node");
    assertEquals(BootstrapChecks.enforceLimits(boundTransportAddress, discoveryType), !"single-node".equals(discoveryType));
}
Also used : BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

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