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));
}
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());
}
use of org.elasticsearch.common.transport.BoundTransportAddress 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.common.transport.BoundTransportAddress in project elasticsearch by elastic.
the class Node method writePortsFile.
/** Writes a file to the logs dir containing the ports for the given transport type */
private void writePortsFile(String type, BoundTransportAddress boundAddress) {
Path tmpPortsFile = environment.logsFile().resolve(type + ".ports.tmp");
try (BufferedWriter writer = Files.newBufferedWriter(tmpPortsFile, Charset.forName("UTF-8"))) {
for (TransportAddress address : boundAddress.boundAddresses()) {
InetAddress inetAddress = InetAddress.getByName(address.getAddress());
if (inetAddress instanceof Inet6Address && inetAddress.isLinkLocalAddress()) {
// no link local, just causes problems
continue;
}
writer.write(NetworkAddress.format(new InetSocketAddress(inetAddress, address.getPort())) + "\n");
}
} catch (IOException e) {
throw new RuntimeException("Failed to write ports file", e);
}
Path portsFile = environment.logsFile().resolve(type + ".ports");
try {
Files.move(tmpPortsFile, portsFile, StandardCopyOption.ATOMIC_MOVE);
} catch (IOException e) {
throw new RuntimeException("Failed to rename ports file", e);
}
}
use of org.elasticsearch.common.transport.BoundTransportAddress in project elasticsearch by elastic.
the class Netty4TransportMultiPortIntegrationIT method testThatInfosAreExposed.
@Network
public void testThatInfosAreExposed() throws Exception {
NodesInfoResponse response = client().admin().cluster().prepareNodesInfo().clear().setTransport(true).get();
for (NodeInfo nodeInfo : response.getNodes()) {
assertThat(nodeInfo.getTransport().getProfileAddresses().keySet(), hasSize(1));
assertThat(nodeInfo.getTransport().getProfileAddresses(), hasKey("client1"));
BoundTransportAddress boundTransportAddress = nodeInfo.getTransport().getProfileAddresses().get("client1");
for (TransportAddress transportAddress : boundTransportAddress.boundAddresses()) {
assertThat(transportAddress, instanceOf(TransportAddress.class));
}
// bound addresses
for (TransportAddress transportAddress : boundTransportAddress.boundAddresses()) {
assertThat(transportAddress, instanceOf(TransportAddress.class));
assertThat(transportAddress.address().getPort(), is(allOf(greaterThanOrEqualTo(randomPort), lessThanOrEqualTo(randomPort + 10))));
}
// publish address
assertThat(boundTransportAddress.publishAddress(), instanceOf(TransportAddress.class));
TransportAddress publishAddress = boundTransportAddress.publishAddress();
assertThat(NetworkAddress.format(publishAddress.address().getAddress()), is("127.0.0.7"));
assertThat(publishAddress.address().getPort(), is(4321));
}
}
Aggregations