use of org.elasticsearch.transport.BindTransportException 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));
}
use of org.elasticsearch.transport.BindTransportException in project elasticsearch by elastic.
the class SimpleNetty4TransportTests method testBindUnavailableAddress.
public void testBindUnavailableAddress() {
// this is on a lower level since it needs access to the TransportService before it's started
int port = serviceA.boundAddress().publishAddress().getPort();
Settings settings = Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "foobar").put(TransportService.TRACE_LOG_INCLUDE_SETTING.getKey(), "").put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), "NOTHING").put("transport.tcp.port", port).build();
ClusterSettings clusterSettings = new ClusterSettings(settings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
BindTransportException bindTransportException = expectThrows(BindTransportException.class, () -> {
MockTransportService transportService = nettyFromThreadPool(settings, threadPool, Version.CURRENT, clusterSettings, true);
try {
transportService.start();
} finally {
transportService.stop();
transportService.close();
}
});
assertEquals("Failed to bind to [" + port + "]", bindTransportException.getMessage());
}
use of org.elasticsearch.transport.BindTransportException in project elasticsearch-jetty by sonian.
the class JettyHttpServerTransport method doStart.
@Override
protected void doStart() throws ElasticsearchException {
PortsRange portsRange = new PortsRange(port);
final AtomicReference<Exception> lastException = new AtomicReference<Exception>();
Log.setLog(loggerWrapper);
portsRange.iterate(new PortsRange.PortCallback() {
@Override
public boolean onPortNumber(int portNumber) {
try {
Server server = null;
XmlConfiguration lastXmlConfiguration = null;
Object[] objs = new Object[jettyConfig.length];
Map<String, String> esProperties = jettySettings(bindHost, portNumber);
for (int i = 0; i < jettyConfig.length; i++) {
String configFile = jettyConfig[i];
URL config = environment.resolveConfig(configFile);
XmlConfiguration xmlConfiguration = new XmlConfiguration(config);
// in the later configurations
if (lastXmlConfiguration != null) {
xmlConfiguration.getIdMap().putAll(lastXmlConfiguration.getIdMap());
} else {
xmlConfiguration.getIdMap().put("ESServerTransport", JettyHttpServerTransport.this);
xmlConfiguration.getIdMap().put("ESClient", client);
}
// Inject elasticsearch properties
xmlConfiguration.getProperties().putAll(esProperties);
objs[i] = xmlConfiguration.configure();
lastXmlConfiguration = xmlConfiguration;
}
// Find jetty Server with id jettyConfigServerId
Object serverObject = lastXmlConfiguration.getIdMap().get(jettyConfigServerId);
if (serverObject != null) {
if (serverObject instanceof Server) {
server = (Server) serverObject;
}
} else {
// For compatibility - if it's not available, find first available jetty Server
for (Object obj : objs) {
if (obj instanceof Server) {
server = (Server) obj;
break;
}
}
}
if (server == null) {
logger.error("Cannot find server with id [{}] in configuration files [{}]", jettyConfigServerId, jettyConfig);
lastException.set(new ElasticsearchException("Cannot find server with id " + jettyConfigServerId));
return true;
}
// Keep it for now for backward compatibility with previous versions of jetty.xml
server.setAttribute(TRANSPORT_ATTRIBUTE, JettyHttpServerTransport.this);
// Start all lifecycle objects configured by xml configurations
for (Object obj : objs) {
if (obj instanceof LifeCycle) {
LifeCycle lifeCycle = (LifeCycle) obj;
if (!lifeCycle.isRunning()) {
lifeCycle.start();
}
}
}
jettyServer = server;
lastException.set(null);
} catch (BindException e) {
lastException.set(e);
return false;
} catch (Exception e) {
logger.error("Jetty Startup Failed ", e);
lastException.set(e);
return true;
}
return true;
}
});
if (lastException.get() != null) {
throw new BindHttpException("Failed to bind to [" + port + "]", lastException.get());
}
InetSocketAddress jettyBoundAddress = findFirstInetConnector(jettyServer);
if (jettyBoundAddress != null) {
InetSocketAddress publishAddress;
try {
publishAddress = new InetSocketAddress(networkService.resolvePublishHostAddress(publishHost), jettyBoundAddress.getPort());
} catch (Exception e) {
throw new BindTransportException("Failed to resolve publish address", e);
}
this.boundAddress = new BoundTransportAddress(new InetSocketTransportAddress(jettyBoundAddress), new InetSocketTransportAddress(publishAddress));
} else {
throw new BindHttpException("Failed to find a jetty connector with Inet transport");
}
}
use of org.elasticsearch.transport.BindTransportException in project crate by crate.
the class PostgresNetty method resolveBindAddress.
private BoundTransportAddress resolveBindAddress() {
// Bind and start to accept incoming connections.
try {
InetAddress[] hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
for (InetAddress address : hostAddresses) {
if (address instanceof Inet4Address || address instanceof Inet6Address) {
boundAddresses.add(bindAddress(address));
}
}
} catch (IOException e) {
throw new BindPostgresException("Failed to resolve binding network host", e);
}
final InetAddress publishInetAddress;
try {
publishInetAddress = networkService.resolvePublishHostAddresses(publishHosts);
} catch (Exception e) {
throw new BindTransportException("Failed to resolve publish address", e);
}
final int publishPort = resolvePublishPort(boundAddresses, publishInetAddress);
final InetSocketAddress publishAddress = new InetSocketAddress(publishInetAddress, publishPort);
return new BoundTransportAddress(boundAddresses.toArray(new TransportAddress[0]), new TransportAddress(publishAddress));
}
use of org.elasticsearch.transport.BindTransportException in project crate by crate.
the class PostgresNettyPublishPortTest method testPublishAddressOverride.
@Test
public void testPublishAddressOverride() {
// Check override for network.publish_host
Settings settingsWithCustomPublish = Settings.builder().put("network.publish_host", "cantbindtothis").build();
NetworkService networkService = new NetworkService(Collections.emptyList());
StubUserManager userManager = new StubUserManager();
PostgresNetty psql = new PostgresNetty(settingsWithCustomPublish, mock(SQLOperations.class), userManager, networkService, new AlwaysOKAuthentication(userName -> User.CRATE_USER), new NettyBootstrap(), mock(SslContextProvider.class));
try {
psql.doStart();
fail("Should have failed due to custom hostname");
} catch (BindTransportException e) {
// that's what we want
assertThat(e.getCause(), instanceOf(UnknownHostException.class));
} finally {
psql.doStop();
psql.close();
}
}
Aggregations