Search in sources :

Example 1 with WorkflowState

use of com.emc.storageos.workflow.WorkflowState 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 2 with WorkflowState

use of com.emc.storageos.workflow.WorkflowState in project coprhd-controller by CoprHD.

the class WorkflowService method verifySuspendedWorkflow.

protected static void verifySuspendedWorkflow(Workflow workflow) {
    if (workflow.getCompletionState() == null) {
        throw APIException.badRequests.workflowCompletionStateNotFound(workflow.getId());
    }
    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);
}
Also used : WorkflowState(com.emc.storageos.workflow.WorkflowState)

Example 3 with WorkflowState

use of com.emc.storageos.workflow.WorkflowState in project coprhd-controller by CoprHD.

the class WorkflowService method suspendWorkflowStep.

/**
 * Suspends a workflow when it tries to execute a given step, and all other executing steps
 * have suspended.
 * @preq none
 * @brief Suspends a workflow
 * @param uri - URI of the workflow.
 * @param stepURI - URI of the workflow step
 * @return - No data returned in response body
 */
@PUT
@Path("/{id}/suspend/{stepId}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public Response suspendWorkflowStep(@PathParam("id") URI uri, @PathParam("stepId") URI stepURI) {
    Workflow workflow = queryResource(uri);
    if (userIsOnlyTenantAdmin()) {
        // User is only tenant admin so only allow rollback on workflows for that tenant.
        if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
            throw APIException.badRequests.userNotAuthorizedForWorkflow();
        }
    }
    // Verify the workflow is either RUNNING or ROLLING_BACK
    EnumSet<WorkflowState> expected = EnumSet.of(WorkflowState.RUNNING, WorkflowState.ROLLING_BACK);
    if (workflow.getCompletionState() == null) {
        throw APIException.badRequests.workflowCompletionStateNotFound(workflow.getId());
    }
    WorkflowState completionState = WorkflowState.valueOf(workflow.getCompletionState());
    ArgValidator.checkFieldForValueFromEnum(completionState, "Workflow State", expected);
    if (!NullColumnValueGetter.isNullURI(stepURI)) {
        // Validate step id.
        WorkflowStep step = _dbClient.queryObject(WorkflowStep.class, stepURI);
        ArgValidator.checkEntityNotNull(step, stepURI, isIdEmbeddedInURL(stepURI));
    }
    String taskId = UUID.randomUUID().toString();
    getController().suspendWorkflowStep(uri, stepURI, taskId);
    return Response.ok().build();
}
Also used : WorkflowState(com.emc.storageos.workflow.WorkflowState) WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) Workflow(com.emc.storageos.db.client.model.Workflow) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

WorkflowState (com.emc.storageos.workflow.WorkflowState)3 Workflow (com.emc.storageos.db.client.model.Workflow)2 WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)1 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1