Search in sources :

Example 56 with FilePolicy

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

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

the class FilePolicyService method doesResHasPolicyOfSameType.

private boolean doesResHasPolicyOfSameType(StringSet existingPolicies, FilePolicy filePolicy) {
    if (existingPolicies != null && !existingPolicies.isEmpty()) {
        List<URI> existingFilePolicyURIs = new ArrayList<URI>();
        for (String existingPolicy : existingPolicies) {
            existingFilePolicyURIs.add(URI.create(existingPolicy));
        }
        Iterator<FilePolicy> iterator = _dbClient.queryIterativeObjects(FilePolicy.class, existingFilePolicyURIs, true);
        if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
            while (iterator.hasNext()) {
                FilePolicy fp = iterator.next();
                if (FilePolicy.FilePolicyType.file_replication.name().equals(fp.getFilePolicyType())) {
                    return true;
                }
            }
        } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
            while (iterator.hasNext()) {
                FilePolicy fp = iterator.next();
                if (FilePolicy.FilePolicyType.file_snapshot.name().equals(fp.getFilePolicyType())) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 58 with FilePolicy

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

the class FilePolicyService method getFilePoliciesForGivenUser.

protected FilePolicyListRestRep getFilePoliciesForGivenUser() {
    FilePolicyListRestRep filePolicyList = new FilePolicyListRestRep();
    List<URI> ids = _dbClient.queryByType(FilePolicy.class, true);
    List<FilePolicy> filePolicies = _dbClient.queryObject(FilePolicy.class, ids);
    StorageOSUser user = getUserFromContext();
    // else only return the list, which input tenant has access.
    if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
        for (FilePolicy filePolicy : filePolicies) {
            filePolicyList.add(toNamedRelatedResource(filePolicy, filePolicy.getFilePolicyName()));
        }
    } else {
        // otherwise, filter by only authorized to use
        URI tenant = null;
        tenant = URI.create(user.getTenantId());
        Set<FilePolicy> policySet = new HashSet<FilePolicy>();
        for (FilePolicy filePolicy : filePolicies) {
            if (_permissionsHelper.tenantHasUsageACL(tenant, filePolicy)) {
                policySet.add(filePolicy);
            }
        }
        // Also adding vpools which sub-tenants of the user have access to.
        List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
        for (FilePolicy filePolicy : filePolicies) {
            if (_permissionsHelper.tenantHasUsageACL(subtenants, filePolicy)) {
                policySet.add(filePolicy);
            }
        }
        for (FilePolicy filePolicy : policySet) {
            filePolicyList.add(toNamedRelatedResource(filePolicy, filePolicy.getFilePolicyName()));
        }
    }
    return filePolicyList;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) FilePolicyListRestRep(com.emc.storageos.model.file.policy.FilePolicyListRestRep) URI(java.net.URI) HashSet(java.util.HashSet)

Example 59 with FilePolicy

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

the class FilePolicyService method getFilePolicy.

/**
 * @brief Get details of a file policy.
 *
 * @param id
 *            of the file policy.
 * @return File policy information.
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR, Role.TENANT_ADMIN })
public FilePolicyRestRep getFilePolicy(@PathParam("id") URI id) {
    _log.info("Request recieved to get the file policy of id: {}", id);
    FilePolicy filepolicy = queryResource(id);
    ArgValidator.checkEntity(filepolicy, id, true);
    return map(filepolicy, _dbClient);
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 60 with FilePolicy

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

the class VirtualPoolService method populateCommonVirtualPoolUpdateParams.

/**
 * This method is responsible to populate common VirtualPoolUpdateParams.
 *
 * @param vpool : id of VirtualPool to update.
 * @param param : VirtualPoolParam to update.
 */
protected void populateCommonVirtualPoolUpdateParams(VirtualPool vpool, VirtualPoolUpdateParam param) {
    if (param.getName() != null && !param.getName().isEmpty()) {
        if (!param.getName().equalsIgnoreCase(vpool.getLabel())) {
            if (vpool.getType().equalsIgnoreCase(Type.file.name())) {
                // check if any file policies are assigned to the vpool
                if ((vpool.getFilePolicies() != null) && !(vpool.getFilePolicies().isEmpty())) {
                    _log.error(String.format("Failed to update the name of virtual pool %s as a policy is assigned", vpool.getLabel()));
                    throw APIException.badRequests.cannotUpdateVpoolNameAssignedFilePolicy(vpool.getLabel());
                }
                // if file policy is assigned to project level then also it has file vpool associated with it.
                // In this scenario association is only way.so need to iterate through all the policy to get vpool
                // reference.
                List<URI> filePolicyList = _dbClient.queryByType(FilePolicy.class, true);
                for (URI filePolicy : filePolicyList) {
                    FilePolicy policyObj = _dbClient.queryObject(FilePolicy.class, filePolicy);
                    if ((policyObj != null && policyObj.getAssignedResources() != null) && (!NullColumnValueGetter.isNullURI(policyObj.getFilePolicyVpool())) && (policyObj.getFilePolicyVpool().equals(vpool.getId()))) {
                        _log.error(String.format("Failed to update the name of virtual pool %s as policy %s is assigned at higher level", vpool.getLabel(), policyObj.getFilePolicyName()));
                        throw APIException.badRequests.cannotUpdateVpoolNameAssignedFilePolicyAtHigherLevel(vpool.getLabel(), policyObj.getFilePolicyName());
                    }
                }
            }
            checkForDuplicateName(param.getName(), VirtualPool.class);
        }
        vpool.setLabel(param.getName());
    }
    ArgValidator.checkFieldValueWithExpected(!VirtualPool.ProvisioningType.NONE.name().equalsIgnoreCase(param.getProvisionType()), VPOOL_PROVISIONING_TYPE, param.getProvisionType(), VirtualPool.ProvisioningType.Thick, VirtualPool.ProvisioningType.Thin);
    if (null != param.getProtocolChanges()) {
        if (null != param.getProtocolChanges().getAdd()) {
            validateVirtualPoolProtocol(vpool.getType(), param.getProtocolChanges().getAdd().getProtocols());
            vpool.addProtocols(param.getProtocolChanges().getAdd().getProtocols());
        }
        if (null != param.getProtocolChanges().getRemove()) {
            validateVirtualPoolProtocol(vpool.getType(), param.getProtocolChanges().getRemove().getProtocols());
            vpool.removeProtocols(param.getProtocolChanges().getRemove().getProtocols());
        }
        // There should be at least one protocol associated with vPool all the time.
        if (vpool.getProtocols().isEmpty()) {
            throw APIException.badRequests.cannotRemoveAllValues(VPOOL_PROTOCOLS, "vPool");
        }
    }
    if (null != param.getProvisionType()) {
        vpool.setSupportedProvisioningType(param.getProvisionType());
    }
    StringSetMap arrayInfo = vpool.getArrayInfo();
    if (null == arrayInfo) {
        vpool.setArrayInfo(new StringSetMap());
    }
    // the storage pool.
    if (null != param.getVarrayChanges()) {
        VirtualArrayAssignments addedNH = param.getVarrayChanges().getAdd();
        if ((addedNH != null) && (!addedNH.getVarrays().isEmpty())) {
            VirtualArrayService.checkVirtualArrayURIs(addedNH.getVarrays(), _dbClient);
            vpool.addVirtualArrays(addedNH.getVarrays());
        }
        // Validate that the neighborhoods to be unassigned from the storage
        // pool reference existing neighborhoods in the database and remove
        // them from the storage pool.
        VirtualArrayAssignments removedNH = param.getVarrayChanges().getRemove();
        if ((removedNH != null) && (!removedNH.getVarrays().isEmpty())) {
            VirtualArrayService.checkVirtualArrayURIs(removedNH.getVarrays(), _dbClient);
            vpool.removeVirtualArrays(removedNH.getVarrays());
        }
    }
    if (null != param.getDescription()) {
        vpool.setDescription(param.getDescription());
    }
    if (null != param.getUseMatchedPools()) {
        // are not removed
        if (!param.getUseMatchedPools() && vpool.getUseMatchedPools()) {
            checkPoolsWithResources(null, vpool, _dbClient);
        }
        vpool.setUseMatchedPools(param.getUseMatchedPools());
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualArrayAssignments(com.emc.storageos.model.pools.VirtualArrayAssignments) URI(java.net.URI)

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