use of com.emc.storageos.model.file.policy.FilePolicyProjectAssignParam 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;
}
Aggregations