Search in sources :

Example 1 with VnicProfileMappingEntity

use of org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity in project ovirt-engine by oVirt.

the class RegisterEntityModel method updateExternalVnicProfilesPerTargetCluster.

/**
 * on first call: create new mappings with no target profile for each interface of the entities being registered.
 * on subsequent calls: repopulate with existing mappings and user selections
 */
private Map<Cluster, Set<VnicProfileMappingEntity>> updateExternalVnicProfilesPerTargetCluster() {
    Map<Cluster, Set<VnicProfileMappingEntity>> updated = new HashMap<>();
    // the update may be for several VMs or VmTemplates over various clusters
    for (E importEntityData : getEntities().getItems()) {
        Cluster cluster = importEntityData.getCluster().getSelectedItem();
        // get the set of profiles being updated for the cluster or create new
        Set<VnicProfileMappingEntity> clusterVnicProfileMappings;
        if (updated.containsKey(cluster)) {
            clusterVnicProfileMappings = updated.get(cluster);
        } else {
            clusterVnicProfileMappings = new HashSet<>();
            updated.put(cluster, clusterVnicProfileMappings);
        }
        // get the previous set of profiles for the cluster or create new
        Set<VnicProfileMappingEntity> previousClusterVnicProfileMappings;
        if (externalVnicProfilesPerTargetCluster.containsKey(cluster)) {
            previousClusterVnicProfileMappings = externalVnicProfilesPerTargetCluster.get(cluster);
        } else {
            previousClusterVnicProfileMappings = new HashSet<>();
        }
        // create or set mappings according to currently existing interfaces and previous user selections
        Set<VnicProfileMappingEntity> vmVnicProfiles = getNewVnicProfileMappings(getInterfaces(importEntityData), previousClusterVnicProfileMappings);
        clusterVnicProfileMappings.addAll(vmVnicProfiles);
    }
    return updated;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) VnicProfileMappingEntity(org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity) Cluster(org.ovirt.engine.core.common.businessentities.Cluster)

Example 2 with VnicProfileMappingEntity

use of org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity in project ovirt-engine by oVirt.

the class RegisterEntityModel method getNewVnicProfileMappings.

/**
 * create a {@link VnicProfileMappingEntity} with no target profile for each pre-loaded interface of the registered entity
 * if a previous mapping for the same source profile is not found.
 *
 * @param interfaces the interfaces of the registered entity initially loaded by the frontend when the register action started
 * @param previousClusterVnicProfileMappings the mappings passed to {@link VnicProfileMappingModel}, with user selections of target profiles
 * @return a set of mappings for all interfaces of registered entity
 */
private Set<VnicProfileMappingEntity> getNewVnicProfileMappings(List<VmNetworkInterface> interfaces, Set<VnicProfileMappingEntity> previousClusterVnicProfileMappings) {
    Set<VnicProfileMappingEntity> result = new HashSet<>();
    for (VmNetworkInterface vnic : interfaces) {
        VnicProfileMappingEntity newMapping = new VnicProfileMappingEntity(vnic.getNetworkName(), vnic.getVnicProfileName(), null);
        VnicProfileMappingEntity mapping = previousClusterVnicProfileMappings.stream().filter(x -> x.isSameSourceProfile(newMapping)).findFirst().orElse(newMapping);
        // warning: the Set.add() uses the equals of {@link VnicProfileMappingEntity} which only compares the source profile
        result.add(mapping);
    }
    return result;
}
Also used : VmNetworkInterface(org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface) VnicProfileMappingEntity(org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)2 VnicProfileMappingEntity (org.ovirt.engine.ui.uicommonweb.models.vms.register.VnicProfileMappingEntity)2 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)1 VmNetworkInterface (org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface)1