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