use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.
the class AffinityGroupListModel method remove.
private void remove() {
if (getWindow() != null) {
return;
}
ConfirmationModel model = new ConfirmationModel();
setConfirmWindow(model);
model.setTitle(ConstantsManager.getInstance().getConstants().removeAffinityGroupsTitle());
model.setHelpTag(HelpTag.remove_affinity_groups);
// $NON-NLS-1$
model.setHashName("remove_affinity_groups");
ArrayList<String> list = new ArrayList<>();
for (AffinityGroup affinityGroup : getSelectedItems()) {
list.add(affinityGroup.getName());
}
model.setItems(list);
// $NON-NLS-1$
UICommand command = UICommand.createDefaultOkUiCommand("OnRemove", this);
model.getCommands().add(command);
// $NON-NLS-1$
model.getCommands().add(UICommand.createCancelUiCommand("Cancel", this));
}
use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.
the class AffinityRulesEnforcer method chooseNextVmToMigrateFromVMsAffinity.
private VM chooseNextVmToMigrateFromVMsAffinity(Cluster cluster, List<AffinityGroup> allAffinityGroups) {
List<AffinityGroup> allHardAffinityGroups = getAllHardAffinityGroupsForVMsAffinity(allAffinityGroups);
Set<Set<Guid>> unifiedPositiveAffinityGroups = AffinityRulesUtils.getUnifiedPositiveAffinityGroups(allHardAffinityGroups);
List<AffinityGroup> unifiedAffinityGroups = AffinityRulesUtils.setsToAffinityGroups(unifiedPositiveAffinityGroups);
// Add negative affinity groups
for (AffinityGroup ag : allHardAffinityGroups) {
if (ag.isVmNegative()) {
unifiedAffinityGroups.add(ag);
}
}
// Create a set of all VMs in affinity groups
Set<Guid> allVms = new HashSet<>();
for (AffinityGroup group : unifiedAffinityGroups) {
allVms.addAll(group.getVmIds());
}
Map<Guid, VM> vmsMap = vmDao.getVmsByIds(new ArrayList<>(allVms)).stream().collect(Collectors.toMap(VM::getId, vm -> vm));
Map<Guid, Guid> vmToHost = vmsMap.values().stream().filter(vm -> vm.getRunOnVds() != null).collect(Collectors.toMap(VM::getId, VM::getRunOnVds));
// There is no need to migrate when no collision was detected
Set<AffinityGroup> violatedAffinityGroups = checkForVMAffinityGroupViolations(unifiedAffinityGroups, vmToHost, FailMode.GET_ALL);
if (violatedAffinityGroups.isEmpty()) {
log.debug("No affinity group collision detected for cluster {}. Standing by.", cluster.getId());
return null;
}
// Find a VM that is breaking the affinityGroup and can be theoretically migrated
// - start with bigger Affinity Groups
List<AffinityGroup> affGroupsBySize = new ArrayList<>(violatedAffinityGroups);
Collections.sort(affGroupsBySize, Collections.reverseOrder(new AffinityGroupComparator()));
for (AffinityGroup affinityGroup : affGroupsBySize) {
final List<List<Guid>> candidateVmGroups;
if (affinityGroup.isVmPositive()) {
candidateVmGroups = groupVmsViolatingPositiveAg(affinityGroup, vmsMap);
log.info("Positive affinity group violation detected");
} else if (affinityGroup.isVmNegative()) {
candidateVmGroups = groupVmsViolatingNegativeAg(affinityGroup, vmsMap);
log.info("Negative affinity group violation detected");
} else {
continue;
}
// Look for a valid VM to migrate on all hosts
for (List<Guid> group : candidateVmGroups) {
Collections.shuffle(group);
for (Guid vmId : group) {
VM vm = vmsMap.get(vmId);
if (isVmMigrationValid(cluster, vm)) {
return vm;
}
}
}
}
// No possible migration..
return null;
}
use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.
the class AffinityRulesEnforcer method getVmToHostsAffinityGroupCandidates.
/**
* Get a list of candidate VMs (by VM ids) from the VM to host affinity groups.
* This list will contain all VMs that violate the host affinity policies
* sorted according to the number of violations (descending).
*
* @param allVMtoHostsAffinityGroups VM to Host affinity groups.
* @param vmsMap VMs map with key: vm id , value: associated vm object.
* @param isVdsAffinityEnforcing true - Hard affinity constraint, false - Soft affinity constraint.
* @return list of candidate VMs for migration by VM to Host affinities.
*/
private List<Guid> getVmToHostsAffinityGroupCandidates(List<AffinityGroup> allVMtoHostsAffinityGroups, Map<Guid, VM> vmsMap, boolean isVdsAffinityEnforcing) {
Map<Guid, Integer> vmToHostsAffinityMap = new HashMap<>();
// Iterate over all affinity groups and check the currently running
// VMs for compliance, record violations per VM
allVMtoHostsAffinityGroups.stream().filter(AffinityGroup::isVdsAffinityEnabled).filter(ag -> ag.isVdsEnforcing() == isVdsAffinityEnforcing).forEach(g -> {
Set<Guid> affHosts = new HashSet<>(g.getVdsIds());
g.getVmIds().forEach(vm_id -> {
VM vm = vmsMap.get(vm_id);
if (vm == null) {
return;
}
if (affHosts.contains(vm.getRunOnVds()) && !g.isVdsPositive()) {
// Negative affinity violated
vmToHostsAffinityMap.put(vm_id, 1 + vmToHostsAffinityMap.getOrDefault(vm_id, 0));
} else if (!affHosts.contains(vm.getRunOnVds()) && g.isVdsPositive()) {
// Positive affinity violated
vmToHostsAffinityMap.put(vm_id, 1 + vmToHostsAffinityMap.getOrDefault(vm_id, 0));
}
});
});
// Sort according the to the number of violations
return vmToHostsAffinityMap.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getValue)).map(Map.Entry::getKey).collect(Collectors.toList());
}
use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.
the class AffinityRulesUtils method getUnifiedPositiveAffinityGroups.
/**
* Take all positive affinity groups and merge all groups that reference the same VM
* together.
*
* Ex. groups A+B, B+C, D+E, A+D, F+G are in fact just two bigger groups:
* A+B+C+D+E and F+G
*
* The algorithm starts by creating single element groups from all VMs
* It then goes through all affinity groups and merges all VM groups that contain
* VMs from the currently processed AffinityGroup.
*/
public static Set<Set<Guid>> getUnifiedPositiveAffinityGroups(List<AffinityGroup> affinityGroups) {
Set<Set<Guid>> uag = new HashSet<>();
Map<Guid, Set<Guid>> vmIndex = new HashMap<>();
/**
* Initialize the single element groups by taking all VMs that are referenced
* from any affinity group
*/
for (Iterator<AffinityGroup> it = affinityGroups.iterator(); it.hasNext(); ) {
AffinityGroup ag = it.next();
for (Guid id : ag.getVmIds()) {
Set<Guid> temp = new HashSet<>();
temp.add(id);
uag.add(temp);
vmIndex.put(id, temp);
}
}
// that contain the referenced VMs into one.
for (AffinityGroup ag : affinityGroups) {
if (ag.isVmPositive()) {
Set<Guid> mergedGroup = new HashSet<>();
for (Guid id : ag.getVmIds()) {
// Get the current groups VM(id) belongs to
Set<Guid> existingGroup = vmIndex.get(id);
// Merge it with the currently computed mergeGroup
mergedGroup.addAll(existingGroup);
// And remove it from the valid groups
// (it will be re-added as part of a bigger group)
uag.remove(existingGroup);
// Update the per-VM index
for (Guid vm : existingGroup) {
vmIndex.put(vm, mergedGroup);
}
}
uag.add(mergedGroup);
}
}
return uag;
}
use of org.ovirt.engine.core.common.scheduling.AffinityGroup in project ovirt-engine by oVirt.
the class AffinityRulesUtils method setsToAffinityGroups.
/**
* Convert positive affinity group sets to a proper AffinityGroup objects.
* Use lists so the order is defined as we want an deterministic algorithm further on.
*
* @param uag A set of sets containing the unified POSITIVE affinity groups.
* @return List of AffinityGroup objects representing the provided unified affinity groups
*/
static List<AffinityGroup> setsToAffinityGroups(Set<Set<Guid>> uag) {
List<AffinityGroup> output = new ArrayList<>();
for (Set<Guid> s : uag) {
AffinityGroup temp = new AffinityGroup();
temp.setVmAffinityRule(EntityAffinityRule.POSITIVE);
List<Guid> entities = new ArrayList<>();
entities.addAll(s);
temp.setVmIds(entities);
output.add(temp);
}
return output;
}
Aggregations