Search in sources :

Example 16 with Workflow

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

the class WorkflowService method getTopLevelWorkflow.

/**
 * Gets the top-level workflow for the passed workflow. Returns the passed workflow
 * if it has no parent workflow and is therefore a top-level workflow.
 *
 * @param workflow A reference to the workflow
 *
 * @return
 */
private Workflow getTopLevelWorkflow(Workflow workflow) {
    Workflow topLevelWorkflow = workflow;
    Workflow parentWorkflow = getParentWorkflow(workflow);
    if (parentWorkflow != null) {
        topLevelWorkflow = getTopLevelWorkflow(parentWorkflow);
    }
    return topLevelWorkflow;
}
Also used : Workflow(com.emc.storageos.db.client.model.Workflow)

Example 17 with Workflow

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

the class WorkflowService method getActiveWorkflows.

/**
 * Returns the active workflows.
 *
 * @brief List active workflows
 */
@GET
@Path("/active")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowList getActiveWorkflows() {
    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() == false) {
            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 18 with Workflow

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

the class WorkflowService method rollbackWorkflow.

/**
 * Rolls back a suspended workflow.
 * @preq none
 * @brief Rolls back a suspended workflow
 * @param uri - URI of the suspended workflow.
 * @return - No data returned in response body
 */
@PUT
@Path("/{id}/rollback")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public TaskResourceRep rollbackWorkflow(@PathParam("id") URI uri) {
    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();
        }
    }
    verifySuspendedWorkflow(workflow);
    String taskId = UUID.randomUUID().toString();
    Operation op = initTaskStatus(_dbClient, workflow, taskId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_ROLLBACK);
    getController().rollbackWorkflow(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 19 with Workflow

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

Example 20 with Workflow

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

the class ControllerWorkflowCleanupHandler method cleanupWorkflow.

private void cleanupWorkflow() {
    log.info("Start workflow cleanup");
    List<URI> workflowIds = dbClient.queryByType(Workflow.class, true);
    Iterator<Workflow> workflows = dbClient.queryIterativeObjects(Workflow.class, workflowIds);
    int cnt = 0;
    while (workflows.hasNext()) {
        Workflow workflow = workflows.next();
        if (!workflow.getCompleted()) {
            completeWorkflow(workflow.getId());
            cnt++;
        }
    }
    log.info("Total {} workflows processed", cnt);
}
Also used : Workflow(com.emc.storageos.db.client.model.Workflow) URI(java.net.URI) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

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