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;
}
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();
}
}
}
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);
}
}
Aggregations