Search in sources :

Example 86 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.

the class NodeDisconnectIT method testNotifyOnDisconnectInSniffer.

public void testNotifyOnDisconnectInSniffer() throws IOException {
    internalCluster().ensureAtLeastNumDataNodes(2);
    final Set<DiscoveryNode> disconnectedNodes = Collections.synchronizedSet(new HashSet<>());
    try (TransportClient client = new MockTransportClient(Settings.builder().put("cluster.name", internalCluster().getClusterName()).build(), Collections.emptySet(), (n, e) -> disconnectedNodes.add(n))) {
        int numNodes = 0;
        for (TransportService service : internalCluster().getInstances(TransportService.class)) {
            numNodes++;
            client.addTransportAddress(service.boundAddress().publishAddress());
        }
        Set<TransportAddress> discoveryNodes = client.connectedNodes().stream().map(n -> n.getAddress()).collect(Collectors.toSet());
        assertEquals(numNodes, discoveryNodes.size());
        assertEquals(0, disconnectedNodes.size());
        internalCluster().stopRandomDataNode();
        client.getNodesService().doSample();
        assertEquals(1, disconnectedNodes.size());
        assertTrue(discoveryNodes.contains(disconnectedNodes.stream().findAny().get().getAddress()));
    }
    assertEquals(1, disconnectedNodes.size());
}
Also used : HashSet(java.util.HashSet) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) Settings(org.elasticsearch.common.settings.Settings) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ESIntegTestCase(org.elasticsearch.test.ESIntegTestCase) CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL(org.elasticsearch.client.transport.TransportClient.CLIENT_TRANSPORT_NODES_SAMPLER_INTERVAL) Set(java.util.Set) IOException(java.io.IOException) TransportService(org.elasticsearch.transport.TransportService) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportService(org.elasticsearch.transport.TransportService) TransportAddress(org.elasticsearch.common.transport.TransportAddress) MockTransportClient(org.elasticsearch.transport.MockTransportClient)

Example 87 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.

the class TransportClientIT method testNodeVersionIsUpdated.

public void testNodeVersionIsUpdated() throws IOException, NodeValidationException {
    TransportClient client = (TransportClient) internalCluster().client();
    try (Node node = new MockNode(Settings.builder().put(internalCluster().getDefaultSettings()).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put("node.name", "testNodeVersionIsUpdated").put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME).put(NetworkModule.HTTP_ENABLED.getKey(), false).put(Node.NODE_DATA_SETTING.getKey(), false).put("cluster.name", "foobar").build(), Arrays.asList(MockTcpTransportPlugin.class, TestZenDiscovery.TestPlugin.class)).start()) {
        TransportAddress transportAddress = node.injector().getInstance(TransportService.class).boundAddress().publishAddress();
        client.addTransportAddress(transportAddress);
        // since we force transport clients there has to be one node started that we connect to.
        assertThat(client.connectedNodes().size(), greaterThanOrEqualTo(1));
        // connected nodes have updated version
        for (DiscoveryNode discoveryNode : client.connectedNodes()) {
            assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT));
        }
        for (DiscoveryNode discoveryNode : client.listedNodes()) {
            assertThat(discoveryNode.getId(), startsWith("#transport#-"));
            assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
        }
        assertThat(client.filteredNodes().size(), equalTo(1));
        for (DiscoveryNode discoveryNode : client.filteredNodes()) {
            assertThat(discoveryNode.getVersion(), equalTo(Version.CURRENT.minimumCompatibilityVersion()));
        }
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) MockTransportClient(org.elasticsearch.transport.MockTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress) MockNode(org.elasticsearch.node.MockNode) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Node(org.elasticsearch.node.Node) MockNode(org.elasticsearch.node.MockNode) TestZenDiscovery(org.elasticsearch.test.discovery.TestZenDiscovery)

Example 88 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.

the class TcpTransport method createBoundTransportAddress.

private BoundTransportAddress createBoundTransportAddress(String name, Settings profileSettings, List<InetSocketAddress> boundAddresses) {
    String[] boundAddressesHostStrings = new String[boundAddresses.size()];
    TransportAddress[] transportBoundAddresses = new TransportAddress[boundAddresses.size()];
    for (int i = 0; i < boundAddresses.size(); i++) {
        InetSocketAddress boundAddress = boundAddresses.get(i);
        boundAddressesHostStrings[i] = boundAddress.getHostString();
        transportBoundAddresses[i] = new TransportAddress(boundAddress);
    }
    final String[] publishHosts;
    if (TransportSettings.DEFAULT_PROFILE.equals(name)) {
        publishHosts = TransportSettings.PUBLISH_HOST.get(settings).toArray(Strings.EMPTY_ARRAY);
    } else {
        publishHosts = profileSettings.getAsArray("publish_host", boundAddressesHostStrings);
    }
    final InetAddress publishInetAddress;
    try {
        publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
    } catch (Exception e) {
        throw new BindTransportException("Failed to resolve publish address", e);
    }
    final int publishPort = resolvePublishPort(name, settings, profileSettings, boundAddresses, publishInetAddress);
    final TransportAddress publishAddress = new TransportAddress(new InetSocketAddress(publishInetAddress, publishPort));
    return new BoundTransportAddress(transportBoundAddresses, publishAddress);
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) InetSocketAddress(java.net.InetSocketAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) InetAddress(java.net.InetAddress) ElasticsearchException(org.elasticsearch.ElasticsearchException) NotCompressedException(org.elasticsearch.common.compress.NotCompressedException) StreamCorruptedException(java.io.StreamCorruptedException) CancelledKeyException(java.nio.channels.CancelledKeyException) NetworkExceptionHelper.isCloseConnectionException(org.elasticsearch.common.transport.NetworkExceptionHelper.isCloseConnectionException) BindException(java.net.BindException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) NetworkExceptionHelper.isConnectException(org.elasticsearch.common.transport.NetworkExceptionHelper.isConnectException)

Example 89 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.

the class TransportClientBenchmark method client.

@Override
protected TransportClient client(String benchmarkTargetHost) throws Exception {
    TransportClient client = new PreBuiltTransportClient(Settings.EMPTY, NoopPlugin.class);
    client.addTransportAddress(new TransportAddress(InetAddress.getByName(benchmarkTargetHost), 9300));
    return client;
}
Also used : TransportClient(org.elasticsearch.client.transport.TransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) PreBuiltTransportClient(org.elasticsearch.transport.client.PreBuiltTransportClient) TransportAddress(org.elasticsearch.common.transport.TransportAddress)

Example 90 with TransportAddress

use of org.elasticsearch.common.transport.TransportAddress in project elasticsearch by elastic.

the class ESIntegTestCase method createRestClient.

protected static RestClient createRestClient(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback, String protocol) {
    final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    final List<NodeInfo> nodes = nodeInfos.getNodes();
    assertFalse(nodeInfos.hasFailures());
    List<HttpHost> hosts = new ArrayList<>();
    for (NodeInfo node : nodes) {
        if (node.getHttp() != null) {
            TransportAddress publishAddress = node.getHttp().address().publishAddress();
            InetSocketAddress address = publishAddress.address();
            hosts.add(new HttpHost(NetworkAddress.format(address.getAddress()), address.getPort(), protocol));
        }
    }
    RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()]));
    if (httpClientConfigCallback != null) {
        builder.setHttpClientConfigCallback(httpClientConfigCallback);
    }
    return builder.build();
}
Also used : NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) HttpHost(org.apache.http.HttpHost) TransportAddress(org.elasticsearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RestClientBuilder(org.elasticsearch.client.RestClientBuilder)

Aggregations

TransportAddress (org.elasticsearch.common.transport.TransportAddress)129 Settings (org.elasticsearch.common.settings.Settings)46 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)45 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)33 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)30 InetSocketAddress (java.net.InetSocketAddress)28 InetAddress (java.net.InetAddress)22 PreBuiltTransportClient (org.elasticsearch.transport.client.PreBuiltTransportClient)20 HashSet (java.util.HashSet)16 UnknownHostException (java.net.UnknownHostException)15 TransportClient (org.elasticsearch.client.transport.TransportClient)15 TransportService (org.elasticsearch.transport.TransportService)14 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)12 ClusterState (org.elasticsearch.cluster.ClusterState)12 NetworkService (org.elasticsearch.common.network.NetworkService)12 ThreadPool (org.elasticsearch.threadpool.ThreadPool)12 HashMap (java.util.HashMap)11 List (java.util.List)11