Search in sources :

Example 21 with TransportAddress

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

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);
    assertTrue(BootstrapChecks.enforceLimits(boundTransportAddress));
}
Also used : BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress)

Example 22 with TransportAddress

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

the class BootstrapChecksTests method testEnforceLimitsWhenBoundToNonLocalAddress.

public void testEnforceLimitsWhenBoundToNonLocalAddress() {
    final List<TransportAddress> transportAddresses = new ArrayList<>();
    final TransportAddress nonLocalTransportAddress = buildNewFakeTransportAddress();
    transportAddresses.add(nonLocalTransportAddress);
    for (int i = 0; i < randomIntBetween(0, 7); i++) {
        final TransportAddress randomTransportAddress = randomBoolean() ? buildNewFakeTransportAddress() : new TransportAddress(InetAddress.getLoopbackAddress(), i);
        transportAddresses.add(randomTransportAddress);
    }
    final TransportAddress publishAddress = randomBoolean() ? buildNewFakeTransportAddress() : new TransportAddress(InetAddress.getLoopbackAddress(), 0);
    final BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
    Collections.shuffle(transportAddresses, random());
    when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
    when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
    assertTrue(BootstrapChecks.enforceLimits(boundTransportAddress));
}
Also used : BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress)

Example 23 with TransportAddress

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

the class BootstrapChecksTests method testNonProductionMode.

public void testNonProductionMode() throws NodeValidationException {
    // nothing should happen since we are in non-production mode
    final List<TransportAddress> transportAddresses = new ArrayList<>();
    for (int i = 0; i < randomIntBetween(1, 8); i++) {
        TransportAddress localTransportAddress = new TransportAddress(InetAddress.getLoopbackAddress(), i);
        transportAddresses.add(localTransportAddress);
    }
    TransportAddress publishAddress = new TransportAddress(InetAddress.getLoopbackAddress(), 0);
    BoundTransportAddress boundTransportAddress = mock(BoundTransportAddress.class);
    when(boundTransportAddress.boundAddresses()).thenReturn(transportAddresses.toArray(new TransportAddress[0]));
    when(boundTransportAddress.publishAddress()).thenReturn(publishAddress);
    BootstrapChecks.check(Settings.EMPTY, boundTransportAddress, Collections.emptyList());
}
Also used : BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress)

Example 24 with TransportAddress

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

the class Netty4HttpServerTransport method createBoundHttpAddress.

private BoundTransportAddress createBoundHttpAddress() {
    // Bind and start to accept incoming connections.
    InetAddress[] hostAddresses;
    try {
        hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
    } catch (IOException e) {
        throw new BindHttpException("Failed to resolve host [" + Arrays.toString(bindHosts) + "]", e);
    }
    List<TransportAddress> boundAddresses = new ArrayList<>(hostAddresses.length);
    for (InetAddress address : hostAddresses) {
        boundAddresses.add(bindAddress(address));
    }
    final InetAddress publishInetAddress;
    try {
        publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
    } catch (Exception e) {
        throw new BindTransportException("Failed to resolve publish address", e);
    }
    final int publishPort = resolvePublishPort(settings, boundAddresses, publishInetAddress);
    final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
    return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), new TransportAddress(publishAddress));
}
Also used : TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) BindTransportException(org.elasticsearch.transport.BindTransportException) IOException(java.io.IOException) BindHttpException(org.elasticsearch.http.BindHttpException) InetAddress(java.net.InetAddress) BindHttpException(org.elasticsearch.http.BindHttpException) BindTransportException(org.elasticsearch.transport.BindTransportException) ReadTimeoutException(io.netty.handler.timeout.ReadTimeoutException) IOException(java.io.IOException)

Example 25 with TransportAddress

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

the class Netty4HttpServerTransportTests method testBindUnavailableAddress.

public void testBindUnavailableAddress() {
    try (Netty4HttpServerTransport transport = new Netty4HttpServerTransport(Settings.EMPTY, networkService, bigArrays, threadPool, xContentRegistry(), new NullDispatcher())) {
        transport.start();
        TransportAddress remoteAddress = randomFrom(transport.boundAddress().boundAddresses());
        Settings settings = Settings.builder().put("http.port", remoteAddress.getPort()).build();
        try (Netty4HttpServerTransport otherTransport = new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(), new NullDispatcher())) {
            BindHttpException bindHttpException = expectThrows(BindHttpException.class, () -> otherTransport.start());
            assertEquals("Failed to bind to [" + remoteAddress.getPort() + "]", bindHttpException.getMessage());
        }
    }
}
Also used : NullDispatcher(org.elasticsearch.http.NullDispatcher) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BindHttpException(org.elasticsearch.http.BindHttpException) Settings(org.elasticsearch.common.settings.Settings) HttpTransportSettings(org.elasticsearch.http.HttpTransportSettings)

Aggregations

TransportAddress (org.elasticsearch.common.transport.TransportAddress)89 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)32 Settings (org.elasticsearch.common.settings.Settings)29 ArrayList (java.util.ArrayList)24 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)24 IOException (java.io.IOException)21 InetSocketAddress (java.net.InetSocketAddress)20 InetAddress (java.net.InetAddress)19 UnknownHostException (java.net.UnknownHostException)12 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)12 TransportService (org.elasticsearch.transport.TransportService)12 HashSet (java.util.HashSet)11 TransportClient (org.elasticsearch.client.transport.TransportClient)11 NetworkService (org.elasticsearch.common.network.NetworkService)11 MockTransportService (org.elasticsearch.test.transport.MockTransportService)11 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)10 HashMap (java.util.HashMap)9 List (java.util.List)9 Logger (org.apache.logging.log4j.Logger)9 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)9