use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.
the class WorkflowTest method test03_three_level_wf_three_steps_each_simple.
@Test
public /**
* This tests a three level hierarchical workflow that passes.
*/
void test03_three_level_wf_three_steps_each_simple() {
// Expected results for this test case
final String[] testSuccessSteps = { "L0S1 sub", "L0S2 sub", "L0S3 sub", "L1S1 sub", "L1S2 sub", "L1S3 sub", "L2S1 sub", "L2S2 sub", "L2S3 sub" };
final String[] testErrorSteps = {};
final String[] testCancelledSteps = {};
final String[] testSuspendedSteps = {};
final String testname = new Object() {
}.getClass().getEnclosingMethod().getName();
printLog(testname + " started");
// Don't cause in failures
workflowService.setSuspendClassMethodTestOnly(null);
workflowService.setSuspendOnErrorTestOnly(true);
injectedFailures.clear();
String taskId = UUID.randomUUID().toString();
generate3StepWF(0, 3, taskId);
WorkflowState state = waitOnWorkflowComplete(taskId);
printLog("Top level workflow state: " + state);
Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
assertTrue(state == WorkflowState.SUCCESS);
validateStepStates(stepMap, testSuccessSteps, testErrorSteps, testCancelledSteps, testSuspendedSteps);
printLog(testname + " completed");
}
use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.
the class WorkflowTest method test24_test_workflow_scrubber.
/**
* workflow scrubber does the following:
* deletes workflows older than some predetermined amount of time
* deletes all associated workflow steps if the workflow is deleted
* deletes all orphaned workflow steps
*/
@Test
public void test24_test_workflow_scrubber() {
final String testname = new Object() {
}.getClass().getEnclosingMethod().getName();
printLog(testname + " started");
WorkflowScrubberExecutor scrubber = new WorkflowScrubberExecutor();
scrubber.setDbClient(dbClient);
// it's required for this test that there are no previously existing workflows or workflow steps
Iterator<com.emc.storageos.db.client.model.Workflow> wfs = dbClient.queryIterativeObjects(com.emc.storageos.db.client.model.Workflow.class, dbClient.queryByType(com.emc.storageos.db.client.model.Workflow.class, true));
while (wfs.hasNext()) {
dbClient.removeObject(wfs.next());
}
Iterator<WorkflowStep> wfSteps = dbClient.queryIterativeObjects(WorkflowStep.class, dbClient.queryByType(WorkflowStep.class, true));
while (wfSteps.hasNext()) {
dbClient.removeObject(wfSteps.next());
}
Iterator<WorkflowStepData> wfStepData = dbClient.queryIterativeObjects(WorkflowStepData.class, dbClient.queryByType(WorkflowStepData.class, true));
while (wfStepData.hasNext()) {
dbClient.removeObject(wfStepData.next());
}
Object[] args = new Object[1];
String taskId = UUID.randomUUID().toString();
args[0] = taskId;
long maxWFAge = WorkflowScrubberExecutor.WORKFLOW_HOLDING_TIME_MSEC;
Long currentTime = System.currentTimeMillis();
Calendar dateInPast = Calendar.getInstance();
dateInPast.setTime(new Date(currentTime - maxWFAge));
// create a completed workflow with one step (scrubber should leave this one alone)
com.emc.storageos.db.client.model.Workflow completedWorkflow = new com.emc.storageos.db.client.model.Workflow();
completedWorkflow.setId(URIUtil.createId(com.emc.storageos.db.client.model.Workflow.class));
completedWorkflow.setCompleted(true);
dbClient.createObject(completedWorkflow);
WorkflowStep completedWorkflowStep = new WorkflowStep();
completedWorkflowStep.setId(URIUtil.createId(WorkflowStep.class));
completedWorkflowStep.setWorkflowId(completedWorkflow.getId());
dbClient.createObject(completedWorkflowStep);
WorkflowStepData completedWorkflowStepData = new WorkflowStepData();
completedWorkflowStepData.setId(URIUtil.createId(WorkflowStepData.class));
completedWorkflowStepData.setWorkflowId(completedWorkflow.getId());
dbClient.createObject(completedWorkflowStepData);
// Create a workflow older than max age (one step)
com.emc.storageos.db.client.model.Workflow dbWorkflow = new com.emc.storageos.db.client.model.Workflow();
dbWorkflow.setId(URIUtil.createId(com.emc.storageos.db.client.model.Workflow.class));
dbWorkflow.setCompleted(true);
dbClient.createObject(dbWorkflow);
dbWorkflow.setCreationTime(dateInPast);
dbClient.updateObject(dbWorkflow);
WorkflowStep step = new WorkflowStep();
step.setId(URIUtil.createId(WorkflowStep.class));
step.setWorkflowId(dbWorkflow.getId());
dbClient.createObject(step);
WorkflowStepData stepData = new WorkflowStepData();
stepData.setId(URIUtil.createId(WorkflowStepData.class));
stepData.setWorkflowId(dbWorkflow.getId());
dbClient.createObject(stepData);
// create a workflow step with a null workflow reference (orphaned step)
step = new WorkflowStep();
step.setId(URIUtil.createId(WorkflowStep.class));
dbClient.createObject(step);
stepData = new WorkflowStepData();
stepData.setId(URIUtil.createId(WorkflowStepData.class));
dbClient.createObject(stepData);
// create a workflow step with a valid but non-existing workflow id (orphaned step)
step = new WorkflowStep();
step.setId(URIUtil.createId(WorkflowStep.class));
step.setWorkflowId(URIUtil.createId(com.emc.storageos.db.client.model.Workflow.class));
dbClient.createObject(step);
stepData = new WorkflowStepData();
stepData.setId(URIUtil.createId(WorkflowStepData.class));
step.setWorkflowId(URIUtil.createId(com.emc.storageos.db.client.model.Workflow.class));
dbClient.createObject(stepData);
// create a workflow with one step then delete the workflow only (orphaned step)
dbWorkflow = new com.emc.storageos.db.client.model.Workflow();
dbWorkflow.setId(URIUtil.createId(com.emc.storageos.db.client.model.Workflow.class));
dbClient.createObject(dbWorkflow);
step = new WorkflowStep();
step.setId(URIUtil.createId(WorkflowStep.class));
step.setWorkflowId(dbWorkflow.getId());
dbClient.createObject(step);
stepData = new WorkflowStepData();
stepData.setId(URIUtil.createId(WorkflowStepData.class));
stepData.setWorkflowId(dbWorkflow.getId());
dbClient.createObject(stepData);
dbClient.removeObject(dbWorkflow);
List<URI> wfUris = copyUriList(dbClient.queryByType(com.emc.storageos.db.client.model.Workflow.class, true));
assertTrue(wfUris.size() == 2);
List<URI> wfStepUris = copyUriList(dbClient.queryByType(WorkflowStep.class, true));
assertTrue(wfStepUris.size() == 5);
List<URI> wfStepDataUris = copyUriList(dbClient.queryByType(WorkflowStepData.class, true));
assertTrue(wfStepDataUris.size() == 5);
scrubber.deleteOldWorkflows();
wfUris = copyUriList(dbClient.queryByType(com.emc.storageos.db.client.model.Workflow.class, true));
assertTrue(wfUris.size() == 1);
assertTrue(wfUris.contains(completedWorkflow.getId()));
wfStepUris = copyUriList(dbClient.queryByType(WorkflowStep.class, true));
assertTrue(wfStepUris.size() == 1);
assertTrue(wfStepUris.contains(completedWorkflowStep.getId()));
wfStepDataUris = copyUriList(dbClient.queryByType(WorkflowStepData.class, true));
assertTrue(wfStepDataUris.size() == 1);
assertTrue(wfStepDataUris.contains(completedWorkflowStepData.getId()));
// clean up
dbClient.removeObject(completedWorkflow);
dbClient.removeObject(completedWorkflowStep);
printLog(testname + " completed");
}
use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.
the class FileProtectionPolicyUpdateCompleter method getWorkFlowSteps.
private List<WorkflowStep> getWorkFlowSteps(DbClient dbClient) {
URI workFlowId = getWorkFlowId();
List<WorkflowStep> workFlowSteps = new ArrayList<WorkflowStep>();
if (workFlowId != null) {
URIQueryResultList stepURIs = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getWorkflowWorkflowStepConstraint(workFlowId), stepURIs);
Iterator<URI> iter = stepURIs.iterator();
while (iter.hasNext()) {
URI workflowStepURI = iter.next();
WorkflowStep step = dbClient.queryObject(WorkflowStep.class, workflowStepURI);
workFlowSteps.add(step);
}
}
return workFlowSteps;
}
use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.
the class FileProtectionPolicyUpdateCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
FilePolicy filePolicy = dbClient.queryObject(FilePolicy.class, getId());
int numStepsFailed = 0;
int numPolicies = 0;
List<WorkflowStep> workFlowSteps = getWorkFlowSteps(dbClient);
if (workFlowSteps != null && !workFlowSteps.isEmpty()) {
StringBuffer strErrorMsg = new StringBuffer();
strErrorMsg.append("The following workflow step(s) failed :");
numPolicies = workFlowSteps.size();
for (WorkflowStep workFlowStep : workFlowSteps) {
if (workFlowStep.getState() != null && workFlowStep.getState().equalsIgnoreCase("error")) {
numStepsFailed++;
strErrorMsg.append(workFlowStep.getDescription());
}
}
if (numStepsFailed > 0) {
_log.error("Update file protection policy failed with {}" + strErrorMsg.toString());
}
}
dbClient.updateObject(filePolicy);
// Update the task error, if the task failed!!!
if (numStepsFailed > 0) {
int successPolicies = numPolicies - numStepsFailed;
_log.error(String.format("Failed to Update %s storage policies and successfully updated %s policies", numStepsFailed, successPolicies));
ServiceError serviceError = DeviceControllerException.errors.deviceProtectionPolicyOperationFailed(filePolicy.getId().toString(), "update", numStepsFailed, successPolicies);
setStatus(dbClient, status, serviceError);
} else {
setStatus(dbClient, status, coded);
}
}
use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.
the class WorkflowScrubberExecutor method deleteOldWorkflows.
/**
* Scan all the workflows, delete:
* workflows older than WORKFLOW_HOLDING_TIME_MSEC
* workflow steps associated with any workflow deleted
* workflowStepData associated with any workflow deleted
* Also finds and deletes:
* orphaned workflow steps (steps without a valid workflow)
* orphaned workflowStepData (without a workflow)
*/
public void deleteOldWorkflows() {
log.info("Scanning for old workflows to be deleted");
List<URI> workflowURIs = dbClient.queryByType(Workflow.class, true);
Iterator<Workflow> workflowItr = dbClient.queryIterativeObjects(Workflow.class, workflowURIs);
Long currentTime = System.currentTimeMillis();
int workflowCount = 0, workflowsDeletedCount = 0, stepsDeletedCount = 0, stepDataDeletedCount = 0;
while (workflowItr.hasNext()) {
workflowCount++;
Workflow workflow = workflowItr.next();
URI uri = workflow.getId();
try {
Long creationTime = (workflow.getCreationTime() == null) ? (currentTime - WORKFLOW_HOLDING_TIME_MSEC) : workflow.getCreationTime().getTimeInMillis();
Long age = currentTime - creationTime;
if (age >= WORKFLOW_HOLDING_TIME_MSEC) {
log.info("Processing workflow {} age (msec) {}", uri, age);
// Find all the WorkflowSteps for this Workflow, and them mark them for deletion.
URIQueryResultList stepURIs = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getWorkflowWorkflowStepConstraint(uri), stepURIs);
Iterator<WorkflowStep> wfStepItr = dbClient.queryIterativeObjects(WorkflowStep.class, stepURIs);
while (wfStepItr.hasNext()) {
WorkflowStep step = wfStepItr.next();
URI stepURI = step.getId();
stepsDeletedCount++;
dbClient.removeObject(step);
log.info("Workflow step {} for workflow {} marked inactive", stepURI, uri);
}
// Find all the WorkflowStepData for this Workflow, and them mark them for deletion.
URIQueryResultList stepDataURIs = new URIQueryResultList();
dbClient.queryByConstraint(ContainmentConstraint.Factory.getWorkflowStepDataConstraint(uri), stepDataURIs);
Iterator<WorkflowStepData> wfStepDataItr = dbClient.queryIterativeObjects(WorkflowStepData.class, stepDataURIs);
while (wfStepDataItr.hasNext()) {
WorkflowStepData stepData = wfStepDataItr.next();
stepDataDeletedCount++;
dbClient.removeObject(stepData);
log.info("Workflow step data {} for workflow {} marked inactive", stepData.getId(), uri);
}
// Mark the workflow itself for deletion
if (!workflow.getInactive()) {
workflowsDeletedCount++;
dbClient.removeObject(workflow);
log.info("Workflow {} marked inactive", uri);
}
}
} catch (Exception ex) {
log.error("Exception processing workflow: " + uri, ex);
}
}
// now query workflow steps and clean up any orphaned steps
Iterator<WorkflowStep> workflowStepItr = dbClient.queryIterativeObjects(WorkflowStep.class, dbClient.queryByType(WorkflowStep.class, true));
while (workflowStepItr.hasNext()) {
WorkflowStep step = workflowStepItr.next();
if (NullColumnValueGetter.isNullURI(step.getWorkflowId())) {
// step is orphaned -- delete it
stepsDeletedCount++;
dbClient.removeObject(step);
log.info("Orphaned workflow step {} marked inactive", step.getId());
} else {
Workflow wf = dbClient.queryObject(Workflow.class, step.getWorkflowId());
if (wf == null || wf.getInactive()) {
// step is orphaned -- delete it
stepsDeletedCount++;
dbClient.removeObject(step);
log.info("Orphaned workflow step {} marked inactive", step.getId());
}
}
}
// now query workflow step data and clean up any orphaned step data
Iterator<WorkflowStepData> workflowStepDataItr = dbClient.queryIterativeObjects(WorkflowStepData.class, dbClient.queryByType(WorkflowStepData.class, true));
while (workflowStepDataItr.hasNext()) {
WorkflowStepData stepData = workflowStepDataItr.next();
if (NullColumnValueGetter.isNullURI(stepData.getWorkflowId())) {
// step data is orphaned -- delete it
stepDataDeletedCount++;
dbClient.removeObject(stepData);
log.info("Orphaned workflow step data {} marked inactive", stepData.getId());
} else {
Workflow wf = dbClient.queryObject(Workflow.class, stepData.getWorkflowId());
if (wf == null || wf.getInactive()) {
// step data is orphaned -- delete it
stepDataDeletedCount++;
dbClient.removeObject(stepData);
log.info("Orphaned workflow step data {} marked inactive", stepData.getId());
}
}
}
log.info("Done scanning for old workflows; {} workflows analyzed; {} old workflows deleted; {} workflow steps deleted; {} workflow step data deleted", workflowCount, workflowsDeletedCount, stepsDeletedCount, stepDataDeletedCount);
}
Aggregations