Lior Vernia has uploaded a new change for review. Change subject: engine: Implement HostNetworkQos [de]serialization ......................................................................
engine: Implement HostNetworkQos [de]serialization Implemented HostNetworkQosMapper, which serializes and deserializes HostNetworkQos entities according to the vdsm contract. Change-Id: I8fab9e53938823463ff01af0a153390804f276c3 Signed-off-by: Lior Vernia <[email protected]> --- A backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostNetworkQosMapper.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java 2 files changed, 88 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/22/34122/1 diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostNetworkQosMapper.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostNetworkQosMapper.java new file mode 100644 index 0000000..170c1ea --- /dev/null +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/HostNetworkQosMapper.java @@ -0,0 +1,81 @@ +package org.ovirt.engine.core.vdsbroker.vdsbroker; + +import java.util.HashMap; +import java.util.Map; + +import org.ovirt.engine.core.common.businessentities.network.HostNetworkQos; + +public class HostNetworkQosMapper { + + private static final int MBITS_TO_BITS = 1000000; + + private final Map<String, Object> rootEntry; + + public HostNetworkQosMapper(Map<String, Object> rootEntry) { + this.rootEntry = rootEntry; + } + + public void serialize(HostNetworkQos qos) { + if (qos == null) { + return; + } + + Map<String, Object> outboundEntry = new HashMap<>(); + serializeValue(outboundEntry, VdsProperties.HOST_QOS_LINKSHARE, qos.getOutAverageLinkshare()); + serializeValue(outboundEntry, VdsProperties.HOST_QOS_UPPERLIMIT, qos.getOutAverageUpperlimit(), MBITS_TO_BITS); + serializeValue(outboundEntry, VdsProperties.HOST_QOS_REALTIME, qos.getOutAverageRealtime(), MBITS_TO_BITS); + if (outboundEntry.isEmpty()) { + return; + } + + Map<String, Object> qosEntry = new HashMap<>(); + qosEntry.put(VdsProperties.HOST_QOS_OUTBOUND, outboundEntry); + + rootEntry.put(VdsProperties.HOST_QOS, qosEntry); + } + + private void serializeValue(Map<String, Object> entry, String curveKey, Integer value) { + serializeValue(entry, curveKey, value, 1); + } + + private void serializeValue(Map<String, Object> entry, String curveKey, Integer value, int conversionRate) { + if (value != null) { + Map<String, Integer> parameters = new HashMap<>(); + parameters.put(VdsProperties.HOST_QOS_AVERAGE, value * conversionRate); + entry.put(curveKey, parameters); + } + } + + public HostNetworkQos deserialize() { + Map<String, Object> qosEntry = (Map<String, Object>) rootEntry.get(VdsProperties.HOST_QOS); + if (qosEntry == null) { + return null; + } + + Map<String, Object> outboundEntry = (Map<String, Object>) qosEntry.get(VdsProperties.HOST_QOS_OUTBOUND); + if (outboundEntry == null) { + return null; + } + + HostNetworkQos qos = new HostNetworkQos(); + qos.setOutAverageLinkshare(deserializeValue(outboundEntry, VdsProperties.HOST_QOS_LINKSHARE)); + qos.setOutAverageUpperlimit(deserializeValue(outboundEntry, VdsProperties.HOST_QOS_UPPERLIMIT, MBITS_TO_BITS)); + qos.setOutAverageRealtime(deserializeValue(outboundEntry, VdsProperties.HOST_QOS_REALTIME, MBITS_TO_BITS)); + return qos; + } + + private Integer deserializeValue(Map<String, Object> entry, String curveKey) { + return deserializeValue(entry, curveKey, 1); + } + + private Integer deserializeValue(Map<String, Object> entry, String curveKey, int conversionRate) { + Map<String, Integer> parameters = (Map<String, Integer>) entry.get(curveKey); + if (parameters == null) { + return null; + } + + Integer average = parameters.get(VdsProperties.HOST_QOS_AVERAGE); + return (average == null) ? null : (int) (average / conversionRate); + } + +} diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java index 2eaa0f4..a1c8c6f 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsProperties.java @@ -369,8 +369,13 @@ public static final String action = "action"; // Network QoS - public static final String HOST_QOS_INBOUND = "qosInbound"; - public static final String HOST_QOS_OUTBOUND = "qosOutbound"; + public static final String HOST_QOS = "hostQos"; + public static final String HOST_QOS_INBOUND = "in"; + public static final String HOST_QOS_OUTBOUND = "out"; + public static final String HOST_QOS_LINKSHARE = "ls"; + public static final String HOST_QOS_UPPERLIMIT = "ul"; + public static final String HOST_QOS_REALTIME = "rt"; + public static final String HOST_QOS_AVERAGE = "m2"; public static final String QOS_INBOUND = "inbound"; public static final String QOS_OUTBOUND = "outbound"; public static final String QOS_AVERAGE = "average"; -- To view, visit http://gerrit.ovirt.org/34122 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8fab9e53938823463ff01af0a153390804f276c3 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
