Search in sources :

Example 41 with Task

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);
}
Also used : Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) FileOrchestrationController(com.emc.storageos.fileorchestrationcontroller.FileOrchestrationController) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 42 with Task

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);
    }
}
Also used : Task(com.emc.storageos.db.client.model.Task) TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 43 with Task

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);
}
Also used : Task(com.emc.storageos.db.client.model.Task) MapTask(com.emc.storageos.api.mapper.functions.MapTask) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 44 with Task

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();
}
Also used : Task(com.emc.storageos.db.client.model.Task) MapTask(com.emc.storageos.api.mapper.functions.MapTask) Workflow(com.emc.storageos.db.client.model.Workflow) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 45 with Task

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;
}
Also used : Task(com.emc.storageos.db.client.model.Task)

Aggregations

Task (com.emc.storageos.db.client.model.Task)57 URI (java.net.URI)21 Operation (com.emc.storageos.db.client.model.Operation)20 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)17 DataObject (com.emc.storageos.db.client.model.DataObject)15 NamedURI (com.emc.storageos.db.client.model.NamedURI)13 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)8 MapTask (com.emc.storageos.api.mapper.functions.MapTask)7 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)7 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)7 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)7 Volume (com.emc.storageos.db.client.model.Volume)6 WorkflowStep (com.emc.storageos.db.client.model.WorkflowStep)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)5