use of org.platformlayer.InetAddressChooser in project platformlayer by platformlayer.
the class NetworkPoint method getBestAddress.
public String getBestAddress(NetworkPoint src) throws OpsException {
InetAddressChooser chooser;
if (!src.isPublicAddress()) {
chooser = InetAddressChooser.preferIpv6();
} else {
chooser = InetAddressChooser.preferIpv4();
}
InetAddress address = getBestAddress(src, chooser);
if (address == null) {
return null;
}
return address.getHostAddress();
}
use of org.platformlayer.InetAddressChooser in project platformlayer by platformlayer.
the class DatabaseController method buildLinkTargetConfiguration.
@Override
public Map<String, String> buildLinkTargetConfiguration(LinkConsumer consumer) throws OpsException {
ItemBase serverItem = platformLayer.getItem(model.server);
DatabaseServer databaseServer = providers.toInterface(serverItem, DatabaseServer.class);
InetAddressChooser inetAddressChooser = consumer.getInetAddressChooser();
return databaseServer.buildTargetConfiguration(model.username, model.password, model.databaseName, inetAddressChooser);
}
use of org.platformlayer.InetAddressChooser in project platformlayer by platformlayer.
the class PlatformLayerDatabaseController method buildLinkTargetConfiguration.
@Override
public Map<String, String> buildLinkTargetConfiguration(LinkConsumer consumer) throws OpsException {
ItemBase serverItem = platformLayer.getItem(model.server);
DatabaseServer databaseServer = providers.toInterface(serverItem, DatabaseServer.class);
InetAddressChooser inetAddressChooser = consumer.getInetAddressChooser();
return databaseServer.buildTargetConfiguration(model.username, model.password, model.databaseName, inetAddressChooser);
}
use of org.platformlayer.InetAddressChooser in project platformlayer by platformlayer.
the class SimpleApp method getConfigurationProperties.
protected Map<String, String> getConfigurationProperties() throws OpsException {
Map<String, String> config = Maps.newHashMap();
if (context.links != null) {
NetworkPoint networkPoint = NetworkPoint.forTargetInContext();
InetAddressChooser inetAddressChooser = NearestAddressChooser.build(networkPoint);
SimpleLinkConsumer consumer = new SimpleLinkConsumer(consumerKey, inetAddressChooser);
config.putAll(consumeHelper.buildLinkTargetProperties(consumer, context.links.getLinks()));
}
return config;
}
use of org.platformlayer.InetAddressChooser in project platformlayer by platformlayer.
the class HttpBackends method buildUri.
public URI buildUri(NetworkPoint src, String scheme, ItemBase model, int port) throws OpsException {
Machine machine = instances.getMachine(model);
InetAddressChooser chooser = InetAddressChooser.preferIpv6();
InetAddress address = machine.getNetworkPoint().getBestAddress(src, chooser);
String host = InetAddresses.toAddrString(address);
URI uri;
try {
uri = new URI(scheme, null, host, port, null, null, null);
} catch (URISyntaxException e) {
throw new OpsException("Error building URI", e);
}
return uri;
}
Aggregations