Search in sources :

Example 1 with FileReplicationTopologyParam

use of com.emc.storageos.model.file.policy.FileReplicationTopologyParam 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 FileReplicationTopologyParam

use of com.emc.storageos.model.file.policy.FileReplicationTopologyParam in project coprhd-controller by CoprHD.

the class FileProtectionPolicies method getFileReplicationTopologyParamSet.

private static Set<FileReplicationTopologyParam> getFileReplicationTopologyParamSet(List<FileReplicationTopology> replicationTopologies) {
    Set<FileReplicationTopologyParam> topologyParamSet = new HashSet<FileReplicationTopologyParam>();
    for (FileReplicationTopology replicationTopology : replicationTopologies) {
        FileReplicationTopologyParam param = new FileReplicationTopologyParam();
        param.setSourceVArray((uri(replicationTopology.sourceVArray)));
        Set<URI> targetVArrays = new HashSet<URI>();
        targetVArrays.add((uri(replicationTopology.targetVArray)));
        param.setTargetVArrays(targetVArrays);
        topologyParamSet.add(param);
    }
    return topologyParamSet;
}
Also used : FileReplicationTopologyParam(com.emc.storageos.model.file.policy.FileReplicationTopologyParam) URI(java.net.URI) HashSet(java.util.HashSet)

Example 3 with FileReplicationTopologyParam

use of com.emc.storageos.model.file.policy.FileReplicationTopologyParam in project coprhd-controller by CoprHD.

the class FileProtectionPolicies method updateAssignPolicyParam.

private static Boolean updateAssignPolicyParam(AssignPolicyForm assignPolicy, FilePolicyAssignParam param) {
    Boolean policyAssignment = false;
    FilePolicyRestRep existingPolicy = getViprClient().fileProtectionPolicies().get(URI.create(assignPolicy.id));
    param.setApplyOnTargetSite(assignPolicy.applyOnTargetSite);
    // Get source and target varrays
    if (FilePolicyType.file_replication.name().equalsIgnoreCase(existingPolicy.getType())) {
        List<FileReplicationTopology> replicationTopologies = null;
        if (assignPolicy.topologiesString != null && !assignPolicy.topologiesString.isEmpty()) {
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            replicationTopologies = Arrays.asList((gson.fromJson(assignPolicy.topologiesString, FileReplicationTopology[].class)));
        }
        Set<FileReplicationTopologyParam> toploSet = getFileReplicationTopologyParamSet(replicationTopologies);
        param.setFileReplicationtopologies(toploSet);
    }
    if (FilePolicyApplyLevel.project.name().equalsIgnoreCase(existingPolicy.getAppliedAt())) {
        FilePolicyProjectAssignParam projectAssignParams = new FilePolicyProjectAssignParam();
        projectAssignParams.setVpool(uri(assignPolicy.vpool));
        List<String> existingProjects = stringRefIds(existingPolicy.getAssignedResources());
        List<String> projects = Lists.newArrayList();
        if (assignPolicy.projects != null) {
            projects = assignPolicy.projects;
        }
        Set<String> add = Sets.newHashSet(CollectionUtils.subtract(projects, existingProjects));
        // Assign new projects
        Set<URI> assignProjects = new HashSet<URI>();
        if (!add.isEmpty()) {
            for (String project : add) {
                assignProjects.add(uri(project));
            }
            policyAssignment = true;
        }
        projectAssignParams.setAssigntoProjects(assignProjects);
        param.setProjectAssignParams(projectAssignParams);
    } else if (FilePolicyApplyLevel.vpool.name().equalsIgnoreCase(existingPolicy.getAppliedAt())) {
        FilePolicyVpoolAssignParam vpoolAssignParams = new FilePolicyVpoolAssignParam();
        List<String> existingvPools = stringRefIds(existingPolicy.getAssignedResources());
        List<String> vPools = Lists.newArrayList();
        if (assignPolicy.vpool != null) {
            vPools.add(assignPolicy.vpool);
        }
        if (FilePolicyType.file_snapshot.name().equalsIgnoreCase(existingPolicy.getType()) && assignPolicy.virtualPools != null) {
            vPools.addAll(assignPolicy.virtualPools);
        }
        Set<String> add = Sets.newHashSet(CollectionUtils.subtract(vPools, existingvPools));
        Set<URI> assignVpools = new HashSet<URI>();
        if (!add.isEmpty()) {
            for (String vpool : add) {
                assignVpools.add(uri(vpool));
            }
            policyAssignment = true;
        }
        vpoolAssignParams.setAssigntoVpools(assignVpools);
        param.setVpoolAssignParams(vpoolAssignParams);
    }
    return policyAssignment;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) GsonBuilder(com.google.gson.GsonBuilder) FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) Gson(com.google.gson.Gson) FileReplicationTopologyParam(com.emc.storageos.model.file.policy.FileReplicationTopologyParam) URI(java.net.URI) FilePolicyProjectAssignParam(com.emc.storageos.model.file.policy.FilePolicyProjectAssignParam) FilePolicyVpoolAssignParam(com.emc.storageos.model.file.policy.FilePolicyVpoolAssignParam) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

FileReplicationTopologyParam (com.emc.storageos.model.file.policy.FileReplicationTopologyParam)3 URI (java.net.URI)3 HashSet (java.util.HashSet)2 FileReplicationTopology (com.emc.storageos.db.client.model.FileReplicationTopology)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 FilePolicyProjectAssignParam (com.emc.storageos.model.file.policy.FilePolicyProjectAssignParam)1 FilePolicyRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep)1 FilePolicyVpoolAssignParam (com.emc.storageos.model.file.policy.FilePolicyVpoolAssignParam)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1