Search in sources :

Example 1 with FilePolicyVpoolAssignParam

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

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 FileReplicationTopologyParam (com.emc.storageos.model.file.policy.FileReplicationTopologyParam)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1