use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class EvenDistributionWeightPolicyUnit method reverseEvenDistributionScore.
public List<Pair<Guid, Integer>> reverseEvenDistributionScore(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters) {
float maxMemoryOfVdsInCluster = getMaxMemoryOfVdsInCluster(hosts);
List<Pair<Guid, Integer>> scores = new ArrayList<>();
for (VDS vds : hosts) {
int score = MaxSchedulerWeight - 1;
if (vds.getVmCount() > 0) {
score -= calcEvenDistributionScore(maxMemoryOfVdsInCluster, vds, vm, cluster.getCountThreadsAsCores());
}
scores.add(new Pair<>(vds.getId(), score));
}
return scores;
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class QuotaManager method consume.
/**
* Consume from quota according to the parameters.
*
* @param parameters
* - Quota consumption parameters
* @return - true if the request was validated and set
*/
public boolean consume(QuotaConsumptionParametersWrapper parameters) throws InvalidQuotaParametersException {
Pair<AuditLogType, AuditLogableBase> auditLogPair = new Pair<>();
auditLogPair.setSecond(parameters.getAuditLogable());
StoragePool storagePool = parameters.getAuditLogable().getStoragePool();
if (storagePool == null) {
throw new InvalidQuotaParametersException("Null storage pool passed to QuotaManager");
}
addStoragePoolToCacheWithLock(storagePool.getId());
lock.readLock().lock();
try {
if (parameters.getStoragePool().getQuotaEnforcementType() != QuotaEnforcementTypeEnum.DISABLED) {
synchronized (storagePoolQuotaMap.get(storagePool.getId())) {
return validateAndCompleteParameters(parameters, auditLogPair) && internalConsumeAndReleaseHandler(parameters, auditLogPair);
}
}
} finally {
lock.readLock().unlock();
getQuotaManagerAuditLogger().auditLog(auditLogPair.getFirst(), auditLogPair.getSecond());
}
return true;
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class HaReservationHandling method findReplacementForHost.
private boolean findReplacementForHost(Cluster cluster, VDS host, List<VM> vmList, List<Pair<Guid, Pair<Integer, Integer>>> hostsUnutilizedResources) {
Map<Guid, Pair<Integer, Integer>> additionalHostsUtilizedResources = new HashMap<>();
for (VM vm : vmList) {
int curVmMemSize = 0;
if (vm.getUsageMemPercent() != null) {
curVmMemSize = (int) Math.round(vm.getMemSizeMb() * (vm.getUsageMemPercent() / 100.0));
}
// Make sure we reserve at least the guaranteed amount of memory or more
// if the VM is using more than that.
curVmMemSize = Math.max(curVmMemSize, vm.getMinAllocatedMem());
int curVmCpuPercent = 0;
if (vm.getUsageCpuPercent() != null) {
curVmCpuPercent = vm.getUsageCpuPercent() * vm.getNumOfCpus() / slaValidator.getEffectiveCpuCores(host, cluster.getCountThreadsAsCores());
}
log.debug("VM '{}'. CPU usage: {}%, RAM required: {}MB", vm.getName(), curVmCpuPercent, curVmMemSize);
boolean foundForCurVm = false;
for (Pair<Guid, Pair<Integer, Integer>> hostData : hostsUnutilizedResources) {
// Make sure not to run on the same Host as the Host we are testing
if (hostData.getFirst().equals(host.getId())) {
continue;
}
// Check Memory and CPU
if (hostData.getSecond() != null && hostData.getSecond().getSecond() != null && hostData.getSecond().getFirst() != null) {
int memoryFree = hostData.getSecond().getSecond();
int cpuFree = hostData.getSecond().getFirst();
long additionalMemory = 0;
int additionalCpu = 0;
if (additionalHostsUtilizedResources.get(hostData.getFirst()) != null) {
additionalCpu = additionalHostsUtilizedResources.get(hostData.getFirst()).getFirst();
additionalMemory = additionalHostsUtilizedResources.get(hostData.getFirst()).getSecond();
}
if ((memoryFree - additionalMemory) >= curVmMemSize && (cpuFree - additionalCpu) >= curVmCpuPercent) {
// Found a place for current vm, add the RAM and CPU size to additionalHostsUtilizedResources
Pair<Integer, Integer> cpuRamPair = additionalHostsUtilizedResources.get(hostData.getFirst());
if (cpuRamPair != null) {
cpuRamPair.setFirst(cpuRamPair.getFirst() + curVmCpuPercent);
cpuRamPair.setSecond(cpuRamPair.getSecond() + curVmMemSize);
} else {
cpuRamPair = new Pair<>(curVmCpuPercent, curVmMemSize);
additionalHostsUtilizedResources.put(hostData.getFirst(), cpuRamPair);
}
foundForCurVm = true;
break;
}
}
}
if (!foundForCurVm) {
log.info("Did not found a replacement host for VM '{}'", vm.getName());
return false;
}
}
return true;
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class EvenDistributionWeightPolicyUnit method score.
@Override
public List<Pair<Guid, Integer>> score(Cluster cluster, List<VDS> hosts, VM vm, Map<String, String> parameters) {
float maxMemoryOfVdsInCluster = getMaxMemoryOfVdsInCluster(hosts);
boolean countThreadsAsCores = cluster.getCountThreadsAsCores();
List<Pair<Guid, Integer>> scores = new ArrayList<>();
for (VDS vds : hosts) {
scores.add(new Pair<>(vds.getId(), calcEvenDistributionScore(maxMemoryOfVdsInCluster, vds, vm, countThreadsAsCores)));
}
return scores;
}
use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.
the class AuditLogConditionFieldAutoCompleterTest method testformatValueWithTime.
@Test
public void testformatValueWithTime() {
Pair<String, String> pair = new Pair<>();
IConditionFieldAutoCompleter comp = new AuditLogConditionFieldAutoCompleter();
Date date = new Date(72, 0, 12);
String dateString = DateFormat.getDateInstance(DateFormat.SHORT).format(date);
pair.setSecond(dateString);
comp.formatValue("TIME", pair, false);
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT);
assertEquals(quote(fmt.format(date)), pair.getSecond());
pair.setSecond("1");
comp.formatValue("TIME", pair, false);
// Try today
// SimpleDateFormat fmt = new SimpleDateFormat("MM/dd/yyyy" +
// " 23:59:59 ");
// Today begins at 00:00 - this is why we reset the DateTime object to midnight.
DateTime dt = new DateTime(new Date());
dt = dt.resetToMidnight();
assertEquals(quote(fmt.format(dt)), pair.getSecond());
// Try Yesterday
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
pair.setSecond("2");
comp.formatValue("TIME", pair, false);
// Yesterday (as any other day) begins at 00:00 - this is why we reset the DateTime object to midnight.
dt = new DateTime(cal.getTime());
dt = dt.resetToMidnight();
assertEquals(quote(fmt.format(dt)), pair.getSecond());
// Just going to test that this works
pair.setSecond("Wednesday");
comp.formatValue("TIME", pair, false);
assertFalse("Day should be transformed to a date", pair.getSecond().equals("Wednesday"));
}
Aggregations