use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class FilePolicyService method unassignFilePolicy.
/**
* Unassign File Policy
*
* @param id
* of the file policy.
* @param FilePolicyUnAssignParam
* @brief Unassign file policy from vpool, project, file system
* @return TaskResourceRep
*/
@POST
@Path("/{id}/unassign-policy")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.TENANT_ADMIN })
public TaskResourceRep unassignFilePolicy(@PathParam("id") URI id, FilePolicyUnAssignParam param) {
_log.info("Unassign File Policy :{} request received.", id);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
FilePolicy filepolicy = this._dbClient.queryObject(FilePolicy.class, id);
ArgValidator.checkEntity(filepolicy, id, true);
StringBuilder errorMsg = new StringBuilder();
Operation op = _dbClient.createTaskOpStatus(FilePolicy.class, filepolicy.getId(), task, ResourceOperationTypeEnum.UNASSIGN_FILE_POLICY);
op.setDescription("unassign File Policy from resources ");
// As the action done by tenant/system admin
// Set corresponding tenant uri as task's tenant!!!
Task taskObj = op.getTask(filepolicy.getId());
StorageOSUser user = getUserFromContext();
URI userTenantUri = URI.create(user.getTenantId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, filepolicy, "unassign", taskObj, userTenantUri);
if (filepolicy.getAssignedResources() == null || filepolicy.getAssignedResources().isEmpty()) {
_log.info("File Policy: " + id + " doesn't have any assigned resources.");
_dbClient.ready(FilePolicy.class, filepolicy.getId(), task);
return toTask(filepolicy, task, op);
}
ArgValidator.checkFieldNotNull(param.getUnassignfrom(), "unassign_from");
Set<URI> unassignFrom = param.getUnassignfrom();
if (unassignFrom != null) {
for (URI uri : unassignFrom) {
canUserUnAssignPolicyAtGivenLevel(filepolicy, uri);
if (!filepolicy.getAssignedResources().contains(uri.toString())) {
errorMsg.append("Provided resource URI is either being not assigned to the file policy:" + filepolicy.getId() + " or it is a invalid URI");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyUnAssignParam(filepolicy.getFilePolicyName(), errorMsg.toString());
}
}
}
FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
try {
controller.unassignFilePolicy(filepolicy.getId(), unassignFrom, task);
auditOp(OperationTypeEnum.UNASSIGN_FILE_POLICY, true, "BEGIN", filepolicy.getId().toString(), filepolicy.getLabel());
} catch (BadRequestException e) {
op = _dbClient.error(FilePolicy.class, filepolicy.getId(), task, e);
_log.error("Error Unassigning File policy {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Unassigning Files Policy {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return toTask(filepolicy, task, op);
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class FilePolicyService method updateFilePolicy.
/**
* @brief Update the file policy
*
* @param id
* the URI of a ViPR FilePolicy
* @param param
* FilePolicyUpdateParam
* @return FilePolicyCreateResp
*/
@PUT
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateFilePolicy(@PathParam("id") URI id, FilePolicyUpdateParam param) {
ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
FilePolicy filePolicy = this._dbClient.queryObject(FilePolicy.class, id);
ArgValidator.checkEntity(filePolicy, id, true);
_log.info("validate and update file policy parameters started -- ");
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
updateFileReplicationPolicy(filePolicy, param);
} else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
updateFileSnapshotPolicy(filePolicy, param);
}
// if No storage resource, update the original policy template!!
_dbClient.updateObject(filePolicy);
String task = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(FilePolicy.class, filePolicy.getId(), task, ResourceOperationTypeEnum.UPDATE_FILE_POLICY_BY_POLICY_STORAGE_RESOURCE);
op.setDescription("update file protection policy by policy storage resource");
// As the action done by system admin
// Set system uri as task's tenant!!!
Task taskObj = op.getTask(filePolicy.getId());
StorageOSUser user = getUserFromContext();
URI userTenantUri = URI.create(user.getTenantId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "update", taskObj, userTenantUri);
if (filePolicy.getPolicyStorageResources() != null && !filePolicy.getPolicyStorageResources().isEmpty()) {
_log.info("Updating the storage system policy started..");
updateStorageSystemFileProtectionPolicy(filePolicy, param, task);
return toTask(filePolicy, task, op);
} else {
op = _dbClient.ready(FilePolicy.class, filePolicy.getId(), task);
return toTask(filePolicy, task, op);
}
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class TaskService method getTags.
/**
* @brief List tags assigned to resource
* Returns assigned tags
*
* @prereq none
*
* @param id
* the URN of a ViPR Resource
* @return Tags information
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/tags")
@Override
public Tags getTags(@PathParam("id") URI id) {
Task task = queryResource(id);
verifyUserHasAccessToTenants(Collections.singletonList(task.getTenant()));
return super.getTags(id);
}
use of com.emc.storageos.db.client.model.Task 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();
}
use of com.emc.storageos.db.client.model.Task in project coprhd-controller by CoprHD.
the class WorkflowService method postTaskWarningMessage.
/**
* Adds a warning message to the top level task(s) associated with this step.
* Traverses upward through any workflow parents and then retrieves any tasks
* matching the root workflow's orchestration task id and adds the warning message.
* @param stepId -- Arbitrariy step id
* @param message -- warning message to be added
* @return true if was able to add the warning message, false if not
*/
public boolean postTaskWarningMessage(String stepId, String message) {
Workflow workflow = getWorkflowFromStepId(stepId);
Workflow parentWorkflow = null;
do {
parentWorkflow = getParentWorkflow(workflow);
if (parentWorkflow != null) {
workflow = parentWorkflow;
}
} while (parentWorkflow != null);
// Now look to see if there are corresponding tasks for the top level Workflow.
List<Task> foundTasks = TaskUtils.findTasksForRequestId(_dbClient, workflow.getOrchTaskId());
for (Task task : foundTasks) {
task.addWarningMessage(message);
}
if (!foundTasks.isEmpty()) {
_dbClient.updateObject(foundTasks);
return true;
}
return false;
}
Aggregations