Search in sources :

Example 1 with Task

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

the class HostService method hostHasPendingTasks.

/**
 * Check for pending tasks on the Host
 *
 * @param hostURI Host ID
 * @return true if the host has pending tasks, false otherwise
 */
private boolean hostHasPendingTasks(URI hostURI) {
    boolean hasPendingTasks = false;
    List<Task> taskList = TaskUtils.findResourceTasks(_dbClient, hostURI);
    for (Task task : taskList) {
        if (task.isPending()) {
            hasPendingTasks = true;
            break;
        }
    }
    return hasPendingTasks;
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task)

Example 2 with Task

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

the class ExportService method waitForTaskCompletion.

boolean waitForTaskCompletion(URI resourceId, String task) throws InterruptedException {
    int tryCnt = 0;
    Task taskObj = null;
    // while(tryCnt < RETRY_COUNT){
    while (true) {
        _log.info("THE TASK var is {}", task);
        Thread.sleep(40000);
        taskObj = TaskUtils.findTaskForRequestId(_dbClient, resourceId, task);
        _log.info("THE TASKOBJ is {}", taskObj.toString());
        _log.info("THE TASKOBJ.GETSTATUS is {}", taskObj.getStatus().toString());
        if (taskObj != null) {
            if (taskObj.getStatus().equals("ready")) {
                return true;
            }
            if (taskObj.getStatus().equals("error")) {
                return false;
            } else {
                tryCnt++;
            }
        } else {
            return false;
        }
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint)

Example 3 with Task

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

the class WorkflowService method isTopLevelWorkflowForUserTenant.

/**
 * Determines if the passed top-level workflow is valid for the user's tenant.
 * Child workflows should not be passed to this routine.
 *
 * @param topLevelWorkflow A reference to a top-level workflow.
 *
 * @return true if the user's tenant is the workflow tenant.
 */
private boolean isTopLevelWorkflowForUserTenant(Workflow topLevelWorkflow) {
    boolean workflowForTenant = false;
    // Since the tenant is not directly associated to a workflow, we find the
    // Task instance(s) whose request id is the same as the orchestration task
    // id for the workflow. We can then get the tenant from the task and compare
    // that tenant to the user tenant.
    String wfOrchTaskId = topLevelWorkflow.getOrchTaskId();
    List<Task> wfTasks = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Task.class, AlternateIdConstraint.Factory.getTasksByRequestIdConstraint(wfOrchTaskId));
    if (!wfTasks.isEmpty()) {
        for (Task wfTask : wfTasks) {
            // the tenant.
            if (wfTask.getTenant().toString().equals(getUserFromContext().getTenantId())) {
                workflowForTenant = true;
                break;
            }
        }
    }
    return workflowForTenant;
}
Also used : Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask)

Example 4 with Task

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

the class TaskService method deleteTask.

/**
 * Deletes the specified task. After this operation has been called, the task will no longer be accessible.
 *
 * @brief Deletes a task
 * @param taskId
 *            ID of the task to be deleted
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{taskId}/delete")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN }, acls = { ACL.OWN })
public Response deleteTask(@PathParam("taskId") URI taskId) {
    Task task = queryResource(taskId);
    // Permission Check
    if (task.getTenant().equals(TenantOrg.SYSTEM_TENANT)) {
        verifySystemAdmin();
    } else {
        verifyUserHasAccessToTenants(Lists.newArrayList(task.getTenant()));
    }
    _dbClient.removeObject(task);
    auditOp(OperationTypeEnum.DELETE_TASK, true, null, task.getId().toString(), task.getLabel());
    return Response.ok().build();
}
Also used : Task(com.emc.storageos.db.client.model.Task) MapTask(com.emc.storageos.api.mapper.functions.MapTask) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with Task

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

the class TaskService method queryResource.

protected Task queryResource(URI id) {
    ArgValidator.checkUri(id);
    Task task = _dbClient.queryObject(Task.class, id);
    ArgValidator.checkEntityNotNull(task, id, isIdEmbeddedInURL(id));
    return task;
}
Also used : Task(com.emc.storageos.db.client.model.Task) MapTask(com.emc.storageos.api.mapper.functions.MapTask)

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