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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations