Lior Vernia has uploaded a new change for review. Change subject: engine: Extract common code to update interface statistics ......................................................................
engine: Extract common code to update interface statistics Code was duplicated to perform the same thing for VdsNetworkInterface and VmNetworkInterface, now it's re-used. Change-Id: I195e365ae4c5898c3cb5ffb1f090bc0e62470186 Signed-off-by: Lior Vernia <[email protected]> --- M backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java 1 file changed, 19 insertions(+), 18 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/63/36463/1 diff --git a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java index f952227..7096cb8 100644 --- a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java +++ b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java @@ -55,6 +55,8 @@ import org.ovirt.engine.core.common.businessentities.network.InterfaceStatus; import org.ovirt.engine.core.common.businessentities.network.Network; import org.ovirt.engine.core.common.businessentities.network.NetworkBootProtocol; +import org.ovirt.engine.core.common.businessentities.network.NetworkInterface; +import org.ovirt.engine.core.common.businessentities.network.NetworkStatistics; import org.ovirt.engine.core.common.businessentities.network.VdsInterfaceType; import org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface; import org.ovirt.engine.core.common.businessentities.network.VdsNetworkStatistics; @@ -432,17 +434,9 @@ stats.setName((String) ((nic.get(VdsProperties.VM_INTERFACE_NAME) instanceof String) ? nic .get(VdsProperties.VM_INTERFACE_NAME) : null)); } - Double rx_rate = AssignDoubleValue(nic, VdsProperties.rx_rate); - Double rx_dropped = AssignDoubleValue(nic, VdsProperties.rx_dropped); - Double tx_rate = AssignDoubleValue(nic, VdsProperties.tx_rate); - Double tx_dropped = AssignDoubleValue(nic, VdsProperties.tx_dropped); - stats.getStatistics().setReceiveRate(rx_rate != null ? rx_rate : 0); - stats.getStatistics().setReceiveDropRate(rx_dropped != null ? rx_dropped : 0); - stats.getStatistics().setTransmitRate(tx_rate != null ? tx_rate : 0); - stats.getStatistics().setTransmitDropRate(tx_dropped != null ? tx_dropped : 0); + updateInterfaceStatistics(nic, stats); stats.setMacAddress((String) ((nic.get(VdsProperties.MAC_ADDR) instanceof String) ? nic .get(VdsProperties.MAC_ADDR) : null)); - stats.setSpeed(AssignIntValue(nic, VdsProperties.INTERFACE_SPEED)); } } @@ -791,15 +785,7 @@ VdsNetworkInterface iface = nicsByName.get(entry.getKey()); iface.setVdsId(vds.getId()); Map<String, Object> dict = (Map<String, Object>) entry.getValue(); - Double rx_rate = AssignDoubleValue(dict, VdsProperties.rx_rate); - Double rx_dropped = AssignDoubleValue(dict, VdsProperties.rx_dropped); - Double tx_rate = AssignDoubleValue(dict, VdsProperties.tx_rate); - Double tx_dropped = AssignDoubleValue(dict, VdsProperties.tx_dropped); - iface.getStatistics().setReceiveRate(rx_rate != null ? rx_rate : 0); - iface.getStatistics().setReceiveDropRate(rx_dropped != null ? rx_dropped : 0); - iface.getStatistics().setTransmitRate(tx_rate != null ? tx_rate : 0); - iface.getStatistics().setTransmitDropRate(tx_dropped != null ? tx_dropped : 0); - iface.setSpeed(AssignIntValue(dict, VdsProperties.INTERFACE_SPEED)); + updateInterfaceStatistics(dict, iface); iface.getStatistics().setStatus(AssignInterfaceStatusValue(dict, VdsProperties.iface_status)); if (!NetworkUtils.isVlan(iface) && !iface.isBondSlave()) { @@ -888,6 +874,21 @@ } + private static void updateInterfaceStatistics(Map<String, Object> dict, NetworkInterface<?> iface) { + Double rx_rate = AssignDoubleValue(dict, VdsProperties.rx_rate); + Double rx_dropped = AssignDoubleValue(dict, VdsProperties.rx_dropped); + Double tx_rate = AssignDoubleValue(dict, VdsProperties.tx_rate); + Double tx_dropped = AssignDoubleValue(dict, VdsProperties.tx_dropped); + + NetworkStatistics stats = iface.getStatistics(); + stats.setReceiveRate(rx_rate != null ? rx_rate : 0); + stats.setReceiveDropRate(rx_dropped != null ? rx_dropped : 0); + stats.setTransmitRate(tx_rate != null ? tx_rate : 0); + stats.setTransmitDropRate(tx_dropped != null ? tx_dropped : 0); + + iface.setSpeed(AssignIntValue(dict, VdsProperties.INTERFACE_SPEED)); + } + private static double computeInterfaceUsage(VdsNetworkInterface iface) { return Math.max(truncatePercentage(iface.getStatistics().getReceiveRate()), truncatePercentage(iface.getStatistics().getTransmitRate())); -- To view, visit http://gerrit.ovirt.org/36463 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I195e365ae4c5898c3cb5ffb1f090bc0e62470186 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
