Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Rewrote arranging of NICs in Host/Networks subtab
......................................................................

webadmin: Rewrote arranging of NICs in Host/Networks subtab

Some needed refactoring as well as algorithmic changes to improve
computational complexity - old algorithm was naive and would perform in
O(n^2), reduced to O(n) thanks to the sorting done in the host
interfaces query.

Change-Id: I0b464cc023282ceab868230a1c31638ebe75de4d
Signed-off-by: Lior Vernia <[email protected]>
---
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostInterfaceListModel.java
1 file changed, 96 insertions(+), 95 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/12000/1

diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostInterfaceListModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostInterfaceListModel.java
index de2440b..235ae4b 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostInterfaceListModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/hosts/HostInterfaceListModel.java
@@ -448,111 +448,112 @@
     {
         ArrayList<HostInterfaceLineModel> items = new 
ArrayList<HostInterfaceLineModel>();
         setOriginalItems((ArrayList<VdsNetworkInterface>) source);
-        // Add bonded interfaces.
-        for (VdsNetworkInterface nic : source)
-        {
-            if ((nic.getBonded() == null ? false : nic.getBonded()))
-            {
-                HostInterfaceLineModel model = new HostInterfaceLineModel();
-                model.setInterfaces(new ArrayList<HostInterface>());
-                model.setInterface(nic);
-                model.setVLans(new ArrayList<HostVLan>());
-                model.setIsBonded(true);
-                model.setBondName(nic.getName());
-                model.setAddress(nic.getAddress());
-                model.setNetworkName(nic.getNetworkName());
-                model.setIsManagement(nic.getIsManagement());
 
-                items.add(model);
-            }
+        Iterator<VdsNetworkInterface> i = source.iterator();
+        VdsNetworkInterface nic = i.hasNext() ? i.next() : null;
+        HostInterfaceLineModel model;
+
+        // First appear the bonds
+        while (nic != null && nic.getBonded() != null && nic.getBonded()) {
+            model = lineModelFromBond(nic);
+            items.add(model);
+            nic = i.hasNext() ? i.next() : null;
+
+            // Each bond is followed by any interfaces it contains
+            nic = gatherBondedInterfaces(model, nic, i);
+
+            // Bond's interfaces are followed by any associated VLAN NICs
+            nic = gatherVlanInterfaces(model, nic, i);
         }
 
-        // Find for each bond containing interfaces.
-        for (HostInterfaceLineModel model : items)
-        {
-            if (model.getIsBonded())
-            {
-                for (VdsNetworkInterface nic : source)
-                {
-                    if (StringHelper.stringsEqual(nic.getBondName(), 
model.getBondName()))
-                    {
-                        HostInterface hi = new HostInterface();
-                        hi.setInterface(nic);
-                        hi.setName(nic.getName());
-                        hi.setAddress(nic.getAddress());
-                        hi.setMAC(nic.getMacAddress());
-                        hi.setSpeed(nic.getSpeed());
-                        hi.setRxRate(nic.getStatistics().getReceiveRate());
-                        hi.setRxDrop(nic.getStatistics().getReceiveDropRate());
-                        hi.setTxRate(nic.getStatistics().getTransmitRate());
-                        
hi.setTxDrop(nic.getStatistics().getTransmitDropRate());
-                        hi.setStatus(nic.getStatistics().getStatus());
-                        hi.getPropertyChangedEvent().addListener(this);
+        // After the bonds appear the non-bonded NICs
+        while (nic != null) {
+            model = lineModelFromInterface(nic);
+            model.getInterfaces().add(hostInterfaceFromNic(nic));
+            items.add(model);
+            nic = i.hasNext() ? i.next() : null;
 
-                        model.getInterfaces().add(hi);
-                    }
-                }
-            }
-        }
-
-        // Add not bonded interfaces with no vlan.
-        for (VdsNetworkInterface nic : source)
-        {
-            if (!(nic.getBonded() == null ? false : nic.getBonded()) && 
StringHelper.isNullOrEmpty(nic.getBondName())
-                    && nic.getVlanId() == null)
-            {
-                HostInterfaceLineModel model = new HostInterfaceLineModel();
-                model.setInterfaces(new ArrayList<HostInterface>());
-                model.setVLans(new ArrayList<HostVLan>());
-                model.setNetworkName(nic.getNetworkName());
-                model.setIsManagement(nic.getIsManagement());
-
-                // There is only one interface.
-                HostInterface hi = new HostInterface();
-                hi.setInterface(nic);
-                hi.setName(nic.getName());
-                hi.setAddress(nic.getAddress());
-                hi.setMAC(nic.getMacAddress());
-                hi.setSpeed(nic.getSpeed());
-                hi.setRxRate(nic.getStatistics().getReceiveRate());
-                hi.setRxDrop(nic.getStatistics().getReceiveDropRate());
-                hi.setTxRate(nic.getStatistics().getTransmitRate());
-                hi.setTxDrop(nic.getStatistics().getTransmitDropRate());
-                hi.setStatus(nic.getStatistics().getStatus());
-                hi.getPropertyChangedEvent().addListener(this);
-
-                model.getInterfaces().add(hi);
-
-                items.add(model);
-            }
-        }
-
-        // Find vlans.
-        for (HostInterfaceLineModel model : items)
-        {
-            String nicName = model.getIsBonded() ? model.getBondName() : 
model.getInterfaces().get(0).getName();
-
-            for (VdsNetworkInterface nic : source)
-            {
-                if (nic.getVlanId() != null
-                        && StringHelper.stringsEqual(nicName + "." + 
nic.getVlanId(), nic.getName())) //$NON-NLS-1$
-                {
-                    HostVLan hv = new HostVLan();
-                    hv.setInterface(nic);
-                    hv.setName(nic.getName());
-                    hv.setNetworkName(nic.getNetworkName());
-                    hv.setAddress(nic.getAddress());
-                    hv.getPropertyChangedEvent().addListener(this);
-
-                    model.getVLans().add(hv);
-                }
-            }
+            // Each NIC is followed by any associated VLAN NICs
+            nic = gatherVlanInterfaces(model, nic, i);
         }
 
         setItems(items);
         UpdateActionAvailability();
     }
 
+    private VdsNetworkInterface gatherBondedInterfaces(HostInterfaceLineModel 
model,
+            VdsNetworkInterface nic,
+            Iterator<VdsNetworkInterface> i) {
+        while (nic != null && nic.getBondName() != null && 
nic.getBondName().equals(model.getBondName())) {
+            model.getInterfaces().add(hostInterfaceFromNic(nic));
+            nic = i.hasNext() ? i.next() : null;
+        }
+        return nic;
+    }
+
+    private VdsNetworkInterface gatherVlanInterfaces(HostInterfaceLineModel 
model,
+            VdsNetworkInterface nic,
+            Iterator<VdsNetworkInterface> i) {
+        while (nic != null && nic.getVlanId() != null
+                && nic.getName().equals(new StringBuilder()
+                        .append(model.getIsBonded() ? model.getBondName() : 
model.getInterfaces().get(0).getName())
+                        .append('.')
+                        .append(nic.getVlanId())
+                        .toString())) {
+            model.getVLans().add(hostVlanFromNic(nic));
+            nic = i.hasNext() ? i.next() : null;
+        }
+        return nic;
+    }
+
+    private HostInterfaceLineModel lineModelFromInterface(VdsNetworkInterface 
nic) {
+        HostInterfaceLineModel model = new HostInterfaceLineModel();
+        model.setInterfaces(new ArrayList<HostInterface>());
+        model.setVLans(new ArrayList<HostVLan>());
+        model.setNetworkName(nic.getNetworkName());
+        model.setIsManagement(nic.getIsManagement());
+
+        return model;
+    }
+
+    private HostInterfaceLineModel lineModelFromBond(VdsNetworkInterface nic) {
+        HostInterfaceLineModel model = lineModelFromInterface(nic);
+        model.setInterface(nic);
+        model.setIsBonded(true);
+        model.setBondName(nic.getName());
+        model.setAddress(nic.getAddress());
+
+        return model;
+    }
+
+    private HostInterface hostInterfaceFromNic(VdsNetworkInterface nic) {
+        HostInterface hi = new HostInterface();
+        hi.setInterface(nic);
+        hi.setName(nic.getName());
+        hi.setAddress(nic.getAddress());
+        hi.setMAC(nic.getMacAddress());
+        hi.setSpeed(nic.getSpeed());
+        hi.setRxRate(nic.getStatistics().getReceiveRate());
+        hi.setRxDrop(nic.getStatistics().getReceiveDropRate());
+        hi.setTxRate(nic.getStatistics().getTransmitRate());
+        hi.setTxDrop(nic.getStatistics().getTransmitDropRate());
+        hi.setStatus(nic.getStatistics().getStatus());
+        hi.getPropertyChangedEvent().addListener(this);
+
+        return hi;
+    }
+
+    private HostVLan hostVlanFromNic(VdsNetworkInterface nic) {
+        HostVLan hv = new HostVLan();
+        hv.setInterface(nic);
+        hv.setName(nic.getName());
+        hv.setNetworkName(nic.getNetworkName());
+        hv.setAddress(nic.getAddress());
+        hv.getPropertyChangedEvent().addListener(this);
+
+        return hv;
+    }
+
     @Override
     public void eventRaised(Event ev, Object sender, EventArgs args)
     {


--
To view, visit http://gerrit.ovirt.org/12000
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0b464cc023282ceab868230a1c31638ebe75de4d
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

Reply via email to