Search in sources :

Example 16 with WorkflowStep

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

the class WorkflowTest method test15_two_level_wf_error_level2_step3_with_retry.

@Test
public /**
 * This tests a two level hierarchical workflow where the lowest level last step fails.
 * After the workflow suspends, remove the error and resume the workflow.
 * The resulting workflow should pass all steps.
 */
void test15_two_level_wf_error_level2_step3_with_retry() {
    // 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");
    workflowService.setSuspendClassMethodTestOnly(null);
    workflowService.setSuspendOnErrorTestOnly(true);
    injectedFailures.clear();
    // level 2, step 3
    addInjectedFailure(1, 3);
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 2, 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) {
        // clear the error and try and resume.
        injectedFailures.clear();
        String resumeTaskId = UUID.randomUUID().toString();
        workflowService.resumeWorkflow(workflow.getWorkflowURI(), resumeTaskId);
        taskStatusMap.put(taskId, WorkflowState.CREATED);
        state = waitOnWorkflowComplete(taskId);
        printLog("Top level workflow state after resume: " + state);
        stepMap = readWorkflowFromDb(taskId);
        assertTrue(state == WorkflowState.SUCCESS);
        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 17 with WorkflowStep

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

the class WorkflowTest method test11_two_wf_three_steps_method_suspend_first_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 test11_two_wf_three_steps_method_suspend_first_step_resume_task_verification() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L1S2 sub", "L0S3 sub", "L1S3 sub" };
    final String[] testaSuspendedSteps = { "L1S1 sub", "L0S2 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() + ".deepfirstnop");
    workflowService.setSuspendOnErrorTestOnly(true);
    String taskId = UUID.randomUUID().toString();
    // Generate a three step workflow.
    Workflow workflow = generate3StepWF(0, 2, taskId);
    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");
    // Since this will retry the upper-level workflow, it will generate another 3 step workflow, which will also
    // suspend if we don't remove it.
    workflowService.setSuspendClassMethodTestOnly(null);
    // Make sure the task is "pending" while it is running
    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 18 with WorkflowStep

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

the class WorkflowTest method test09_one_wf_one_step_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 test09_one_wf_one_step_method_suspend_first_step_resume_task_verification() {
    // Expected results for this test case
    final String[] testaSuccessSteps = {};
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = {};
    final String[] testaSuspendedSteps = { "L0S1 sub" };
    final String[] testbSuccessSteps = { "L0S1 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
    workflow.createStep("first deep", genMsg(0, 1, "sub"), null, nullURI, this.getClass().getName(), false, this.getClass(), deepfirstnopMethod(0, 1), deepfirstnopMethod(0, 1), 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 19 with WorkflowStep

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

the class WorkflowTest method test12_one_wf_three_steps_method_suspend_resume.

@Test
public /**
 * This test does a suspend of a selected step, followed by a resume after the workflow is suspended.
 * The result should be a successfully completed workflow.
 */
void test12_one_wf_three_steps_method_suspend_resume() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S3 sub" };
    final String[] testaSuspendedSteps = { "L0S2 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();
    workflowService.setSuspendClassMethodTestOnly(this.getClass().getSimpleName() + ".sub");
    workflowService.setSuspendOnErrorTestOnly(true);
    sleepMillis = SLEEP_MILLIS;
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 1, taskId);
    Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
    WorkflowStep step2 = stepMap.get("L0S2 sub");
    workflowService.suspendWorkflowStep(workflow.getWorkflowURI(), step2.getId(), UUID.randomUUID().toString());
    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);
    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);
    sleepMillis = 0;
    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 20 with WorkflowStep

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

the class WorkflowTest method test13_two_level_wf_three_steps_error_on_level_1_step_3_rollback.

@Test
public /**
 * This tests a two level hierarchical workflow where the lowest level last step fails.
 * After the workflow suspends, rollback the workflow. Then it verifies all the steps were
 * correctly cancelled or rolled back.
 */
void test13_two_level_wf_three_steps_error_on_level_1_step_3_rollback() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub", "L1S1 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S3 sub" };
    final String[] testaSuspendedSteps = { "L0S2 sub", "L1S3 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L1S1 sub", "Rollback L0S1 sub", "Rollback L0S2 sub", "Rollback L1S1 sub", "Rollback L1S2 sub", "Rollback L1S3 sub", "L1S2 sub" };
    final String[] testbErrorSteps = { "L0S2 sub", "L1S3 sub" };
    final String[] testbCancelledSteps = { "L0S3 sub" };
    final String[] testbSuspendedSteps = {};
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    workflowService.setSuspendClassMethodTestOnly(null);
    workflowService.setSuspendOnErrorTestOnly(true);
    injectedFailures.clear();
    // level 1, step 3
    addInjectedFailure(1, 3);
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 2, taskId);
    WorkflowState state = waitOnWorkflowComplete(taskId);
    printLog("Top level workflow state: " + state);
    assertTrue(state == WorkflowState.SUSPENDED_ERROR);
    Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
    validateStepStates(stepMap, testaSuccessSteps, testaErrorSteps, testaCancelledSteps, testaSuspendedSteps);
    if (state == WorkflowState.SUSPENDED_ERROR) {
        String rollbackTaskId = UUID.randomUUID().toString();
        taskStatusMap.remove(taskId);
        injectedFailures.clear();
        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)

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