Search in sources :

Example 26 with WorkflowStep

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

the class WorkflowService method getStep.

/**
 * Returns a single WorkflowStep.
 *
 * @param stepId
 * @brief Show workflow step
 * @return Single WorkflowStep
 */
@GET
@Path("/steps/{stepid}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowStepRestRep getStep(@PathParam("stepid") URI stepId) {
    ArgValidator.checkFieldUriType(stepId, WorkflowStep.class, "stepid");
    WorkflowStep step = _dbClient.queryObject(WorkflowStep.class, stepId);
    ArgValidator.checkEntityNotNull(step, stepId, isIdEmbeddedInURL(stepId));
    Workflow workflow = queryResource(step.getWorkflowId());
    if (userIsOnlyTenantAdmin()) {
        // User is only tenant admin so only return workflow steps for that tenant.
        if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
            throw APIException.badRequests.userNotAuthorizedForWorkflowStep();
        }
    }
    return map(step, getChildWorkflows(step));
}
Also used : 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) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 27 with WorkflowStep

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

the class WorkflowService method getStepList.

/**
 * Gets a list of all the steps in a particular workflow.
 *
 * @param id the URN of a ViPR workflow
 * @brief List workflow steps
 * @return List of steps of a workflow
 */
@GET
@Path("/{id}/steps")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public StepList getStepList(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Workflow.class, "id");
    Workflow workflow = queryResource(id);
    if (userIsOnlyTenantAdmin()) {
        // User is only tenant admin so only return steps for workflows for that tenant.
        if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
            throw APIException.badRequests.userNotAuthorizedForWorkflow();
        }
    }
    StepList list = new StepList();
    URIQueryResultList stepURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getWorkflowWorkflowStepConstraint(id), stepURIs);
    Iterator<URI> iter = stepURIs.iterator();
    while (iter.hasNext()) {
        URI workflowStepURI = iter.next();
        WorkflowStep step = _dbClient.queryObject(WorkflowStep.class, workflowStepURI);
        list.getSteps().add(map(step, getChildWorkflows(step)));
    }
    return list;
}
Also used : WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) StepList(com.emc.storageos.model.workflow.StepList) Workflow(com.emc.storageos.db.client.model.Workflow) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 28 with WorkflowStep

use of com.emc.storageos.db.client.model.WorkflowStep 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

WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)28 DataObject (com.emc.storageos.db.client.model.DataObject)16 Test (org.junit.Test)16 URI (java.net.URI)7 Operation (com.emc.storageos.db.client.model.Operation)6 Task (com.emc.storageos.db.client.model.Task)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 Workflow (com.emc.storageos.db.client.model.Workflow)5 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WorkflowStepData (com.emc.storageos.db.client.model.WorkflowStepData)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Joiner (com.emc.storageos.db.joiner.Joiner)1 StepList (com.emc.storageos.model.workflow.StepList)1 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)1