Search in sources :

Example 11 with Workflow

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

the class WorkflowScrubberExecutor method deleteOldWorkflows.

/**
 * Scan all the workflows, delete:
 *     workflows older than WORKFLOW_HOLDING_TIME_MSEC
 *     workflow steps associated with any workflow deleted
 *     workflowStepData associated with any workflow deleted
 * Also finds and deletes:
 *     orphaned workflow steps (steps without a valid workflow)
 *     orphaned workflowStepData (without a workflow)
 */
public void deleteOldWorkflows() {
    log.info("Scanning for old workflows to be deleted");
    List<URI> workflowURIs = dbClient.queryByType(Workflow.class, true);
    Iterator<Workflow> workflowItr = dbClient.queryIterativeObjects(Workflow.class, workflowURIs);
    Long currentTime = System.currentTimeMillis();
    int workflowCount = 0, workflowsDeletedCount = 0, stepsDeletedCount = 0, stepDataDeletedCount = 0;
    while (workflowItr.hasNext()) {
        workflowCount++;
        Workflow workflow = workflowItr.next();
        URI uri = workflow.getId();
        try {
            Long creationTime = (workflow.getCreationTime() == null) ? (currentTime - WORKFLOW_HOLDING_TIME_MSEC) : workflow.getCreationTime().getTimeInMillis();
            Long age = currentTime - creationTime;
            if (age >= WORKFLOW_HOLDING_TIME_MSEC) {
                log.info("Processing workflow {} age (msec) {}", uri, age);
                // Find all the WorkflowSteps for this Workflow, and them mark them for deletion.
                URIQueryResultList stepURIs = new URIQueryResultList();
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getWorkflowWorkflowStepConstraint(uri), stepURIs);
                Iterator<WorkflowStep> wfStepItr = dbClient.queryIterativeObjects(WorkflowStep.class, stepURIs);
                while (wfStepItr.hasNext()) {
                    WorkflowStep step = wfStepItr.next();
                    URI stepURI = step.getId();
                    stepsDeletedCount++;
                    dbClient.removeObject(step);
                    log.info("Workflow step {} for workflow {} marked inactive", stepURI, uri);
                }
                // Find all the WorkflowStepData for this Workflow, and them mark them for deletion.
                URIQueryResultList stepDataURIs = new URIQueryResultList();
                dbClient.queryByConstraint(ContainmentConstraint.Factory.getWorkflowStepDataConstraint(uri), stepDataURIs);
                Iterator<WorkflowStepData> wfStepDataItr = dbClient.queryIterativeObjects(WorkflowStepData.class, stepDataURIs);
                while (wfStepDataItr.hasNext()) {
                    WorkflowStepData stepData = wfStepDataItr.next();
                    stepDataDeletedCount++;
                    dbClient.removeObject(stepData);
                    log.info("Workflow step data {} for workflow {} marked inactive", stepData.getId(), uri);
                }
                // Mark the workflow itself for deletion
                if (!workflow.getInactive()) {
                    workflowsDeletedCount++;
                    dbClient.removeObject(workflow);
                    log.info("Workflow {} marked inactive", uri);
                }
            }
        } catch (Exception ex) {
            log.error("Exception processing workflow: " + uri, ex);
        }
    }
    // now query workflow steps and clean up any orphaned steps
    Iterator<WorkflowStep> workflowStepItr = dbClient.queryIterativeObjects(WorkflowStep.class, dbClient.queryByType(WorkflowStep.class, true));
    while (workflowStepItr.hasNext()) {
        WorkflowStep step = workflowStepItr.next();
        if (NullColumnValueGetter.isNullURI(step.getWorkflowId())) {
            // step is orphaned -- delete it
            stepsDeletedCount++;
            dbClient.removeObject(step);
            log.info("Orphaned workflow step {} marked inactive", step.getId());
        } else {
            Workflow wf = dbClient.queryObject(Workflow.class, step.getWorkflowId());
            if (wf == null || wf.getInactive()) {
                // step is orphaned -- delete it
                stepsDeletedCount++;
                dbClient.removeObject(step);
                log.info("Orphaned workflow step {} marked inactive", step.getId());
            }
        }
    }
    // now query workflow step data and clean up any orphaned step data
    Iterator<WorkflowStepData> workflowStepDataItr = dbClient.queryIterativeObjects(WorkflowStepData.class, dbClient.queryByType(WorkflowStepData.class, true));
    while (workflowStepDataItr.hasNext()) {
        WorkflowStepData stepData = workflowStepDataItr.next();
        if (NullColumnValueGetter.isNullURI(stepData.getWorkflowId())) {
            // step data is orphaned -- delete it
            stepDataDeletedCount++;
            dbClient.removeObject(stepData);
            log.info("Orphaned workflow step data {} marked inactive", stepData.getId());
        } else {
            Workflow wf = dbClient.queryObject(Workflow.class, stepData.getWorkflowId());
            if (wf == null || wf.getInactive()) {
                // step data is orphaned -- delete it
                stepDataDeletedCount++;
                dbClient.removeObject(stepData);
                log.info("Orphaned workflow step data {} marked inactive", stepData.getId());
            }
        }
    }
    log.info("Done scanning for old workflows; {} workflows analyzed; {} old workflows deleted; {} workflow steps deleted; {} workflow step data deleted", workflowCount, workflowsDeletedCount, stepsDeletedCount, stepDataDeletedCount);
}
Also used : WorkflowStep(com.emc.storageos.db.client.model.WorkflowStep) WorkflowStepData(com.emc.storageos.db.client.model.WorkflowStepData) Workflow(com.emc.storageos.db.client.model.Workflow) URI(java.net.URI) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 12 with Workflow

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

the class WorkflowService method getWorkflow.

/**
 * Returns information about the specified workflow.
 *
 * @param id the URN of a ViPR workflow
 * @brief Show workflow
 * @return Information of specific workflow
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowRestRep getWorkflow(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Workflow.class, "id");
    Workflow workflow = queryResource(id);
    if (userIsOnlyTenantAdmin()) {
        // User is only tenant admin so only return workflows for that tenant.
        if (!isTopLevelWorkflowForUserTenant(getTopLevelWorkflow(workflow))) {
            throw APIException.badRequests.userNotAuthorizedForWorkflow();
        }
    }
    return map(workflow);
}
Also used : 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 13 with Workflow

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

the class WorkflowService method getWorkflows.

/**
 * Returns a list of all Workflows.
 *
 * @brief List all workflows
 * @return WorkflowList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowList getWorkflows() {
    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;
            }
        }
        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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with Workflow

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

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

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