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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations