Search in sources :

Example 6 with WorkflowStep

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

the class WorkflowTest method test06_one_wf_method_suspend_third_step_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 test06_one_wf_method_suspend_third_step_resume() {
    // 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", "L0S3 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();
    sleepMillis = SLEEP_MILLIS;
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 1, taskId);
    Map<String, WorkflowStep> stepMap = readWorkflowFromDb(taskId);
    WorkflowStep step3 = stepMap.get("L0S3 sub");
    workflowService.suspendWorkflowStep(workflow.getWorkflowURI(), step3.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 7 with WorkflowStep

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

the class WorkflowTest method test07_one_wf_three_steps_method_suspend_second_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 test07_one_wf_three_steps_method_suspend_second_step_resume_task_verification() {
    // 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();
    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() + ".sub");
    workflowService.setSuspendOnErrorTestOnly(true);
    String taskId = UUID.randomUUID().toString();
    // Generate a three step workflow.
    Workflow workflow = generate3StepWF(0, 1, 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");
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    workflowService.resumeWorkflow(workflow.getWorkflowURI(), UUID.randomUUID().toString());
    // changing the sleep times, this may not work properly.
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("pending"));
    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 8 with WorkflowStep

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

the class WorkflowTest method test04_three_level_wf_error_level2_step3_with_retry.

@Test
public /**
 * This tests a three 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 test04_three_level_wf_error_level2_step3_with_retry() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub", "L1S1 sub", "L2S1 sub", "L2S2 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S3 sub", "L1S3 sub" };
    final String[] testaSuspendedSteps = { "L0S2 sub", "L1S2 sub", "L2S3 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L0S2 sub", "L0S3 sub", "L1S1 sub", "L1S2 sub", "L1S3 sub", "L2S1 sub", "L2S2 sub", "L2S3 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(2, 3);
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 3, 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 9 with WorkflowStep

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

the class WorkflowTest method test05_three_level_wf_error_level2_step3_with_rollback.

@Test
public /**
 * This tests a three 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 test05_three_level_wf_error_level2_step3_with_rollback() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub", "L1S1 sub", "L2S1 sub", "L2S2 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S3 sub", "L1S3 sub" };
    final String[] testaSuspendedSteps = { "L0S2 sub", "L1S2 sub", "L2S3 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L1S1 sub", "L2S1 sub", "L2S2 sub", "Rollback L0S1 sub", "Rollback L0S2 sub", "Rollback L1S1 sub", "Rollback L1S2 sub", "Rollback L2S3 sub", "Rollback L2S1 sub", "Rollback L2S2 sub" };
    final String[] testbErrorSteps = { "L0S2 sub", "L1S2 sub", "L2S3 sub" };
    final String[] testbCancelledSteps = { "L0S3 sub", "L1S3 sub" };
    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(2, 3);
    String taskId = UUID.randomUUID().toString();
    Workflow workflow = generate3StepWF(0, 3, 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);
        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)

Example 10 with WorkflowStep

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

the class WorkflowTest method test15_one_wf_four_step_two_methods_suspended_two_resumes.

@Test
public /**
 * This test makes sure if you have multiple steps with the same signature, they all get suspended.
 */
void test15_one_wf_four_step_two_methods_suspended_two_resumes() {
    // Expected results for this test case
    final String[] testaSuccessSteps = { "L0S1 sub" };
    final String[] testaErrorSteps = {};
    final String[] testaCancelledSteps = { "L0S4 sub", "L0S3 sub" };
    final String[] testaSuspendedSteps = { "L0S2 sub" };
    final String[] testbSuccessSteps = { "L0S1 sub", "L0S2 sub" };
    final String[] testbErrorSteps = {};
    final String[] testbCancelledSteps = { "L0S4 sub" };
    final String[] testbSuspendedSteps = { "L0S3 sub" };
    final String[] testcSuccessSteps = { "L0S1 sub", "L0S2 sub", "L0S3 sub", "L0S4 sub" };
    final String[] testcErrorSteps = {};
    final String[] testcCancelledSteps = {};
    final String[] testcSuspendedSteps = {};
    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() + ".sub");
    workflowService.setSuspendOnErrorTestOnly(true);
    String taskId = UUID.randomUUID().toString();
    // Generate a three step workflow.
    Workflow workflow = generate4StepWF(0, 1, taskId);
    com.emc.storageos.db.client.model.Workflow dbWF = dbClient.queryObject(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI());
    Operation op = dbClient.createTaskOpStatus(com.emc.storageos.db.client.model.Workflow.class, workflow.getWorkflowURI(), taskId, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    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 1st 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"));
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    workflowService.resumeWorkflow(workflow.getWorkflowURI(), UUID.randomUUID().toString());
    state = waitOnWorkflowComplete(taskId);
    printLog("Workflow state after1st resume: " + state);
    assertTrue(state == WorkflowState.SUSPENDED_NO_ERROR);
    stepMap = readWorkflowFromDb(taskId);
    validateStepStates(stepMap, testbSuccessSteps, testbErrorSteps, testbCancelledSteps, testbSuspendedSteps);
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("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, testcSuccessSteps, testcErrorSteps, testcCancelledSteps, testcSuspendedSteps);
    wfTask = dbClient.queryObject(Task.class, wfTask.getId());
    assertTrue(wfTask.getStatus().equals("ready"));
    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)

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