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