Search in sources :

Example 26 with FilePolicy

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

the class IsilonFileStorageDevice method checkFilePolicyExistsOrCreate.

@Override
public BiosCommandResult checkFilePolicyExistsOrCreate(StorageSystem storageObj, FileDeviceInputOutput args) {
    FilePolicy filePolicy = args.getFileProtectionPolicy();
    BiosCommandResult result = null;
    try {
        IsilonApi isi = getIsilonDevice(storageObj);
        String clusterName = isi.getClusterConfig().getName();
        String filePolicyBasePath = getFilePolicyPath(storageObj, filePolicy.getApplyAt(), args);
        checkAppliedResourceNamePartOfFilePolicyPath(filePolicyBasePath, filePolicy, args);
        String snapshotPolicyScheduleName = FileOrchestrationUtils.generateNameForSnapshotIQPolicy(clusterName, filePolicy, null, args, filePolicyBasePath);
        IsilonSnapshotSchedule isilonSnapshotSchedule = getEquivalentIsilonSnapshotSchedule(isi, filePolicyBasePath);
        if (isilonSnapshotSchedule != null) {
            String filePolicySnapshotSchedule = getIsilonPolicySchedule(filePolicy);
            _log.info("Comparing snapshot schedule between CoprHD policy: {} and Isilon policy: {}.", filePolicySnapshotSchedule, isilonSnapshotSchedule.getSchedule());
            if (isilonSnapshotSchedule.getSchedule().equalsIgnoreCase(filePolicySnapshotSchedule)) {
                // Verify the policy was mapped to FileStorageResource
                if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, storageObj, filePolicy, args, filePolicyBasePath)) {
                    _log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
                    FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, filePolicyBasePath, isilonSnapshotSchedule.getName(), isilonSnapshotSchedule.getId().toString(), null, null, null);
                }
                result = BiosCommandResult.createSuccessfulResult();
            } else {
                _log.info("Snapshot schedule differs between Isilon policy and CoprHD file policy. So, create policy in Isilon...");
                // Create snapshot policy.
                createIsilonSnapshotPolicySchedule(storageObj, filePolicy, filePolicyBasePath, snapshotPolicyScheduleName, args, filePolicyBasePath);
                result = BiosCommandResult.createSuccessfulResult();
            }
        } else {
            // Create snapshot policy.
            createIsilonSnapshotPolicySchedule(storageObj, filePolicy, filePolicyBasePath, snapshotPolicyScheduleName, args, filePolicyBasePath);
            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) IsilonSnapshotSchedule(com.emc.storageos.isilon.restapi.IsilonSnapshotSchedule) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 27 with FilePolicy

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

the class IsilonFileStorageDevice method updateStorageSystemFileProtectionPolicy.

@Override
public BiosCommandResult updateStorageSystemFileProtectionPolicy(StorageSystem storage, FileDeviceInputOutput args) {
    FilePolicy existingPolicy = args.getFileProtectionPolicy();
    PolicyStorageResource policyRes = args.getPolicyStorageResource();
    FilePolicyUpdateParam policyUpdateParam = args.getFileProtectionPolicyUpdateParam();
    IsilonApi isi = getIsilonDevice(storage);
    BiosCommandResult result = null;
    try {
        if (existingPolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name())) {
            boolean isVersion8above = false;
            if (VersionChecker.verifyVersionDetails(ONEFS_V8, storage.getFirmwareVersion()) >= 0) {
                isVersion8above = true;
            }
            return updateStorageSystemFileReplicationPolicy(isi, policyRes, existingPolicy, policyUpdateParam, isVersion8above);
        } else if (existingPolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_snapshot.name())) {
            return updateStorageSystemFileSnapshotPolicy(isi, policyRes, existingPolicy, policyUpdateParam);
        } else {
            String errorMsg = "Invalid policy type {} " + existingPolicy.getFilePolicyType();
            _log.error(errorMsg);
            final ServiceCoded serviceCoded = DeviceControllerException.errors.jobFailedOpMsg(OperationTypeEnum.UPDATE_STORAGE_SYSTEM_POLICY_BY_POLICY_RESOURCE.toString(), errorMsg);
            result = BiosCommandResult.createErrorResult(serviceCoded);
            existingPolicy.getOpStatus().updateTaskStatus(args.getOpId(), result.toOperation());
            return result;
        }
    } catch (IsilonException e) {
        _log.error("Update storage system policy for file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FilePolicyUpdateParam(com.emc.storageos.model.file.policy.FilePolicyUpdateParam) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 28 with FilePolicy

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

the class IsilonFileStorageDevice method checkNewPolicyPathHasData.

/**
 * Method to check if the path of the 'to be created' file policy on the target array contains data
 *
 * @param vpool
 * @param project
 * @param fs - Target Filesystem
 * @param virtualNAS
 * @param isi - Isilon Api Object
 */
private void checkNewPolicyPathHasData(VirtualPool vpool, Project project, FileShare fs, VirtualNAS virtualNAS, IsilonApi isi) {
    if (fs.getPersonality() != null && fs.getPersonality().equalsIgnoreCase(PersonalityTypes.TARGET.name())) {
        FileShare sourceFs = _dbClient.queryObject(FileShare.class, fs.getParentFileShare().getURI());
        List<FilePolicy> replicationPolicies = FileOrchestrationUtils.getReplicationPolices(_dbClient, vpool, project, sourceFs);
        if (replicationPolicies != null && !replicationPolicies.isEmpty()) {
            if (replicationPolicies.size() > 1) {
                _log.warn("More than one replication policy found {}", replicationPolicies.size());
                throw DeviceControllerException.exceptions.failToCreateFileSystem(String.format("More than one replication policy found: %s for Fileshare %s", replicationPolicies.size(), sourceFs.getId()));
            }
            FilePolicy fileRepPolicy = replicationPolicies.get(0);
            String policyPath = null;
            FileDeviceInputOutput args = new FileDeviceInputOutput();
            args.setVPool(vpool);
            args.setProject(project);
            args.setvNAS(virtualNAS);
            policyPath = generatePathForPolicy(fileRepPolicy, fs, args);
            // Add the suffix only for local replication policy at higher level
            if (fileRepPolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.LOCAL.name()) && !FilePolicyApplyLevel.file_system.name().equalsIgnoreCase(fileRepPolicy.getApplyAt())) {
                policyPath = policyPath + "_localTarget";
            }
            // Policy path on target array will be checked at all levels
            _log.info("Check if Policy path has data on Target array: " + policyPath);
            if (StringUtils.isNotEmpty(policyPath) && isi.existsDir(policyPath) && isi.fsDirHasData(policyPath)) {
                _log.error("File system creation failed due to directory path {} already exists and contains data", policyPath);
                throw DeviceControllerException.exceptions.failToCreateFileSystem(policyPath);
            } else {
                _log.info("Policy path doesn't exist on target array. Proceeding with policy creation");
            }
        }
    }
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare)

Example 29 with FilePolicy

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

the class IsilonFileStorageDevice method getReplicationPolicyAppliedOnFS.

public static FilePolicy getReplicationPolicyAppliedOnFS(FileShare fs, DbClient dbClient) {
    StringSet existingFSPolicies = fs.getFilePolicies();
    List<URI> existingFSPolicyURIs = new ArrayList<>();
    for (String filePolicyURI : existingFSPolicies) {
        existingFSPolicyURIs.add(URI.create(filePolicyURI));
    }
    Iterator<FilePolicy> iterator = dbClient.queryIterativeObjects(FilePolicy.class, existingFSPolicyURIs, true);
    while (iterator.hasNext()) {
        FilePolicy fp = iterator.next();
        if (fp.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name())) {
            _log.info("Found replication policy :{}  applied to the file system:  {}.", fp.toString(), fs.getId());
            return fp;
        }
    }
    return null;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 30 with FilePolicy

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

the class FileReplicationPolicyUpdateTargetPoolMigration method getRemoteReplicationPolicies.

private Map<String, FilePolicy> getRemoteReplicationPolicies() {
    Map<String, FilePolicy> remoteReplPolicies = new HashMap<String, FilePolicy>();
    List<URI> policies = dbClient.queryByType(FilePolicy.class, true);
    List<FilePolicy> filePolicies = dbClient.queryObject(FilePolicy.class, policies);
    for (FilePolicy policy : filePolicies) {
        if (policy != null && policy.getFilePolicyType().equalsIgnoreCase(FilePolicy.FilePolicyType.file_replication.name()) && FileReplicationType.REMOTE.name().equalsIgnoreCase(policy.getFileReplicationType())) {
            remoteReplPolicies.put(policy.getFilePolicyName(), policy);
        }
    }
    return remoteReplPolicies;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) HashMap(java.util.HashMap) 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