use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class TaskService method resumeTask.
/**
* Resumes a task. This can only be performed on a Task that has status of: suspended_no_error
* Retries a task. This can only be performed on a Task that has status of: suspended_error
*
* In the case of retry, we will retry the controller workflow starting at the failed step.
*
* @brief Resumes a task
* @param taskId
* ID of the task to be resumed
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{taskId}/resume")
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public Response resumeTask(@PathParam("taskId") URI taskId) {
Task task = queryResource(taskId);
// Permission Check
if (task.getTenant().equals(TenantOrg.SYSTEM_TENANT)) {
verifySystemAdmin();
} else {
verifyUserHasAccessToTenants(Lists.newArrayList(task.getTenant()));
}
Workflow workflow = validateWorkflow(task);
String opId = UUID.randomUUID().toString();
// Resume the workflow
WorkflowService.initTaskStatus(_dbClient, workflow, opId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_RESUME);
getWorkflowController().resumeWorkflow(workflow.getId(), opId);
return Response.ok().build();
}
use of com.emc.storageos.db.client.model.Workflow 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;
}
use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class WorkflowService method queryResource.
protected Workflow queryResource(URI id) {
ArgValidator.checkUri(id);
Workflow workflow = _dbClient.queryObject(Workflow.class, id);
ArgValidator.checkEntityNotNull(workflow, id, isIdEmbeddedInURL(id));
return workflow;
}
use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class WorkflowService method resumeWorkflow.
/**
* Resumes a suspended workflow.
* @preq none
* @brief Resumes a suspended workflow
* @param uri - URI of the suspended workflow.
* @return - No data returned in response body
*/
@PUT
@Path("/{id}/resume")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public TaskResourceRep resumeWorkflow(@PathParam("id") URI uri) {
Workflow workflow = queryResource(uri);
if (userIsOnlyTenantAdmin()) {
// User is only tenant admin so only allow resume 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_RESUME);
getController().resumeWorkflow(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 getParentWorkflow.
/**
* Gets the parent workflow for the passed workflow.
*
* @param workflow A reference to the workflow
*
* @return The parent workflow or null for a top-level workflow.
*/
private Workflow getParentWorkflow(Workflow workflow) {
Workflow parentWorkflow = null;
if (workflow != null) {
List<WorkflowStep> wfSteps = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, WorkflowStep.class, AlternateIdConstraint.Factory.getWorkflowStepByStepId(workflow.getOrchTaskId()));
if (!wfSteps.isEmpty()) {
// There should only be a single workflow step that has a step id that is equal
// to the orchestration task id for a workflow. The workflow for that step is
// the parent workflow for the passed workflow.
URI parentWorkflowURI = wfSteps.get(0).getWorkflowId();
parentWorkflow = queryResource(parentWorkflowURI);
}
}
return parentWorkflow;
}
Aggregations