Search in sources :

Example 26 with Task

use of com.emc.storageos.db.client.model.Task 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 27 with Task

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

the class WorkflowTest method test21_completer_clears_pending_task_wf_suspended.

@Test
public /**
 * Tests to make sure tasks are cleared if the workflow is suspended without an error
 */
void test21_completer_clears_pending_task_wf_suspended() {
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    workflowService.setSuspendClassMethodTestOnly(this.getClass().getSimpleName() + ".deepfirstnop");
    workflowService.setSuspendOnErrorTestOnly(true);
    injectedFailures.clear();
    // addInjectedFailure(0, 3); // level 0, step 3
    Volume resource = createVolumeResource();
    String taskId = UUID.randomUUID().toString();
    Operation op = dbClient.createTaskOpStatus(Volume.class, resource.getId(), taskId, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    Task task = requeryTask(resource, taskId, op);
    assertTrue(task.getStatus().equals("pending"));
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    Workflow workflow = workflowService.getNewWorkflow(this, "validate completer clears pending task", false, taskId);
    // first step
    String lastStepId = workflow.createStep("first deep", genMsg(0, 1, "sub"), null, nullURI, this.getClass().getName(), false, this.getClass(), deepfirstnopMethod(0, 1), deepfirstnopMethod(0, 1), false, null);
    int nsteps = 2;
    byte[] bigArgs = new byte[2500];
    String[] args = new String[1];
    args[0] = taskId;
    sleepMillis = SLEEP_MILLIS;
    for (int i = 0; i < nsteps; i++) {
        String message = String.format("Step %d of %d steps", i + 1, nsteps);
        lastStepId = workflow.createStep("null", message, lastStepId, nullURI, this.getClass().getName(), false, this.getClass(), stepBigArgsMethod(bigArgs), stepBigArgsMethod(bigArgs), false, null);
    }
    CompleterDoesntClearTask completer = new CompleterDoesntClearTask(taskId);
    workflow.executePlan(completer, "Validation of step data complete", new WorkflowCallback(), args, null, null);
    WorkflowState state = waitOnWorkflowComplete(taskId);
    assertTrue(state == WorkflowState.SUSPENDED_NO_ERROR);
    task = requeryTask(resource, taskId, op);
    printLog("task stauts is " + task.getStatus());
    assertTrue(task.getStatus().equals("suspended_no_error"));
    printLog(testname + " completed successfully");
}
Also used : Task(com.emc.storageos.db.client.model.Task) Volume(com.emc.storageos.db.client.model.Volume) DataObject(com.emc.storageos.db.client.model.DataObject) Operation(com.emc.storageos.db.client.model.Operation) Test(org.junit.Test)

Example 28 with Task

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

the class WorkflowTest method test19_completer_clears_pending_task.

@Test
public /**
 * Tests that the workflow completer clears tasks left pending by the steps.
 */
void test19_completer_clears_pending_task() {
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    int nsteps = 5;
    byte[] bigArgs = new byte[2500];
    String taskId = UUID.randomUUID().toString();
    String[] args = new String[1];
    args[0] = taskId;
    sleepMillis = SLEEP_MILLIS;
    injectedFailures.clear();
    // create a resource so we can hang a task off of it
    Volume resource = createVolumeResource();
    Operation op = dbClient.createTaskOpStatus(Volume.class, resource.getId(), taskId, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    Task task = requeryTask(resource, taskId, op);
    assertTrue(task.getStatus().equals("pending"));
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    Workflow workflow = workflowService.getNewWorkflow(this, "validate completer clears pending task", false, taskId);
    String lastStepId = null;
    for (int i = 0; i < nsteps; i++) {
        String message = String.format("Step %d of %d steps", i + 1, nsteps);
        lastStepId = workflow.createStep("null", message, lastStepId, nullURI, this.getClass().getName(), false, this.getClass(), stepBigArgsMethod(bigArgs), stepBigArgsMethod(bigArgs), false, null);
    }
    CompleterDoesntClearTask completer = new CompleterDoesntClearTask(taskId);
    workflow.executePlan(completer, "Validation of step data complete", new WorkflowCallback(), args, null, null);
    task = requeryTask(resource, taskId, op);
    assertTrue(task.getStatus().equals("pending"));
    WorkflowState state = waitOnWorkflowComplete(taskId);
    printLog("Workflow state: " + state);
    assertTrue(state == WorkflowState.SUCCESS);
    task = requeryTask(resource, taskId, op);
    assertTrue(task.getStatus().equals("ready"));
    printLog(testname + " completed successfully");
}
Also used : Task(com.emc.storageos.db.client.model.Task) Volume(com.emc.storageos.db.client.model.Volume) DataObject(com.emc.storageos.db.client.model.DataObject) Operation(com.emc.storageos.db.client.model.Operation) Test(org.junit.Test)

Example 29 with Task

use of com.emc.storageos.db.client.model.Task 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)

Example 30 with Task

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

the class WorkflowTest method test20_completer_clears_pending_task_wf_failed.

@Test
public /**
 * Tests that the workflow completer clears tasks left pending by the steps.
 */
void test20_completer_clears_pending_task_wf_failed() {
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    workflowService.setSuspendClassMethodTestOnly(null);
    workflowService.setSuspendOnErrorTestOnly(false);
    injectedFailures.clear();
    // level 0, step 3
    addInjectedFailure(0, 3);
    Volume resource = createVolumeResource();
    String taskId = UUID.randomUUID().toString();
    Operation op = dbClient.createTaskOpStatus(Volume.class, resource.getId(), taskId, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    Task task = requeryTask(resource, taskId, op);
    assertTrue(task.getStatus().equals("pending"));
    taskStatusMap.put(taskId, WorkflowState.CREATED);
    Workflow workflow = workflowService.getNewWorkflow(this, "validate completer clears pending task", false, 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);
    String[] args = new String[1];
    args[0] = taskId;
    CompleterDoesntClearTask completer = new CompleterDoesntClearTask(taskId);
    workflow.executePlan(completer, "Validation of step data complete", new WorkflowCallback(), args, null, null);
    WorkflowState state = waitOnWorkflowComplete(taskId);
    assertTrue(state == WorkflowState.ERROR);
    task = requeryTask(resource, taskId, op);
    printLog("task stauts is " + task.getStatus());
    assertTrue(task.getStatus().equals("error"));
    printLog(testname + " completed successfully");
}
Also used : Task(com.emc.storageos.db.client.model.Task) Volume(com.emc.storageos.db.client.model.Volume) DataObject(com.emc.storageos.db.client.model.DataObject) Operation(com.emc.storageos.db.client.model.Operation) Test(org.junit.Test)

Aggregations

Task (com.emc.storageos.db.client.model.Task)57 URI (java.net.URI)21 Operation (com.emc.storageos.db.client.model.Operation)20 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)17 DataObject (com.emc.storageos.db.client.model.DataObject)15 NamedURI (com.emc.storageos.db.client.model.NamedURI)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)8 MapTask (com.emc.storageos.api.mapper.functions.MapTask)7 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)7 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)7 Volume (com.emc.storageos.db.client.model.Volume)6 WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)5