Alona Kaplan has uploaded a new change for review.

Change subject: engine: introducing vfsConfigNetworks and vfsConfigLabels tables
......................................................................

engine: introducing vfsConfigNetworks and vfsConfigLabels tables

vfsConfigNetworks - mapping between the vfsConfig and its networks.
vfsConfigLabels - mapping between the vfsConfig and its labels.

This patch contains creation of the tables and adding crud actions to them.
The crud actions are part of the HostNicVfsConfigDao.

Change-Id: Ia383df7060b97c17459ef4576d300e7de217e966
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/HostNicVfsConfig.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M packaging/dbscripts/network_sp.sql
M packaging/dbscripts/upgrade/03_06_0590_add_host_nic_vfs_config_table.sql
A 
packaging/dbscripts/upgrade/03_06_0600_add_vfs_config_networks_and_labels_tables.sql
9 files changed, 566 insertions(+), 30 deletions(-)


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

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/HostNicVfsConfig.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/HostNicVfsConfig.java
index 38a65c3..9b756f7 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/HostNicVfsConfig.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/HostNicVfsConfig.java
@@ -1,8 +1,9 @@
 package org.ovirt.engine.core.common.businessentities.network;
 
 import java.io.Serializable;
-import java.util.List;
+import java.util.HashSet;
 import java.util.Objects;
+import java.util.Set;
 
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.IVdcQueryable;
@@ -24,9 +25,9 @@
 
     private boolean allNetworksAllowed;
 
-    private List<Guid> networks;
+    private Set<Guid> networks = new HashSet<>();
 
-    private List<String> labels;
+    private Set<String> labels = new HashSet<>();
 
     public Guid getNicId() {
         return nicId;
@@ -68,19 +69,19 @@
         this.allNetworksAllowed = allNetworksAllowed;
     }
 
-    public List<Guid> getNetworks() {
+    public Set<Guid> getNetworks() {
         return networks;
     }
 
-    public void setNetworks(List<Guid> networks) {
+    public void setNetworks(Set<Guid> networks) {
         this.networks = networks;
     }
 
-    public List<String> getLabels() {
+    public Set<String> getLabels() {
         return labels;
     }
 
-    public void setLabels(List<String> labels) {
+    public void setLabels(Set<String> labels) {
         this.labels = labels;
     }
 
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java
index 038c906..dc2d065 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDao.java
@@ -5,5 +5,41 @@
 import org.ovirt.engine.core.dao.GenericDao;
 
 public interface HostNicVfsConfigDao extends GenericDao<HostNicVfsConfig, 
Guid> {
+    /**
+     * Attaches a network to the allowed network list of the specified vfs 
config
+     *
+     * @param vfsConfigId
+     *            host nic vfs config id
+     *        networkId
+     *            network id
+     */
+    void addNetwork(Guid vfsConfigId, Guid networkId);
 
+    /**
+     * Removes a network from the allowed network list of the specified vfs 
config
+     *
+     * @param vfsConfigId
+     *            host nic vfs config id
+     *        networkId
+     *            network id
+     */
+    void removeNetwork(Guid vfsConfigId, Guid networkId);
+
+    /**
+     * Attaches a network to the allowed network list of the specified vfs 
config
+     *
+     * @param vfsConfigId
+     *            host nic vfs config id
+     *        label
+     */
+    void addLabel(Guid vfsConfigId, String label);
+
+    /**
+     * Removes a label from the allowed labels list of the specified vfs config
+     *
+     * @param vfsConfigId
+     *            host nic vfs config id
+     *        label
+     */
+    void removeLabel(Guid vfsConfigId, String label);
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java
index 02759d1..0e1bdf4 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoDbFacadeImpl.java
@@ -2,11 +2,16 @@
 
 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.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade;
 import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.SingleColumnRowMapper;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 
 public class HostNicVfsConfigDaoDbFacadeImpl extends 
DefaultGenericDaoDbFacade<HostNicVfsConfig, Guid> implements 
HostNicVfsConfigDao {
@@ -57,4 +62,134 @@
             return entity;
         }
     }
+
+    @Override
+    public HostNicVfsConfig get(Guid id) {
+        HostNicVfsConfig vfsConfig = super.get(id);
+        fillNetworksAndLabelsDataOnConfig(vfsConfig);
+        return vfsConfig;
+    }
+
+    @Override
+    public List<HostNicVfsConfig> getAll() {
+        List<HostNicVfsConfig> allConfigs = super.getAll();
+        for (HostNicVfsConfig vfsConfig : allConfigs) {
+            fillNetworksAndLabelsDataOnConfig(vfsConfig);
+        }
+        return allConfigs;
+    }
+
+    private void fillNetworksAndLabelsDataOnConfig(HostNicVfsConfig vfsConfig) 
{
+        if (vfsConfig == null) {
+            return;
+        }
+
+        Guid id = vfsConfig.getId();
+        vfsConfig.setNetworks(getNetworksByVfsConfigId(id));
+        vfsConfig.setLabels(getLabelsByVfsConfigId(id));
+    }
+
+    @Override
+    public void save(HostNicVfsConfig entity) {
+        super.save(entity);
+        saveNetworksAndLabels(entity);
+    }
+
+    @Override
+    public void update(HostNicVfsConfig entity) {
+        super.update(entity);
+        removeAllNetworksByVfsConfigId(entity.getId());
+        removeAllLabelsByVfsConfigId(entity.getId());
+        saveNetworksAndLabels(entity);
+    }
+
+    private void saveNetworksAndLabels(HostNicVfsConfig entity) {
+        massNetworksUpdate(entity.getId(), entity.getNetworks());
+        massLabelsUpdate(entity.getId(), entity.getLabels());
+    }
+
+    private MapSqlParameterSource createVfsConfigIdParameter(Guid vfsConfigId) 
{
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
+                .addValue("vfs_config_id", vfsConfigId);
+        return parameterSource;
+    }
+
+    // VfsConfigNetworks
+
+    Set<Guid> getNetworksByVfsConfigId(Guid vfsConfigId) {
+        return new 
HashSet<Guid>(getCallsHandler().executeReadList("GetNetworksByVfsConfigId", 
createGuidMapper(),
+                createVfsConfigIdParameter(vfsConfigId)));
+    }
+
+    @Override
+    public void addNetwork(Guid vfsConfigId, Guid networkId) {
+        getCallsHandler().executeModification("InsertvfsConfigNetwork",
+                createNetworkParametersMapper(vfsConfigId, networkId));
+    }
+
+    private void massNetworksUpdate(Guid vfsConfigId, Set<Guid> networks) {
+        List<MapSqlParameterSource> executions = new 
ArrayList<>(networks.size());
+        for (Guid networkId : networks) {
+            executions.add(createNetworkParametersMapper(vfsConfigId, 
networkId));
+        }
+
+        getCallsHandler().executeStoredProcAsBatch("InsertvfsConfigNetwork", 
executions);
+    }
+
+    @Override
+    public void removeNetwork(Guid vfsConfigId, Guid networkId) {
+        getCallsHandler().executeModification("DeletevfsConfigNetwork",
+                createNetworkParametersMapper(vfsConfigId, networkId));
+    }
+
+    private void removeAllNetworksByVfsConfigId(Guid vfsConfigId) {
+        MapSqlParameterSource parameterSource = 
createVfsConfigIdParameter(vfsConfigId);
+        getCallsHandler().executeModification("DeleteAllvfsConfigNetworks", 
parameterSource);
+    }
+
+    private MapSqlParameterSource createNetworkParametersMapper(Guid 
vfsConfigId, Guid networkId) {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
+                .addValue("vfs_config_id", vfsConfigId)
+                .addValue("network_id", networkId);
+        return parameterSource;
+    }
+
+    // VfsConfigLabels
+
+    Set<String> getLabelsByVfsConfigId(Guid vfsConfigId) {
+        return new 
HashSet<String>(getCallsHandler().executeReadList("GetLabelsByVfsConfigId",
+                new SingleColumnRowMapper<String>(),
+                createVfsConfigIdParameter(vfsConfigId)));
+    }
+
+    @Override
+    public void addLabel(Guid vfsConfigId, String label) {
+        getCallsHandler().executeModification("InsertvfsConfigLabel", 
createLabelParametersMapper(vfsConfigId, label));
+    }
+
+    private void massLabelsUpdate(Guid vfsConfigId, Set<String> labels) {
+        List<MapSqlParameterSource> executions = new 
ArrayList<>(labels.size());
+        for (String label : labels) {
+            executions.add(createLabelParametersMapper(vfsConfigId, label));
+        }
+
+        getCallsHandler().executeStoredProcAsBatch("InsertvfsConfigLabel", 
executions);
+    }
+
+    @Override
+    public void removeLabel(Guid vfsConfigId, String label) {
+        getCallsHandler().executeModification("DeletevfsConfigLabel", 
createLabelParametersMapper(vfsConfigId, label));
+    }
+
+    private void removeAllLabelsByVfsConfigId(Guid vfsConfigId) {
+        MapSqlParameterSource parameterSource = 
createVfsConfigIdParameter(vfsConfigId);
+        getCallsHandler().executeModification("DeleteAllvfsConfigLabels", 
parameterSource);
+    }
+
+    private MapSqlParameterSource createLabelParametersMapper(Guid 
vfsConfigId, String label) {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
+                .addValue("vfs_config_id", vfsConfigId)
+                .addValue("label", label);
+        return parameterSource;
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
index a6ff175..29adf68 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
@@ -433,7 +433,7 @@
      * <li>storage_pool_id: rhel6.iscsi 
(6d849ebf-755f-4552-ad09-9a090cda105d)</li>
      * </ul>
      */
-    protected static final Guid NETWORK_ENGINE_2 = new 
Guid("58d5c1c6-cb15-4832-b2a4-023770607189");
+    public static final Guid NETWORK_ENGINE_2 = new 
Guid("58d5c1c6-cb15-4832-b2a4-023770607189");
 
     /**
      * Predefined Network for testing with the following properties :
@@ -681,6 +681,7 @@
     public static final Guid CPU_PROFILE_1 = new 
Guid("fd81f1e1-785b-4579-ab75-1419ebb87052");
     public static final Guid CPU_PROFILE_2 = new 
Guid("fd81f1e1-785b-4579-ab75-1419ebb87053");
 
-    public static final Guid HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED = new 
Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c1");
-    public static final Guid HOST_NIC_VFS_CONFIG = new 
Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c2");
+    public static final Guid HOST_NIC_VFS_CONFIG = new 
Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c1");
+    public static final Guid HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_1 = 
new Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c2");
+    public static final Guid HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2 = 
new Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c3");
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoTest.java
index c66e5dd..003b90a 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/HostNicVfsConfigDaoTest.java
@@ -3,11 +3,19 @@
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.junit.Test;
 import org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig;
+import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dao.BaseDAOTestCase;
 import org.ovirt.engine.core.dao.FixturesTool;
@@ -15,7 +23,15 @@
 public class HostNicVfsConfigDaoTest extends BaseDAOTestCase {
     private HostNicVfsConfigDao dao;
 
-    private static final int NUM_OF_CONFIGS = 3;
+    // Map the vfsConfig id to the number of networks and labels it has
+    private static final Map<Guid, Pair<Integer, Integer>> EXPECTED_GUIDS;
+    static {
+        Map<Guid, Pair<Integer, Integer>> tmpMap = new HashMap<>();
+        tmpMap.put(new Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c1"), new 
Pair<>(0, 0));
+        tmpMap.put(new Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c2"), new 
Pair<>(2, 2));
+        tmpMap.put(new Guid("6b31bcc8-c6c3-4884-9a10-5f1f076f20c3"), new 
Pair<>(1, 3));
+        EXPECTED_GUIDS = Collections.unmodifiableMap(tmpMap);
+    }
 
     @Override
     public void setUp() throws Exception {
@@ -39,10 +55,23 @@
      */
     @Test
     public void testGetById() {
-        HostNicVfsConfig result = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED);
+        HostNicVfsConfig result = dao.get(FixturesTool.HOST_NIC_VFS_CONFIG);
 
         assertNotNull(result);
-        assertEquals(FixturesTool.HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED, 
result.getId());
+        assertEquals(FixturesTool.HOST_NIC_VFS_CONFIG, result.getId());
+        checkNetworksAndLabels(result, 0, 0);
+    }
+
+    /**
+     * Ensures that retrieving a hostNicVfsConfig with 
<code>allNetworkAllowed=false</code> by id works as expected.
+     */
+    @Test
+    public void testGetByIdNotAllNetworksAllowed() {
+        HostNicVfsConfig result = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_1);
+
+        assertNotNull(result);
+        
assertEquals(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_1, 
result.getId());
+        checkNetworksAndLabels(result, 2, 2);
     }
 
     /**
@@ -53,15 +82,32 @@
         List<HostNicVfsConfig> result = dao.getAll();
 
         assertNotNull(result);
-        assertEquals(NUM_OF_CONFIGS, result.size());
+        assertEquals(EXPECTED_GUIDS.size(), result.size());
+
+        for (HostNicVfsConfig vfsConfig : result) {
+            assertTrue(EXPECTED_GUIDS.containsKey(vfsConfig.getId()));
+            Pair<Integer, Integer> expectedConfig = 
EXPECTED_GUIDS.get(vfsConfig.getId());
+            checkNetworksAndLabels(vfsConfig, expectedConfig.getFirst(), 
expectedConfig.getSecond());
+        }
     }
 
     /**
-     * Ensures that saving a hostNicVfsConfig works as expected.
+     * Ensures that saving a hostNicVfsConfig works as expected. No network 
and labels are added.
      */
     @Test
     public void testSave() {
+        commonSave(true);
+    }
 
+    /**
+     * Ensures that saving a hostNicVfsConfig works as expected. Network and 
labels are added.
+     */
+    @Test
+    public void testSaveAddNetworksAndLabels() {
+        commonSave(false);
+    }
+
+    private void commonSave(boolean allNetworksAllowed) {
         HostNicVfsConfig newConfig = new HostNicVfsConfig();
 
         newConfig.setId(Guid.newGuid());
@@ -69,7 +115,13 @@
         newConfig.setMaxNumOfVfs(10);
         newConfig.setNumOfVfs(10);
         newConfig.setNumOfFreeVfs(10);
-        newConfig.setAllNetworksAllowed(true);
+
+        newConfig.setAllNetworksAllowed(allNetworksAllowed);
+
+        if (!allNetworksAllowed) {
+            addNetworks(newConfig);
+            addLabels(newConfig);
+        }
 
         dao.save(newConfig);
 
@@ -80,24 +132,79 @@
     }
 
     /**
-     * Ensures updating a hostNicVfsConfig works as expected.
+     * Ensures that saving a hostNicVfsConfig works as expected. 
AllNetworkAllowed is true before and after the update.
      */
     @Test
     public void testUpdate() {
-        HostNicVfsConfig before = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED);
+        commonUpdate(FixturesTool.HOST_NIC_VFS_CONFIG, true);
+    }
+
+    /**
+     * Ensures that saving a hostNicVfsConfig works as expected. 
AllNetworkAllowed is true before the update and false
+     * after the update.
+     */
+    @Test
+    public void testUpdateAddNetworkAndLabel() {
+        commonUpdate(FixturesTool.HOST_NIC_VFS_CONFIG, false);
+    }
+
+    /**
+     * Ensures that saving a hostNicVfsConfig works as expected. 
AllNetworkAllowed is false before the update and true
+     * after the update.
+     */
+    @Test
+    public void testUpdateRemoveNetworksAndLabels() {
+        
commonUpdate(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, true);
+    }
+
+    /**
+     * Ensures that saving a hostNicVfsConfig works as expected. 
AllNetworkAllowed is false before the update and false
+     * after the update. The networks and the labels are modified.
+     */
+    @Test
+    public void testUpdateModifyNetworkAndLabels() {
+        
commonUpdate(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, 
false);
+    }
+
+    private void commonUpdate(Guid vfsConfigId, boolean allNetworksAllowed) {
+        HostNicVfsConfig before = dao.get(vfsConfigId);
 
         before.setNicId(FixturesTool.VDS_NETWORK_INTERFACE2);
         before.setMaxNumOfVfs(before.getMaxNumOfVfs() + 1);
         before.setNumOfVfs(before.getNumOfVfs() + 1);
         before.setNumOfFreeVfs(before.getNumOfFreeVfs() + 1);
-        before.setAllNetworksAllowed(!before.isAllNetworksAllowed());
+        before.setAllNetworksAllowed(allNetworksAllowed);
+
+        if (allNetworksAllowed) {
+            before.setNetworks(new HashSet<Guid>());
+            before.setLabels(new HashSet<String>());
+        } else {
+            addNetworks(before);
+            addLabels(before);
+        }
 
         dao.update(before);
 
-        HostNicVfsConfig after = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED);
+        HostNicVfsConfig after = dao.get(vfsConfigId);
 
         assertNotNull(after);
         assertHostNicVfsConfigEquals(before, after);
+    }
+
+    private void addLabels(HostNicVfsConfig newConfig) {
+        Set<String> labels = new HashSet<>();
+        labels.add("lbl1");
+        labels.add("lbl2");
+        labels.add("lbl3");
+        labels.add("lbl4");
+        newConfig.setLabels(labels);
+    }
+
+    private void addNetworks(HostNicVfsConfig newConfig) {
+        Set<Guid> networks = new HashSet<>();
+        networks.add(FixturesTool.NETWORK_ENGINE);
+        networks.add(FixturesTool.NETWORK_ENGINE_2);
+        newConfig.setNetworks(networks);
     }
 
     /**
@@ -105,23 +212,120 @@
      */
     @Test
     public void testRemove() {
-        HostNicVfsConfig result = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED);
+        commonRemove(FixturesTool.HOST_NIC_VFS_CONFIG);
+    }
+
+    /**
+     * Ensures that removing a hostNicVfsConfig works as expected. The deleted 
vfsConfig has networks and labels, the
+     * test makes sure they were deleted as well.
+     */
+    @Test
+    public void testRemoveWithNetworkAndLabels() {
+        
commonRemove(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_1);
+
+        Set<Guid> networks =
+                ((HostNicVfsConfigDaoDbFacadeImpl) 
dao).getNetworksByVfsConfigId(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_1);
+        Set<String> labels =
+                ((HostNicVfsConfigDaoDbFacadeImpl) 
dao).getLabelsByVfsConfigId(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_1);
+
+        checkNetworks(networks, 0);
+        checkLabels(labels, 0);
+    }
+
+    private void commonRemove(Guid id) {
+        HostNicVfsConfig result = dao.get(id);
 
         assertNotNull(result);
 
         dao.remove(result.getId());
 
-        result = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_ALL_NETWORKS_ALLOWED);
+        result = dao.get(id);
 
         assertNull(result);
     }
 
+    private void checkNetworks(HostNicVfsConfig vfsConfig, int numOfNetworks) {
+        checkNetworks(vfsConfig.getNetworks(), numOfNetworks);
+    }
+
+    private void checkNetworks(Set<Guid> networks, int numOfNetworks) {
+        assertEquals("num of networks", numOfNetworks, getListSize(networks));
+    }
+
+    private void checkLabels(HostNicVfsConfig vfsConfig, int numOfLabels) {
+        checkLabels(vfsConfig.getLabels(), numOfLabels);
+    }
+
+    private void checkLabels(Set<String> labels, int numOfLabels) {
+        assertEquals("num of labels", numOfLabels, getListSize(labels));
+    }
+
+    private int getListSize(Collection<?> collection) {
+        return collection == null ? 0 : collection.size();
+    }
+
+    private void checkNetworksAndLabels(HostNicVfsConfig result, int 
numOfNetworks, int numOfLabels) {
+        checkLabels(result, numOfLabels);
+        checkNetworks(result, numOfNetworks);
+    }
+
     private void assertHostNicVfsConfigEquals(HostNicVfsConfig config1, 
HostNicVfsConfig config2) {
-        assertEquals(config1.getId(), config2.getId());
-        assertEquals(config1.getNicId(), config2.getNicId());
-        assertEquals(config1.getMaxNumOfVfs(), config2.getMaxNumOfVfs());
-        assertEquals(config1.getNumOfVfs(), config2.getNumOfVfs());
-        assertEquals(config1.getNumOfFreeVfs(), config2.getNumOfFreeVfs());
-        assertEquals(config1.isAllNetworksAllowed(), 
config2.isAllNetworksAllowed());
+        assertEquals("id", config1.getId(), config2.getId());
+        assertEquals("nic_id", config1.getNicId(), config2.getNicId());
+        assertEquals("max_num_of_vfs", config1.getMaxNumOfVfs(), 
config2.getMaxNumOfVfs());
+        assertEquals("num_of_vfs", config1.getNumOfVfs(), 
config2.getNumOfVfs());
+        assertEquals("num_of_free_vfs", config1.getNumOfFreeVfs(), 
config2.getNumOfFreeVfs());
+        assertEquals("all_networks_allowed", config1.isAllNetworksAllowed(), 
config2.isAllNetworksAllowed());
+        assertEquals("networks", config1.getNetworks(), config2.getNetworks());
+        assertEquals("labels", config1.getLabels(), config2.getLabels());
+    }
+
+    @Test
+    public void testAddNetwork() {
+        HostNicVfsConfig vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkNetworks(vfsConfig, 1);
+
+        
dao.addNetwork(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, 
FixturesTool.NETWORK_ENGINE_2);
+
+        vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkNetworks(vfsConfig, 2);
+    }
+
+    @Test
+    public void testRemoveNetwork() {
+        HostNicVfsConfig vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkNetworks(vfsConfig, 1);
+
+        
dao.removeNetwork(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, 
vfsConfig.getNetworks()
+                .iterator()
+                .next());
+
+        vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkNetworks(vfsConfig, 0);
+    }
+
+    @Test
+    public void testAddLabel() {
+        HostNicVfsConfig vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkLabels(vfsConfig, 3);
+
+        String label = "newLbl";
+        
dao.addLabel(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, 
label);
+
+        vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkLabels(vfsConfig, 4);
+    }
+
+    @Test
+    public void testRemoveLabel() {
+        HostNicVfsConfig vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkLabels(vfsConfig, 3);
+
+        
dao.removeLabel(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2, 
vfsConfig.getLabels()
+                .iterator()
+                .next());
+
+        vfsConfig = 
dao.get(FixturesTool.HOST_NIC_VFS_CONFIG_NOT_ALL_NETWORKS_ALLOWED_2);
+        checkLabels(vfsConfig, 2);
     }
 }
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index e66852b..6da0b8b 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -7403,6 +7403,7 @@
             <value>NOTSTARTED</value>
         </row>
      </table>
+
      <table name="host_nic_vfs_config">
         <column>id</column>
         <column>nic_id</column>
@@ -7428,11 +7429,51 @@
         </row>
         <row>
             <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c3</value>
-            <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9dd</value>
+            <value>ba31682e-6ae7-4f9d-8c6f-04c93acca9de</value>
             <value>20</value>
             <value>20</value>
             <value>20</value>
             <value>false</value>
         </row>
      </table>
+     <table name="vfs_config_networks">
+        <column>vfs_config_id</column>
+        <column>network_id</column>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c2</value>
+            <value>58d5c1c6-cb15-4832-b2a4-023770607188</value>
+        </row>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c2</value>
+            <value>58d5c1c6-cb15-4832-b2a4-023770607189</value>
+        </row>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c3</value>
+            <value>58d5c1c6-cb15-4832-b2a4-023770607188</value>
+        </row>
+     </table>
+     <table name="vfs_config_labels">
+        <column>vfs_config_id</column>
+        <column>label</column>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c2</value>
+            <value>label1</value>
+        </row>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c2</value>
+            <value>label2</value>
+        </row>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c3</value>
+            <value>label1</value>
+        </row>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c3</value>
+            <value>label2</value>
+        </row>
+        <row>
+            <value>6b31bcc8-c6c3-4884-9a10-5f1f076f20c3</value>
+            <value>label3</value>
+        </row>
+     </table>
 </dataset>
diff --git a/packaging/dbscripts/network_sp.sql 
b/packaging/dbscripts/network_sp.sql
index 7bb5830..6ef94f4 100644
--- a/packaging/dbscripts/network_sp.sql
+++ b/packaging/dbscripts/network_sp.sql
@@ -1374,3 +1374,86 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+----------------------------------------------------------------------
+--  vfsConfigNetworks
+----------------------------------------------------------------------
+
+Create or replace FUNCTION InsertvfsConfigNetwork(v_vfs_config_id UUID,
+       v_network_id  UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+INSERT INTO vfs_config_networks(vfs_config_id, network_id)
+       VALUES(v_vfs_config_id, v_network_id);
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION DeletevfsConfigNetwork(v_vfs_config_id UUID,
+       v_network_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+   DELETE FROM vfs_config_networks
+   WHERE vfs_config_id = v_vfs_config_id and network_id = v_network_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION DeleteAllvfsConfigNetworks(v_vfs_config_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+   DELETE FROM vfs_config_networks
+   WHERE vfs_config_id = v_vfs_config_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION GetNetworksByVfsConfigId(v_vfs_config_id UUID) 
RETURNS SETOF UUID STABLE
+AS $procedure$
+BEGIN
+   RETURN QUERY SELECT network_id
+   FROM vfs_config_networks
+   WHERE vfs_config_id = v_vfs_config_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+----------------------------------------------------------------------
+--  vfsConfigLabels
+----------------------------------------------------------------------
+
+Create or replace FUNCTION InsertvfsConfigLabel(v_vfs_config_id UUID,
+       v_label TEXT)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+INSERT INTO vfs_config_labels(vfs_config_id, label)
+       VALUES(v_vfs_config_id, v_label);
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION DeletevfsConfigLabel(v_vfs_config_id UUID,
+       v_label TEXT)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+   DELETE FROM vfs_config_labels
+   WHERE vfs_config_id = v_vfs_config_id and label = v_label;
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION DeleteAllvfsConfigLabels(v_vfs_config_id UUID)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+   DELETE FROM vfs_config_labels
+   WHERE vfs_config_id = v_vfs_config_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+Create or replace FUNCTION GetLabelsByVfsConfigId(v_vfs_config_id UUID) 
RETURNS SETOF TEXT STABLE
+AS $procedure$
+BEGIN
+   RETURN QUERY SELECT label
+   FROM vfs_config_labels
+   WHERE vfs_config_id = v_vfs_config_id;
+END; $procedure$
+LANGUAGE plpgsql;
diff --git 
a/packaging/dbscripts/upgrade/03_06_0590_add_host_nic_vfs_config_table.sql 
b/packaging/dbscripts/upgrade/03_06_0590_add_host_nic_vfs_config_table.sql
index 13c0d17..852c42f 100644
--- a/packaging/dbscripts/upgrade/03_06_0590_add_host_nic_vfs_config_table.sql
+++ b/packaging/dbscripts/upgrade/03_06_0590_add_host_nic_vfs_config_table.sql
@@ -11,7 +11,7 @@
   num_of_free_vfs INTEGER NOT NULL,
   all_networks_allowed BOOLEAN NOT NULL,
   _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
-  _update_date TIMESTAMP WITH TIME ZONE default NULL,
+  _update_date TIMESTAMP WITH TIME ZONE default NULL
 );
 
 
diff --git 
a/packaging/dbscripts/upgrade/03_06_0600_add_vfs_config_networks_and_labels_tables.sql
 
b/packaging/dbscripts/upgrade/03_06_0600_add_vfs_config_networks_and_labels_tables.sql
new file mode 100644
index 0000000..b00827f
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_06_0600_add_vfs_config_networks_and_labels_tables.sql
@@ -0,0 +1,35 @@
+-- ----------------------------------------------------------------------
+--  table vfs_config_networks 
+-- ----------------------------------------------------------------------
+
+CREATE TABLE vfs_config_networks
+(
+  vfs_config_id UUID NOT NULL,
+  network_id UUID NOT NULL,
+  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
+  _update_date TIMESTAMP WITH TIME ZONE default NULL
+);
+
+
+select fn_db_create_constraint('vfs_config_networks', 
'vfs_config_networks_pk', 'PRIMARY KEY(vfs_config_id, network_id)');
+select fn_db_create_constraint('vfs_config_networks', 
'vfs_config_networks_id_fk', 'FOREIGN KEY(vfs_config_id) REFERENCES 
host_nic_vfs_config(id) ON DELETE CASCADE');
+select fn_db_create_constraint('vfs_config_networks', 
'vfs_config_networks_network_fk', 'FOREIGN KEY(network_id) REFERENCES 
network(id) ON DELETE CASCADE');
+select fn_db_create_index('IDX_vfs_config_networks_vfs_config_id', 
'vfs_config_networks', 'vfs_config_id', '');
+
+
+-- ----------------------------------------------------------------------
+--  table vfs_config_labels
+-- ----------------------------------------------------------------------
+
+CREATE TABLE vfs_config_labels
+(
+  vfs_config_id UUID NOT NULL,
+  label TEXT NOT NULL,
+  _create_date TIMESTAMP WITH TIME ZONE default LOCALTIMESTAMP,
+  _update_date TIMESTAMP WITH TIME ZONE default NULL
+);
+
+
+select fn_db_create_constraint('vfs_config_labels', 'vfs_config_labels_pk', 
'PRIMARY KEY(vfs_config_id, label)');
+select fn_db_create_constraint('vfs_config_labels', 'vfs_config_labels_id_fk', 
'FOREIGN KEY(vfs_config_id) REFERENCES host_nic_vfs_config(id) ON DELETE 
CASCADE');
+select fn_db_create_index('IDX_vfs_config_labels_vfs_config_id', 
'vfs_config_labels', 'vfs_config_id', '');


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

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

Reply via email to