Search in sources :

Example 16 with FilePolicyRestRep

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;
}
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)

Example 17 with FilePolicyRestRep

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();
    }
}
Also used : FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) FlashException(controllers.util.FlashException)

Example 18 with FilePolicyRestRep

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);
}
Also used : FileVirtualPoolRestRep(com.emc.storageos.model.vpool.FileVirtualPoolRestRep) FileVirtualPoolProtectionParam(com.emc.storageos.model.vpool.FileVirtualPoolProtectionParam) FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep)

Example 19 with FilePolicyRestRep

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();
    }
}
Also used : FilePolicyUpdateParam(com.emc.storageos.model.file.policy.FilePolicyUpdateParam) FilePolicyCreateParam(com.emc.storageos.model.file.policy.FilePolicyCreateParam) FilePolicyCreateResp(com.emc.storageos.model.file.policy.FilePolicyCreateResp) FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) URI(java.net.URI) FlashException(controllers.util.FlashException)

Example 20 with FilePolicyRestRep

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();
    }
}
Also used : FilePolicyRestRep(com.emc.storageos.model.file.policy.FilePolicyRestRep) FlashException(controllers.util.FlashException)

Aggregations

FilePolicyRestRep (com.emc.storageos.model.file.policy.FilePolicyRestRep)21 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)8 Asset (com.emc.sa.asset.annotation.Asset)6 AssetDependencies (com.emc.sa.asset.annotation.AssetDependencies)6 AssetOption (com.emc.vipr.model.catalog.AssetOption)6 FlashException (controllers.util.FlashException)6 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)5 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)5 URI (java.net.URI)5 ArrayList (java.util.ArrayList)5 FileVirtualPoolRestRep (com.emc.storageos.model.vpool.FileVirtualPoolRestRep)3 VirtualArrayRestRep (com.emc.storageos.model.varray.VirtualArrayRestRep)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 DataObject (com.emc.storageos.db.client.model.DataObject)1 FilePolicyApplyLevel (com.emc.storageos.db.client.model.FilePolicy.FilePolicyApplyLevel)1 FileReplicationTopology (com.emc.storageos.db.client.model.FileReplicationTopology)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)1