Moti Asayag has uploaded a new change for review.

Change subject: engine: Introduce VnicProfileView and its DAO
......................................................................

engine: Introduce VnicProfileView and its DAO

The VnicProfileView is an extension of the VnicProfile
entity which contains further information required by
the UI.

Change-Id: Ib48832f29d0150d23d68c782be53d521628247e1
Signed-off-by: Moti Asayag <[email protected]>
---
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/FixturesTool.java
A 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
M 
frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/network_sp.sql
10 files changed, 223 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/17018/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
new file mode 100644
index 0000000..3992266
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/network/VnicProfileView.java
@@ -0,0 +1,83 @@
+package org.ovirt.engine.core.common.businessentities.network;
+
+import org.ovirt.engine.core.compat.Version;
+
+
+public class VnicProfileView extends VnicProfile {
+
+    private static final long serialVersionUID = -7873671947250939737L;
+    private String networkName;
+    private String dataCenterName;
+    private Version compatibilityVersion;
+
+    public String getNetworkName() {
+        return networkName;
+    }
+
+    public void setNetworkName(String networkName) {
+        this.networkName = networkName;
+    }
+
+    public String getDataCenterName() {
+        return dataCenterName;
+    }
+
+    public void setDataCenterName(String dataCenterName) {
+        this.dataCenterName = dataCenterName;
+    }
+
+    public Version getCompatibilityVersion() {
+        return compatibilityVersion;
+    }
+
+    public void setCompatibilityVersion(Version compatibilityVersion) {
+        this.compatibilityVersion = compatibilityVersion;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = super.hashCode();
+        result = prime * result + ((getCompatibilityVersion() == null) ? 0 : 
getCompatibilityVersion().hashCode());
+        result = prime * result + ((getDataCenterName() == null) ? 0 : 
getDataCenterName().hashCode());
+        result = prime * result + ((getNetworkName() == null) ? 0 : 
getNetworkName().hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (!super.equals(obj)) {
+            return false;
+        }
+        if (!(obj instanceof VnicProfileView)) {
+            return false;
+        }
+        VnicProfileView other = (VnicProfileView) obj;
+        if (getCompatibilityVersion() == null) {
+            if (other.getCompatibilityVersion() != null) {
+                return false;
+            }
+        } else if 
(!getCompatibilityVersion().equals(other.getCompatibilityVersion())) {
+            return false;
+        }
+        if (getDataCenterName() == null) {
+            if (other.getDataCenterName() != null) {
+                return false;
+            }
+        } else if (!getDataCenterName().equals(other.getDataCenterName())) {
+            return false;
+        }
+        if (getNetworkName() == null) {
+            if (other.getNetworkName() != null) {
+                return false;
+            }
+        } else if (!getNetworkName().equals(other.getNetworkName())) {
+            return false;
+        }
+        return true;
+    }
+}
+
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
index 249294e..1f302c9 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
@@ -109,6 +109,7 @@
 import org.ovirt.engine.core.dao.network.VmNetworkInterfaceDao;
 import org.ovirt.engine.core.dao.network.VmNetworkStatisticsDao;
 import org.ovirt.engine.core.dao.network.VnicProfileDao;
+import org.ovirt.engine.core.dao.network.VnicProfileViewDao;
 import org.ovirt.engine.core.dao.provider.ProviderDao;
 import org.ovirt.engine.core.dao.scheduling.ClusterPolicyDao;
 import org.ovirt.engine.core.dao.scheduling.PolicyUnitDao;
@@ -931,4 +932,13 @@
     public VnicProfileDao getVnicProfileDao() {
         return getDao(VnicProfileDao.class);
     }
+
+    /**
+     * Returns the singleton instance of {@link VnicProfileViewDao}.
+     *
+     * @return the dao
+     */
+    public VnicProfileViewDao getVnicProfileViewDao() {
+        return getDao(VnicProfileViewDao.class);
+    }
 }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
new file mode 100644
index 0000000..c7d8e7b
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDao.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.core.dao.network;
+
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.network.VnicProfileView;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.DAO;
+
+public interface VnicProfileViewDao extends DAO {
+
+    /**
+     * Retrieves all vnic profiles for the given data center.
+     *
+     * @param id
+     *            the data center's ID
+     * @return the list of networks
+     */
+    List<VnicProfileView> getAllForDataCenter(Guid id);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
new file mode 100644
index 0000000..56a2191
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoDbFacadeImpl.java
@@ -0,0 +1,40 @@
+package org.ovirt.engine.core.dao.network;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.List;
+
+import org.ovirt.engine.core.common.businessentities.network.VnicProfileView;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.compat.Version;
+import org.ovirt.engine.core.dao.BaseDAODbFacade;
+import 
org.ovirt.engine.core.dao.network.VnicProfileDaoDbFacadeImpl.VnicProfileRowMapperBase;
+
+public class VnicProfileViewDaoDbFacadeImpl extends BaseDAODbFacade implements 
VnicProfileViewDao {
+
+    @Override
+    public List<VnicProfileView> getAllForDataCenter(Guid id) {
+        return 
getCallsHandler().executeReadList("GetVnicProfileViewsByDataCenterId",
+                VnicProfileViewRowMapper.INSTANCE,
+                getCustomMapSqlParameterSource().addValue("id", id));
+    }
+
+    private static class VnicProfileViewRowMapper extends 
VnicProfileRowMapperBase<VnicProfileView> {
+
+        public static final VnicProfileViewRowMapper INSTANCE = new 
VnicProfileViewRowMapper();
+
+        @Override
+        public VnicProfileView mapRow(ResultSet rs, int rowNum) throws 
SQLException {
+            VnicProfileView entity = super.mapRow(rs, rowNum);
+            entity.setNetworkName(rs.getString("network_name"));
+            entity.setDataCenterName(rs.getString("data_center_name"));
+            entity.setCompatibilityVersion(new 
Version(rs.getString("compatibility_version")));
+            return entity;
+        }
+
+        @Override
+        protected VnicProfileView createVnicProfileEntity() {
+            return new VnicProfileView();
+        }
+    }
+}
diff --git 
a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties 
b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
index a3d5c0d..e6312a8 100644
--- a/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
+++ b/backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
@@ -9,6 +9,7 @@
 InterfaceDao=org.ovirt.engine.core.dao.network.InterfaceDaoDbFacadeImpl
 
VmNetworkInterfaceDao=org.ovirt.engine.core.dao.network.VmNetworkInterfaceDaoDbFacadeImpl
 VnicProfileDao=org.ovirt.engine.core.dao.network.VnicProfileDaoDbFacadeImpl
+VnicProfileViewDao=org.ovirt.engine.core.dao.network.VnicProfileViewDaoDbFacadeImpl
 
VmNetworkStatisticsDao=org.ovirt.engine.core.dao.network.VmNetworkStatisticsDaoDbFacadeImpl
 LunDAO=org.ovirt.engine.core.dao.LunDAODbFacadeImpl
 RoleGroupMapDAO=org.ovirt.engine.core.dao.RoleGroupMapDAODbFacadeImpl
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 ac9585f..6e5c447 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
@@ -417,4 +417,11 @@
      */
     public static final Guid CLUSTER_POLICY_EVEN_DISTRIBUTION = new 
Guid("20d25257-b4bd-4589-92a6-c4c5c5d3fd1a");
     public static final Guid POLICY_UNIT_MIGRATION = new 
Guid("84e6ddee-ab0d-42dd-82f0-c297779db5e5");
+
+    /**
+     * For vnic profile views
+     */
+    public static final Guid DATA_CENTER = new 
Guid("6d849ebf-755f-4552-ad09-9a090cda105d");
+
+    public static final String DATA_CENTER_NAME = "rhel6.iscsi";
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
new file mode 100644
index 0000000..6be7a69
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/network/VnicProfileViewDaoTest.java
@@ -0,0 +1,36 @@
+package org.ovirt.engine.core.dao.network;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.network.VnicProfileView;
+import org.ovirt.engine.core.dao.BaseDAOTestCase;
+import org.ovirt.engine.core.dao.FixturesTool;
+
+public class VnicProfileViewDaoTest extends BaseDAOTestCase {
+    private VnicProfileViewDao dao;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        dao = dbFacade.getVnicProfileViewDao();
+    }
+
+    /**
+     * Ensures the right set of vnic profiles is returned for the given data 
center.
+     */
+    @Test
+    public void testGetAllForProvider() {
+        List<VnicProfileView> result = 
dao.getAllForDataCenter(FixturesTool.DATA_CENTER);
+        assertNotNull(result);
+        assertFalse(result.isEmpty());
+
+        for (VnicProfileView profile : result) {
+            assertEquals(FixturesTool.DATA_CENTER_NAME, 
profile.getDataCenterName());
+        }
+    }
+}
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 eda78fa..d4a1f46 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
@@ -63,6 +63,7 @@
                <include 
name="common/businessentities/network/VmNetworkInterface.java" />
                <include 
name="common/businessentities/network/VmNetworkStatistics.java" />
                <include 
name="common/businessentities/network/VdsNetworkStatistics.java" />
+               <include 
name="common/businessentities/network/VnicProfileView.java" />
 
                <include name="common/businessentities/Commented.java" />
                <include name="common/businessentities/IVdcQueryable.java" />
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index 2858d4e..0e5d256 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -1127,6 +1127,22 @@
 INNER JOIN storage_pool ON network.storage_pool_id = storage_pool.id
 LEFT JOIN providers ON network.provider_network_provider_id = providers.id;
 
+
+CREATE OR REPLACE VIEW vnic_profiles_view
+AS
+SELECT vnic_profiles.id AS id,
+       vnic_profiles.name AS name,
+       vnic_profiles.network_id as network_id,
+       vnic_profiles.port_mirroring as port_mirroring,
+       vnic_profiles.custom_properties as custom_properties,
+       network.name as network_name,
+       storage_pool.name as data_center_name,
+       storage_pool.compatibility_version as compatibility_version
+FROM vnic_profiles
+INNER JOIN network ON vnic_profiles.network_id = network.id
+INNER JOIN storage_pool ON network.storage_pool_id = storage_pool.id;
+
+
 ----------------------------------------------
 -- Query Permissions
 ----------------------------------------------
diff --git a/packaging/dbscripts/network_sp.sql 
b/packaging/dbscripts/network_sp.sql
index 453272b..7e03778 100644
--- a/packaging/dbscripts/network_sp.sql
+++ b/packaging/dbscripts/network_sp.sql
@@ -1122,4 +1122,13 @@
 LANGUAGE plpgsql;
 
 
-
+Create or replace FUNCTION GetVnicProfileViewsByDataCenterId(v_id UUID)
+RETURNS SETOF network_view
+AS $procedure$
+BEGIN
+    RETURN QUERY
+    SELECT *
+    FROM   vnic_profiles_view
+    WHERE  data_center_id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;


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

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