Search in sources :

Example 31 with Task

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

the class WorkflowTest method test23_completer_clears_pending_task_no_workflow.

@Test
public /**
 * Tests that the  completer clears tasks if error is called before the workflow is started.
 * This to test a couple of negative test cases and demonstrates that no extra logic is needed to clear the task if an exception is
 * thrown before the workflow is started or even created
 */
void test23_completer_clears_pending_task_no_workflow() {
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    Volume resource = createVolumeResource();
    // test 20.1 call TaskCompleter.error before creating the workflow
    // create a resource so we can hang a task off of it
    String taskId1 = UUID.randomUUID().toString();
    Operation op = dbClient.createTaskOpStatus(Volume.class, resource.getId(), taskId1, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    Task task = requeryTask(resource, taskId1, op);
    assertTrue(task.getStatus().equals("pending"));
    // call error before even creating the workflow
    CompleterDoesntClearTask completer = new CompleterDoesntClearTask(taskId1);
    completer.error(dbClient, DeviceControllerException.errors.unforeseen());
    task = requeryTask(resource, taskId1, op);
    assertTrue(task.getStatus().equals("error"));
    assertTrue(task.getCompletedFlag());
    // test 20.2 call Task error after creating the workflow but before executing it
    // create a resource so we can hang a task off of it
    String taskId2 = UUID.randomUUID().toString();
    op = dbClient.createTaskOpStatus(Volume.class, resource.getId(), taskId2, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    task = requeryTask(resource, taskId2, op);
    assertTrue(task.getStatus().equals("pending"));
    completer = new CompleterDoesntClearTask(taskId2);
    Workflow workflow = workflowService.getNewWorkflow(this, testname, false, taskId2);
    workflow.createStep(testname, "nop", null, nullURI, this.getClass().getName(), false, this.getClass(), deepfirstnopMethod(1, 1), deepfirstnopMethod(1, 1), false, null);
    // call error before executing the workflow
    completer.error(dbClient, DeviceControllerException.errors.unforeseen());
    task = requeryTask(resource, taskId2, op);
    assertTrue(task.getStatus().equals("error"));
    assertTrue(task.getCompletedFlag());
    // test 20.3 call Task ready without creating a workflow (to test use cases that don't go through the workflow)
    // create a resource so we can hang a task off of it
    String taskId3 = UUID.randomUUID().toString();
    op = dbClient.createTaskOpStatus(Volume.class, resource.getId(), taskId3, ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    task = requeryTask(resource, taskId3, op);
    assertTrue(task.getStatus().equals("pending"));
    completer = new CompleterDoesntClearTask(taskId3);
    // call ready without creating a workflow
    completer.ready(dbClient);
    task = requeryTask(resource, taskId3, op);
    assertTrue(task.getStatus().equals("ready"));
    assertTrue(task.getCompletedFlag());
}
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 32 with Task

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

the class WorkflowTest method test22_completer_clears_pending_task_wf_suspended_with_error.

@Test
public /**
 * Tests to make sure tasks are cleared if the workflow is suspended with an error
 */
void test22_completer_clears_pending_task_wf_suspended_with_error() {
    final String testname = new Object() {
    }.getClass().getEnclosingMethod().getName();
    printLog(testname + " started");
    workflowService.setSuspendClassMethodTestOnly(null);
    workflowService.setSuspendOnErrorTestOnly(true);
    injectedFailures.clear();
    // level 0, step 2
    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.SUSPENDED_ERROR);
    task = requeryTask(resource, taskId, op);
    printLog("task stauts is " + task.getStatus());
    assertTrue(task.getStatus().equals("suspended_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 33 with Task

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

the class VdcControllerTest method addTask.

private void addTask(String requestId, URI vdcId) {
    Task task = new Task();
    task.setId(URIUtil.createId(Task.class));
    task.setRequestId(requestId);
    NamedURI resource = new NamedURI(vdcId, "vdc");
    task.setResource(resource);
    this.dbClient.createObject(task);
}
Also used : Task(com.emc.storageos.db.client.model.Task) NamedURI(com.emc.storageos.db.client.model.NamedURI)

Example 34 with Task

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

the class TaskUtils method cleanupPendingTasks.

/**
 * cleans up pending tasks for a resource and task type older than a specified time
 * @param dbClient
 * @param resourceId resource id
 * @param taskName the task name to match task.getLabel()
 * @param tenantId tenant that owns the resource
 * @param olderThan tasks started before this will be cleared
 */
public static void cleanupPendingTasks(DbClient dbClient, URI resourceId, String taskName, URI tenantId, Calendar olderThan) {
    Iterator<Task> pendingTasks = TaskUtils.findPendingTasksForResource(dbClient, resourceId, tenantId);
    while (pendingTasks.hasNext()) {
        Task task = pendingTasks.next();
        if (task.getLabel().equals(taskName) && (olderThan == null || task.getStartTime().before(olderThan))) {
            task.setProgress(100);
            task.setEndTime(Calendar.getInstance());
            task.setStatus(Task.Status.error.toString());
            task.setMessage("Setting orphaned task to error state");
            dbClient.updateObject(task);
        }
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task)

Example 35 with Task

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

the class TaskUtils method findTenantTasks.

/**
 * This method will find all tasks associated with a tenant.
 * NOTE: This method does NOT work well to scale if a single tenant is performing many
 * thousands of operations. Consider other constraint criteria depending on your needs.
 *
 * @param dbClient
 *            db client
 * @param tenantId
 *            tenant URI
 * @return list of Task objects associated with that tenant
 */
public static ObjectQueryResult<Task> findTenantTasks(DbClient dbClient, URI tenantId) {
    ContainmentConstraint constraint = ContainmentConstraint.Factory.getTenantOrgTaskConstraint(tenantId);
    ObjectQueryResult<Task> queryResult = new ObjectQueryResult(dbClient, constraint);
    queryResult.executeQuery();
    return queryResult;
}
Also used : Task(com.emc.storageos.db.client.model.Task) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

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