Gilad Chaplik has uploaded a new change for review. Change subject: restapi: backward compatibility for cluster's scheduling policy ......................................................................
restapi: backward compatibility for cluster's scheduling policy The engine implementation for cluster policy has changed, thus changing the cluster mapper to handle it, without breaking compatibility. * scheduling_policy_type will be mapped to cluster_policy_name and vice-versa. * thresholds will be mapped to properties map and vice-versa. Change-Id: I4edd7313401670ca225b32d19dd7ad961ccd1b6a Signed-off-by: Gilad Chaplik <gchap...@redhat.com> --- M backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ClusterMapper.java 1 file changed, 29 insertions(+), 43 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/07/16607/1 diff --git a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ClusterMapper.java b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ClusterMapper.java index dd1b521..ea24263 100644 --- a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ClusterMapper.java +++ b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/ClusterMapper.java @@ -2,6 +2,8 @@ import static org.ovirt.engine.api.restapi.utils.VersionUtils.greaterOrEqual; +import java.util.LinkedHashMap; + import org.ovirt.engine.api.model.CPU; import org.ovirt.engine.api.model.Cluster; import org.ovirt.engine.api.model.DataCenter; @@ -16,9 +18,8 @@ import org.ovirt.engine.api.model.Version; import org.ovirt.engine.api.restapi.utils.GuidUtils; import org.ovirt.engine.core.common.businessentities.MigrateOnErrorOptions; -import org.ovirt.engine.core.common.businessentities.VDSGroup; -import org.ovirt.engine.core.common.businessentities.VdsSelectionAlgorithm; import org.ovirt.engine.core.common.businessentities.StoragePool; +import org.ovirt.engine.core.common.businessentities.VDSGroup; public class ClusterMapper { @@ -138,19 +139,22 @@ if (model.isSetPolicy()) { SchedulingPolicyType policyType = SchedulingPolicyType.fromValue(model.getPolicy()); if (policyType != null) { - entity.setselection_algorithm(map(policyType, null)); + entity.setClusterPolicyId(null); + entity.setClusterPolicyName(policyType.name().toLowerCase()); } } if (model.isSetThresholds()) { SchedulingPolicyThresholds thresholds = model.getThresholds(); - if (thresholds.getLow()!=null) { - entity.setlow_utilization(thresholds.getLow()); + entity.setClusterPolicyProperties(new LinkedHashMap<String, String>()); + if (thresholds.getLow() != null) { + entity.getClusterPolicyProperties().put("LowUtilization", thresholds.getLow().toString()); } - if (thresholds.getHigh()!=null) { - entity.sethigh_utilization(thresholds.getHigh()); + if (thresholds.getHigh() != null) { + entity.getClusterPolicyProperties().put("HighUtilization", thresholds.getHigh().toString()); } - if (thresholds.getDuration()!=null) { - entity.setcpu_over_commit_duration_minutes(Math.round(thresholds.getDuration() / 60.0f)); + if (thresholds.getDuration() != null) { + int round = Math.round(thresholds.getDuration() / 60.0f); + entity.getClusterPolicyProperties().put("CpuOverCommitDurationMinutes", Integer.toString(round)); } } return entity; @@ -159,45 +163,27 @@ @Mapping(from = VDSGroup.class, to = SchedulingPolicy.class) public static SchedulingPolicy map(VDSGroup entity, SchedulingPolicy template) { SchedulingPolicy model = template != null ? template : new SchedulingPolicy(); - if (entity.getselection_algorithm() != null) { - model.setPolicy(map(entity.getselection_algorithm(), null)); - if (model.isSetPolicy()) { + if (entity.getClusterPolicyName() != null && !entity.getClusterPolicyName().toLowerCase().equals("none")) { + model.setPolicy(entity.getClusterPolicyName()); + if (entity.getClusterPolicyProperties() != null) { model.setThresholds(new SchedulingPolicyThresholds()); - switch (entity.getselection_algorithm()) { - case PowerSave: - model.getThresholds().setLow(entity.getlow_utilization()); - // No need for break, PowerSave need to call setHight() and setDuration() - // as well. - case EvenlyDistribute: - model.getThresholds().setHigh(entity.gethigh_utilization()); - model.getThresholds().setDuration(entity.getcpu_over_commit_duration_minutes() * 60); - break; - default: - break; + String lowUtilization = entity.getClusterPolicyProperties().get("LowUtilization"); + String highUtilization = entity.getClusterPolicyProperties().get("HighUtilization"); + String cpuOverCommitDurationMinutes = + entity.getClusterPolicyProperties().get("CpuOverCommitDurationMinutes"); + if (lowUtilization != null) { + model.getThresholds().setLow(Integer.parseInt(lowUtilization)); + } + if (highUtilization != null) { + model.getThresholds().setHigh(Integer.parseInt(highUtilization)); + } + if (cpuOverCommitDurationMinutes != null) { + int duration = Integer.parseInt(cpuOverCommitDurationMinutes) * 60; + model.getThresholds().setDuration(duration); } } } return model; - } - - @Mapping(from = SchedulingPolicyType.class, to = VdsSelectionAlgorithm.class) - public static VdsSelectionAlgorithm map(SchedulingPolicyType model, VdsSelectionAlgorithm template) { - switch (model) { - case POWER_SAVING: return VdsSelectionAlgorithm.PowerSave; - case EVENLY_DISTRIBUTED: return VdsSelectionAlgorithm.EvenlyDistribute; - case NONE: return VdsSelectionAlgorithm.None; - default: return null; - } - } - - @Mapping(from = VdsSelectionAlgorithm.class, to = String.class) - public static String map(VdsSelectionAlgorithm entity, String template) { - switch (entity) { - case PowerSave: return SchedulingPolicyType.POWER_SAVING.value(); - case EvenlyDistribute: return SchedulingPolicyType.EVENLY_DISTRIBUTED.value(); - case None: return null; - default: return null; - } } @Mapping(from = StoragePool.class, to = VDSGroup.class) -- To view, visit http://gerrit.ovirt.org/16607 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4edd7313401670ca225b32d19dd7ad961ccd1b6a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches