Search in sources :

Example 1 with InetAddressChooser

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();
}
Also used : InetAddressChooser(org.platformlayer.InetAddressChooser) InetAddress(java.net.InetAddress)

Example 2 with InetAddressChooser

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);
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) InetAddressChooser(org.platformlayer.InetAddressChooser) DatabaseServer(org.platformlayer.ops.databases.DatabaseServer)

Example 3 with 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);
}
Also used : ItemBase(org.platformlayer.core.model.ItemBase) InetAddressChooser(org.platformlayer.InetAddressChooser) DatabaseServer(org.platformlayer.ops.databases.DatabaseServer)

Example 4 with 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;
}
Also used : InetAddressChooser(org.platformlayer.InetAddressChooser) SimpleLinkConsumer(org.platformlayer.ops.uses.SimpleLinkConsumer) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 5 with InetAddressChooser

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;
}
Also used : OpsException(org.platformlayer.ops.OpsException) InetAddressChooser(org.platformlayer.InetAddressChooser) URISyntaxException(java.net.URISyntaxException) InetAddress(java.net.InetAddress) URI(java.net.URI) Machine(org.platformlayer.ops.Machine)

Aggregations

InetAddressChooser (org.platformlayer.InetAddressChooser)7 ItemBase (org.platformlayer.core.model.ItemBase)3 DatabaseServer (org.platformlayer.ops.databases.DatabaseServer)3 InetAddress (java.net.InetAddress)2 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)2 SimpleLinkConsumer (org.platformlayer.ops.uses.SimpleLinkConsumer)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Link (org.platformlayer.core.model.Link)1 Machine (org.platformlayer.ops.Machine)1 OpsException (org.platformlayer.ops.OpsException)1