Moti Asayag has uploaded a new change for review.

Change subject: engine: Retrieve networks by label for a cluster
......................................................................

engine: Retrieve networks by label for a cluster

Adding the ability to fetch networks from the DB
with a specific label, where the networks are all
assigned to a specific cluster.

This will allow to identify which labelled networks
should be configured on the host when a nic is
labeled.

Change-Id: Ibffa2222669a42541cb2da80430d86c8aaddd471
Signed-off-by: Moti Asayag <[email protected]>
---
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkDaoTest.java
3 files changed, 40 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/90/22890/1

diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDao.java
index 896a5026..9c14c0e 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDao.java
@@ -125,4 +125,15 @@
      * @return the network
      */
     Network get(Guid networkId, Guid userID, boolean isFiltered);
+
+    /**
+     * Retrieves the networks with the specified label which are attached to a 
specific Cluster.
+     *
+     * @param label
+     *            the network label
+     * @param clusterId
+     *            the cluster the networks are attached to
+     * @return the networks
+     */
+    List<Network> getAllByLabelForCluster(String label, Guid clusterId);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDaoDbFacadeImpl.java
index 13d3eb4..3a5ad70 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/NetworkDaoDbFacadeImpl.java
@@ -2,10 +2,12 @@
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.NetworkCluster;
 import org.ovirt.engine.core.common.businessentities.network.NetworkStatus;
@@ -116,6 +118,19 @@
     }
 
     @Override
+    public List<Network> getAllByLabelForCluster(String label, Guid clusterId) 
{
+        List<Network> networksInCluster = getAllForCluster(clusterId, null, 
false);
+        List<Network> labeledNetworks = new ArrayList<>();
+        for (Network network : networksInCluster) {
+            if (StringUtils.equals(network.getLabel(), label)) {
+                labeledNetworks.add(network);
+            }
+        }
+
+        return labeledNetworks;
+    }
+
+    @Override
     protected MapSqlParameterSource createIdParameterMapper(Guid id) {
         return getCustomMapSqlParameterSource().addValue("id", id);
     }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkDaoTest.java
index a485841..5f5b904 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/NetworkDaoTest.java
@@ -25,6 +25,7 @@
     private static final String EXISTING_NETWORK_NAME1 = "engine";
     private static final String EXISTING_NETWORK_NAME2 = "engine3";
     private static final int NUM_OF_NETWORKS = 6;
+    private static final String NETWORK_LABEL = "lbl1";
 
     @Override
     public void setUp() throws Exception {
@@ -289,6 +290,19 @@
     }
 
     /**
+     * Ensures a list of networks is returned for a given cluster by a 
specific label
+     */
+    public void getAllByLabelForCluster() {
+        List<Network> result = dao.getAllByLabelForCluster(NETWORK_LABEL, 
cluster);
+        assertNotNull(result);
+        assertFalse(result.isEmpty());
+
+        for (Network network : result) {
+            assertEquals(NETWORK_LABEL, network.getLabel());
+        }
+    }
+
+    /**
      * Ensures that saving a network works as expected.
      */
     @Test


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibffa2222669a42541cb2da80430d86c8aaddd471
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Moti Asayag <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to