mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-04 01:59:35 +00:00
bug6038: consistently map internal IP to hostname in MongoDB processes
This commit is contained in:
1 parent
d8e66345ff
commit
72923ec512
4 files changed
+26
-9
No files matched your search
+10
@@ -152,6 +152,16 @@ public class AwsInstanceImpl<ShardingKey> implements AwsInstance<ShardingKey> {
|
||||
@Override
|
||||
public String getHostname() {
|
||||
final String privateIpAddress = getPrivateAddress().getHostAddress();
|
||||
return getHostnameForPrivateAddress(privateIpAddress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHostname(Optional<Duration> timeoutEmptyMeaningForever) {
|
||||
final String privateIpAddress = getPrivateAddress(timeoutEmptyMeaningForever).getHostAddress();
|
||||
return getHostnameForPrivateAddress(privateIpAddress);
|
||||
}
|
||||
|
||||
private String getHostnameForPrivateAddress(final String privateIpAddress) {
|
||||
final String result;
|
||||
if (privateIpAddress == null) {
|
||||
result = null;
|
||||
|
||||
@@ -65,6 +65,14 @@ public interface Host extends WithID {
|
||||
return getPrivateAddress().getHostAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* By default, this returns the stringified {@link #getPrivateAddress()}. Specialized implementations
|
||||
* may choose to try to map this to a host name through a reverse DNS lookup.
|
||||
*/
|
||||
default String getHostname(Optional<Duration> timeoutEmptyMeaningForever) {
|
||||
return getPrivateAddress(timeoutEmptyMeaningForever).getHostAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to an SSH session for the username specified, using the SSH key pair used to launch the instance, and
|
||||
* opens a "shell" channel. Use the {@link Channel} returned by {@link Channel#setInputStream(java.io.InputStream)
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface Process<LogT extends Log, MetricsT extends Metrics> {
|
||||
}
|
||||
|
||||
default String getHostname(Optional<Duration> timeoutEmptyMeaningForever) {
|
||||
return getHost().getPrivateAddress(timeoutEmptyMeaningForever).getHostAddress();
|
||||
return getHost().getHostname(timeoutEmptyMeaningForever);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.sap.sse.landscape.mongodb;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
@@ -24,18 +23,18 @@ public interface MongoReplicaSet extends Named, MongoEndpoint {
|
||||
*/
|
||||
@Override
|
||||
default URI getURI(Optional<Database> optionalDb) throws URISyntaxException {
|
||||
return getURI(optionalDb, mongoProcess->mongoProcess.getHost().getPrivateAddress());
|
||||
return getURI(optionalDb, mongoProcess->mongoProcess.getHost().getHostname());
|
||||
}
|
||||
|
||||
default URI getURI(Optional<Database> optionalDb, Function<MongoProcess, InetAddress> addressSupplier) throws URISyntaxException {
|
||||
default URI getURI(Optional<Database> optionalDb, Function<MongoProcess, String> addressSupplier) throws URISyntaxException {
|
||||
final StringBuilder result = new StringBuilder("mongodb://");
|
||||
final List<String> hostSpecs = new ArrayList<>();
|
||||
for (final MongoProcess mongoProcess : getInstances()) {
|
||||
final InetAddress address = addressSupplier.apply(mongoProcess);
|
||||
if (address != null) {
|
||||
logger.fine("Adding MongoDB process running on "+address+" to replica set "+this.getName());
|
||||
final String hostname = addressSupplier.apply(mongoProcess);
|
||||
if (hostname != null) {
|
||||
logger.fine("Adding MongoDB process running on "+hostname+" to replica set "+this.getName());
|
||||
final StringBuilder hostSpec = new StringBuilder();
|
||||
hostSpec.append(address.getHostAddress());
|
||||
hostSpec.append(hostname);
|
||||
if (mongoProcess.getPort() != MongoDBConstants.DEFAULT_PORT) {
|
||||
hostSpec.append(":");
|
||||
hostSpec.append(mongoProcess.getPort());
|
||||
@@ -57,7 +56,7 @@ public interface MongoReplicaSet extends Named, MongoEndpoint {
|
||||
default URI getURI(Optional<Database> optionalDb, Optional<Duration> timeoutEmptyMeansForever) throws URISyntaxException {
|
||||
return getURI(optionalDb, mongoProcess->{
|
||||
try {
|
||||
return mongoProcess.getHost().getPublicAddress(timeoutEmptyMeansForever);
|
||||
return mongoProcess.getHost().getPublicAddress(timeoutEmptyMeansForever).getHostAddress();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user