Search in sources :

Example 1 with FindVmAndDestinations

use of org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations in project ovirt-engine by oVirt.

the class CpuAndMemoryBalancingPolicyUnit method balance.

@Override
public Optional<BalanceResult> balance(final Cluster cluster, List<VDS> hosts, Map<String, String> parameters, ArrayList<String> messages) {
    Objects.requireNonNull(hosts);
    Objects.requireNonNull(cluster);
    if (hosts.size() < 2) {
        log.debug("No balancing for cluster '{}', contains only {} host(s)", cluster.getName(), hosts.size());
        return Optional.empty();
    }
    final List<VDS> overUtilizedPrimaryHosts = getPrimarySources(cluster, hosts, parameters);
    final List<VDS> overUtilizedSecondaryHosts = getSecondarySources(cluster, hosts, parameters);
    // if there aren't any overutilized hosts, then there is nothing to balance...
    if ((overUtilizedPrimaryHosts == null || overUtilizedPrimaryHosts.size() == 0) && (overUtilizedSecondaryHosts == null || overUtilizedSecondaryHosts.size() == 0)) {
        log.debug("There is no over-utilized host in cluster '{}'", cluster.getName());
        return Optional.empty();
    }
    FindVmAndDestinations findVmAndDestinations = getFindVmAndDestinations(cluster, parameters);
    Optional<BalanceResult> result = Optional.empty();
    // try balancing based on CPU first
    if (overUtilizedPrimaryHosts != null && overUtilizedPrimaryHosts.size() > 0) {
        // returns hosts with utilization lower than the specified threshold
        List<VDS> underUtilizedHosts = getPrimaryDestinations(cluster, hosts, parameters);
        /* if no host has a spare power, then there is nothing we can do to balance it here, try
               the secondary aporoach */
        if (underUtilizedHosts == null || underUtilizedHosts.size() == 0) {
            log.warn("All candidate hosts have been filtered, can't balance the cluster '{}'" + " based on the CPU usage, will try memory based approach", cluster.getName());
        } else {
            result = getBalance(findVmAndDestinations, overUtilizedPrimaryHosts, underUtilizedHosts);
        }
    }
    // if it is not possible (or necessary) to balance based on CPU, try with memory
    if (!result.isPresent() && (overUtilizedSecondaryHosts != null && overUtilizedSecondaryHosts.size() > 0)) {
        // returns hosts with more free memory than the specified threshold
        List<VDS> underUtilizedHosts = getSecondaryDestinations(cluster, hosts, parameters);
        // if no host has memory to spare, then there is nothing we can do to balance it..
        if (underUtilizedHosts == null || underUtilizedHosts.size() == 0) {
            log.warn("All candidate hosts have been filtered, can't balance the cluster '{}'" + " using memory based approach", cluster.getName());
            return Optional.empty();
        }
        result = getBalance(findVmAndDestinations, overUtilizedSecondaryHosts, underUtilizedHosts);
    }
    // add the current host, it is possible it is the best host after all,
    // because the balancer does not know about affinity for example
    Optional<BalanceResult> finalResult = result;
    result.map(BalanceResult::getCurrentHost).filter(Objects::nonNull).ifPresent(h -> finalResult.ifPresent(res -> res.getCandidateHosts().add(h)));
    return result;
}
Also used : VmStatisticsDao(org.ovirt.engine.core.dao.VmStatisticsDao) ClusterDao(org.ovirt.engine.core.dao.ClusterDao) FindVmAndDestinations(org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations) PolicyUnitImpl(org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl) Date(java.util.Date) VdsCpuUsageComparator(org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) VdsDao(org.ovirt.engine.core.dao.VdsDao) Map(java.util.Map) PolicyUnitParameter(org.ovirt.engine.core.bll.scheduling.PolicyUnitParameter) Config(org.ovirt.engine.core.common.config.Config) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) ConfigValues(org.ovirt.engine.core.common.config.ConfigValues) Collectors(java.util.stream.Collectors) VdsSpmStatus(org.ovirt.engine.core.common.businessentities.VdsSpmStatus) VmDao(org.ovirt.engine.core.dao.VmDao) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) PendingResourceManager(org.ovirt.engine.core.bll.scheduling.pending.PendingResourceManager) Optional(java.util.Optional) BalanceResult(org.ovirt.engine.core.bll.scheduling.external.BalanceResult) SlaValidator(org.ovirt.engine.core.bll.scheduling.SlaValidator) Collections(java.util.Collections) VDS(org.ovirt.engine.core.common.businessentities.VDS) BalanceResult(org.ovirt.engine.core.bll.scheduling.external.BalanceResult) VDS(org.ovirt.engine.core.common.businessentities.VDS) FindVmAndDestinations(org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations)

Aggregations

ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 PolicyUnitImpl (org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl)1 PolicyUnitParameter (org.ovirt.engine.core.bll.scheduling.PolicyUnitParameter)1 SlaValidator (org.ovirt.engine.core.bll.scheduling.SlaValidator)1 BalanceResult (org.ovirt.engine.core.bll.scheduling.external.BalanceResult)1 PendingResourceManager (org.ovirt.engine.core.bll.scheduling.pending.PendingResourceManager)1 FindVmAndDestinations (org.ovirt.engine.core.bll.scheduling.utils.FindVmAndDestinations)1 VdsCpuUsageComparator (org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUsageComparator)1