Search in sources :

Example 1 with BoundTransportAddress

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

the class TcpTransport method bindServer.

protected void bindServer(final String name, final Settings settings) {
    // Bind and start to accept incoming connections.
    InetAddress[] hostAddresses;
    String[] bindHosts = settings.getAsArray("bind_host", null);
    try {
        hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
    } catch (IOException e) {
        throw new BindTransportException("Failed to resolve host " + Arrays.toString(bindHosts) + "", e);
    }
    if (logger.isDebugEnabled()) {
        String[] addresses = new String[hostAddresses.length];
        for (int i = 0; i < hostAddresses.length; i++) {
            addresses[i] = NetworkAddress.format(hostAddresses[i]);
        }
        logger.debug("binding server bootstrap to: {}", (Object) addresses);
    }
    assert hostAddresses.length > 0;
    List<InetSocketAddress> boundAddresses = new ArrayList<>();
    for (InetAddress hostAddress : hostAddresses) {
        boundAddresses.add(bindToPort(name, hostAddress, settings.get("port")));
    }
    final BoundTransportAddress boundTransportAddress = createBoundTransportAddress(name, settings, boundAddresses);
    if (TransportSettings.DEFAULT_PROFILE.equals(name)) {
        this.boundAddress = boundTransportAddress;
    } else {
        profileBoundAddresses.put(name, boundTransportAddress);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Example 2 with BoundTransportAddress

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

the class Bootstrap method setup.

private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
    Settings settings = environment.settings();
    try {
        spawner.spawnNativePluginControllers(environment);
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    spawner.close();
                } catch (IOException e) {
                    throw new ElasticsearchException("Failed to destroy spawned controllers", e);
                }
            }
        });
    } catch (IOException e) {
        throw new BootstrapException(e);
    }
    initializeNatives(environment.tmpFile(), BootstrapSettings.MEMORY_LOCK_SETTING.get(settings), BootstrapSettings.SYSTEM_CALL_FILTER_SETTING.get(settings), BootstrapSettings.CTRLHANDLER_SETTING.get(settings));
    // initialize probes before the security manager is installed
    initializeProbes();
    if (addShutdownHook) {
        Runtime.getRuntime().addShutdownHook(new Thread() {

            @Override
            public void run() {
                try {
                    IOUtils.close(node);
                    LoggerContext context = (LoggerContext) LogManager.getContext(false);
                    Configurator.shutdown(context);
                } catch (IOException ex) {
                    throw new ElasticsearchException("failed to stop node", ex);
                }
            }
        });
    }
    try {
        // look for jar hell
        JarHell.checkJarHell();
    } catch (IOException | URISyntaxException e) {
        throw new BootstrapException(e);
    }
    // Log ifconfig output before SecurityManager is installed
    IfConfig.logIfNecessary();
    // install SM after natives, shutdown hooks, etc.
    try {
        Security.configure(environment, BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING.get(settings));
    } catch (IOException | NoSuchAlgorithmException e) {
        throw new BootstrapException(e);
    }
    node = new Node(environment) {

        @Override
        protected void validateNodeBeforeAcceptingRequests(final Settings settings, final BoundTransportAddress boundTransportAddress, List<BootstrapCheck> checks) throws NodeValidationException {
            BootstrapChecks.check(settings, boundTransportAddress, checks);
        }
    };
}
Also used : Node(org.elasticsearch.node.Node) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LoggerContext(org.apache.logging.log4j.core.LoggerContext) NodeValidationException(org.elasticsearch.node.NodeValidationException) BoundTransportAddress(org.elasticsearch.common.transport.BoundTransportAddress) Settings(org.elasticsearch.common.settings.Settings) SecureSettings(org.elasticsearch.common.settings.SecureSettings)

Example 3 with BoundTransportAddress

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

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

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

Aggregations

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