Lior Vernia has uploaded a new change for review. Change subject: engine: Extracted Network QoS VDSM mapping logic ......................................................................
engine: Extracted Network QoS VDSM mapping logic Extracted the code mapping a NetworkQoS entity to VDSM-readable format to its own class NetworkQosMapper, to be shared with Host Network QoS. This class is now able to also deserialize the VDSM format to construct a NetworkQoS entity. Change-Id: Ieae520848495091532993b95f938ed6d5ad50834 Signed-off-by: Lior Vernia <[email protected]> --- A backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/NetworkQosMapper.java M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java 2 files changed, 80 insertions(+), 33 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/22603/1 diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/NetworkQosMapper.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/NetworkQosMapper.java new file mode 100644 index 0000000..0c710fc --- /dev/null +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/NetworkQosMapper.java @@ -0,0 +1,70 @@ +package org.ovirt.engine.core.vdsbroker.vdsbroker; + +import java.util.HashMap; +import java.util.Map; + +import org.ovirt.engine.core.common.businessentities.network.NetworkQoS; + +public class NetworkQosMapper { + + private static final int MEGABITS_TO_KILOBYTES = 128; + private static final int MEGABYTES_TO_KILOBYTES = 1024; + + private final Map<String, Object> map; + private final String inboundEntry; + private final String outboundEntry; + + public NetworkQosMapper(Map<String, Object> map, String inboundEntry, String outboundEntry) { + this.map = map; + this.inboundEntry = inboundEntry; + this.outboundEntry = outboundEntry; + } + + public void serialize(NetworkQoS qos) { + if (qos != null) { + addQosData(inboundEntry, qos.getInboundAverage(), qos.getInboundPeak(), qos.getInboundBurst()); + addQosData(outboundEntry, qos.getOutboundAverage(), qos.getOutboundPeak(), qos.getOutboundBurst()); + } + } + + public NetworkQoS deserialize() { + Map<String, Integer> inboundData = (Map<String, Integer>) map.get(inboundEntry); + Map<String, Integer> outboundData = (Map<String, Integer>) map.get(outboundEntry); + if (inboundData == null && outboundData == null) { + return null; + } + + NetworkQoS qos = new NetworkQoS(); + if (inboundData != null) { + qos.setInboundAverage(convert(inboundData.get(VdsProperties.QOS_AVERAGE), MEGABITS_TO_KILOBYTES)); + qos.setInboundPeak(convert(inboundData.get(VdsProperties.QOS_PEAK), MEGABITS_TO_KILOBYTES)); + qos.setInboundBurst(convert(inboundData.get(VdsProperties.QOS_BURST), MEGABYTES_TO_KILOBYTES)); + } + if (outboundData != null) { + qos.setOutboundAverage(convert(outboundData.get(VdsProperties.QOS_AVERAGE), MEGABITS_TO_KILOBYTES)); + qos.setOutboundPeak(convert(outboundData.get(VdsProperties.QOS_PEAK), MEGABITS_TO_KILOBYTES)); + qos.setOutboundBurst(convert(outboundData.get(VdsProperties.QOS_BURST), MEGABYTES_TO_KILOBYTES)); + } + return qos; + } + + private void addQosData(String qosEntryName, Integer average, Integer peak, Integer burst) { + + if (average != null && average > 0) { + Map<String, String> qosData = new HashMap<>(); + qosData.put(VdsProperties.QOS_AVERAGE, String.valueOf(average * MEGABITS_TO_KILOBYTES)); + qosData.put(VdsProperties.QOS_PEAK, String.valueOf(peak * MEGABITS_TO_KILOBYTES)); + qosData.put(VdsProperties.QOS_BURST, String.valueOf(burst * MEGABYTES_TO_KILOBYTES)); + map.put(qosEntryName, qosData); + } + } + + private static Integer convert(Integer num, int conversionRate) { + if (num == null) { + return null; + } else { + return (int) (num.floatValue() / conversionRate); + } + } + +} diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java index 90cae81..bd8fe3d 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java @@ -47,8 +47,6 @@ private static final String USB_BUS = "usb"; private final static String FIRST_MASTER_MODEL = "ich9-ehci1"; private static final String CLOUD_INIT_VOL_ID = "config-2"; - private static final int MEGABITS_TO_KILOBYTES = 128; - private static final int MEGABYTES_TO_KILOBYTES = 1024; private final List<Map<String, Object>> devices = new ArrayList<Map<String, Object>>(); private List<VmDevice> managedDevices = null; @@ -607,45 +605,24 @@ VnicProfile vnicProfile, Version vdsGroupCompatibilityVersion) { - if (vnicProfile.getNetworkQosId() != null) { + Guid qosId = vnicProfile.getNetworkQosId(); + if (qosId != null) { if (!FeatureSupported.networkQoS(vdsGroupCompatibilityVersion)) { return false; } - NetworkQoS networkQoS = DbFacade.getInstance().getQosDao().get(vnicProfile.getNetworkQosId()); - if (networkQoS != null) { - Map<String, Object> specParams = (Map<String, Object>) struct.get(VdsProperties.SpecParams); - if (specParams == null) { - specParams = new HashMap<>(); - struct.put(VdsProperties.SpecParams, specParams); - } - - addQosData(specParams, VdsProperties.QOS_INBOUND, - networkQoS.getInboundAverage(), - networkQoS.getInboundPeak(), - networkQoS.getInboundBurst()); - addQosData(specParams, VdsProperties.QOS_OUTBOUND, - networkQoS.getOutboundAverage(), - networkQoS.getOutboundPeak(), - networkQoS.getOutboundBurst()); + Map<String, Object> specParams = (Map<String, Object>) struct.get(VdsProperties.SpecParams); + if (specParams == null) { + specParams = new HashMap<>(); + struct.put(VdsProperties.SpecParams, specParams); } + NetworkQoS networkQoS = DbFacade.getInstance().getQosDao().get(qosId); + NetworkQosMapper qosMapper = + new NetworkQosMapper(specParams, VdsProperties.QOS_INBOUND, VdsProperties.QOS_OUTBOUND); + qosMapper.serialize(networkQoS); } return true; - } - - private static void addQosData(Map<String, Object> specParams, - String containerName, - Integer average, - Integer peak, - Integer burst) { - if (average != null && average > 0) { - Map<String, String> qosData = new HashMap<>(); - qosData.put(VdsProperties.QOS_AVERAGE, String.valueOf(average * MEGABITS_TO_KILOBYTES)); - qosData.put(VdsProperties.QOS_PEAK, String.valueOf(peak * MEGABITS_TO_KILOBYTES)); - qosData.put(VdsProperties.QOS_BURST, String.valueOf(burst * MEGABYTES_TO_KILOBYTES)); - specParams.put(containerName, qosData); - } } public static Map<String, String> getVnicCustomProperties(VnicProfile vnicProfile) { -- To view, visit http://gerrit.ovirt.org/22603 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ieae520848495091532993b95f938ed6d5ad50834 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
