Search in sources :

Example 46 with Task

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

the class WorkflowService method getOrchestrationIdStartTime.

/**
 * Attempts to intuit the start time for a provisioning operation from the orchestrationId.
 * This may be either a step in an outer workflow, or a task. The Workflow itself is not used
 * because when retrying for a workflow lock, a new workflow is created every time.
 *
 * @param workflow
 *            Workflow
 * @return start time in seconds
 */
private Long getOrchestrationIdStartTime(Workflow workflow) {
    Long timeInSeconds = 0L;
    String orchestrationId = workflow._orchTaskId;
    if (workflow._nested) {
        String parentPath = getZKStep2WorkflowPath(orchestrationId);
        try {
            if (_dataManager.checkExists(parentPath) != null) {
                parentPath = (String) _dataManager.getData(parentPath, false);
                // Load the Workflow state from ZK
                if (parentPath != null) {
                    Workflow parentWorkflow = (Workflow) _dataManager.getData(parentPath, false);
                    parentWorkflow = loadWorkflow(parentWorkflow);
                    // Get the StepStatus for our step.
                    StepStatus status = parentWorkflow.getStepStatus(orchestrationId);
                    if (status != null && status.startTime != null) {
                        timeInSeconds = status.startTime.getTime() / MILLISECONDS_IN_SECOND;
                    }
                }
            }
        } catch (Exception ex) {
            _log.error("An error occurred", ex);
        }
    }
    if (timeInSeconds == 0) {
        // See if there is a task with this id.
        List<Task> tasks = TaskUtils.findTasksForRequestId(_dbClient, orchestrationId);
        for (Task task : tasks) {
            timeInSeconds = task.getStartTime().getTimeInMillis() / MILLISECONDS_IN_SECOND;
        }
    }
    if (timeInSeconds == 0) {
        // Last resort - current time
        timeInSeconds = System.currentTimeMillis() / MILLISECONDS_IN_SECOND;
    }
    return timeInSeconds;
}
Also used : Task(com.emc.storageos.db.client.model.Task) StepStatus(com.emc.storageos.workflow.Workflow.StepStatus) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) LockRetryException(com.emc.storageos.locking.LockRetryException)

Example 47 with Task

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

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

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

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

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