Search in sources :

Example 6 with InetAddressChooser

use of org.platformlayer.InetAddressChooser in project platformlayer by platformlayer.

the class StandardTemplateData method getConfigurationProperties.

protected Map<String, String> getConfigurationProperties() throws OpsException {
    Map<String, String> properties = Maps.newHashMap();
    List<Link> modelLinks = getLinks();
    if (modelLinks != null && !modelLinks.isEmpty()) {
        NetworkPoint networkPoint = NetworkPoint.forTargetInContext();
        InetAddressChooser inetAddressChooser = NearestAddressChooser.build(networkPoint);
        SimpleLinkConsumer consumer = new SimpleLinkConsumer(getModel().getKey(), inetAddressChooser);
        properties.putAll(links.buildLinkTargetProperties(consumer, modelLinks));
    }
    return properties;
}
Also used : InetAddressChooser(org.platformlayer.InetAddressChooser) SimpleLinkConsumer(org.platformlayer.ops.uses.SimpleLinkConsumer) Link(org.platformlayer.core.model.Link) NetworkPoint(org.platformlayer.ops.networks.NetworkPoint)

Example 7 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