Search in sources :

Example 16 with Task

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

the class TaskMapper method toCompletedTask.

/**
 * Generate a task that is a complete state. This could be used for cases where the operation
 * does not need to go the controller. That is, it's completed within in the API layer.
 *
 * @param resource
 *            [in] - DataObject, ViPR model object
 * @param taskId
 *            [in] - String task identifier
 * @param operation
 *            [in] - Operation
 * @return TaskResourceRep representing a Task that is completed.
 */
public static TaskResourceRep toCompletedTask(DataObject resource, String taskId, Operation operation) {
    Task task = operation.getTask(resource.getId());
    if (task != null) {
        task.setProgress(100);
        task.setStatus(Operation.Status.ready.name());
        getConfig().getDbClient().persistObject(task);
        return toTask(task);
    } else {
        // It wasn't recently serialized, so fallback to looking for the task in the DB
        task = TaskUtils.findTaskForRequestId(getConfig().getDbClient(), resource.getId(), taskId);
        if (task != null) {
            task.setProgress(100);
            task.setStatus(Operation.Status.ready.name());
            getConfig().getDbClient().persistObject(task);
            return toTask(task);
        } else {
            throw new IllegalStateException(String.format("Task not found for resource %s, op %s in either the operation or the database", resource.getId(), taskId));
        }
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task)

Example 17 with Task

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

the class TaskUtils method findTaskForRequestId.

public static Task findTaskForRequestId(DbClient dbClient, URI resourceId, String requestId) {
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getTasksByRequestIdConstraint(requestId), results);
    Iterator<URI> it = results.iterator();
    while (it.hasNext()) {
        Task task = dbClient.queryObject(Task.class, it.next());
        if (task.getResource().getURI().equals(resourceId)) {
            return task;
        }
    }
    return null;
}
Also used : Task(com.emc.storageos.db.client.model.Task) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 18 with Task

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

the class TaskUtils method getTasks.

private static List<Task> getTasks(DbClient dbClient, Constraint constraint) {
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(constraint, results);
    List<Task> tasks = Lists.newArrayList();
    Iterator<URI> it = results.iterator();
    while (it.hasNext()) {
        Task task = dbClient.queryObject(Task.class, it.next());
        if (task != null) {
            tasks.add(task);
        }
    }
    return tasks;
}
Also used : Task(com.emc.storageos.db.client.model.Task) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 19 with Task

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

the class TaskUtils method findTaskForRequestIdAssociatedResource.

public static Task findTaskForRequestIdAssociatedResource(DbClient dbClient, URI resourceId, String requestId) {
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getTasksByRequestIdConstraint(requestId), results);
    Iterator<URI> it = results.iterator();
    while (it.hasNext()) {
        Task task = dbClient.queryObject(Task.class, it.next());
        if (task.getAssociatedResourcesList().contains(resourceId)) {
            return task;
        }
    }
    return null;
}
Also used : Task(com.emc.storageos.db.client.model.Task) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 20 with Task

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

the class TaskUtils method findTasksForRequestId.

public static List<Task> findTasksForRequestId(DbClient dbClient, String requestId) {
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getTasksByRequestIdConstraint(requestId), results);
    List<Task> tasks = Lists.newArrayList();
    Iterator<URI> it = results.iterator();
    while (it.hasNext()) {
        Task task = dbClient.queryObject(Task.class, it.next());
        tasks.add(task);
    }
    return tasks;
}
Also used : Task(com.emc.storageos.db.client.model.Task) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

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