Search in sources :

Example 61 with FilePolicy

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

the class VirtualPoolService method deleteVirtualPool.

protected Response deleteVirtualPool(VirtualPool.Type type, URI id) {
    ArgValidator.checkUri(id);
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, id);
    ArgValidator.checkEntityNotNull(vpool, id, isIdEmbeddedInURL(id));
    // we need to remove before the virtual pool removal
    if (vpool.getType().equalsIgnoreCase(Type.block.name())) {
        List<URI> quotas = _dbClient.queryByType(QuotaOfCinder.class, true);
        for (URI quota : quotas) {
            QuotaOfCinder quotaObj = _dbClient.queryObject(QuotaOfCinder.class, quota);
            if ((quotaObj.getVpool() != null) && (quotaObj.getVpool().toString().equalsIgnoreCase(vpool.getId().toString()))) {
                _log.debug("Deleting related Vpool for quota object {}.", vpool.getId().toString());
                _dbClient.removeObject(quotaObj);
            }
        }
    }
    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("Failed to update the name of virtual pool as a policy is assigned");
            throw APIException.badRequests.cannotDeleteVpoolAssignedFilePolicy(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.getAssignedResources() != null) && (policyObj.getFilePolicyVpool() != null) && (policyObj.getFilePolicyVpool().toString().equalsIgnoreCase(vpool.getId().toString()))) {
                _log.error("Failed to update the name of virtual pool as a policy is assigned at higher level");
                throw APIException.badRequests.cannotDeleteVpoolAssignedFilePolicy(vpool.getLabel());
            }
        }
    }
    if (!vpool.getType().equals(type.name())) {
        throw APIException.badRequests.providedVirtualPoolNotCorrectType();
    }
    QosSpecification qosSpecification = null;
    // Check if Virtual Pool type equals block type
    if (vpool.getType().equalsIgnoreCase(Type.block.name())) {
        // Get the QoS for the VirtualPool, otherwise throw exception
        qosSpecification = QosService.getQos(vpool.getId(), _dbClient);
    }
    // make sure vpool is unused by volumes/fileshares
    ArgValidator.checkReference(VirtualPool.class, id, checkForDelete(vpool));
    // Check if vpool is set as a continuous copies vpool
    checkIfVpoolIsSetAsContinuousCopiesVpool(vpool);
    // Additional check for VirtualPool that may be hidden in another VirtualPool via the
    // protection settings
    URIQueryResultList settingsResultList = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVpoolProtectionVarraySettingsConstraint(id.toString()), settingsResultList);
    Iterator<URI> settingsListItr = settingsResultList.iterator();
    while (settingsListItr.hasNext()) {
        final URI settingId = settingsListItr.next();
        VpoolProtectionVarraySettings setting = _dbClient.queryObject(VpoolProtectionVarraySettings.class, settingId);
        ArgValidator.checkEntity(setting, settingId, isIdEmbeddedInURL(settingId));
    }
    if (vpool.getProtectionVarraySettings() != null) {
        // Delete all settings associated with the protection settings
        deleteVPoolProtectionVArraySettings(vpool);
    }
    if (vpool.getFileRemoteCopySettings() != null) {
        // Delete all settings associated with the protection settings
        deleteFileVPoolRemoteCopyProtectionSettings(vpool);
    }
    // We also check to see if this virtual pool is specified as the HA virtual pool
    // for some other virtual pool that specifies VPLEX distributed high availability.
    // If this is the case, we disallow the deletion.
    List<URI> vpoolURIs = _dbClient.queryByType(VirtualPool.class, true);
    Iterator<VirtualPool> vpoolsIter = _dbClient.queryIterativeObjects(VirtualPool.class, vpoolURIs);
    while (vpoolsIter.hasNext()) {
        VirtualPool activeVPool = vpoolsIter.next();
        if (!activeVPool.getId().equals(id)) {
            StringMap haMap = activeVPool.getHaVarrayVpoolMap();
            if ((haMap != null) && (!haMap.isEmpty()) && (haMap.values().contains(id.toString()))) {
                // is not allowed.
                throw APIException.badRequests.cantDeleteVPlexHaVPool(activeVPool.getLabel());
            }
        }
    }
    if (vpool.getType().equalsIgnoreCase(Type.block.name()) && qosSpecification != null) {
        // Remove Qos associated to this Virtual Pool
        _dbClient.removeObject(qosSpecification);
    }
    _dbClient.markForDeletion(vpool);
    recordOperation(OperationTypeEnum.DELETE_VPOOL, VPOOL_DELETED_DESCRIPTION, vpool);
    return Response.ok().build();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) QuotaOfCinder(com.emc.storageos.db.client.model.QuotaOfCinder) VpoolProtectionVarraySettings(com.emc.storageos.db.client.model.VpoolProtectionVarraySettings) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) QosSpecification(com.emc.storageos.db.client.model.QosSpecification) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 62 with FilePolicy

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

the class FilePolicyServiceUtils method updatePolicyCapabilities.

/**
 * update the replication policy capabilities into capabilities list from applicable replication policy
 * only a single replication policy across vpool/prject/fs levels
 * otherwise throw appropriate exception.
 *
 * @param dbClient
 * @param currVArray
 * @param vPool
 * @param project
 * @param fs
 * @param capabilities
 * @param errorMsg
 * @return true/false
 */
public static boolean updatePolicyCapabilities(DbClient dbClient, VirtualArray currVArray, VirtualPool vPool, Project project, FileShare fs, VirtualPoolCapabilityValuesWrapper capabilities, StringBuilder errorMsg) {
    List<FilePolicy> eligiblePolicies = FileOrchestrationUtils.getReplicationPolices(dbClient, vPool, project, fs);
    if (eligiblePolicies != null && !eligiblePolicies.isEmpty()) {
        if (eligiblePolicies.size() > 1) {
            if (errorMsg == null) {
                errorMsg = new StringBuilder();
            }
            // Single replication policy across vpool/project/fs
            errorMsg.append("More than one replication policy could not be applied accross vpool/project/fs");
            return false;
        }
        FilePolicy policy = eligiblePolicies.get(0);
        // Update replication policy capabilities!!
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, policy.getFileReplicationType());
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_COPY_MODE, policy.getFileReplicationCopyMode());
        if (vPool.getFrRpoType() != null) {
            // rpo type can be DAYS or HOURS
            capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_RPO_TYPE, vPool.getFrRpoType());
        }
        if (vPool.getFrRpoValue() != null) {
            capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_RPO_VALUE, vPool.getFrRpoValue());
        }
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_APPLIED_AT, policy.getApplyAt());
        // Update target varrys for file placement!!
        Set<String> targetVArrys = new HashSet<String>();
        if (policy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
            if (policy.getReplicationTopologies() != null && !policy.getReplicationTopologies().isEmpty()) {
                for (String strTopology : policy.getReplicationTopologies()) {
                    FileReplicationTopology dbTopology = dbClient.queryObject(FileReplicationTopology.class, URI.create(strTopology));
                    if (currVArray.getId().toString().equalsIgnoreCase(dbTopology.getSourceVArray().toString())) {
                        targetVArrys.addAll(dbTopology.getTargetVArrays());
                        break;
                    }
                }
                if (targetVArrys.isEmpty()) {
                    errorMsg.append("Target VArry is not defined in replication topology for source varry " + currVArray.getId().toString());
                    return false;
                }
                capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VARRAYS, targetVArrys);
                capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, vPool.getId());
            } else {
                errorMsg.append("Replication Topology is not defined for policy " + policy.getFilePolicyName());
                return false;
            }
        } else {
            targetVArrys.add(currVArray.getId().toString());
        }
        return true;
    } else if (vPool.getFileReplicationSupported()) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, FileReplicationType.NONE.name());
        errorMsg.append("No replication policy assigned at any level for virtual pool ").append(vPool.getLabel());
        _log.warn(errorMsg.toString());
        return true;
    }
    return false;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) HashSet(java.util.HashSet) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 63 with FilePolicy

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

the class FileSystemReplicationUtils method getEquivalentPolicyStorageResource.

public static PolicyStorageResource getEquivalentPolicyStorageResource(FileShare fs, DbClient dbClient) {
    FilePolicy fp = getReplicationPolicyAppliedOnFS(fs, dbClient);
    if (fp != null) {
        StringSet policyStrResources = fp.getPolicyStorageResources();
        List<URI> policyStrURIs = new ArrayList<>();
        for (String policyStrResource : policyStrResources) {
            policyStrURIs.add(URI.create(policyStrResource));
        }
        Iterator<PolicyStorageResource> iterator = dbClient.queryIterativeObjects(PolicyStorageResource.class, policyStrURIs, true);
        while (iterator.hasNext()) {
            PolicyStorageResource policyRes = iterator.next();
            if (policyRes.getAppliedAt().equals(fs.getId()) && policyRes.getStorageSystem().equals(fs.getStorageDevice())) {
                return policyRes;
            }
        }
    }
    return null;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) URI(java.net.URI) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource)

Example 64 with FilePolicy

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

the class FileSystemReplicationUtils 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) URI(java.net.URI)

Example 65 with FilePolicy

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

the class FileDeviceController method assignFileSnapshotPolicyToVirtualPools.

@Override
public void assignFileSnapshotPolicyToVirtualPools(URI storageSystemURI, URI vNASURI, URI filePolicyToAssign, URI vpoolURI, String opId) throws ControllerException {
    StorageSystem storageObj = null;
    FilePolicy filePolicy = null;
    VirtualNAS vNAS = null;
    VirtualPool vpool = null;
    try {
        WorkflowStepCompleter.stepExecuting(opId);
        FileDeviceInputOutput args = new FileDeviceInputOutput();
        storageObj = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
        filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
        vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
        if (vNASURI != null) {
            vNAS = _dbClient.queryObject(VirtualNAS.class, vNASURI);
            args.setvNAS(vNAS);
        }
        args.setFileProtectionPolicy(filePolicy);
        args.setVPool(vpool);
        _log.info("Assigning file snapshot policy: {} to vpool: {}", filePolicyToAssign, vpoolURI);
        BiosCommandResult result = getDevice(storageObj.getSystemType()).checkFilePolicyExistsOrCreate(storageObj, args);
        if (result.getCommandPending()) {
            return;
        }
        if (!result.isCommandSuccess() && !result.getCommandPending()) {
            WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
        }
        if (result.isCommandSuccess()) {
            WorkflowStepCompleter.stepSucceded(opId);
        }
    } 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) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) 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)

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