Search in sources :

Example 66 with Pair

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;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 67 with Pair

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;
}
Also used : AuditLogableBase(org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogableBase) AuditLogType(org.ovirt.engine.core.common.AuditLogType) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 68 with Pair

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;
}
Also used : HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 69 with Pair

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;
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) ArrayList(java.util.ArrayList) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 70 with Pair

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"));
}
Also used : DateFormat(java.text.DateFormat) Calendar(java.util.Calendar) Date(java.util.Date) DateTime(org.ovirt.engine.core.compat.DateTime) Pair(org.ovirt.engine.core.common.utils.Pair) Test(org.junit.Test)

Aggregations

Pair (org.ovirt.engine.core.common.utils.Pair)147 ArrayList (java.util.ArrayList)61 Guid (org.ovirt.engine.core.compat.Guid)61 HashMap (java.util.HashMap)30 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 Test (org.junit.Test)24 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Map (java.util.Map)13 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 VM (org.ovirt.engine.core.common.businessentities.VM)12 HashSet (java.util.HashSet)10 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)10 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)10 EngineException (org.ovirt.engine.core.common.errors.EngineException)9 Callable (java.util.concurrent.Callable)8 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8