Search in sources :

Example 11 with BindingScope

use of org.platformlayer.ops.BindingScope 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

BindingScope (org.platformlayer.ops.BindingScope)11 OpsContext (org.platformlayer.ops.OpsContext)10 ItemBase (org.platformlayer.core.model.ItemBase)7 OpsException (org.platformlayer.ops.OpsException)5 Machine (org.platformlayer.ops.Machine)4 RepositoryException (org.platformlayer.RepositoryException)3 OpsTarget (org.platformlayer.ops.OpsTarget)3 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)3 Produces (javax.ws.rs.Produces)2 OpsContextBuilder (org.platformlayer.ops.tasks.OpsContextBuilder)2 TimeSpan (com.fathomdb.TimeSpan)1 Method (java.lang.reflect.Method)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 Action (org.platformlayer.core.model.Action)1 BackupAction (org.platformlayer.core.model.BackupAction)1 ConfigureAction (org.platformlayer.core.model.ConfigureAction)1 DeleteAction (org.platformlayer.core.model.DeleteAction)1