Search in sources :

Example 36 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class BackendAffinityGroupVmsResource method list.

@Override
public Vms list() {
    Vms vms = new Vms();
    AffinityGroup affinityGroup = getEntity();
    if (affinityGroup.getVmIds() != null) {
        for (int i = 0; i < affinityGroup.getVmIds().size(); i++) {
            Vm vm = new Vm();
            vm.setId(affinityGroup.getVmIds().get(i).toString());
            vm.setName(affinityGroup.getVmEntityNames().get(i));
            vm = addLinks(populate(vm, null));
            // remove vm actions, not relevant to this context
            vm.setActions(null);
            vms.getVms().add(vm);
        }
    }
    return vms;
}
Also used : Vm(org.ovirt.engine.api.model.Vm) Vms(org.ovirt.engine.api.model.Vms) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup)

Example 37 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class DrMappingHelper method mapAffinityGroups.

public List<AffinityGroup> mapAffinityGroups(Map<String, String> affinityGroupMap, List<AffinityGroup> affinityGroupsFromParam, String vmName) {
    if (affinityGroupsFromParam == null) {
        return Collections.emptyList();
    }
    List<AffinityGroup> affinityGroupsToAdd = new ArrayList<>();
    affinityGroupsFromParam.forEach(affinityGroup -> {
        log.info("Mapping affinity group '{}' for vm '{}'.", affinityGroup.getName(), vmName);
        String mappedAffinityGroupName = affinityGroupMap.get(affinityGroup.getName());
        if (mappedAffinityGroupName == null) {
            log.warn("Mapping for affinity group '{}' not found, will use the affinity group name from OVF", affinityGroup.getName());
            affinityGroupsToAdd.add(affinityGroup);
        } else {
            log.info("Mapping for affinity group '{}' found, attempting to map to '{}'", affinityGroup.getName(), mappedAffinityGroupName);
            AffinityGroup mappedAffinityGroup = affinityGroupDao.getByName(mappedAffinityGroupName);
            AffinityGroup affinityGroupToAdd = Optional.ofNullable(mappedAffinityGroup).orElse(affinityGroup);
            log.info("Will try to add affinity group: {}", affinityGroupToAdd.getName());
            affinityGroupsToAdd.add(affinityGroupToAdd);
        }
    });
    return affinityGroupsToAdd;
}
Also used : ArrayList(java.util.ArrayList) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup)

Example 38 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class OvfHelper method buildMetadataDictionaryForVm.

/**
 * Adds the given vm metadata to the given map
 */
private String buildMetadataDictionaryForVm(VM vm) {
    List<DiskImage> allVmImages = new ArrayList<>();
    List<DiskImage> filteredDisks = DisksFilter.filterImageDisks(vm.getDiskList(), ONLY_SNAPABLE, ONLY_ACTIVE);
    List<LunDisk> lunDisks = DisksFilter.filterLunDisks(vm.getDiskMap().values());
    List<AffinityGroup> affinityGroups = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
    Set<DbUser> dbUsers = new HashSet<>(dbUserDao.getAllForVm(vm.getId()));
    List<Label> affinityLabels = labelDao.getAllByEntityIds(Collections.singletonList(vm.getId()));
    for (DiskImage diskImage : filteredDisks) {
        List<DiskImage> images = diskImageDao.getAllSnapshotsForLeaf(diskImage.getImageId());
        images.forEach(d -> d.setDiskVmElements(Collections.singletonList(diskImage.getDiskVmElementForVm(vm.getId()))));
        allVmImages.addAll(images);
    }
    FullEntityOvfData fullEntityOvfData = new FullEntityOvfData(vm);
    fullEntityOvfData.setDiskImages(allVmImages);
    fullEntityOvfData.setLunDisks(lunDisks);
    fullEntityOvfData.setAffinityGroups(affinityGroups);
    fullEntityOvfData.setAffinityLabels(affinityLabels);
    fullEntityOvfData.setDbUsers(dbUsers);
    populateUserToRoles(fullEntityOvfData, vm.getId());
    return ovfManager.exportVm(vm, fullEntityOvfData, clusterUtils.getCompatibilityVersion(vm));
}
Also used : ArrayList(java.util.ArrayList) Label(org.ovirt.engine.core.common.businessentities.Label) FullEntityOvfData(org.ovirt.engine.core.common.businessentities.storage.FullEntityOvfData) LunDisk(org.ovirt.engine.core.common.businessentities.storage.LunDisk) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) DiskImage(org.ovirt.engine.core.common.businessentities.storage.DiskImage) DbUser(org.ovirt.engine.core.common.businessentities.aaa.DbUser) HashSet(java.util.HashSet)

Example 39 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class ChangeVMClusterCommand method executeCommand.

@Override
protected void executeCommand() {
    VM vm = getVm();
    boolean clusterRemainedTheSame = originalClusterId.equals(newClusterId);
    if (clusterRemainedTheSame) {
        setSucceeded(true);
        return;
    }
    // update vm interfaces
    List<Network> networks = networkDao.getAllForCluster(newClusterId);
    List<VmNic> interfaces = vmNicDao.getAllForVm(getParameters().getVmId());
    for (final VmNic iface : interfaces) {
        if (iface.getVnicProfileId() != null) {
            final Network network = networkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
            boolean networkFoundInCluster = networks.stream().anyMatch(n -> Objects.equals(n.getId(), network.getId()));
            // interface connection
            if (!networkFoundInCluster) {
                iface.setVnicProfileId(null);
                vmNicDao.update(iface);
            }
        }
    }
    if (vm.getDedicatedVmForVdsList().size() > 0) {
        vm.setDedicatedVmForVdsList(Collections.emptyList());
        dedicatedHostWasCleared = true;
    }
    vm.setClusterId(newClusterId);
    // Set cpu profile from the new cluster
    cpuProfileHelper.assignFirstCpuProfile(vm.getStaticData(), getUserIdIfExternal().orElse(null));
    vmStaticDao.update(vm.getStaticData());
    moveMacsToAnotherMacPoolIfNeeded();
    // change vm cluster should remove the vm from all associated affinity groups
    List<AffinityGroup> allAffinityGroupsByVmId = affinityGroupDao.getAllAffinityGroupsByVmId(vm.getId());
    if (!allAffinityGroupsByVmId.isEmpty()) {
        String groups = allAffinityGroupsByVmId.stream().map(AffinityGroup::getName).collect(Collectors.joining(" "));
        log.info("Due to cluster change, removing VM from associated affinity group(s): {}", groups);
        affinityGroupDao.removeVmFromAffinityGroups(vm.getId());
    }
    setSucceeded(true);
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) Network(org.ovirt.engine.core.common.businessentities.network.Network) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup) VmNic(org.ovirt.engine.core.common.businessentities.network.VmNic)

Example 40 with AffinityGroup

use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.

the class AffinityRulesEnforcerTest method createAffinityGroup.

private AffinityGroup createAffinityGroup(Cluster cluster, EntityAffinityRule vmAffinityRule, final VM... vmList) {
    AffinityGroup ag = new AffinityGroup();
    ag.setId(Guid.newGuid());
    ag.setVmAffinityRule(vmAffinityRule);
    ag.setClusterId(cluster.getId());
    ag.setVmEnforcing(true);
    ag.setVmIds(Arrays.stream(vmList).map(VM::getId).collect(Collectors.toList()));
    return ag;
}
Also used : VM(org.ovirt.engine.core.common.businessentities.VM) AffinityGroup(org.ovirt.engine.core.common.scheduling.AffinityGroup)

Aggregations

AffinityGroup (org.ovirt.engine.core.common.scheduling.AffinityGroup)49 Test (org.junit.Test)20 Guid (org.ovirt.engine.core.compat.Guid)12 ArrayList (java.util.ArrayList)11 VM (org.ovirt.engine.core.common.businessentities.VM)11 HashSet (java.util.HashSet)9 HashMap (java.util.HashMap)7 List (java.util.List)5 Map (java.util.Map)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 PerHostMessages (org.ovirt.engine.core.common.scheduling.PerHostMessages)5 AffinityGroupDao (org.ovirt.engine.core.dao.scheduling.AffinityGroupDao)5 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)4 AffinityGroupCRUDParameters (org.ovirt.engine.core.common.scheduling.parameters.AffinityGroupCRUDParameters)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Collections (java.util.Collections)3