Search in sources :

Example 51 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FileVirtualPoolService method updateFileVirtualPool.

/**
 * Update File VirtualPool only allows if there are no resources associated and
 * list of attributes changed not changed.
 *
 * List of attributes can updated if it satisfies above constraint:
 * assignedStoragePools & useMatchedStoragePools flag.
 *
 * @param param
 *            VirtualPool parameters
 * @brief Update description of file store VirtualPool
 * @return VirtualPool details
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public FileVirtualPoolRestRep updateFileVirtualPool(@PathParam("id") URI id, FileVirtualPoolUpdateParam param) {
    VirtualPool cos = null;
    ArgValidator.checkFieldUriType(id, VirtualPool.class, "id");
    cos = _dbClient.queryObject(VirtualPool.class, id);
    ArgValidator.checkEntity(cos, id, isIdEmbeddedInURL(id));
    if (!cos.getType().equals(VirtualPool.Type.file.name())) {
        throw APIException.badRequests.unexpectedValueForProperty("VPool type", VirtualPool.Type.file.name(), cos.getType());
    }
    VirtualPoolUtil.validateFileVirtualPoolUpdateParams(cos, param, _dbClient);
    URIQueryResultList resultList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualPoolFileshareConstraint(id), resultList);
    for (Iterator<URI> fileShareItr = resultList.iterator(); fileShareItr.hasNext(); ) {
        FileShare fileShare = _dbClient.queryObject(FileShare.class, fileShareItr.next());
        if (!fileShare.getInactive() && checkAttributeValuesChanged(param, cos)) {
            throw APIException.badRequests.vPoolUpdateNotAllowed("FileShares");
        }
    }
    if (param.getProtection() != null && checkProtectionChanged(cos, param.getProtection())) {
        // need to iterate over all the policy and see if policy is associated with vpool .
        // if policy is associated with vpool we can not modify the protection attribute
        List<URI> filePolicyList = _dbClient.queryByType(FilePolicy.class, true);
        for (URI filePolicy : filePolicyList) {
            FilePolicy policyObj = _dbClient.queryObject(FilePolicy.class, filePolicy);
            if (policyObj.getAssignedResources() != null) {
                if (policyObj.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.project.name()) && (policyObj.getFilePolicyVpool() != null)) {
                    if (policyObj.getFilePolicyVpool().toString().equalsIgnoreCase(id.toString())) {
                        checkProtectAttributeAginstPolicy(param.getProtection(), policyObj);
                    }
                } else if (policyObj.getApplyAt().equalsIgnoreCase(FilePolicyApplyLevel.vpool.name())) {
                    StringSet assignedResources = policyObj.getAssignedResources();
                    if (assignedResources.contains(id.toString())) {
                        checkProtectAttributeAginstPolicy(param.getProtection(), policyObj);
                    }
                }
            }
        }
    }
    // set common update VirtualPool Params here.
    populateCommonVirtualPoolUpdateParams(cos, param);
    if (null != param.getSystemType()) {
        if (cos.getArrayInfo() != null && cos.getArrayInfo().containsKey(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE)) {
            for (String systemType : cos.getArrayInfo().get(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE)) {
                cos.getArrayInfo().remove(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE, systemType);
            }
        }
        if (!(VirtualPool.SystemType.NONE.name().equalsIgnoreCase(param.getSystemType()) || VirtualPool.SystemType.isFileTypeSystem(param.getSystemType()))) {
            throw APIException.badRequests.invalidSystemType("File");
        }
        if (cos.getArrayInfo() == null) {
            cos.setArrayInfo(new StringSetMap());
        }
        cos.getArrayInfo().put(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE, param.getSystemType());
    }
    // Update file protection parameters!!!
    if (null != param.getProtection()) {
        updateFileProtectionParamsForVirtualPool(cos, param.getProtection());
    }
    if (null != param.getLongTermRetention()) {
        cos.setLongTermRetention(param.getLongTermRetention());
    }
    StringBuffer errorMessage = new StringBuffer();
    // invokes implicit pool matching algorithm.
    ImplicitPoolMatcher.matchVirtualPoolWithAllStoragePools(cos, _dbClient, _coordinator, errorMessage);
    if (null != cos.getMatchedStoragePools() || null != cos.getInvalidMatchedPools()) {
        ImplicitUnManagedObjectsMatcher.matchVirtualPoolsWithUnManagedFileSystems(cos, _dbClient);
    }
    _dbClient.updateObject(cos);
    recordOperation(OperationTypeEnum.UPDATE_VPOOL, VPOOL_UPDATED_DESCRIPTION, cos);
    return toFileVirtualPool(cos);
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualPoolMapper.toFileVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toFileVirtualPool) MapFileVirtualPool(com.emc.storageos.api.mapper.functions.MapFileVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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 52 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FilePolicyService method getAclsOnPolicy.

protected ACLAssignments getAclsOnPolicy(URI id) {
    FilePolicy policy = queryResource(id);
    ArgValidator.checkEntityNotNull(policy, id, isIdEmbeddedInURL(id));
    ACLAssignments response = new ACLAssignments();
    response.setAssignments(_permissionsHelper.convertToACLEntries(policy.getAcls()));
    return response;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) ACLAssignments(com.emc.storageos.model.auth.ACLAssignments)

Example 53 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FilePolicyService method createFileReplicationPolicy.

/**
 * Validate and create replication policy.
 *
 * @param param
 * @return
 */
private FilePolicyCreateResp createFileReplicationPolicy(FilePolicyCreateParam param) {
    StringBuilder errorMsg = new StringBuilder();
    FilePolicy fileReplicationPolicy = new FilePolicy();
    if (param.getReplicationPolicyParams() == null) {
        errorMsg.append("Required parameter replication_params was missing or empty");
        _log.error("Failed to create snapshot policy due to {} ", errorMsg.toString());
        throw APIException.badRequests.invalidFileReplicationPolicyParam(param.getPolicyName(), errorMsg.toString());
    }
    // Make sure replication type and copy mode are provided
    ArgValidator.checkFieldNotNull(param.getReplicationPolicyParams().getReplicationCopyMode(), "replication_copy_mode");
    ArgValidator.checkFieldNotNull(param.getReplicationPolicyParams().getReplicationType(), "replication_type");
    // Validate replication policy schedule parameters
    boolean isValidSchedule = FilePolicyServiceUtils.validateAndUpdatePolicyScheduleParam(param.getReplicationPolicyParams().getPolicySchedule(), fileReplicationPolicy, errorMsg);
    if (!isValidSchedule && errorMsg.length() > 0) {
        _log.error("Failed to create file replication policy due to {} ", errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyScheduleParam(param.getPolicyName(), errorMsg.toString());
    }
    // validate replication type and copy mode parameters
    ArgValidator.checkFieldValueFromEnum(param.getReplicationPolicyParams().getReplicationType(), "replicationType", EnumSet.allOf(FilePolicy.FileReplicationType.class));
    ArgValidator.checkFieldValueFromEnum(param.getReplicationPolicyParams().getReplicationCopyMode(), "replicationCopyMode", EnumSet.allOf(FilePolicy.FileReplicationCopyMode.class));
    fileReplicationPolicy.setId(URIUtil.createId(FilePolicy.class));
    fileReplicationPolicy.setFilePolicyName(param.getPolicyName());
    fileReplicationPolicy.setLabel(param.getPolicyName());
    fileReplicationPolicy.setFilePolicyType(param.getPolicyType());
    if (param.getPriority() != null) {
        ArgValidator.checkFieldValueFromEnum(param.getPriority(), "priority", EnumSet.allOf(FilePolicyPriority.class));
        fileReplicationPolicy.setPriority(param.getPriority());
    }
    fileReplicationPolicy.setNumWorkerThreads((long) param.getNumWorkerThreads());
    if (param.getPolicyDescription() != null && !param.getPolicyDescription().isEmpty()) {
        fileReplicationPolicy.setFilePolicyDescription(param.getPolicyDescription());
    }
    fileReplicationPolicy.setScheduleFrequency(param.getReplicationPolicyParams().getPolicySchedule().getScheduleFrequency());
    fileReplicationPolicy.setFileReplicationType(param.getReplicationPolicyParams().getReplicationType());
    fileReplicationPolicy.setFileReplicationCopyMode(param.getReplicationPolicyParams().getReplicationCopyMode());
    fileReplicationPolicy.setApplyAt(param.getApplyAt());
    _dbClient.createObject(fileReplicationPolicy);
    _log.info("Policy {} created successfully", fileReplicationPolicy);
    return new FilePolicyCreateResp(fileReplicationPolicy.getId(), toLink(ResourceTypeEnum.FILE_POLICY, fileReplicationPolicy.getId()), fileReplicationPolicy.getLabel());
}
Also used : FileReplicationType(com.emc.storageos.db.client.model.FilePolicy.FileReplicationType) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) FilePolicyPriority(com.emc.storageos.db.client.model.FilePolicy.FilePolicyPriority) FilePolicyCreateResp(com.emc.storageos.model.file.policy.FilePolicyCreateResp)

Example 54 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy in project coprhd-controller by CoprHD.

the class FilePolicyService method queryResource.

@Override
protected FilePolicy queryResource(URI id) {
    ArgValidator.checkUri(id);
    FilePolicy filePolicy = _permissionsHelper.getObjectById(id, FilePolicy.class);
    ArgValidator.checkEntityNotNull(filePolicy, id, isIdEmbeddedInURL(id));
    return filePolicy;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy)

Example 55 with FilePolicy

use of com.emc.storageos.db.client.model.FilePolicy 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)

Aggregations

FilePolicy (com.emc.storageos.db.client.model.FilePolicy)70 URI (java.net.URI)25 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)21 FileShare (com.emc.storageos.db.client.model.FileShare)18 StringSet (com.emc.storageos.db.client.model.StringSet)18 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)18 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)18 ControllerException (com.emc.storageos.volumecontroller.ControllerException)18 ArrayList (java.util.ArrayList)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)15 WorkflowException (com.emc.storageos.workflow.WorkflowException)15 PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)14 MapFilePolicy (com.emc.storageos.api.mapper.functions.MapFilePolicy)13 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)13 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)13 Path (javax.ws.rs.Path)13 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 URISyntaxException (java.net.URISyntaxException)12