Search in sources :

Example 11 with PolicyUnit

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

the class NewClusterPolicyModel method save.

private void save() {
    if (getProgress() != null) {
        return;
    }
    if (!validate()) {
        return;
    }
    startProgress();
    ClusterPolicy policy = new ClusterPolicy();
    policy.setId(clusterPolicy.getId());
    policy.setName(getName().getEntity());
    policy.setDescription(getDescription().getEntity());
    ArrayList<Guid> keys = new ArrayList<>();
    for (PolicyUnit clusterPolicy : getUsedFilters()) {
        keys.add(clusterPolicy.getId());
    }
    policy.setFilters(keys);
    policy.setFilterPositionMap(getFilterPositionMap());
    ArrayList<Pair<Guid, Integer>> pairs = new ArrayList<>();
    for (Pair<PolicyUnit, Integer> pair : getUsedFunctions()) {
        pairs.add(new Pair<>(pair.getFirst().getId(), pair.getSecond()));
    }
    policy.setFunctions(pairs);
    policy.setBalance(getLoadBalanceList().getSelectedItem().getId());
    policy.setParameterMap(KeyValueModel.convertProperties(getCustomPropertySheet().serialize()));
    Frontend.getInstance().runAction(commandType == CommandType.Edit ? ActionType.EditClusterPolicy : ActionType.AddClusterPolicy, new ClusterPolicyCRUDParameters(policy.getId(), policy), result -> {
        NewClusterPolicyModel.this.stopProgress();
        if (result.getReturnValue().getSucceeded()) {
            NewClusterPolicyModel.this.cancel();
        }
    });
}
Also used : ClusterPolicyCRUDParameters(org.ovirt.engine.core.common.scheduling.parameters.ClusterPolicyCRUDParameters) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) ClusterPolicy(org.ovirt.engine.core.common.scheduling.ClusterPolicy) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 12 with PolicyUnit

use of org.ovirt.engine.core.common.scheduling.PolicyUnit 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 13 with PolicyUnit

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

the class SchedulingManager method loadPolicyUnits.

private void loadPolicyUnits() {
    // Load internal policy units
    for (Class<? extends PolicyUnitImpl> unitType : InternalPolicyUnits.getList()) {
        try {
            PolicyUnitImpl unit = InternalPolicyUnits.instantiate(unitType, getPendingResourceManager());
            policyUnits.put(unit.getGuid(), Injector.injectMembers(unit));
        } catch (Exception e) {
            log.error("Could not instantiate a policy unit {}.", unitType.getName(), e);
        }
    }
    // Load all external policy units
    List<PolicyUnit> allPolicyUnits = policyUnitDao.getAll();
    for (PolicyUnit policyUnit : allPolicyUnits) {
        policyUnits.put(policyUnit.getId(), new ExternalPolicyUnit(policyUnit, getPendingResourceManager()));
    }
}
Also used : RankSelectorPolicyUnit(org.ovirt.engine.core.bll.scheduling.policyunits.RankSelectorPolicyUnit) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit)

Example 14 with PolicyUnit

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

the class ExternalSchedulerDiscovery method updateDB.

private void updateDB(ExternalSchedulerDiscoveryResult discoveryResult) {
    List<PolicyUnit> allPolicyUnits = policyUnitDao.getAll();
    Set<PolicyUnit> foundInBoth = new HashSet<>();
    for (ExternalSchedulerDiscoveryUnit unit : discoveryResult.getFilters()) {
        PolicyUnit found = compareToDB(allPolicyUnits, unit, PolicyUnitType.FILTER);
        foundInBoth.add(found);
    }
    for (ExternalSchedulerDiscoveryUnit unit : discoveryResult.getScores()) {
        PolicyUnit found = compareToDB(allPolicyUnits, unit, PolicyUnitType.WEIGHT);
        foundInBoth.add(found);
    }
    for (ExternalSchedulerDiscoveryUnit unit : discoveryResult.getBalance()) {
        PolicyUnit found = compareToDB(allPolicyUnits, unit, PolicyUnitType.LOAD_BALANCING);
        foundInBoth.add(found);
    }
    // found in the db for the current broker, but not found in discovery, mark as such
    markExternalPoliciesAsDisabled(allPolicyUnits.stream().filter(unit -> !foundInBoth.contains(unit)).collect(Collectors.toList()));
}
Also used : PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit) HashSet(java.util.HashSet)

Example 15 with PolicyUnit

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

the class ExternalSchedulerDiscovery method markExternalPoliciesAsDisabled.

private void markExternalPoliciesAsDisabled(List<PolicyUnit> units) {
    for (PolicyUnit policyUnit : units) {
        if (!policyUnit.isInternal()) {
            policyUnit.setEnabled(false);
            policyUnitDao.update(policyUnit);
        }
    }
}
Also used : PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit)

Aggregations

PolicyUnit (org.ovirt.engine.core.common.scheduling.PolicyUnit)24 Guid (org.ovirt.engine.core.compat.Guid)7 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ClusterPolicy (org.ovirt.engine.core.common.scheduling.ClusterPolicy)4 HashSet (java.util.HashSet)2 RankSelectorPolicyUnit (org.ovirt.engine.core.bll.scheduling.policyunits.RankSelectorPolicyUnit)2 Pair (org.ovirt.engine.core.common.utils.Pair)2 FunctionPolicyUnitPanel (org.ovirt.engine.ui.webadmin.section.main.view.popup.scheduling.panels.FunctionPolicyUnitPanel)2 ImageResource (com.google.gwt.resources.client.ImageResource)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 Column (com.google.gwt.user.cellview.client.Column)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1