Search in sources :

Example 1 with BindHttpException

use of org.elasticsearch.http.BindHttpException 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 2 with BindHttpException

use of org.elasticsearch.http.BindHttpException 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)

Example 3 with BindHttpException

use of org.elasticsearch.http.BindHttpException in project crate by crate.

the class Netty4HttpServerTransport method bindAddress.

private TransportAddress bindAddress(final InetAddress hostAddress) {
    final AtomicReference<Exception> lastException = new AtomicReference<>();
    final AtomicReference<InetSocketAddress> boundSocket = new AtomicReference<>();
    boolean success = port.iterate(portNumber -> {
        try {
            synchronized (serverChannels) {
                ChannelFuture future = serverBootstrap.bind(new InetSocketAddress(hostAddress, portNumber)).sync();
                serverChannels.add(future.channel());
                boundSocket.set((InetSocketAddress) future.channel().localAddress());
            }
        } catch (Exception e) {
            lastException.set(e);
            return false;
        }
        return true;
    });
    if (!success) {
        throw new BindHttpException("Failed to bind to [" + port.getPortRangeString() + "]", lastException.get());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Bound http to address {{}}", NetworkAddress.format(boundSocket.get()));
    }
    return new TransportAddress(boundSocket.get());
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) BindHttpException(org.elasticsearch.http.BindHttpException) BindHttpException(org.elasticsearch.http.BindHttpException) SettingsException(org.elasticsearch.common.settings.SettingsException) IOException(java.io.IOException) PatternSyntaxException(java.util.regex.PatternSyntaxException) BindTransportException(org.elasticsearch.transport.BindTransportException)

Example 4 with BindHttpException

use of org.elasticsearch.http.BindHttpException in project sonarqube by SonarSource.

the class EsTester method createNode.

private static Node createNode() {
    try {
        Path tempDir = Files.createTempDirectory("EsTester");
        tempDir.toFile().deleteOnExit();
        int i = 10;
        while (i > 0) {
            int httpPort = getNextAvailable();
            try {
                Node node = startNode(tempDir, httpPort);
                LOG.info("EsTester running ElasticSearch on HTTP port {}", httpPort);
                return node;
            } catch (BindHttpException e) {
                i--;
            }
        }
    } catch (Exception e) {
        throw new IllegalStateException("Fail to start embedded Elasticsearch", e);
    }
    throw new IllegalStateException("Failed to find an open port to connect EsTester's Elasticsearch instance after 10 attempts");
}
Also used : Path(java.nio.file.Path) Node(org.elasticsearch.node.Node) BindHttpException(org.elasticsearch.http.BindHttpException) BindHttpException(org.elasticsearch.http.BindHttpException) NodeValidationException(org.elasticsearch.node.NodeValidationException) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException)

Example 5 with BindHttpException

use of org.elasticsearch.http.BindHttpException in project elasticsearch by elastic.

the class Netty4HttpServerTransport method bindAddress.

private TransportAddress bindAddress(final InetAddress hostAddress) {
    final AtomicReference<Exception> lastException = new AtomicReference<>();
    final AtomicReference<InetSocketAddress> boundSocket = new AtomicReference<>();
    boolean success = port.iterate(portNumber -> {
        try {
            synchronized (serverChannels) {
                ChannelFuture future = serverBootstrap.bind(new InetSocketAddress(hostAddress, portNumber)).sync();
                serverChannels.add(future.channel());
                boundSocket.set((InetSocketAddress) future.channel().localAddress());
            }
        } catch (Exception e) {
            lastException.set(e);
            return false;
        }
        return true;
    });
    if (!success) {
        throw new BindHttpException("Failed to bind to [" + port.getPortRangeString() + "]", lastException.get());
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Bound http to address {{}}", NetworkAddress.format(boundSocket.get()));
    }
    return new TransportAddress(boundSocket.get());
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) AtomicReference(java.util.concurrent.atomic.AtomicReference) BindHttpException(org.elasticsearch.http.BindHttpException) BindHttpException(org.elasticsearch.http.BindHttpException) BindTransportException(org.elasticsearch.transport.BindTransportException) ReadTimeoutException(io.netty.handler.timeout.ReadTimeoutException) IOException(java.io.IOException)

Aggregations

BindHttpException (org.elasticsearch.http.BindHttpException)7 IOException (java.io.IOException)5 TransportAddress (org.elasticsearch.common.transport.TransportAddress)5 InetSocketAddress (java.net.InetSocketAddress)4 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)4 BindTransportException (org.elasticsearch.transport.BindTransportException)4 ChannelFuture (io.netty.channel.ChannelFuture)2 ReadTimeoutException (io.netty.handler.timeout.ReadTimeoutException)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 SettingsException (org.elasticsearch.common.settings.SettingsException)2 Path (java.nio.file.Path)1 NoSuchElementException (java.util.NoSuchElementException)1 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)1 Settings (org.elasticsearch.common.settings.Settings)1 HttpTransportSettings (org.elasticsearch.http.HttpTransportSettings)1 NullDispatcher (org.elasticsearch.http.NullDispatcher)1 Node (org.elasticsearch.node.Node)1