use of com.emc.storageos.model.file.policy.FilePolicyRestRep 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;
}
use of com.emc.storageos.model.file.policy.FilePolicyRestRep in project coprhd-controller by CoprHD.
the class FileProtectionPolicies method assign.
@FlashException(value = "list", keep = true)
public static void assign(String ids) {
FilePolicyRestRep filePolicyRestRep = getViprClient().fileProtectionPolicies().get(uri(ids));
if (filePolicyRestRep != null) {
AssignPolicyForm assignPolicy = new AssignPolicyForm().form(filePolicyRestRep);
addRenderApplyPolicysAt();
addProjectArgs(filePolicyRestRep);
addVpoolArgs(filePolicyRestRep);
render(assignPolicy);
} else {
flash.error(MessagesUtils.get(UNKNOWN, ids));
list();
}
}
use of com.emc.storageos.model.file.policy.FilePolicyRestRep in project coprhd-controller by CoprHD.
the class FileProtectionPolicies method getVpoolForProtectionPolicy.
/**
* This call return the pool or pools which can be associated with policy.
* Currently this does not check vpool is assigned to another policy.
* As we do not have direct reference of policy in file vpool and looping all
* policy and then its assigned resource to figure out it is assign or not
* is causing slowness in GUI.Will address this in future release
*
* @param id
*/
public static void getVpoolForProtectionPolicy(String id) {
Collection<FileVirtualPoolRestRep> vPools = Lists.newArrayList();
FilePolicyRestRep policy = getViprClient().fileProtectionPolicies().get(uri(id));
if (policy.getAssignedResources() != null && !policy.getAssignedResources().isEmpty()) {
NamedRelatedResourceRep vpoolNameRes = null;
// get the first vpool and return it.
if (policy.getAppliedAt().equalsIgnoreCase(FilePolicyApplyLevel.vpool.name())) {
vpoolNameRes = policy.getAssignedResources().get(0);
} else if (policy.getAppliedAt().equalsIgnoreCase(FilePolicyApplyLevel.project.name())) {
vpoolNameRes = policy.getVpool();
}
if (vpoolNameRes != null) {
FileVirtualPoolRestRep vpolRestep = getViprClient().fileVpools().get(vpoolNameRes.getId());
vPools.add(vpolRestep);
renderJSON(vPools);
return;
}
}
List<FileVirtualPoolRestRep> virtualPools = getViprClient().fileVpools().getAll();
for (FileVirtualPoolRestRep vpool : virtualPools) {
// first level filter based on the protection is enabled or not
FileVirtualPoolProtectionParam protectParam = vpool.getProtection();
if (protectParam == null) {
continue;
}
// 2nde level filter based on the applied level of policy and the pool
if (FilePolicyApplyLevel.project.name().equalsIgnoreCase(policy.getAppliedAt()) && !protectParam.getAllowFilePolicyAtProjectLevel()) {
continue;
}
if (FilePolicyApplyLevel.file_system.name().equalsIgnoreCase(policy.getAppliedAt()) && !protectParam.getAllowFilePolicyAtFSLevel()) {
continue;
}
// now add pool into list if matches protection type with policy
if (FilePolicyType.file_snapshot.name().equalsIgnoreCase(policy.getType()) && protectParam.getScheduleSnapshots()) {
vPools.add(vpool);
} else if (FilePolicyType.file_replication.name().equalsIgnoreCase(policy.getType()) && protectParam.getReplicationSupported()) {
vPools.add(vpool);
}
}
renderJSON(vPools);
}
use of com.emc.storageos.model.file.policy.FilePolicyRestRep in project coprhd-controller by CoprHD.
the class FileProtectionPolicies method save.
@FlashException(keep = true, referrer = { "create", "edit" })
public static void save(SchedulePolicyForm schedulePolicy) {
if (schedulePolicy == null) {
Logger.error("No policy parameters passed");
badRequest("No policy parameters passed");
return;
}
schedulePolicy.validate("schedulePolicy");
if (Validation.hasErrors()) {
Common.handleError();
}
schedulePolicy.id = params.get("id");
URI policyId = null;
if (schedulePolicy.isNew()) {
schedulePolicy.tenantId = Models.currentAdminTenant();
FilePolicyCreateParam policyParam = new FilePolicyCreateParam();
updatePolicyParam(schedulePolicy, policyParam, null);
policyParam.setPolicyType(schedulePolicy.policyType);
if (schedulePolicy.description != null && !schedulePolicy.description.isEmpty()) {
policyParam.setPolicyDescription(schedulePolicy.description);
}
FilePolicyCreateResp createdPolicy = getViprClient().fileProtectionPolicies().create(policyParam);
policyId = createdPolicy.getId();
} else {
FilePolicyRestRep schedulePolicyRestRep = getViprClient().fileProtectionPolicies().get(uri(schedulePolicy.id));
FilePolicyUpdateParam input = new FilePolicyUpdateParam();
updatePolicyParam(schedulePolicy, input, schedulePolicyRestRep.getType());
getViprClient().fileProtectionPolicies().update(schedulePolicyRestRep.getId(), input);
policyId = schedulePolicyRestRep.getId();
}
// Update the ACLs
com.emc.vipr.client.core.FileProtectionPolicies filePolicies = getViprClient().fileProtectionPolicies();
schedulePolicy.saveTenantACLs(filePolicies, policyId);
flash.success(MessagesUtils.get("schedulepolicies.saved", schedulePolicy.policyName));
if (StringUtils.isNotBlank(schedulePolicy.referrerUrl)) {
redirect(schedulePolicy.referrerUrl);
} else {
list();
}
}
use of com.emc.storageos.model.file.policy.FilePolicyRestRep in project coprhd-controller by CoprHD.
the class FileProtectionPolicies method edit.
@FlashException(value = "list", keep = true)
public static void edit(String id) {
FilePolicyRestRep filePolicyRestRep = getViprClient().fileProtectionPolicies().get(uri(id));
if (filePolicyRestRep != null) {
SchedulePolicyForm schedulePolicy = new SchedulePolicyForm().form(filePolicyRestRep);
addRenderArgs();
addDateTimeRenderArgs();
addTenantOptionsArgs();
addRenderApplyPolicysAt();
addNumWorkerThreadsArgs();
render(schedulePolicy);
} else {
flash.error(MessagesUtils.get(UNKNOWN, id));
list();
}
}
Aggregations