Search in sources :

Example 26 with Machine

use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.

the class PostgresqlServerController method getJdbcUrl.

@Override
public String getJdbcUrl(String databaseName, InetAddressChooser chooser) throws OpsException {
    Machine itemMachine = instanceHelpers.getMachine(model);
    InetAddress address = itemMachine.getNetworkPoint().getBestAddress(NetworkPoint.forTargetInContext(), chooser);
    String host = address.getHostAddress();
    if (InetAddressUtils.isIpv6(address)) {
        host = "[" + host + "]";
    }
    return "jdbc:postgresql://" + host + ":5432/" + databaseName;
}
Also used : InetAddress(java.net.InetAddress) Machine(org.platformlayer.ops.Machine)

Example 27 with Machine

use of org.platformlayer.ops.Machine in project platformlayer by platformlayer.

the class RecurseOverAll method doRecursion.

public void doRecursion(Object controller, SshKey sshKey, Class<? extends ItemBase> machineItemClass) throws OpsException {
    boolean failed = false;
    for (ItemBase machineItem : platformLayer.listItems(machineItemClass)) {
        switch(machineItem.getState()) {
            case ACTIVE:
                break;
            case DELETED:
                log.warn("Ignoring deleted server: " + machineItem);
                continue;
            default:
                log.warn("Item not yet active: " + machineItem);
                failed = true;
                continue;
        }
        Machine machine = instances.findMachine(machineItem);
        if (machine == null) {
            log.warn("Server instance not found: " + machineItem);
            failed = true;
            continue;
        }
        OpsTarget target = machine.getTarget(sshKey);
        try {
            // Execute the children in a scope with the paired item and machine
            BindingScope scope = BindingScope.push(machine, target, machineItem);
            try {
                OpsContext opsContext = OpsContext.get();
                OperationRecursor.doRecurseChildren(opsContext, controller);
            } finally {
                scope.pop();
            }
        } catch (OpsException e) {
            failed = true;
            log.warn("Error updating machine: " + machine, e);
        }
    }
    if (failed) {
        throw new OpsException("Could not update all servers").setRetry(TimeSpan.ONE_MINUTE);
    }
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) OpsContext(org.platformlayer.ops.OpsContext) Machine(org.platformlayer.ops.Machine) BindingScope(org.platformlayer.ops.BindingScope)

Aggregations

Machine (org.platformlayer.ops.Machine)27 OpsException (org.platformlayer.ops.OpsException)13 OpsTarget (org.platformlayer.ops.OpsTarget)12 ItemBase (org.platformlayer.core.model.ItemBase)7 NetworkPoint (org.platformlayer.ops.networks.NetworkPoint)7 OpsContext (org.platformlayer.ops.OpsContext)5 SshKey (org.platformlayer.ops.helpers.SshKey)5 InetAddress (java.net.InetAddress)4 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)4 Tag (org.platformlayer.core.model.Tag)4 BindingScope (org.platformlayer.ops.BindingScope)4 Handler (org.platformlayer.ops.Handler)4 OpaqueMachine (org.platformlayer.ops.OpaqueMachine)4 List (java.util.List)3 MachineCreationRequest (org.platformlayer.ops.MachineCreationRequest)3 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 TagChanges (org.platformlayer.core.model.TagChanges)2 Tags (org.platformlayer.core.model.Tags)2 ServiceType (org.platformlayer.ids.ServiceType)2