Search in sources :

Example 21 with OpsContext

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

the class ForEach method processDataItems.

private boolean processDataItems(Object controller, List<ItemBase> dataItems, ItemBase machineItem, Machine machine, OpsTarget target) {
    boolean failed = false;
    for (ItemBase dataItem : dataItems) {
        try {
            // Execute the children in a scope
            BindingScope scope = BindingScope.push(machine, target, machineItem, dataItem);
            try {
                OpsContext opsContext = OpsContext.get();
                OperationRecursor.doRecurseChildren(opsContext, controller);
            } finally {
                scope.pop();
            }
        } catch (OpsException e) {
            failed = true;
            log.warn("Error updating machine: " + machine + " with item " + dataItem, e);
        }
    }
    return failed;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ItemBase(org.platformlayer.core.model.ItemBase) OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Example 22 with OpsContext

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

the class OpsTreeBase method doRecurseOperation.

@Override
public void doRecurseOperation() throws OpsException {
    BindingScope scope = null;
    try {
        // TODO: Is this actually safe?
        RecursionState recursionState = this.recursionState;
        this.recursionState = null;
        if (recursionState != null) {
            if (recursionState.preventRecursion) {
                log.warn("Skipping recursion into child items");
                return;
            }
            if (!recursionState.childScope.isEmpty()) {
                scope = BindingScope.push(recursionState.childScope.values());
            }
        }
        OpsContext opsContext = OpsContext.get();
        OperationRecursor.doRecurseChildren(opsContext, this);
    } finally {
        if (scope != null) {
            scope.pop();
        }
    }
}
Also used : OpsContext(org.platformlayer.ops.OpsContext) BindingScope(org.platformlayer.ops.BindingScope)

Example 23 with OpsContext

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

OpsContext (org.platformlayer.ops.OpsContext)23 OpsException (org.platformlayer.ops.OpsException)12 ItemBase (org.platformlayer.core.model.ItemBase)11 BindingScope (org.platformlayer.ops.BindingScope)10 RepositoryException (org.platformlayer.RepositoryException)9 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)9 OpsTarget (org.platformlayer.ops.OpsTarget)6 Machine (org.platformlayer.ops.Machine)5 OpsContextBuilder (org.platformlayer.ops.tasks.OpsContextBuilder)5 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)4 IOException (java.io.IOException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 JAXBException (javax.xml.bind.JAXBException)3 ServiceType (org.platformlayer.ids.ServiceType)3 List (java.util.List)2 GET (javax.ws.rs.GET)2 SecretProvider (org.platformlayer.auth.crypto.SecretProvider)2 ProjectId (org.platformlayer.ids.ProjectId)2