Search in sources :

Example 6 with Workflow

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

the class WorkflowService method getRecentWorkflows.

/**
 * Returns workflows created in the last specified number of minutes.
 *
 * @brief List workflows created in specified time period
 */
@GET
@Path("/recent")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowList getRecentWorkflows(@QueryParam("min") String minutes) {
    if (minutes == null) {
        minutes = "10";
    }
    Long timeDiff = new Long(minutes) * 1000 * 60;
    Long currentTime = System.currentTimeMillis();
    WorkflowList list = new WorkflowList();
    List<URI> workflowIds = _dbClient.queryByType(Workflow.class, true);
    Iterator<Workflow> workflowIter = _dbClient.queryIterativeObjects(Workflow.class, workflowIds);
    while (workflowIter.hasNext()) {
        // A user that has one of the system roles can see any workflow.
        // Otherwise, the workflow must have the same tenant as the user.
        Workflow workflow = workflowIter.next();
        if (userIsOnlyTenantAdmin()) {
            // User is only tenant admin so only return workflows for that tenant.
            if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
                continue;
            }
        }
        if ((currentTime - workflow.getCreationTime().getTimeInMillis()) < timeDiff) {
            list.getWorkflows().add(map(workflow));
        }
    }
    return list;
}
Also used : WorkflowList(com.emc.storageos.model.workflow.WorkflowList) Workflow(com.emc.storageos.db.client.model.Workflow) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with Workflow

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

the class WorkflowService method getCompletedWorkflows.

/**
 * Returns the completed workflows.
 *
 * @brief List completed workflows
 */
@GET
@Path("/completed")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowList getCompletedWorkflows() {
    WorkflowList list = new WorkflowList();
    List<URI> workflowIds = _dbClient.queryByType(Workflow.class, true);
    Iterator<Workflow> workflowIter = _dbClient.queryIterativeObjects(Workflow.class, workflowIds);
    while (workflowIter.hasNext()) {
        // A user that has one of the system roles can see any workflow.
        // Otherwise, the workflow must have the same tenant as the user.
        Workflow workflow = workflowIter.next();
        if (userIsOnlyTenantAdmin()) {
            // User is only tenant admin so only return workflows for that tenant.
            if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
                continue;
            }
        }
        if (workflow.getCompleted() == true) {
            list.getWorkflows().add(map(workflow));
        }
    }
    return list;
}
Also used : WorkflowList(com.emc.storageos.model.workflow.WorkflowList) Workflow(com.emc.storageos.db.client.model.Workflow) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with Workflow

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

the class TaskMapper method toTask.

public static TaskResourceRep toTask(Task task) {
    TaskResourceRep taskResourceRep = new TaskResourceRep();
    mapDataObjectFields(task, taskResourceRep);
    taskResourceRep.setId(task.getId());
    taskResourceRep.setResource(toNamedRelatedResource(task.getResource()));
    // Check to see if there are any associated resources
    List<NamedRelatedResourceRep> associatedRefs = Lists.newArrayList();
    for (URI assocId : task.getAssociatedResourcesList()) {
        DataObject associatedObject = getConfig().getDbClient().queryObject(assocId);
        if (associatedObject != null) {
            associatedRefs.add(toNamedRelatedResource(associatedObject));
        } else {
            log.warn(String.format("For task %s could not find associated object %s", task.getId(), assocId));
        }
    }
    taskResourceRep.setAssociatedResources(associatedRefs);
    if (!StringUtils.isBlank(task.getRequestId())) {
        taskResourceRep.setOpId(task.getRequestId());
    }
    if (task.getWorkflow() != null) {
        taskResourceRep.setWorkflow(toRelatedResource(ResourceTypeEnum.WORKFLOW, task.getWorkflow()));
    }
    if (!task.getTenant().equals(TenantOrg.SYSTEM_TENANT)) {
        taskResourceRep.setTenant(DbObjectMapper.toRelatedResource(ResourceTypeEnum.TENANT, task.getTenant()));
    }
    // Operation
    taskResourceRep.setState(task.getStatus());
    if (task.getServiceCode() != null) {
        taskResourceRep.setServiceError(toServiceErrorRestRep(toServiceCode(task.getServiceCode()), task.getMessage()));
    } else {
        taskResourceRep.setMessage(task.getMessage());
        if (!task.getWarningMessages().isEmpty()) {
            taskResourceRep.setWarningMessages(new ArrayList<String>(task.getWarningMessages()));
        }
    }
    taskResourceRep.setDescription(task.getDescription());
    // COP-23486
    // 
    // This is a workaround to migration post-commit delete source volumes. We would like to be able to
    // mark this Task as one that cannot be rolled back, however at the time there is no framework to
    // detect the state of not being able to rollback, so we will catch this specific situation from the
    // message so we can "flip the flag" of allowable operations by the UI.
    taskResourceRep.setAllowedOperations(Task.AllowedOperations.none_specified.name());
    if (task.getWorkflow() != null) {
        Workflow wf = configInstance.getDbClient().queryObject(Workflow.class, task.getWorkflow());
        if (wf != null && NullColumnValueGetter.isNotNullValue(wf.getCompletionMessage()) && wf.getCompletionMessage().contains("post-migration delete of original source backing volumes")) {
            taskResourceRep.setAllowedOperations(Task.AllowedOperations.retry_only.name());
        }
    }
    taskResourceRep.setStartTime(task.getStartTime());
    taskResourceRep.setEndTime(task.getEndTime());
    taskResourceRep.setProgress(task.getProgress() != null ? task.getProgress() : 0);
    taskResourceRep.setQueuedStartTime(task.getQueuedStartTime());
    taskResourceRep.setQueueName(task.getQueueName());
    return taskResourceRep;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Workflow(com.emc.storageos.db.client.model.Workflow) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) URI(java.net.URI)

Example 9 with Workflow

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

the class WorkflowTaskCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    updateWorkflowStatus(status, coded);
    Operation update = new Operation();
    switch(status) {
        case ready:
            update.ready();
            break;
        case error:
            update.error(coded);
            break;
        case suspended_no_error:
            update.suspendedNoError("workflow suspended due to request or configuration");
            break;
        case suspended_error:
            update.suspendedError(coded);
            break;
    }
    Workflow workflow = dbClient.queryObject(Workflow.class, getId());
    workflow.getOpStatus().updateTaskStatus(getOpId(), update);
    dbClient.updateObject(workflow);
    _log.info("WorkflowTaskCompleter status: " + status.toString());
}
Also used : Workflow(com.emc.storageos.db.client.model.Workflow) Operation(com.emc.storageos.db.client.model.Operation)

Example 10 with Workflow

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

the class TaskService method rollbackTask.

/**
 * Rolls back a task. This can only be performed on a Task with status: suspended_error
 *
 * @brief rolls back a task
 * @param taskId
 *            ID of the task to roll back
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{taskId}/rollback")
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public Response rollbackTask(@PathParam("taskId") URI taskId) {
    Task task = queryResource(taskId);
    // Permission Check
    if (task.getTenant().equals(TenantOrg.SYSTEM_TENANT)) {
        verifySystemAdmin();
    } else {
        verifyUserHasAccessToTenants(Lists.newArrayList(task.getTenant()));
    }
    Workflow workflow = validateWorkflow(task);
    String opId = UUID.randomUUID().toString();
    // Rollback the workflow
    WorkflowService.initTaskStatus(_dbClient, workflow, opId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_ROLLBACK);
    getWorkflowController().rollbackWorkflow(workflow.getId(), opId);
    return Response.ok().build();
}
Also used : Task(com.emc.storageos.db.client.model.Task) MapTask(com.emc.storageos.api.mapper.functions.MapTask) Workflow(com.emc.storageos.db.client.model.Workflow) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

Workflow (com.emc.storageos.db.client.model.Workflow)20 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)12 Produces (javax.ws.rs.Produces)12 Path (javax.ws.rs.Path)11 URI (java.net.URI)9 GET (javax.ws.rs.GET)7 WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)5 WorkflowList (com.emc.storageos.model.workflow.WorkflowList)4 Operation (com.emc.storageos.db.client.model.Operation)3 PUT (javax.ws.rs.PUT)3 MapTask (com.emc.storageos.api.mapper.functions.MapTask)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 Task (com.emc.storageos.db.client.model.Task)2 WorkflowState (com.emc.storageos.workflow.WorkflowState)2 POST (javax.ws.rs.POST)2 DataObject (com.emc.storageos.db.client.model.DataObject)1 WorkflowStepData (com.emc.storageos.db.client.model.WorkflowStepData)1 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)1 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)1