Search in sources :

Example 1 with BoundTransportAddress

use of org.opensearch.common.transport.BoundTransportAddress in project OpenSearch by opensearch-project.

the class Bootstrap method setup.

private void setup(boolean addShutdownHook, Environment environment) throws BootstrapException {
    Settings settings = environment.settings();
    try {
        spawner.spawnNativeControllers(environment, true);
    } 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, spawner);
                    LoggerContext context = (LoggerContext) LogManager.getContext(false);
                    Configurator.shutdown(context);
                    if (node != null && node.awaitClose(10, TimeUnit.SECONDS) == false) {
                        throw new IllegalStateException("Node didn't stop within 10 seconds. " + "Any outstanding requests or tasks might get killed.");
                    }
                } catch (IOException ex) {
                    throw new OpenSearchException("failed to stop node", ex);
                } catch (InterruptedException e) {
                    LogManager.getLogger(Bootstrap.class).warn("Thread got interrupted while waiting for the node to shutdown.");
                    Thread.currentThread().interrupt();
                }
            }
        });
    }
    try {
        // look for jar hell
        final Logger logger = LogManager.getLogger(JarHell.class);
        JarHell.checkJarHell(logger::debug);
    } 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 BootstrapContext context, final BoundTransportAddress boundTransportAddress, List<BootstrapCheck> checks) throws NodeValidationException {
            BootstrapChecks.check(context, boundTransportAddress, checks);
        }
    };
}
Also used : Node(org.opensearch.node.Node) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DeprecationLogger(org.opensearch.common.logging.DeprecationLogger) Logger(org.apache.logging.log4j.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext) NodeValidationException(org.opensearch.node.NodeValidationException) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) OpenSearchException(org.opensearch.OpenSearchException) Settings(org.opensearch.common.settings.Settings) SecureSettings(org.opensearch.common.settings.SecureSettings)

Example 2 with BoundTransportAddress

use of org.opensearch.common.transport.BoundTransportAddress in project OpenSearch by opensearch-project.

the class AbstractHttpServerTransport method bindServer.

protected void bindServer() {
    // 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);
    TransportAddress publishAddress = new TransportAddress(new InetSocketAddress(publishInetAddress, publishPort));
    this.boundAddress = new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), publishAddress);
    logger.info("{}", boundAddress);
}
Also used : BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) BindTransportException(org.opensearch.transport.BindTransportException) IOException(java.io.IOException) InetAddress(java.net.InetAddress) CancelledKeyException(java.nio.channels.CancelledKeyException) IOException(java.io.IOException) BindTransportException(org.opensearch.transport.BindTransportException)

Example 3 with BoundTransportAddress

use of org.opensearch.common.transport.BoundTransportAddress in project OpenSearch by opensearch-project.

the class HttpInfoTests method testCorrectlyDisplayPublishedCname.

public void testCorrectlyDisplayPublishedCname() throws Exception {
    InetAddress localhost = InetAddress.getByName("localhost");
    int port = 9200;
    assertPublishAddress(new HttpInfo(new BoundTransportAddress(new TransportAddress[] { new TransportAddress(localhost, port) }, new TransportAddress(localhost, port)), 0L), "localhost/" + NetworkAddress.format(localhost) + ':' + port);
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) InetAddress(java.net.InetAddress)

Example 4 with BoundTransportAddress

use of org.opensearch.common.transport.BoundTransportAddress in project OpenSearch by opensearch-project.

the class HttpInfoTests method testCorrectDisplayPublishedIpv6.

public void testCorrectDisplayPublishedIpv6() throws Exception {
    int port = 9200;
    TransportAddress localhost = new TransportAddress(InetAddress.getByName(NetworkAddress.format(InetAddress.getByName("0:0:0:0:0:0:0:1"))), port);
    assertPublishAddress(new HttpInfo(new BoundTransportAddress(new TransportAddress[] { localhost }, localhost), 0L), localhost.toString());
}
Also used : TransportAddress(org.opensearch.common.transport.TransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress)

Example 5 with BoundTransportAddress

use of org.opensearch.common.transport.BoundTransportAddress in project OpenSearch by opensearch-project.

the class SeedHostsResolverTests method testUnknownHost.

public void testUnknownHost() {
    final Logger logger = mock(Logger.class);
    final NetworkService networkService = new NetworkService(Collections.emptyList());
    final String hostname = randomAlphaOfLength(8);
    final UnknownHostException unknownHostException = new UnknownHostException(hostname);
    final Transport transport = new MockNioTransport(Settings.EMPTY, Version.CURRENT, threadPool, networkService, PageCacheRecycler.NON_RECYCLING_INSTANCE, new NamedWriteableRegistry(Collections.emptyList()), new NoneCircuitBreakerService()) {

        @Override
        public BoundTransportAddress boundAddress() {
            return new BoundTransportAddress(new TransportAddress[] { new TransportAddress(InetAddress.getLoopbackAddress(), 9300) }, new TransportAddress(InetAddress.getLoopbackAddress(), 9300));
        }

        @Override
        public TransportAddress[] addressesFromString(String address) throws UnknownHostException {
            throw unknownHostException;
        }
    };
    closeables.push(transport);
    final TransportService transportService = new TransportService(Settings.EMPTY, transport, threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null, Collections.emptySet());
    closeables.push(transportService);
    final List<TransportAddress> transportAddresses = SeedHostsResolver.resolveHostsLists(new CancellableThreads(), executorService, logger, Arrays.asList(hostname), transportService, TimeValue.timeValueSeconds(30));
    assertThat(transportAddresses, empty());
    verify(logger).warn("failed to resolve host [" + hostname + "]", unknownHostException);
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) CancellableThreads(org.opensearch.common.util.CancellableThreads) UnknownHostException(java.net.UnknownHostException) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) TransportAddress(org.opensearch.common.transport.TransportAddress) Logger(org.apache.logging.log4j.Logger) TransportService(org.opensearch.transport.TransportService) BoundTransportAddress(org.opensearch.common.transport.BoundTransportAddress) NetworkService(org.opensearch.common.network.NetworkService) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) Transport(org.opensearch.transport.Transport) MockNioTransport(org.opensearch.transport.nio.MockNioTransport) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)24 TransportAddress (org.opensearch.common.transport.TransportAddress)20 ArrayList (java.util.ArrayList)9 InetAddress (java.net.InetAddress)7 IOException (java.io.IOException)6 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)6 NetworkService (org.opensearch.common.network.NetworkService)6 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)6 MockNioTransport (org.opensearch.transport.nio.MockNioTransport)6 UnknownHostException (java.net.UnknownHostException)5 Logger (org.apache.logging.log4j.Logger)5 Settings (org.opensearch.common.settings.Settings)5 InetSocketAddress (java.net.InetSocketAddress)4 CancellableThreads (org.opensearch.common.util.CancellableThreads)4 Transport (org.opensearch.transport.Transport)4 TransportService (org.opensearch.transport.TransportService)4 List (java.util.List)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 NodeInfo (org.opensearch.action.admin.cluster.node.info.NodeInfo)3 TransportInfo (org.opensearch.transport.TransportInfo)3