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);
}
};
}
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);
}
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);
}
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());
}
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);
}
Aggregations