use of com.emc.storageos.db.client.model.Operation.Status in project coprhd-controller by CoprHD.
the class WorkflowService method rollbackWorkflow.
/**
* Roll back the workflow
*
* @param uri
* - The workflow URI
*/
private void rollbackWorkflow(URI uri) {
_log.info(String.format("Rollback requested workflow: %s", uri));
Workflow workflow = loadWorkflowFromUri(uri);
if (workflow == null) {
throw WorkflowException.exceptions.workflowNotFound(uri.toString());
}
if (workflow.getWorkflowURI() == null) {
workflow.setWorkflowURI(uri);
logWorkflow(workflow, false);
persistWorkflow(workflow);
}
removeRollbackSteps(workflow);
// See if there are child Workflows that need to be rolled back.
// These are roll-backed first.
Map<String, com.emc.storageos.db.client.model.Workflow> childWFMap = getChildWorkflowsMap(workflow);
for (Entry<String, com.emc.storageos.db.client.model.Workflow> entry : childWFMap.entrySet()) {
String parentStepId = entry.getKey();
Workflow child = loadWorkflowFromUri(entry.getValue().getId());
WorkflowState state = child.getWorkflowState();
switch(state) {
case SUSPENDED_ERROR:
case SUSPENDED_NO_ERROR:
_dbClient.pending(com.emc.storageos.db.client.model.Workflow.class, child.getWorkflowURI(), parentStepId, "rolling back sub-workflow");
rollbackWorkflow(child.getWorkflowURI());
Status status = waitOnOperationComplete(com.emc.storageos.db.client.model.Workflow.class, child.getWorkflowURI(), parentStepId);
_log.info(String.format("Child rollback task %s completed with state %s", child.getWorkflowURI(), status.name()));
break;
default:
continue;
}
}
// Now try to start rollback of top level Workflow
_dbClient.pending(com.emc.storageos.db.client.model.Workflow.class, uri, workflow.getOrchTaskId(), "rolling back top-level-workflow");
InterProcessLock workflowLock = null;
try {
workflowLock = lockWorkflow(workflow);
workflow.setRollingBackFromSuspend(true);
boolean rollBackStarted = initiateRollback(workflow);
if (rollBackStarted) {
_log.info(String.format("Rollback initiated workflow %s", uri));
} else {
// We were unable to initiate rollback, probably because there is no rollback handler somehwere
// Initiate end processing on the workflow, which will release the workflowLock.
doWorkflowEndProcessing(workflow, false, workflowLock);
workflowLock = null;
}
} finally {
unlockWorkflow(workflow, workflowLock);
}
}
use of com.emc.storageos.db.client.model.Operation.Status in project coprhd-controller by CoprHD.
the class WorkflowService method waitOnOperationComplete.
/**
* Waits on an operation to complete.
*
* @param clazz
* -- Class extending DataObject
* @param uri
* -- URI of object
* @param taskId
* -- Task id to be examined
* @return -- Status (returns Status.error if record could not found)
*/
private Status waitOnOperationComplete(Class<? extends DataObject> clazz, URI uri, String taskId) {
Status status = Status.pending;
do {
DataObject dobj = _dbClient.queryObject(uri);
if (dobj == null || dobj.getInactive() || dobj.getOpStatus() == null || !dobj.getOpStatus().containsKey(taskId)) {
return Status.error;
}
Operation operation = dobj.getOpStatus().get(taskId);
status = Status.toStatus(operation.getStatus());
} while (status == Status.pending);
return status;
}
Aggregations