Search in sources :

Example 6 with BindHttpException

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

the class Netty4HttpPublishPortTests method testHttpPublishPort.

public void testHttpPublishPort() throws Exception {
    int boundPort = randomIntBetween(9000, 9100);
    int otherBoundPort = randomIntBetween(9200, 9300);
    int publishPort = resolvePublishPort(Settings.builder().put(HttpTransportSettings.SETTING_HTTP_PUBLISH_PORT.getKey(), 9080).build(), randomAddresses(), getByName("127.0.0.2"));
    assertThat("Publish port should be explicitly set to 9080", publishPort, equalTo(9080));
    publishPort = resolvePublishPort(Settings.EMPTY, asList(address("127.0.0.1", boundPort), address("127.0.0.2", otherBoundPort)), getByName("127.0.0.1"));
    assertThat("Publish port should be derived from matched address", publishPort, equalTo(boundPort));
    publishPort = resolvePublishPort(Settings.EMPTY, asList(address("127.0.0.1", boundPort), address("127.0.0.2", boundPort)), getByName("127.0.0.3"));
    assertThat("Publish port should be derived from unique port of bound addresses", publishPort, equalTo(boundPort));
    final BindHttpException e = expectThrows(BindHttpException.class, () -> resolvePublishPort(Settings.EMPTY, asList(address("127.0.0.1", boundPort), address("127.0.0.2", otherBoundPort)), getByName("127.0.0.3")));
    assertThat(e.getMessage(), containsString("Failed to auto-resolve http publish port"));
    publishPort = resolvePublishPort(Settings.EMPTY, asList(address("0.0.0.0", boundPort), address("127.0.0.2", otherBoundPort)), getByName("127.0.0.1"));
    assertThat("Publish port should be derived from matching wildcard address", publishPort, equalTo(boundPort));
    if (NetworkUtils.SUPPORTS_V6) {
        publishPort = resolvePublishPort(Settings.EMPTY, asList(address("0.0.0.0", boundPort), address("127.0.0.2", otherBoundPort)), getByName("::1"));
        assertThat("Publish port should be derived from matching wildcard address", publishPort, equalTo(boundPort));
    }
}
Also used : BindHttpException(org.elasticsearch.http.BindHttpException)

Example 7 with BindHttpException

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

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 : BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) 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) SettingsException(org.elasticsearch.common.settings.SettingsException) IOException(java.io.IOException) PatternSyntaxException(java.util.regex.PatternSyntaxException) BindTransportException(org.elasticsearch.transport.BindTransportException)

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