Search in sources :

Example 21 with BoundTransportAddress

use of org.elasticsearch.common.transport.BoundTransportAddress 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 22 with BoundTransportAddress

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

the class MockTransportService method extractTransportAddresses.

public static TransportAddress[] extractTransportAddresses(TransportService transportService) {
    HashSet<TransportAddress> transportAddresses = new HashSet<>();
    BoundTransportAddress boundTransportAddress = transportService.boundAddress();
    transportAddresses.addAll(Arrays.asList(boundTransportAddress.boundAddresses()));
    transportAddresses.add(boundTransportAddress.publishAddress());
    return transportAddresses.toArray(new TransportAddress[transportAddresses.size()]);
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) HashSet(java.util.HashSet)

Aggregations

BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)22 TransportAddress (org.elasticsearch.common.transport.TransportAddress)16 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 InetAddress (java.net.InetAddress)7 InetSocketAddress (java.net.InetSocketAddress)7 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)7 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)6 NetworkService (org.elasticsearch.common.network.NetworkService)6 Settings (org.elasticsearch.common.settings.Settings)6 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)6 MockTransportService (org.elasticsearch.test.transport.MockTransportService)6 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)6 UnknownHostException (java.net.UnknownHostException)5 Logger (org.apache.logging.log4j.Logger)5 Transport (org.elasticsearch.transport.Transport)5 TransportService (org.elasticsearch.transport.TransportService)5 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 List (java.util.List)3