Search in sources :

Example 21 with FilePolicy

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

the class FilePolicyService method assignFilePolicy.

/**
 * Assign File Policy
 *
 * @param id
 *            of the file policy.
 * @param param
 *            FilePolicyAssignParam
 * @brief Assign file policy to vpool, project, file system
 * @return FilePolicyAssignResp
 */
@POST
@Path("/{id}/assign-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 assignFilePolicy(@PathParam("id") URI id, FilePolicyAssignParam param) {
    ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
    FilePolicy filepolicy = this._dbClient.queryObject(FilePolicy.class, id);
    ArgValidator.checkEntity(filepolicy, id, true);
    // Verify user has permission to assign policy
    canUserAssignPolicyAtGivenLevel(filepolicy);
    String applyAt = filepolicy.getApplyAt();
    FilePolicyApplyLevel appliedAt = FilePolicyApplyLevel.valueOf(applyAt);
    switch(appliedAt) {
        case vpool:
            return assignFilePolicyToVpools(param, filepolicy);
        case project:
            return assignFilePolicyToProjects(param, filepolicy);
        default:
            throw APIException.badRequests.invalidFilePolicyApplyLevel(appliedAt.name());
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) FilePolicyApplyLevel(com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel) 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 22 with FilePolicy

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

the class FilePolicyService method updateAcls.

/**
 * Add or remove individual File Policy ACL entry(s). Request body must include at least one add or remove
 * operation.
 *
 * @param id
 *            the URN of a ViPR File Policy
 * @param changes
 *            ACL assignment changes
 * @brief Add or remove ACL entries from file store VirtualPool
 * @return No data returned in response body
 */
@PUT
@Path("/{id}/acl")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN, Role.SYSTEM_ADMIN, Role.RESTRICTED_SECURITY_ADMIN }, blockProxies = true)
public ACLAssignments updateAcls(@PathParam("id") URI id, ACLAssignmentChanges changes) {
    FilePolicy policy = queryResource(id);
    ArgValidator.checkEntityNotNull(policy, id, isIdEmbeddedInURL(id));
    _permissionsHelper.updateACLs(policy, changes, new PermissionsHelper.UsageACLFilter(_permissionsHelper));
    _dbClient.updateObject(policy);
    return getAclsOnPolicy(id);
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) MapFilePolicy(com.emc.storageos.api.mapper.functions.MapFilePolicy) PermissionsHelper(com.emc.storageos.api.service.authorization.PermissionsHelper) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 23 with FilePolicy

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

the class IsilonFileStorageDevice method doApplyFilePolicy.

@Override
public BiosCommandResult doApplyFilePolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    FileShare fs = args.getFs();
    try {
        FilePolicy filePolicy = args.getFileProtectionPolicy();
        String policyPath = generatePathForPolicy(filePolicy, fs, args);
        // Verify the ViPR resource on which the policy is applying is present in
        // Isilon path definition.
        // Otherwise, this method throws corresponding exception.
        checkAppliedResourceNamePartOfFilePolicyPath(policyPath, filePolicy, args);
        // Otherwise applied the policy on corresponding Isilon device path.
        if (checkPolicyAppliedOnPath(storageObj, args, policyPath)) {
            String msg = String.format("File Policy template %s is already applied on storage system %s path %s", filePolicy.getFilePolicyName(), storageObj.getLabel(), policyPath);
            _log.info(msg);
            return BiosCommandResult.createSuccessfulResult();
        } else {
            if (filePolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name())) {
                doApplyFileReplicationPolicy(filePolicy, args, fs, storageObj);
            } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
                doApplyFileSnapshotPolicy(filePolicy, args, fs, storageObj);
            }
            return BiosCommandResult.createSuccessfulResult();
        }
    } catch (IsilonException e) {
        _log.error("apply file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 24 with FilePolicy

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

the class IsilonFileStorageDevice method checkFileReplicationPolicyExistsOrCreate.

@Override
public BiosCommandResult checkFileReplicationPolicyExistsOrCreate(StorageSystem sourceStorageObj, StorageSystem targetStorageObj, FileDeviceInputOutput sourceSytemArgs, FileDeviceInputOutput targetSytemArgs) {
    FilePolicy filePolicy = sourceSytemArgs.getFileProtectionPolicy();
    // Source Path
    String sourcePath = getFilePolicyPath(sourceStorageObj, filePolicy.getApplyAt(), sourceSytemArgs);
    String targetPath = getFilePolicyPath(targetStorageObj, filePolicy.getApplyAt(), targetSytemArgs);
    if (FileReplicationType.LOCAL.name().equalsIgnoreCase(filePolicy.getFileReplicationType())) {
        targetPath = targetPath + "_localTarget";
    }
    // Policy Name
    BiosCommandResult result = null;
    try {
        IsilonApi sourceIsi = getIsilonDevice(sourceStorageObj);
        IsilonApi targetIsi = getIsilonDevice(targetStorageObj);
        String sourceClusterName = sourceIsi.getClusterConfig().getName();
        String targetClusterName = targetIsi.getClusterConfig().getName();
        checkAppliedResourceNamePartOfFilePolicyPath(sourcePath, filePolicy, sourceSytemArgs);
        String policyName = FileOrchestrationUtils.generateNameForSyncIQPolicy(sourceClusterName, targetClusterName, filePolicy, null, sourceSytemArgs, sourcePath);
        ArrayList<IsilonSyncPolicy> isiReplicationPolicies = sourceIsi.getReplicationPolicies().getList();
        IsilonSyncPolicy isilonReplicationSchedule = checkForReplicationPolicyOnIsilon(isiReplicationPolicies, filePolicy, sourcePath, targetPath);
        if (isilonReplicationSchedule != null) {
            boolean validPolicy = validateIsilonReplicationPolicy(isilonReplicationSchedule, filePolicy, targetPath, targetStorageObj, sourceStorageObj);
            if (validPolicy) {
                // Verify the policy was mapped to FileStorageResource
                if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, sourceStorageObj, filePolicy, sourceSytemArgs, sourcePath)) {
                    _log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
                    FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, sourceStorageObj, filePolicy, sourceSytemArgs, sourcePath, isilonReplicationSchedule.getName(), isilonReplicationSchedule.getId(), targetStorageObj, targetSytemArgs.getvNAS(), targetPath);
                }
                result = BiosCommandResult.createSuccessfulResult();
            } else {
                throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), "File policy and Isilon syncIQ policy differs for path: " + sourcePath);
            }
        } else {
            // to avoid DL
            if (targetIsi.existsDir(targetPath) && targetIsi.fsDirHasData(targetPath)) {
                // Fail to assign policy to target which has data in it!!!
                String errMsg = String.format("Target %s:%s directory has content in it", targetClusterName, targetPath);
                _log.error("Unable create policy due to, {}", errMsg);
                throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), errMsg);
            }
            // Create replication sync policy.
            createIsilonSyncPolicy(sourceStorageObj, targetStorageObj, filePolicy, sourcePath, targetPath, policyName, sourceSytemArgs, targetSytemArgs);
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (IsilonException e) {
        _log.error("Assigning file policy failed.", e);
        result = BiosCommandResult.createErrorResult(e);
    }
    return result;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 25 with FilePolicy

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

the class IsilonFileStorageDevice method doUnassignFilePolicy.

@Override
public BiosCommandResult doUnassignFilePolicy(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    try {
        IsilonApi isi = getIsilonDevice(storage);
        FilePolicy filePolicy = args.getFileProtectionPolicy();
        PolicyStorageResource policyResource = args.getPolicyStorageResource();
        if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
            // Get the policy details by id
            IsilonSyncPolicy isiSyncPolicy = isi.getReplicationPolicy(policyResource.getPolicyNativeId());
            if (isiSyncPolicy != null) {
                _log.info("deleting Isilon replication policy: {}", isiSyncPolicy.toString());
                String policyName = isiSyncPolicy.getName();
                JobState policyState = isiSyncPolicy.getLastJobState();
                if (policyState.equals(JobState.running) || policyState.equals(JobState.paused)) {
                    _log.info("Canceling Replication Policy  -{} because policy is in - {} state ", policyName, policyState);
                    // If the policy is running, Cancel the job before unassign policy!!
                    BiosCommandResult cmdResult = mirrorOperations.doCancelReplicationPolicy(isi, isiSyncPolicy.getName());
                    if (!cmdResult.isCommandSuccess()) {
                        return cmdResult;
                    } else {
                        // If the replication job still running through exception
                        isiSyncPolicy = isi.getReplicationPolicy(isiSyncPolicy.getName());
                        if (isiSyncPolicy.getLastJobState().equals(JobState.running)) {
                            ServiceError error = DeviceControllerErrors.isilon.jobFailed("Unable Stop Replication policy and policy state  :" + isiSyncPolicy.getLastJobState().toString());
                            return BiosCommandResult.createErrorResult(error);
                        }
                    }
                }
                // delete replication policy using policy id
                isi.deleteReplicationPolicy(isiSyncPolicy.getId());
            } else {
                _log.info("replication policy: {} doesn't exists on storage system", filePolicy.toString());
            }
            return BiosCommandResult.createSuccessfulResult();
        } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
            IsilonSnapshotSchedule isiSchedulePolicy = getEquivalentIsilonSnapshotSchedule(isi, policyResource.getResourcePath());
            if (isiSchedulePolicy != null) {
                _log.info("deleting Isilon Snapshot schedule: {}", isiSchedulePolicy.toString());
                isi.deleteSnapshotSchedule(policyResource.getPolicyNativeId());
            } else {
                _log.info("snapshot schedule: {} doesn't exists on storage system", filePolicy.toString());
            }
            return BiosCommandResult.createSuccessfulResult();
        }
        return BiosCommandResult.createSuccessfulResult();
    } catch (IsilonException e) {
        _log.error("unassign file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) JobState(com.emc.storageos.isilon.restapi.IsilonSyncPolicy.JobState) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) IsilonSnapshotSchedule(com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

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