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