Search in sources :

Example 26 with ClusterPolicy

use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.

the class SchedulingManager method getClusterPoliciesNamesByPolicyUnitId.

/**
 * returns all cluster policies names containing the specific policy unit.
 * @return List of cluster policy names that use the referenced policyUnitId
 *         or null if the policy unit is not available.
 */
public List<String> getClusterPoliciesNamesByPolicyUnitId(Guid policyUnitId) {
    List<String> list = new ArrayList<>();
    final PolicyUnitImpl policyUnitImpl = policyUnits.get(policyUnitId);
    if (policyUnitImpl == null) {
        log.warn("Trying to find usages of non-existing policy unit '{}'", policyUnitId);
        return null;
    }
    PolicyUnit policyUnit = policyUnitImpl.getPolicyUnit();
    if (policyUnit != null) {
        for (ClusterPolicy clusterPolicy : policyMap.values()) {
            switch(policyUnit.getPolicyUnitType()) {
                case FILTER:
                    Collection<Guid> filters = clusterPolicy.getFilters();
                    if (filters != null && filters.contains(policyUnitId)) {
                        list.add(clusterPolicy.getName());
                    }
                    break;
                case WEIGHT:
                    Collection<Pair<Guid, Integer>> functions = clusterPolicy.getFunctions();
                    if (functions == null) {
                        break;
                    }
                    for (Pair<Guid, Integer> pair : functions) {
                        if (pair.getFirst().equals(policyUnitId)) {
                            list.add(clusterPolicy.getName());
                            break;
                        }
                    }
                    break;
                case LOAD_BALANCING:
                    if (policyUnitId.equals(clusterPolicy.getBalance())) {
                        list.add(clusterPolicy.getName());
                    }
                    break;
                default:
                    break;
            }
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) RankSelectorPolicyUnit(org.ovirt.engine.core.bll.scheduling.policyunits.RankSelectorPolicyUnit) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) Guid(org.ovirt.engine.core.compat.Guid) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 27 with ClusterPolicy

use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.

the class SchedulingManager method schedule.

public Optional<Guid> schedule(Cluster cluster, VM vm, List<Guid> hostBlackList, List<Guid> hostWhiteList, List<Guid> destHostIdList, List<String> messages, RunVmDelayer runVmDelayer, String correlationId) {
    prepareClusterLock(cluster.getId());
    try {
        log.debug("Scheduling started, correlation Id: {}", correlationId);
        checkAllowOverbooking(cluster);
        lockCluster(cluster.getId());
        List<VDS> vdsList = vdsDao.getAllForClusterWithStatus(cluster.getId(), VDSStatus.Up);
        vdsList = removeBlacklistedHosts(vdsList, hostBlackList);
        vdsList = keepOnlyWhitelistedHosts(vdsList, hostWhiteList);
        refreshCachedPendingValues(vdsList);
        ClusterPolicy policy = policyMap.get(cluster.getClusterPolicyId());
        Map<String, String> parameters = createClusterPolicyParameters(cluster);
        vdsList = runFilters(policy.getFilters(), cluster, vdsList, vm, parameters, policy.getFilterPositionMap(), messages, runVmDelayer, true, correlationId);
        if (vdsList.isEmpty()) {
            return Optional.empty();
        }
        Optional<Guid> bestHost = selectBestHost(cluster, vm, destHostIdList, vdsList, policy, parameters);
        if (bestHost.isPresent() && !bestHost.get().equals(vm.getRunOnVds())) {
            Guid bestHostId = bestHost.get();
            getPendingResourceManager().addPending(new PendingCpuCores(bestHostId, vm, vm.getNumOfCpus()));
            getPendingResourceManager().addPending(new PendingMemory(bestHostId, vm, vmOverheadCalculator.getStaticOverheadInMb(vm)));
            getPendingResourceManager().addPending(new PendingOvercommitMemory(bestHostId, vm, vmOverheadCalculator.getTotalRequiredMemoryInMb(vm)));
            getPendingResourceManager().addPending(new PendingVM(bestHostId, vm));
            // Add pending records for all specified hugepage sizes
            for (Map.Entry<Integer, Integer> hugepage : HugePageUtils.getHugePages(vm.getStaticData()).entrySet()) {
                getPendingResourceManager().addPending(new PendingHugePages(bestHostId, vm, hugepage.getKey(), hugepage.getValue()));
            }
            getPendingResourceManager().notifyHostManagers(bestHostId);
            markVfsAsUsedByVm(vm, bestHostId);
        }
        return bestHost;
    } catch (InterruptedException e) {
        log.error("scheduling interrupted, correlation Id: {}: {}", correlationId, e.getMessage());
        log.debug("Exception: ", e);
        return Optional.empty();
    } finally {
        releaseCluster(cluster.getId());
        log.debug("Scheduling ended, correlation Id: {}", correlationId);
    }
}
Also used : PendingMemory(org.ovirt.engine.core.bll.scheduling.pending.PendingMemory) VDS(org.ovirt.engine.core.common.businessentities.VDS) PendingVM(org.ovirt.engine.core.bll.scheduling.pending.PendingVM) PendingHugePages(org.ovirt.engine.core.bll.scheduling.pending.PendingHugePages) Guid(org.ovirt.engine.core.compat.Guid) PendingCpuCores(org.ovirt.engine.core.bll.scheduling.pending.PendingCpuCores) PendingOvercommitMemory(org.ovirt.engine.core.bll.scheduling.pending.PendingOvercommitMemory) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 28 with ClusterPolicy

use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.

the class ClusterPolicyCRUDCommand method checkRemoveEditValidations.

protected boolean checkRemoveEditValidations() {
    Guid clusterPolicyId = getParameters().getClusterPolicyId();
    if (clusterPolicyId == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    ClusterPolicy clusterPolicy = schedulingManager.getClusterPolicy(clusterPolicyId);
    if (clusterPolicy == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    if (clusterPolicy.isLocked()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    return true;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy)

Example 29 with ClusterPolicy

use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.

the class ClusterPolicyCRUDCommand method checkAddEditValidations.

protected boolean checkAddEditValidations() {
    List<ClusterPolicy> clusterPolicies = schedulingManager.getClusterPolicies();
    if (getClusterPolicy() == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_PARAMETERS_INVALID);
    }
    for (ClusterPolicy clusterPolicy : clusterPolicies) {
        if (!clusterPolicy.getId().equals(getClusterPolicy().getId()) && clusterPolicy.getName().equals(getClusterPolicy().getName())) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_NAME_INUSE);
        }
    }
    Map<Guid, PolicyUnitImpl> map = schedulingManager.getPolicyUnitsMap();
    Set<Guid> existingPolicyUnits = new HashSet<>();
    // check filter policy units
    if (getClusterPolicy().getFilters() != null) {
        for (Guid filterId : getClusterPolicy().getFilters()) {
            if (isPolicyUnitExists(filterId, existingPolicyUnits)) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT);
            }
            PolicyUnitImpl policyUnitImpl = map.get(filterId);
            if (policyUnitImpl == null) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
            }
            if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.FILTER) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FILTER_NOT_IMPLEMENTED);
            }
        }
    }
    // check filters positions (there could be only one filter attached to first (-1) and last (-1)
    if (getClusterPolicy().getFilterPositionMap() != null) {
        boolean hasFirst = false;
        boolean hasLast = false;
        for (Integer position : getClusterPolicy().getFilterPositionMap().values()) {
            if (position == -1) {
                if (!hasFirst) {
                    hasFirst = true;
                } else {
                    return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_ONLY_ONE_FILTER_CAN_BE_FIRST);
                }
            } else if (position == 1) {
                if (!hasLast) {
                    hasLast = true;
                } else {
                    return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_ONLY_ONE_FILTER_CAN_BE_LAST);
                }
            }
        }
    }
    // check function policy units
    if (getClusterPolicy().getFunctions() != null) {
        for (Pair<Guid, Integer> functionPair : getClusterPolicy().getFunctions()) {
            if (isPolicyUnitExists(functionPair.getFirst(), existingPolicyUnits)) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_DUPLICATE_POLICY_UNIT);
            }
            PolicyUnitImpl policyUnitImpl = map.get(functionPair.getFirst());
            if (policyUnitImpl == null) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
            }
            if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.WEIGHT) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_NOT_IMPLEMENTED);
            }
            if (functionPair.getSecond() < 0) {
                return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_FUNCTION_FACTOR_NEGATIVE);
            }
        }
    }
    // check balance policy unit
    if (getClusterPolicy().getBalance() != null) {
        PolicyUnitImpl policyUnitImpl = map.get(getClusterPolicy().getBalance());
        if (policyUnitImpl == null) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
        }
        if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.LOAD_BALANCING) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_BALANCE_NOT_IMPLEMENTED);
        }
    }
    // check selector policy unit
    if (getClusterPolicy().getSelector() != null) {
        PolicyUnitImpl policyUnitImpl = map.get(getClusterPolicy().getSelector());
        if (policyUnitImpl == null) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_UNKNOWN_POLICY_UNIT);
        }
        if (policyUnitImpl.getPolicyUnit().getPolicyUnitType() != PolicyUnitType.SELECTOR) {
            return failValidation(EngineMessage.ACTION_TYPE_FAILED_CLUSTER_POLICY_SELECTOR_NOT_IMPLEMENTED);
        }
    }
    List<ValidationError> validationErrors = SimpleCustomPropertiesUtil.getInstance().validateProperties(schedulingManager.getCustomPropertiesRegexMap(getClusterPolicy()), getClusterPolicy().getParameterMap());
    if (!validationErrors.isEmpty()) {
        SimpleCustomPropertiesUtil.getInstance().handleCustomPropertiesError(validationErrors, getReturnValue().getValidationMessages());
        return false;
    }
    return true;
}
Also used : PolicyUnitImpl(org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl) Guid(org.ovirt.engine.core.compat.Guid) ValidationError(org.ovirt.engine.core.common.utils.customprop.ValidationError) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) HashSet(java.util.HashSet)

Example 30 with ClusterPolicy

use of org.ovirt.engine.core.common.scheduling.ClusterPolicy in project ovirt-engine by oVirt.

the class SchedulingPolicyMapper method map.

@Mapping(from = Weight.class, to = ClusterPolicy.class)
public static ClusterPolicy map(Weight model, ClusterPolicy template) {
    ClusterPolicy entity = template != null ? template : new ClusterPolicy();
    if (model.isSetSchedulingPolicyUnit() && model.getSchedulingPolicyUnit().isSetId()) {
        Guid guid = GuidUtils.asGuid(model.getSchedulingPolicyUnit().getId());
        if (entity.getFunctions() == null) {
            entity.setFunctions(new ArrayList<>());
        }
        entity.getFunctions().add(new Pair<>(guid, model.isSetFactor() ? model.getFactor() : 1));
    }
    return entity;
}
Also used : Guid(org.ovirt.engine.core.compat.Guid) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy)

Aggregations

ClusterPolicy (org.ovirt.engine.core.common.scheduling.ClusterPolicy)37 Guid (org.ovirt.engine.core.compat.Guid)20 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 ClusterPolicyCRUDParameters (org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters)7 Cluster (org.ovirt.engine.core.common.businessentities.Cluster)4 PolicyUnit (org.ovirt.engine.core.common.scheduling.PolicyUnit)4 VDS (org.ovirt.engine.core.common.businessentities.VDS)3 Pair (org.ovirt.engine.core.common.utils.Pair)3 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BaseCommandTest (org.ovirt.engine.core.bll.BaseCommandTest)2 QueryParametersBase (org.ovirt.engine.core.common.queries.QueryParametersBase)2 QueryReturnValue (org.ovirt.engine.core.common.queries.QueryReturnValue)2 ValidationError (org.ovirt.engine.core.common.utils.customprop.ValidationError)2 Arrays (java.util.Arrays)1