Search in sources :

Example 1 with FileReplicationTopology

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

the class FilePolicyService method updateFileReplicationTopologyInfo.

private void updateFileReplicationTopologyInfo(FilePolicyAssignParam param, FilePolicy filepolicy) {
    if (FilePolicyType.file_replication.name().equalsIgnoreCase(filepolicy.getFilePolicyType()) && filepolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
        if (param.getFileReplicationtopologies() != null && !param.getFileReplicationtopologies().isEmpty()) {
            List<FileReplicationTopology> dbTopologies = queryDBReplicationTopologies(filepolicy);
            for (FileReplicationTopologyParam topologyParam : param.getFileReplicationtopologies()) {
                // Get existing topologies for given policy
                Boolean foundExistingTopology = false;
                if (dbTopologies != null && !dbTopologies.isEmpty()) {
                    for (FileReplicationTopology topology : dbTopologies) {
                        if (topology.getSourceVArray() != null && topology.getSourceVArray().toString().equalsIgnoreCase(topologyParam.getSourceVArray().toString())) {
                            _log.info("Updating the existing topology...");
                            if (topologyParam.getTargetVArrays() != null && !topologyParam.getTargetVArrays().isEmpty()) {
                                StringSet requestTargetVarraySet = new StringSet();
                                for (Iterator<URI> iterator = topologyParam.getTargetVArrays().iterator(); iterator.hasNext(); ) {
                                    URI targetVArray = iterator.next();
                                    requestTargetVarraySet.add(targetVArray.toString());
                                }
                                // Thow an error if admin want to change the topology for policy with resources!!
                                if (filepolicy.getPolicyStorageResources() != null && !filepolicy.getPolicyStorageResources().isEmpty()) {
                                    if (topology.getTargetVArrays() != null && !topology.getTargetVArrays().containsAll(requestTargetVarraySet)) {
                                        StringBuffer errorMsg = new StringBuffer();
                                        errorMsg.append("Topology can not be changed for policy {} with existing resources " + filepolicy.getFilePolicyName());
                                        _log.error(errorMsg.toString());
                                        throw APIException.badRequests.invalidFilePolicyAssignParam(filepolicy.getFilePolicyName(), errorMsg.toString());
                                    }
                                }
                                topology.setTargetVArrays(requestTargetVarraySet);
                                _dbClient.updateObject(topology);
                            }
                            if (filepolicy.getReplicationTopologies() == null || !filepolicy.getReplicationTopologies().contains(topology.getId().toString())) {
                                filepolicy.addReplicationTopology(topology.getId().toString());
                                _dbClient.updateObject(filepolicy);
                            }
                            foundExistingTopology = true;
                            break;
                        }
                    }
                }
                if (!foundExistingTopology) {
                    // Create DB entry for Replication topology
                    FileReplicationTopology dbReplTopology = new FileReplicationTopology();
                    dbReplTopology.setId(URIUtil.createId(FileReplicationTopology.class));
                    dbReplTopology.setPolicy(filepolicy.getId());
                    dbReplTopology.setSourceVArray(topologyParam.getSourceVArray());
                    StringSet targetArrays = new StringSet();
                    if (topologyParam.getTargetVArrays() != null && !topologyParam.getTargetVArrays().isEmpty()) {
                        for (URI uriTargetArray : topologyParam.getTargetVArrays()) {
                            targetArrays.add(uriTargetArray.toString());
                        }
                        dbReplTopology.setTargetVArrays(targetArrays);
                    }
                    _dbClient.createObject(dbReplTopology);
                    if (filepolicy.getReplicationTopologies() == null || !filepolicy.getReplicationTopologies().contains(dbReplTopology.getId().toString())) {
                        filepolicy.addReplicationTopology(dbReplTopology.getId().toString());
                        _dbClient.updateObject(filepolicy);
                    }
                }
            }
        }
    }
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) FileReplicationTopologyParam(com.emc.storageos.model.file.policy.FileReplicationTopologyParam) URI(java.net.URI) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 2 with FileReplicationTopology

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

the class FilePolicyService method updatePolicyCapabilities.

private static boolean updatePolicyCapabilities(DbClient dbClient, StringSet sourceVArraySet, VirtualPool vPool, FilePolicy policy, VirtualPoolCapabilityValuesWrapper capabilities, StringBuilder errorMsg) {
    // Update replication policy capabilities!!
    capabilities.put(VirtualPoolCapabilityValuesWrapper.VPOOL_PROJECT_POLICY_ASSIGN, true);
    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 varrays for file placement!!
    if (policy.getFileReplicationType() != null && policy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
        if (policy.getReplicationTopologies() != null && !policy.getReplicationTopologies().isEmpty()) {
            Set<String> targetVArrays = new HashSet<String>();
            for (String strTopology : policy.getReplicationTopologies()) {
                FileReplicationTopology dbTopology = dbClient.queryObject(FileReplicationTopology.class, URI.create(strTopology));
                if (sourceVArraySet.contains(dbTopology.getSourceVArray().toString())) {
                    targetVArrays.addAll(dbTopology.getTargetVArrays());
                    break;
                }
            }
            if (targetVArrays.isEmpty()) {
                errorMsg.append("Target Varrays are not defined in replication topology for source varrays " + sourceVArraySet + ". ");
                return false;
            }
            capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VARRAYS, targetVArrays);
            capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TARGET_VPOOL, vPool.getId());
        } else {
            errorMsg.append("Replication Topology is not defined for policy " + policy.getFilePolicyName() + ". ");
            return false;
        }
    }
    return true;
}
Also used : HashSet(java.util.HashSet) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 3 with FileReplicationTopology

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

the class FilePolicyService method getSourceVArraySet.

private StringSet getSourceVArraySet(VirtualPool vpool, FilePolicy filePolicy) {
    StringSet vpoolVArraySet = vpool.getVirtualArrays();
    if (filePolicy.getFileReplicationType() != null && filePolicy.getFileReplicationType().equalsIgnoreCase(FileReplicationType.REMOTE.name())) {
        Set<String> topologyVArraySet = new HashSet<String>();
        List<FileReplicationTopology> dbTopologies = queryDBReplicationTopologies(filePolicy);
        if (dbTopologies != null && !dbTopologies.isEmpty()) {
            for (Iterator<FileReplicationTopology> iterator = dbTopologies.iterator(); iterator.hasNext(); ) {
                FileReplicationTopology fileReplicationTopology = iterator.next();
                topologyVArraySet.add(fileReplicationTopology.getSourceVArray().toString());
            }
        }
        vpoolVArraySet.retainAll(topologyVArraySet);
    }
    return vpoolVArraySet;
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) HashSet(java.util.HashSet) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 4 with FileReplicationTopology

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

the class FileReplicationPolicyUpdateTargetPoolMigration method queryDBReplicationTopologies.

private List<FileReplicationTopology> queryDBReplicationTopologies(FilePolicy policy) {
    try {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileReplicationPolicyTopologyConstraint(policy.getId());
        List<FileReplicationTopology> topologies = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileReplicationTopology.class, containmentConstraint);
        return topologies;
    } catch (Exception e) {
        logger.error("Error while querying {}", e);
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Example 5 with FileReplicationTopology

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

the class FileReplicationPolicyUpdateTargetPoolMigration method process.

@Override
public void process() throws MigrationCallbackException {
    logger.info("File replication policy to update it's target pool in topology migration START");
    DbClient dbClient = getDbClient();
    try {
        List<URI> virtualPoolURIs = dbClient.queryByType(VirtualPool.class, true);
        Iterator<VirtualPool> virtualPools = dbClient.queryIterativeObjects(VirtualPool.class, virtualPoolURIs, true);
        List<FileReplicationTopology> replPolicyTopologies = new ArrayList<FileReplicationTopology>();
        Map<String, FilePolicy> replicationPolicies = getRemoteReplicationPolicies();
        if (replicationPolicies.isEmpty()) {
            logger.info("No remote replication policies found in system... ");
            return;
        }
        // Update the target vpool in topology for that policy
        while (virtualPools.hasNext()) {
            VirtualPool virtualPool = virtualPools.next();
            if (VirtualPool.Type.file.name().equals(virtualPool.getType()) && virtualPool.getFileReplicationType() != null && FileReplicationType.REMOTE.name().equalsIgnoreCase(virtualPool.getFileReplicationType())) {
                logger.info("Getting replicaiton policies associated with vpool {} ", virtualPool.getLabel());
                // Get the existing replication policy
                // which was created with vpool name followed by _Replication_Policy
                String polName = virtualPool.getLabel() + "_Replication_Policy";
                FilePolicy replPolicy = replicationPolicies.get(polName);
                if (replPolicy != null) {
                    // Get the replication topologies for the policy!!
                    List<FileReplicationTopology> policyTopologies = queryDBReplicationTopologies(replPolicy);
                    if (policyTopologies != null && !policyTopologies.isEmpty()) {
                        // Get the target vpool from the vpool!
                        String targetVarray = null;
                        String targetVPool = null;
                        Map<URI, VpoolRemoteCopyProtectionSettings> remoteSettings = virtualPool.getFileRemoteProtectionSettings(virtualPool, dbClient);
                        if (remoteSettings != null && !remoteSettings.isEmpty()) {
                            // till now CoprHD supports only single target!!
                            for (Map.Entry<URI, VpoolRemoteCopyProtectionSettings> entry : remoteSettings.entrySet()) {
                                if (entry != null) {
                                    targetVarray = entry.getKey().toString();
                                    if (entry.getValue() != null && entry.getValue().getVirtualPool() != null) {
                                        targetVPool = entry.getValue().getVirtualPool().toString();
                                    }
                                    break;
                                }
                            }
                        }
                        for (FileReplicationTopology topology : policyTopologies) {
                            if (virtualPool.getVirtualArrays().contains(topology.getSourceVArray().toASCIIString()) && topology.getTargetVArrays().contains(targetVarray)) {
                                if (targetVarray != null && targetVPool != null) {
                                    topology.setTargetVAVPool(targetVarray + SEPARATOR + targetVPool);
                                    replPolicyTopologies.add(topology);
                                }
                            }
                        }
                    }
                } else {
                    logger.info("No remote replication policy with name {} ", polName);
                }
            }
        }
        // Udate DB
        if (!replPolicyTopologies.isEmpty()) {
            logger.info("Modified {} topologies ", replPolicyTopologies.size());
            dbClient.updateObject(replPolicyTopologies);
        }
    } catch (Exception ex) {
        logger.error("Exception occured while migrating file replication policy topology ");
        logger.error(ex.getMessage(), ex);
    }
    logger.info("File replication policy to update it's target pool in topology migration END");
}
Also used : VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) DbClient(com.emc.storageos.db.client.DbClient) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) ArrayList(java.util.ArrayList) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) HashMap(java.util.HashMap) Map(java.util.Map) FileReplicationTopology(com.emc.storageos.db.client.model.FileReplicationTopology)

Aggregations

FileReplicationTopology (com.emc.storageos.db.client.model.FileReplicationTopology)11 URI (java.net.URI)5 StringSet (com.emc.storageos.db.client.model.StringSet)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)4 FilePolicy (com.emc.storageos.db.client.model.FilePolicy)3 DbClient (com.emc.storageos.db.client.DbClient)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)2 VpoolRemoteCopyProtectionSettings (com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)2 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)2 TaskMapper.toTask (com.emc.storageos.api.mapper.TaskMapper.toTask)1 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)1 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1