use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class WorkflowService method getRecentWorkflows.
/**
* Returns workflows created in the last specified number of minutes.
*
* @brief List workflows created in specified time period
*/
@GET
@Path("/recent")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowList getRecentWorkflows(@QueryParam("min") String minutes) {
if (minutes == null) {
minutes = "10";
}
Long timeDiff = new Long(minutes) * 1000 * 60;
Long currentTime = System.currentTimeMillis();
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 ((currentTime - workflow.getCreationTime().getTimeInMillis()) < timeDiff) {
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 getCompletedWorkflows.
/**
* Returns the completed workflows.
*
* @brief List completed workflows
*/
@GET
@Path("/completed")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public WorkflowList getCompletedWorkflows() {
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() == true) {
list.getWorkflows().add(map(workflow));
}
}
return list;
}
use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class TaskMapper method toTask.
public static TaskResourceRep toTask(Task task) {
TaskResourceRep taskResourceRep = new TaskResourceRep();
mapDataObjectFields(task, taskResourceRep);
taskResourceRep.setId(task.getId());
taskResourceRep.setResource(toNamedRelatedResource(task.getResource()));
// Check to see if there are any associated resources
List<NamedRelatedResourceRep> associatedRefs = Lists.newArrayList();
for (URI assocId : task.getAssociatedResourcesList()) {
DataObject associatedObject = getConfig().getDbClient().queryObject(assocId);
if (associatedObject != null) {
associatedRefs.add(toNamedRelatedResource(associatedObject));
} else {
log.warn(String.format("For task %s could not find associated object %s", task.getId(), assocId));
}
}
taskResourceRep.setAssociatedResources(associatedRefs);
if (!StringUtils.isBlank(task.getRequestId())) {
taskResourceRep.setOpId(task.getRequestId());
}
if (task.getWorkflow() != null) {
taskResourceRep.setWorkflow(toRelatedResource(ResourceTypeEnum.WORKFLOW, task.getWorkflow()));
}
if (!task.getTenant().equals(TenantOrg.SYSTEM_TENANT)) {
taskResourceRep.setTenant(DbObjectMapper.toRelatedResource(ResourceTypeEnum.TENANT, task.getTenant()));
}
// Operation
taskResourceRep.setState(task.getStatus());
if (task.getServiceCode() != null) {
taskResourceRep.setServiceError(toServiceErrorRestRep(toServiceCode(task.getServiceCode()), task.getMessage()));
} else {
taskResourceRep.setMessage(task.getMessage());
if (!task.getWarningMessages().isEmpty()) {
taskResourceRep.setWarningMessages(new ArrayList<String>(task.getWarningMessages()));
}
}
taskResourceRep.setDescription(task.getDescription());
// COP-23486
//
// This is a workaround to migration post-commit delete source volumes. We would like to be able to
// mark this Task as one that cannot be rolled back, however at the time there is no framework to
// detect the state of not being able to rollback, so we will catch this specific situation from the
// message so we can "flip the flag" of allowable operations by the UI.
taskResourceRep.setAllowedOperations(Task.AllowedOperations.none_specified.name());
if (task.getWorkflow() != null) {
Workflow wf = configInstance.getDbClient().queryObject(Workflow.class, task.getWorkflow());
if (wf != null && NullColumnValueGetter.isNotNullValue(wf.getCompletionMessage()) && wf.getCompletionMessage().contains("post-migration delete of original source backing volumes")) {
taskResourceRep.setAllowedOperations(Task.AllowedOperations.retry_only.name());
}
}
taskResourceRep.setStartTime(task.getStartTime());
taskResourceRep.setEndTime(task.getEndTime());
taskResourceRep.setProgress(task.getProgress() != null ? task.getProgress() : 0);
taskResourceRep.setQueuedStartTime(task.getQueuedStartTime());
taskResourceRep.setQueueName(task.getQueueName());
return taskResourceRep;
}
use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class WorkflowTaskCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
updateWorkflowStatus(status, coded);
Operation update = new Operation();
switch(status) {
case ready:
update.ready();
break;
case error:
update.error(coded);
break;
case suspended_no_error:
update.suspendedNoError("workflow suspended due to request or configuration");
break;
case suspended_error:
update.suspendedError(coded);
break;
}
Workflow workflow = dbClient.queryObject(Workflow.class, getId());
workflow.getOpStatus().updateTaskStatus(getOpId(), update);
dbClient.updateObject(workflow);
_log.info("WorkflowTaskCompleter status: " + status.toString());
}
use of com.emc.storageos.db.client.model.Workflow in project coprhd-controller by CoprHD.
the class TaskService method rollbackTask.
/**
* Rolls back a task. This can only be performed on a Task with status: suspended_error
*
* @brief rolls back a task
* @param taskId
* ID of the task to roll back
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{taskId}/rollback")
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public Response rollbackTask(@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();
// Rollback the workflow
WorkflowService.initTaskStatus(_dbClient, workflow, opId, Operation.Status.pending, ResourceOperationTypeEnum.WORKFLOW_ROLLBACK);
getWorkflowController().rollbackWorkflow(workflow.getId(), opId);
return Response.ok().build();
}
Aggregations