Search in sources :

Example 21 with WorkflowStep

use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.

the class WorkflowTest method test08_one_wf_three_steps_method_suspend_first_step_resume_task_verification.

@Test
public /**
 * This test sets a class and method to suspend, makes sure it suspends, and continues it.
 * The result should be a fully successful workflow.
 */
void test08_one_wf_three_steps_method_suspend_first_step_resume_task_verification() {
    // Expected results for this test case
    final String[] testaSuccessSteps = {};
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S3 sub", "L0S2 sub" };
    final String[] testaSuspendedSteps = { "L0S1 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L0S2 sub", "L0S3 sub" };
    final String[] testbErrorSteps = {};
    final String[] testbCancelledSteps = {};
    final String[] testbSuspendedSteps = {};
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    injectedFailures.clear();
    sleepMillis = SLEEP_MILLIS;
    // We're not allowed to (and probably shouldn't) change system properties in the unit tester.
    // So we can override the class/method directly in the Workflow Service.
    workflowService.setSuspendClassMethodTestOnly(this.getClass().getSimpleName() + ".deepfirstnop");
    workflowService.setSuspendOnErrorTestOnly(true);
    String taskId = UUID.randomUUID().toString();
    String[] args = new String[1];
    args[0] = taskId;
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    Workflow workflow = workflowService.getNewWorkflow(this, "generate3StepWF", false, taskId);
    WorkflowTaskCompleter completer = new WorkflowTaskCompleter(workflow.getWorkflowURI(), taskId);
    // first step
    String lastStep = workflow.createStep("first deep", genMsg(0, 1, "sub"), null, nullURI, this.getClass().getName(), false, this.getClass(), deepfirstnopMethod(0, 1), deepfirstnopMethod(0, 1), false, null);
    // second step
    lastStep = workflow.createStep("second", genMsg(0, 2, "sub"), lastStep, nullURI, this.getClass().getName(), false, this.getClass(), subMethod(0, 1, 2), nopMethod(0, 2), false, null);
    // third step
    lastStep = workflow.createStep("third deep", genMsg(0, 3, "sub"), lastStep, nullURI, this.getClass().getName(), false, this.getClass(), deeplastnopMethod(0, 3), deeplastnopMethod(0, 3), false, null);
    Operation op = dbClient.createTaskOpStatus(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI(), taskId, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    // Execute and go
    workflow.executePlan(completer, String.format("Workflow level %d successful", 0), new WorkflowCallback(), args, null, null);
    // Generate a three step workflow.
    com.emc.storageos.db.client.model.Workflow dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    dbWF.getOpStatus().put(taskId, op);
    Task wfTask = toTask(dbWF, taskId, op);
    // Gather the steps from the DB and wait for the workflow to hit a known "stopped" state
    Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
    WorkflowState state = waitOnWorkflowComplete(taskId);
    printLog("Workflow state after suspend: " + state);
    assertTrue(state == WorkflowState.SUSPENDED_NO_ERROR);
    stepMap = readWorkflowFromDb(taskId);
    validateStepStates(stepMap, testaSuccessSteps, testaErrorSteps, testaCancelledSteps, testaSuspendedSteps);
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("suspended_no_error"));
    // Verify the completion state was filled in
    dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    assertNotNull(dbWF.getCompletionState());
    assertEquals(String.format("Workflow completion state found: " + dbWF.getCompletionState()), dbWF.getCompletionState(), "SUSPENDED_NO_ERROR");
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    workflowService.resumeWorkflow(workflow.getWorkflowURI(), UUID.randomUUID().toString());
    state = waitOnWorkflowComplete(taskId);
    printLog("Workflow state after resume: " + state);
    assertTrue(state == WorkflowState.SUCCESS);
    stepMap = readWorkflowFromDb(taskId);
    validateStepStates(stepMap, testbSuccessSteps, testbErrorSteps, testbCancelledSteps, testbSuspendedSteps);
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("ready"));
    // Verify the completion state was filled in
    dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    assertNotNull(dbWF.getCompletionState());
    assertEquals(String.format("Workflow completion state found: " + dbWF.getCompletionState()), dbWF.getCompletionState(), "SUCCESS");
    sleepMillis = 0;
    printLog(testname + " completed");
}
Also used : Task(com.emc.storageos.db.client.model.Task) WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) Operation(com.emc.storageos.db.client.model.Operation) DataObject(com.emc.storageos.db.client.model.DataObject) Test(org.junit.Test)

Example 22 with WorkflowStep

use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.

the class WorkflowTest method readWorkflowFromDb.

/**
 * Reads a workflow from the database. Called recursively for sub-workflows.
 *
 * @param orchTaskId
 *            -- the Orchestration task id.
 * @return A map from step description to WorkflowStep entry
 */
private Map<String, WorkflowStep> readWorkflowFromDb(String orchTaskId) {
    Map<String, WorkflowStep> msgToStep = new HashMap<String, WorkflowStep>();
    Joiner j = new Joiner(dbClient);
    List<WorkflowStep> steps = j.join(com.emc.storageos.db.client.model.Workflow.class, "wf").match("orchTaskId", orchTaskId).join("wf", WorkflowStep.class, "step", "workflow").go().list("step");
    for (WorkflowStep step : steps) {
        msgToStep.put(step.getDescription(), step);
        System.out.println(String.format("Step %s: status: %s message: %s", step.getDescription(), step.getState(), step.getMessage()));
        // Check for sub-workflow.
        Map<String, WorkflowStep> subWorkflowMap = readWorkflowFromDb(step.getStepId());
        msgToStep.putAll(subWorkflowMap);
    }
    return msgToStep;
}
Also used : Joiner(com.emc.storageos.db.joiner.Joiner) WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) HashMap(java.util.HashMap)

Example 23 with WorkflowStep

use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.

the class WorkflowTest method test10_two_wf_three_steps_method_suspend_last_step_resume_task_verification.

@Test
public /**
 * This test creates a two layer workflow where a step in the inner WF gets suspended.  Verify the top-level task.
 * The result should be a fully successful workflow.
 */
void test10_two_wf_three_steps_method_suspend_last_step_resume_task_verification() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub", "L1S1 sub", "L1S2 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S3 sub" };
    final String[] testaSuspendedSteps = { "L0S2 sub", "L1S3 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L0S2 sub", "L0S3 sub", "L1S1 sub", "L1S2 sub", "L1S3 sub" };
    final String[] testbErrorSteps = {};
    final String[] testbCancelledSteps = {};
    final String[] testbSuspendedSteps = {};
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    injectedFailures.clear();
    sleepMillis = SLEEP_MILLIS;
    // We're not allowed to (and probably shouldn't) change system properties in the unit tester.
    // So we can override the class/method directly in the Workflow Service.
    workflowService.setSuspendClassMethodTestOnly(this.getClass().getSimpleName() + ".deeplastnop");
    workflowService.setSuspendOnErrorTestOnly(true);
    String taskId = UUID.randomUUID().toString();
    // Generate a three step workflow.
    Workflow workflow = generate3StepWF(0, 2, taskId);
    // NOTE: Creating the Task object AFTER executing the workflow may lead to odd Task results.
    Operation op = dbClient.createTaskOpStatus(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI(), taskId, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    com.emc.storageos.db.client.model.Workflow dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    dbWF.getOpStatus().put(taskId, op);
    Task wfTask = toTask(dbWF, taskId, op);
    // Gather the steps from the DB and wait for the workflow to hit a known "stopped" state
    Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
    WorkflowState state = waitOnWorkflowComplete(taskId);
    printLog("Workflow state after suspend: " + state);
    assertTrue(state == WorkflowState.SUSPENDED_NO_ERROR);
    stepMap = readWorkflowFromDb(taskId);
    validateStepStates(stepMap, testaSuccessSteps, testaErrorSteps, testaCancelledSteps, testaSuspendedSteps);
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("suspended_no_error"));
    // Verify the completion state was filled in
    dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    assertNotNull(dbWF.getCompletionState());
    assertEquals(String.format("Workflow completion state found: " + dbWF.getCompletionState()), dbWF.getCompletionState(), "SUSPENDED_NO_ERROR");
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    workflowService.resumeWorkflow(workflow.getWorkflowURI(), UUID.randomUUID().toString());
    state = waitOnWorkflowComplete(taskId);
    printLog("Workflow state after resume: " + state);
    assertTrue(state == WorkflowState.SUCCESS);
    stepMap = readWorkflowFromDb(taskId);
    validateStepStates(stepMap, testbSuccessSteps, testbErrorSteps, testbCancelledSteps, testbSuspendedSteps);
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("ready"));
    // Verify the completion state was filled in
    dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    assertNotNull(dbWF.getCompletionState());
    assertEquals(String.format("Workflow completion state found: " + dbWF.getCompletionState()), dbWF.getCompletionState(), "SUCCESS");
    sleepMillis = 0;
    printLog(testname + " completed");
}
Also used : Task(com.emc.storageos.db.client.model.Task) WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) Operation(com.emc.storageos.db.client.model.Operation) DataObject(com.emc.storageos.db.client.model.DataObject) Test(org.junit.Test)

Example 24 with WorkflowStep

use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.

the class WorkflowTest method test14_one_wf_three_steps_error_on_step_3_rollback.

@Test
public /**
 * This test will perform a simple workflow that fails on the last step, and is asked to rollback.
 * The rollback step will fail, causing the other rollback steps to be cancelled.
 */
void test14_one_wf_three_steps_error_on_step_3_rollback() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub", "L0S2 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = {};
    final String[] testaSuspendedSteps = { "L0S3 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L0S2 sub" };
    final String[] testbErrorSteps = { "L0S3 sub", "Rollback L0S3 sub" };
    final String[] testbCancelledSteps = { "Rollback L0S1 sub", "Rollback L0S2 sub" };
    final String[] testbSuspendedSteps = {};
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    workflowService.setSuspendClassMethodTestOnly(null);
    workflowService.setSuspendOnErrorTestOnly(true);
    injectedFailures.clear();
    // level 0, step 3
    addInjectedFailure(0, 3);
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 1, taskId);
    WorkflowState state = waitOnWorkflowComplete(taskId);
    printLog("Top level workflow state: " + state);
    Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
    assertTrue(state == WorkflowState.SUSPENDED_ERROR);
    validateStepStates(stepMap, testaSuccessSteps, testaErrorSteps, testaCancelledSteps, testaSuspendedSteps);
    if (state == WorkflowState.SUSPENDED_ERROR) {
        String rollbackTaskId = UUID.randomUUID().toString();
        taskStatusMap.remove(taskId);
        workflowService.rollbackWorkflow(workflow.getWorkflowURI(), rollbackTaskId);
        state = waitOnWorkflowComplete(taskId);
        printLog("Top level workflow state after rollback: " + state);
        stepMap = readWorkflowFromDb(taskId);
        validateStepStates(stepMap, testbSuccessSteps, testbErrorSteps, testbCancelledSteps, testbSuspendedSteps);
    }
    printLog(testname + " completed");
}
Also used : WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) DataObject(com.emc.storageos.db.client.model.DataObject) Test(org.junit.Test)

Example 25 with WorkflowStep

use of com.emc.storageos.db.client.model.WorkflowStep in project coprhd-controller by CoprHD.

the class WorkflowTest method validateStepStates.

/**
 * Given the step descrption to WorkflowStep map computed by readWorkflowsFromDb,
 * check that the steps (as given by the descriptions) are in the correct states.
 *
 * @param descriptionToStepMap
 * @param successSteps
 * @param errorSteps
 * @param cancelledSteps
 */
void validateStepStates(Map<String, WorkflowStep> descriptionToStepMap, String[] successSteps, String[] errorSteps, String[] cancelledSteps, String[] suspendedSteps) {
    // check success steps
    for (String successStep : successSteps) {
        WorkflowStep step = descriptionToStepMap.get(successStep);
        assertNotNull("Step not found: " + successStep, step);
        assertEquals(String.format("Step %s expected SUCCESS but in state %s", step.getDescription(), step.getState()), StepState.SUCCESS.name(), step.getState());
    }
    // check error steps
    for (String errorStep : errorSteps) {
        WorkflowStep step = descriptionToStepMap.get(errorStep);
        assertNotNull("Step not found: " + errorStep, step);
        assertEquals(String.format("Step %s expected ERROR but in state %s", step.getDescription(), step.getState()), StepState.ERROR.name(), step.getState());
    }
    // check cancelled steps
    for (String cancelledStep : cancelledSteps) {
        WorkflowStep step = descriptionToStepMap.get(cancelledStep);
        assertNotNull("Step not found: " + cancelledStep, step);
        assertEquals(String.format("Step %s expected CANCELLED but in state %s", step.getDescription(), step.getState()), StepState.CANCELLED.name(), step.getState());
    }
    // check suspended steps
    for (String suspendedStep : suspendedSteps) {
        WorkflowStep step = descriptionToStepMap.get(suspendedStep);
        assertNotNull("Step not found: " + suspendedStep, step);
        boolean isSuspended = (step.getState().equalsIgnoreCase(StepState.SUSPENDED_ERROR.name()) || step.getState().equalsIgnoreCase(StepState.SUSPENDED_NO_ERROR.name()));
        assertTrue(String.format("Step %s expected SUSPENDED but in state %s", step.getDescription(), step.getState()), isSuspended);
    }
}
Also used : WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep)

Aggregations

WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)28 DataObject (com.emc.storageos.db.client.model.DataObject)16 Test (org.junit.Test)16 URI (java.net.URI)7 Operation (com.emc.storageos.db.client.model.Operation)6 Task (com.emc.storageos.db.client.model.Task)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 Workflow (com.emc.storageos.db.client.model.Workflow)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WorkflowStepData (com.emc.storageos.db.client.model.WorkflowStepData)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Joiner (com.emc.storageos.db.joiner.Joiner)1 StepList (com.emc.storageos.model.workflow.StepList)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1