Lior Vernia has uploaded a new change for review.

Change subject: webadmin: Move Network QoS logic to common ground
......................................................................

webadmin: Move Network QoS logic to common ground

Made the following changes to allow Host Network QoS access to logic
implemented for VM Network QoS:

* Created an AsyncDataProvider method to conveniently retrieve
NetworkQoS entities for a given DC, which also adds the empty QoS
(unlimited) to the top of the list.

* Moved the empty network QoS definition from VnicProfileModel to
NetworkQoSModel. It's the best location I found for it in the
frontend, otherwise it belongs in the common project (but the backend
doesn't use it).

* Moved the QoS selection logic to Linq.

Change-Id: Ib32cfe2392e86431323176fa9ef3e0aa00dbb841
Signed-off-by: Lior Vernia <lver...@redhat.com>
---
M 
frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/NetworkQoSModel.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/profiles/VnicProfileModel.java
5 files changed, 43 insertions(+), 27 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/22605/1

diff --git 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
index 28fd3f0..811ec40 100644
--- 
a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
+++ 
b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
@@ -176,6 +176,7 @@
 
                <!--QoS-->
                <include 
name="common/businessentities/network/NetworkQoS.java"/>
+               <include 
name="common/businessentities/network/DcBoundNetworkQos.java"/>
 
                <!-- Misc -->
                <include name="common/AuditLogType.java" />
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
index f8b403c..5aa68cd 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/Linq.java
@@ -36,6 +36,7 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.NetworkInterface;
+import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfileView;
@@ -49,6 +50,7 @@
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.clusters.ClusterNetworkModel;
+import org.ovirt.engine.ui.uicommonweb.models.datacenters.NetworkQoSModel;
 import org.ovirt.engine.ui.uicommonweb.models.hosts.HostInterfaceListModel;
 import org.ovirt.engine.ui.uicommonweb.models.providers.ExternalNetwork;
 import org.ovirt.engine.ui.uicommonweb.models.storage.LunModel;
@@ -460,6 +462,15 @@
         return null;
     }
 
+    public static NetworkQoS findNetworkQosById(Iterable<NetworkQoS> items, 
Guid qosId) {
+        for (NetworkQoS qos : items) {
+            if (qos.getId().equals(qosId)) {
+                return qos;
+            }
+        }
+        return NetworkQoSModel.getEmptyQos();
+    }
+
     public static ArrayList<VDS> findAllVDSByPmEnabled(ArrayList<VDS> items)
     {
         ArrayList<VDS> ret = new ArrayList<VDS>();
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
index c215a46..62b9083 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/dataprovider/AsyncDataProvider.java
@@ -66,6 +66,7 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import org.ovirt.engine.core.common.businessentities.gluster.ServiceType;
 import org.ovirt.engine.core.common.businessentities.network.Network;
+import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import 
org.ovirt.engine.core.common.businessentities.network.VmNetworkInterface;
@@ -138,6 +139,7 @@
 import org.ovirt.engine.ui.uicommonweb.models.ApplicationModeHelper;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.LoginModel;
+import org.ovirt.engine.ui.uicommonweb.models.datacenters.NetworkQoSModel;
 import org.ovirt.engine.ui.uicommonweb.models.vms.WANDisableEffects;
 import org.ovirt.engine.ui.uicommonweb.models.vms.WanColorDepth;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
@@ -1177,6 +1179,19 @@
         
Frontend.getInstance().runQuery(VdcQueryType.GetAllNetworksByClusterId, new 
IdQueryParameters(clusterId), aQuery);
     }
 
+    public static void getAllNetworkQos(Guid dcId, AsyncQuery query) {
+        query.converterCallback = new IAsyncConverter<List<NetworkQoS>>() {
+
+            @Override
+            public List<NetworkQoS> Convert(Object returnValue, AsyncQuery 
asyncQuery) {
+                List<NetworkQoS> qosList = returnValue == null ? new 
ArrayList<NetworkQoS>() : (List<NetworkQoS>) returnValue;
+                qosList.add(0, NetworkQoSModel.getEmptyQos());
+                return qosList;
+            }
+        };
+        
Frontend.getInstance().runQuery(VdcQueryType.GetAllNetworkQosByStoragePoolId, 
new IdQueryParameters(dcId), query);
+    }
+
     public static void getDataCenterById(AsyncQuery aQuery, Guid dataCenterId) 
{
         aQuery.converterCallback = new IAsyncConverter() {
             @Override
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/NetworkQoSModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/NetworkQoSModel.java
index 815e4ce..9e50357 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/NetworkQoSModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/datacenters/NetworkQoSModel.java
@@ -4,6 +4,7 @@
 import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
 import org.ovirt.engine.core.common.queries.ConfigurationValues;
+import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.StringHelper;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
 import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
@@ -20,6 +21,7 @@
 
 public abstract class NetworkQoSModel extends Model {
 
+    private static NetworkQoS emptyQos;
 
     private final ListModel sourceListModel;
     private ListModel dataCenters;
@@ -196,6 +198,15 @@
         stopProgress();
     }
 
+    public static NetworkQoS getEmptyQos() {
+        if (emptyQos == null) {
+            emptyQos = new NetworkQoS();
+            
emptyQos.setName(ConstantsManager.getInstance().getConstants().unlimitedQoSTitle());
+            emptyQos.setId(Guid.Empty);
+        }
+        return emptyQos;
+    }
+
     public ListModel getDataCenters() {
         return dataCenters;
     }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/profiles/VnicProfileModel.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/profiles/VnicProfileModel.java
index 290a5ae..08d81c7 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/profiles/VnicProfileModel.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/profiles/VnicProfileModel.java
@@ -13,7 +13,6 @@
 import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
 import 
org.ovirt.engine.core.common.queries.GetDeviceCustomPropertiesParameters;
-import org.ovirt.engine.core.common.queries.IdQueryParameters;
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.compat.Guid;
@@ -22,7 +21,9 @@
 import org.ovirt.engine.ui.frontend.AsyncQuery;
 import org.ovirt.engine.ui.frontend.Frontend;
 import org.ovirt.engine.ui.frontend.INewAsyncCallback;
+import org.ovirt.engine.ui.uicommonweb.Linq;
 import org.ovirt.engine.ui.uicommonweb.UICommand;
+import org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider;
 import org.ovirt.engine.ui.uicommonweb.models.EntityModel;
 import org.ovirt.engine.ui.uicommonweb.models.ListModel;
 import org.ovirt.engine.ui.uicommonweb.models.Model;
@@ -36,7 +37,6 @@
 
 public abstract class VnicProfileModel extends Model {
 
-    private static NetworkQoS emptyQos;
 
     private EntityModel name;
     private EntityModel portMirroring;
@@ -49,15 +49,6 @@
     private VnicProfile vnicProfile = null;
     private final boolean customPropertiesVisible;
     private final Guid defaultQosId;
-
-    private static NetworkQoS getEmptyQos() {
-        if (emptyQos == null) {
-            emptyQos = new NetworkQoS();
-            
emptyQos.setName(ConstantsManager.getInstance().getConstants().unlimitedQoSTitle());
-            emptyQos.setId(Guid.Empty);
-        }
-        return emptyQos;
-    }
 
     public EntityModel getName()
     {
@@ -284,16 +275,13 @@
             @Override
             public void onSuccess(Object model, Object ReturnValue)
             {
-                ArrayList<NetworkQoS> networkQoSes =
-                        (ArrayList<NetworkQoS>) ((VdcQueryReturnValue) 
ReturnValue).getReturnValue();
-                networkQoSes.add(0, getEmptyQos());
+                List<NetworkQoS> networkQoSes = (List<NetworkQoS>) ReturnValue;
                 getNetworkQoS().setItems(networkQoSes);
-                setSelectedNetworkQoSId(defaultQosId);
+                
getNetworkQoS().setSelectedItem(Linq.findNetworkQosById(networkQoSes, 
defaultQosId));
             }
         };
 
-        IdQueryParameters queryParams = new IdQueryParameters(dcId);
-        
Frontend.getInstance().runQuery(VdcQueryType.GetAllNetworkQosByStoragePoolId, 
queryParams, _asyncQuery);
+        AsyncDataProvider.getAllNetworkQos(dcId, _asyncQuery);
     }
 
     public boolean validate()
@@ -309,15 +297,5 @@
 
     protected VdcActionParametersBase getActionParameters() {
         return new VnicProfileParameters(vnicProfile);
-    }
-
-    private void setSelectedNetworkQoSId(Guid networkQoSId) {
-        for (Object item : getNetworkQoS().getItems()) {
-            if (((NetworkQoS) item).getId().equals(networkQoSId)) {
-                getNetworkQoS().setSelectedItem(item);
-                return;
-            }
-        }
-        getNetworkQoS().setSelectedItem(getEmptyQos());
     }
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib32cfe2392e86431323176fa9ef3e0aa00dbb841
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Lior Vernia <lver...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to