Search in sources :

Example 16 with PolicyStorageResource

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

the class FileOrchestrationUtils method updatePolicyStorageResource.

/**
 * Create/Update the File policy resource
 *
 * @param dbClient
 * @param system
 * @param filePolicy
 * @param args
 * @param sourcePath
 * @return
 */
public static PolicyStorageResource updatePolicyStorageResource(DbClient dbClient, StorageSystem system, FilePolicy filePolicy, FileDeviceInputOutput args, String sourcePath, String name, String policyNativeId, StorageSystem targetSystem, NASServer targetNasServer, String targetPath) {
    PolicyStorageResource policyStorageResource = new PolicyStorageResource();
    policyStorageResource.setId(URIUtil.createId(PolicyStorageResource.class));
    policyStorageResource.setFilePolicyId(filePolicy.getId());
    policyStorageResource.setStorageSystem(system.getId());
    policyStorageResource.setPolicyNativeId(policyNativeId);
    policyStorageResource.setName(name);
    policyStorageResource.setLabel(name);
    policyStorageResource.setResourcePath(sourcePath);
    NASServer nasServer = null;
    if (args.getvNAS() != null) {
        nasServer = args.getvNAS();
    } else {
        // Get the physical NAS for the storage system!!
        PhysicalNAS pNAS = getSystemPhysicalNAS(dbClient, system);
        if (pNAS != null) {
            nasServer = pNAS;
        }
    }
    policyStorageResource.setNasServer(nasServer.getId());
    setPolicyStorageAppliedAt(filePolicy, args, policyStorageResource);
    policyStorageResource.setNativeGuid(NativeGUIDGenerator.generateNativeGuidForFilePolicyResource(system, nasServer.getNasName(), filePolicy.getFilePolicyType(), sourcePath, NativeGUIDGenerator.FILE_STORAGE_RESOURCE));
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicy.FilePolicyType.file_replication.name())) {
        // Update the target resource details!!!
        FileReplicaPolicyTargetMap fileReplicaPolicyTargetMap = new FileReplicaPolicyTargetMap();
        FileReplicaPolicyTarget target = new FileReplicaPolicyTarget();
        if (targetNasServer != null) {
            target.setNasServer(targetNasServer.getId().toString());
        } else {
            PhysicalNAS pNAS = FileOrchestrationUtils.getSystemPhysicalNAS(dbClient, targetSystem);
            if (pNAS != null) {
                target.setNasServer(pNAS.getId().toString());
            }
        }
        target.setAppliedAt(filePolicy.getApplyAt());
        target.setStorageSystem(targetSystem.getId().toString());
        target.setPath(targetPath);
        String key = target.getFileTargetReplicaKey();
        fileReplicaPolicyTargetMap.put(key, target);
        policyStorageResource.setFileReplicaPolicyTargetMap(fileReplicaPolicyTargetMap);
    }
    dbClient.createObject(policyStorageResource);
    filePolicy.addPolicyStorageResources(policyStorageResource.getId());
    dbClient.updateObject(filePolicy);
    _log.info("PolicyStorageResource object created successfully for {} ", system.getLabel() + policyStorageResource.getAppliedAt());
    return policyStorageResource;
}
Also used : NASServer(com.emc.storageos.db.client.model.NASServer) FileReplicaPolicyTargetMap(com.emc.storageos.db.client.model.FileReplicaPolicyTargetMap) FileReplicaPolicyTarget(com.emc.storageos.db.client.model.FileReplicaPolicyTarget) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS)

Example 17 with PolicyStorageResource

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

the class FileDeviceController method updateStorageSystemFileProtectionPolicy.

@Override
public void updateStorageSystemFileProtectionPolicy(URI storage, URI policy, URI policyRes, FilePolicyUpdateParam policyUpdateParam, String opId) throws InternalException {
    ControllerUtils.setThreadLocalLogData(policy, opId);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    try {
        FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, policy);
        PolicyStorageResource policyResource = _dbClient.queryObject(PolicyStorageResource.class, policyRes);
        if (filePolicy != null && policyResource != null) {
            StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storage);
            _log.info("Updating File protection ile Policy  {}", policy);
            args.setFileProtectionPolicy(filePolicy);
            args.setPolicyStorageResource(policyResource);
            args.setFileProtectionPolicyUpdateParam(policyUpdateParam);
            args.setFileOperation(true);
            args.setOpId(opId);
            // Do the Operation on device.
            BiosCommandResult result = getDevice(storageObj.getSystemType()).updateStorageSystemFileProtectionPolicy(storageObj, args);
            if (!result.isCommandSuccess() && !result.getCommandPending()) {
                WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
            }
            if (result.isCommandSuccess()) {
                WorkflowStepCompleter.stepSucceded(opId);
            }
        } else {
            throw DeviceControllerException.exceptions.invalidObjectNull();
        }
    } catch (Exception e) {
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        WorkflowStepCompleter.stepFailed(opId, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 18 with PolicyStorageResource

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

the class IsilonFileStorageDevice method doStartMirrorLink.

@Override
public BiosCommandResult doStartMirrorLink(StorageSystem system, FileShare fs, TaskCompleter completer) {
    FileShare sourceFS = null;
    FileShare targetFS = null;
    StorageSystem sourceSystem = null;
    StorageSystem targetSystem = null;
    boolean isMirrorPolicy = false;
    if (fs.getPersonality().equals(PersonalityTypes.TARGET.name())) {
        sourceFS = _dbClient.queryObject(FileShare.class, fs.getParentFileShare());
        targetFS = fs;
        isMirrorPolicy = true;
    } else if (fs.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
        sourceFS = fs;
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(fs.getMirrorfsTargets());
        if (!targetfileUris.isEmpty()) {
            targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        } else {
            ServiceError serviceError = DeviceControllerErrors.isilon.unableToGetTargetFileSystem(sourceFS.getLabel());
            return BiosCommandResult.createErrorResult(serviceError);
        }
    }
    sourceSystem = _dbClient.queryObject(StorageSystem.class, sourceFS.getStorageDevice());
    targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
    PolicyStorageResource policyStrRes = getEquivalentPolicyStorageResource(sourceFS, _dbClient);
    if (policyStrRes != null) {
        // get the policy details by policy native id
        IsilonSyncPolicy syncPolicy = policyNativeIdValidation(sourceSystem, policyStrRes);
        String policyName = syncPolicy.getName();
        // In case of fail back we need to append _mirror name since we are starting the target FS mirror policy
        if (isMirrorPolicy) {
            String mirrorPolicyName = syncPolicy.getName();
            mirrorPolicyName = mirrorPolicyName.concat(MIRROR_POLICY);
            // call start operation on mirror policy from target system to source system
            return doStartTargetMirrorPolicy(sourceSystem, policyName, targetSystem, mirrorPolicyName, completer);
        } else {
            // call action 'start' on source policy
            return mirrorOperations.doStartReplicationPolicy(system, policyName, completer);
        }
    }
    ServiceError serviceError = DeviceControllerErrors.isilon.unableToCreateFileShare();
    return BiosCommandResult.createErrorResult(serviceError);
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) IsilonList(com.emc.storageos.isilon.restapi.IsilonApi.IsilonList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 19 with PolicyStorageResource

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

the class IsilonFileStorageDevice method doApplyFileReplicationPolicy.

private BiosCommandResult doApplyFileReplicationPolicy(FilePolicy filePolicy, FileDeviceInputOutput args, FileShare fs, StorageSystem storageObj) {
    IsilonApi isi = getIsilonDevice(storageObj);
    FileShare targetFS = null;
    String sourcePath = generatePathForPolicy(filePolicy, fs, args);
    String scheduleValue = getIsilonPolicySchedule(filePolicy);
    String targetPath = null;
    String targetHost = null;
    StorageSystem targetSystem = null;
    NASServer targetNasServer = null;
    if (fs.getPersonality() != null && PersonalityTypes.SOURCE.name().equalsIgnoreCase(fs.getPersonality())) {
        String targetFs = fs.getMirrorfsTargets().iterator().next();
        targetFS = _dbClient.queryObject(FileShare.class, URI.create(targetFs));
        targetPath = generatePathForPolicy(filePolicy, targetFS, args);
        // Add the suffix only for local replication policy at higher level
        if (filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.LOCAL.name()) && !FilePolicyApplyLevel.file_system.name().equalsIgnoreCase(filePolicy.getApplyAt())) {
            targetPath = targetPath + "_localTarget";
        }
        // Get the target smart connect zone!!
        targetHost = FileOrchestrationUtils.getTargetHostPortForReplication(_dbClient, targetFS);
        targetSystem = _dbClient.queryObject(StorageSystem.class, targetFS.getStorageDevice());
        if (targetFS.getVirtualNAS() != null) {
            targetNasServer = _dbClient.queryObject(VirtualNAS.class, targetFS.getVirtualNAS());
        }
    }
    IsilonApi isiApiOfTarget = getIsilonDevice(targetSystem);
    String targetClusterName = isiApiOfTarget.getClusterConfig().getName();
    String sourceClustername = isi.getClusterConfig().getName();
    String policyName = FileOrchestrationUtils.generateNameForSyncIQPolicy(sourceClustername, targetClusterName, filePolicy, fs, args, sourcePath);
    IsilonSyncPolicy isiSynIQPolicy = getEquivalentIsilonSyncIQPolicy(isi, sourcePath);
    PolicyStorageResource policyStorageResource = null;
    if (isiSynIQPolicy != null) {
        boolean validPolicy = validateIsilonReplicationPolicy(isiSynIQPolicy, filePolicy, targetPath, targetSystem, storageObj);
        if (validPolicy) {
            _log.info("File Policy {} is already applied and running.", filePolicy.toString());
            // Verify the policy was mapped to FileStorageResource
            if (null == FileOrchestrationUtils.findPolicyStorageResourceByNativeId(_dbClient, storageObj, filePolicy, args, sourcePath)) {
                _log.info("Isilon policy found for {}, creating policy storage resouce to further management", filePolicy.getFilePolicyName());
                // update the policy object in DB
                policyStorageResource = FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, sourcePath, isiSynIQPolicy.getName(), isiSynIQPolicy.getId(), targetSystem, targetNasServer, targetPath);
                // for existing policy's on device
                // label - label is generated from ViPR
                policyStorageResource.setLabel(policyName);
                _dbClient.updateObject(policyStorageResource);
            }
            return BiosCommandResult.createSuccessfulResult();
        } else {
            throw DeviceControllerException.exceptions.assignFilePolicyFailed(filePolicy.getFilePolicyName(), filePolicy.getApplyAt(), "File policy and Isilon syncIQ policy differs for path: " + sourcePath);
        }
    } else {
        IsilonSyncPolicy policy = new IsilonSyncPolicy(policyName, sourcePath, targetPath, targetHost, IsilonSyncPolicy.Action.sync);
        IsilonSyncPolicy8Above policycopy = new IsilonSyncPolicy8Above();
        if (scheduleValue != null && !scheduleValue.isEmpty()) {
            policy.setSchedule(scheduleValue);
        }
        if (filePolicy.getFilePolicyDescription() != null) {
            policy.setDescription(filePolicy.getFilePolicyDescription());
        }
        if (filePolicy.getNumWorkerThreads() != null && filePolicy.getNumWorkerThreads() > 0) {
            policy.setWorkersPerNode(filePolicy.getNumWorkerThreads().intValue());
        }
        policy.setEnabled(true);
        String policyId = null;
        if (VersionChecker.verifyVersionDetails(ONEFS_V8, storageObj.getFirmwareVersion()) >= 0) {
            if (filePolicy.getPriority() != null) {
                policycopy = policycopy.copy(policy);
                policycopy.setPriority(FilePolicyPriority.valueOf(filePolicy.getPriority()).ordinal());
            }
            policyId = isi.createReplicationPolicy8above(policycopy);
        } else {
            policyId = isi.createReplicationPolicy(policy);
        }
        if (policyId != null) {
            _log.info("Isilon File Policy {} created successfully with id {}", policyName, policyId);
            // update the policy object in DB
            FileOrchestrationUtils.updatePolicyStorageResource(_dbClient, storageObj, filePolicy, args, sourcePath, policyName, policyId, targetSystem, targetNasServer, targetPath);
            return BiosCommandResult.createSuccessfulResult();
        }
    }
    return BiosCommandResult.createSuccessfulResult();
}
Also used : NASServer(com.emc.storageos.db.client.model.NASServer) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) IsilonSyncPolicy8Above(com.emc.storageos.isilon.restapi.IsilonSyncPolicy8Above) IsilonSyncPolicy(com.emc.storageos.isilon.restapi.IsilonSyncPolicy) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 20 with PolicyStorageResource

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

the class IsilonFileStorageDevice method checkPolicyAppliedOnPath.

/**
 * This method checks these entries for existing policy
 * return true, if the policy is already applied on the path, otherwise false.
 *
 * Policy storage resource is storing all storage system paths
 * on which the policy template is applied.
 *
 * @param storageObj - The storage system on which the policy is to be checked
 * @param args
 * @param policyPath
 * @return
 */
private boolean checkPolicyAppliedOnPath(StorageSystem storageObj, FileDeviceInputOutput args, String policyPath) {
    // 
    FilePolicy filePolicy = args.getFileProtectionPolicy();
    if (filePolicy != null && !filePolicy.getInactive()) {
        StringSet policyStrRes = filePolicy.getPolicyStorageResources();
        if (policyStrRes != null && !policyStrRes.isEmpty()) {
            for (String policyStrRe : policyStrRes) {
                PolicyStorageResource strRes = _dbClient.queryObject(PolicyStorageResource.class, URIUtil.uri(policyStrRe));
                if (strRes != null && strRes.getStorageSystem().toString().equals(storageObj.getId().toString()) && strRes.getResourcePath().equalsIgnoreCase(policyPath)) {
                    return true;
                }
            }
        }
    }
    String msg = String.format("File Policy template %s was not applied on storage system %s path %s", filePolicy.getFilePolicyName(), storageObj.getLabel(), policyPath);
    _log.info(msg);
    return false;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Aggregations

PolicyStorageResource (com.emc.storageos.db.client.model.PolicyStorageResource)29 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)11 ArrayList (java.util.ArrayList)11 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)9 IsilonSyncPolicy (com.emc.storageos.isilon.restapi.IsilonSyncPolicy)8 FileShare (com.emc.storageos.db.client.model.FileShare)6 StringSet (com.emc.storageos.db.client.model.StringSet)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 NASServer (com.emc.storageos.db.client.model.NASServer)5 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)5 IsilonApi (com.emc.storageos.isilon.restapi.IsilonApi)5 URI (java.net.URI)5 PhysicalNAS (com.emc.storageos.db.client.model.PhysicalNAS)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)4 ControllerException (com.emc.storageos.volumecontroller.ControllerException)4 WorkflowException (com.emc.storageos.workflow.WorkflowException)4 FileReplicaPolicyTarget (com.emc.storageos.db.client.model.FileReplicaPolicyTarget)3 FileReplicaPolicyTargetMap (com.emc.storageos.db.client.model.FileReplicaPolicyTargetMap)3