Search in sources :

Example 1 with PolicyUnitImpl

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

the class GetAllPolicyUnitsQuery method executeQueryCommand.

@Override
protected void executeQueryCommand() {
    Map<Guid, PolicyUnitImpl> map = schedulingManager.getPolicyUnitsMap();
    List<PolicyUnit> retList = new ArrayList<>();
    for (PolicyUnitImpl policyUnitImpl : map.values()) {
        retList.add(policyUnitImpl.getPolicyUnit());
    }
    getQueryReturnValue().setReturnValue(retList);
}
Also used : PolicyUnitImpl(org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) PolicyUnit(org.ovirt.engine.core.common.scheduling.PolicyUnit)

Example 2 with PolicyUnitImpl

use of org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl 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)

Aggregations

PolicyUnitImpl (org.ovirt.engine.core.bll.scheduling.PolicyUnitImpl)2 Guid (org.ovirt.engine.core.compat.Guid)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ClusterPolicy (org.ovirt.engine.core.common.scheduling.ClusterPolicy)1 PolicyUnit (org.ovirt.engine.core.common.scheduling.PolicyUnit)1 ValidationError (org.ovirt.engine.core.common.utils.customprop.ValidationError)1