Search in sources :

Example 1 with Workflow

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

the class TaskService method resumeTask.

/**
 * Resumes a task. This can only be performed on a Task that has status of: suspended_no_error
 * Retries a task. This can only be performed on a Task that has status of: suspended_error
 *
 * In the case of retry, we will retry the controller workflow starting at the failed step.
 *
 * @brief Resumes a task
 * @param taskId
 *            ID of the task to be resumed
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{taskId}/resume")
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public Response resumeTask(@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();
    // Resume the workflow
    WorkflowService.initTaskStatus(_dbClient, workflow, opId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_RESUME);
    getWorkflowController().resumeWorkflow(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)

Example 2 with Workflow

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

the class TaskService method validateWorkflow.

/**
 * Validate a task's workflow information for the purpose of restarting the workflow.
 *
 * @param task
 *            task object
 * @return a workflow (as a convenience)
 */
private Workflow validateWorkflow(Task task) {
    // Validate there is a workflow ID
    if (task.getWorkflow() == null) {
        throw APIException.badRequests.noWorkflowAssociatedWithTask(task.getId());
    }
    // Validate the workflow exists
    Workflow workflow = _dbClient.queryObject(Workflow.class, task.getWorkflow());
    if (workflow == null) {
        throw APIException.badRequests.noWorkflowAssociatedWithURI(task.getWorkflow());
    }
    // Validate the workflow is in any state
    if (workflow.getCompletionState() == null) {
        throw APIException.badRequests.workflowCompletionStateNotFound(workflow.getId());
    }
    // Validate the workflow is in the right state
    WorkflowState state = WorkflowState.valueOf(WorkflowState.class, workflow.getCompletionState());
    EnumSet<WorkflowState> expected = EnumSet.of(WorkflowState.SUSPENDED_NO_ERROR, WorkflowState.SUSPENDED_ERROR);
    ArgValidator.checkFieldForValueFromEnum(state, "Workflow completion state", expected);
    return workflow;
}
Also used : WorkflowState(com.emc.storageos.workflow.WorkflowState) Workflow(com.emc.storageos.db.client.model.Workflow)

Example 3 with Workflow

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

the class WorkflowService method queryResource.

protected Workflow queryResource(URI id) {
    ArgValidator.checkUri(id);
    Workflow workflow = _dbClient.queryObject(Workflow.class, id);
    ArgValidator.checkEntityNotNull(workflow, id, isIdEmbeddedInURL(id));
    return workflow;
}
Also used : Workflow(com.emc.storageos.db.client.model.Workflow)

Example 4 with Workflow

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

the class WorkflowService method resumeWorkflow.

/**
 * Resumes a suspended workflow.
 * @preq none
 * @brief Resumes a suspended workflow
 * @param uri - URI of the suspended workflow.
 * @return - No data returned in response body
 */
@PUT
@Path("/{id}/resume")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public TaskResourceRep resumeWorkflow(@PathParam("id") URI uri) {
    Workflow workflow = queryResource(uri);
    if (userIsOnlyTenantAdmin()) {
        // User is only tenant admin so only allow resume on workflows for that tenant.
        if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
            throw APIException.badRequests.userNotAuthorizedForWorkflow();
        }
    }
    verifySuspendedWorkflow(workflow);
    String taskId = UUID.randomUUID().toString();
    Operation op = initTaskStatus(_dbClient, workflow, taskId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_RESUME);
    getController().resumeWorkflow(uri, taskId);
    return toTask(workflow, taskId, op);
}
Also used : Workflow(com.emc.storageos.db.client.model.Workflow) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with Workflow

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

the class WorkflowService method getParentWorkflow.

/**
 * Gets the parent workflow for the passed workflow.
 *
 * @param workflow A reference to the workflow
 *
 * @return The parent workflow or null for a top-level workflow.
 */
private Workflow getParentWorkflow(Workflow workflow) {
    Workflow parentWorkflow = null;
    if (workflow != null) {
        List<WorkflowStep> wfSteps = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, WorkflowStep.class, AlternateIdConstraint.Factory.getWorkflowStepByStepId(workflow.getOrchTaskId()));
        if (!wfSteps.isEmpty()) {
            // There should only be a single workflow step that has a step id that is equal
            // to the orchestration task id for a workflow. The workflow for that step is
            // the parent workflow for the passed workflow.
            URI parentWorkflowURI = wfSteps.get(0).getWorkflowId();
            parentWorkflow = queryResource(parentWorkflowURI);
        }
    }
    return parentWorkflow;
}
Also used : WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) Workflow(com.emc.storageos.db.client.model.Workflow) URI(java.net.URI)

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