Kanagaraj M has uploaded a new change for review.

Change subject: engine: adding vds_gluster table and dao operations
......................................................................

engine: adding vds_gluster table and dao operations

A new table 'vds_gluster' is added. Currently this will
store the gluster UUID of the host and the table has a
reference field(vds_id) to vds_static table.

All the operations on this table like insert, update and
remover are implemented

Change-Id: I04ba0a7bf1eaa964db731cdfa24ab6875e0b1513
Signed-off-by: Kanagaraj M <kmayi...@redhat.com>
---
A backend/manager/dbscripts/upgrade/03_03_0040_add_vds_gluster_table.sql
A backend/manager/dbscripts/vds_gluster_sp.sql
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/VdsGluster.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/gluster/VdsGlusterDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoDbFacadeImpl.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/gluster/VdsGlusterDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
10 files changed, 432 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/63/14063/1

diff --git 
a/backend/manager/dbscripts/upgrade/03_03_0040_add_vds_gluster_table.sql 
b/backend/manager/dbscripts/upgrade/03_03_0040_add_vds_gluster_table.sql
new file mode 100644
index 0000000..161812b
--- /dev/null
+++ b/backend/manager/dbscripts/upgrade/03_03_0040_add_vds_gluster_table.sql
@@ -0,0 +1,18 @@
+Create or replace FUNCTION fn_add_vds_gluster_table()
+RETURNS void
+AS $function$
+BEGIN
+    CREATE TABLE vds_gluster
+    (
+      id UUID NOT NULL,
+      vds_id UUID NOT NULL references vds_static(vds_id) ON DELETE CASCADE,
+      host_uuid UUID NOT NULL,
+      CONSTRAINT pk_vds_gluster PRIMARY KEY(id)
+    ) WITH OIDS;
+    CREATE INDEX IDX_vds_gluster_vds_id ON vds_gluster(vds_id);
+    CREATE UNIQUE INDEX IDX_vds_gluster_unique ON vds_gluster(vds_id, 
host_uuid);
+END; $function$
+LANGUAGE plpgsql;
+
+select fn_add_vds_gluster_table();
+drop function fn_add_vds_gluster_table();
diff --git a/backend/manager/dbscripts/vds_gluster_sp.sql 
b/backend/manager/dbscripts/vds_gluster_sp.sql
new file mode 100644
index 0000000..ae778a0
--- /dev/null
+++ b/backend/manager/dbscripts/vds_gluster_sp.sql
@@ -0,0 +1,111 @@
+/*--------------------------------------------------------------
+Stored procedures for database operations on vds_gluster table
+--------------------------------------------------------------*/
+
+Create or replace FUNCTION InsertVdsGluster(v_id UUID,
+                                            v_vds_id UUID,
+                                            v_host_uuid UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    INSERT INTO vds_gluster(id, vds_id, host_uuid)
+    VALUES (v_id, v_vds_id, v_host_uuid);
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION GetVdsGlusterById(v_id UUID)
+RETURNS SETOF vds_gluster
+AS $procedure$
+BEGIN
+    RETURN QUERY SELECT id, vds_id, host_uuid
+    FROM vds_gluster
+    WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION GetVdsGlusterByVdsId(v_vds_id UUID)
+RETURNS SETOF vds_gluster
+AS $procedure$
+BEGIN
+    RETURN QUERY SELECT id, vds_id, host_uuid
+    FROM vds_gluster
+    WHERE vds_id = v_vds_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION DeleteVdsGlusterById(v_id UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    DELETE FROM vds_gluster
+    WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION DeleteVdsGlusterByIds(v_ids TEXT)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    DELETE FROM vds_gluster
+    WHERE id in (select * from fnSplitterUuid(v_ids));
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION DeleteVdsGlusterByVdsId(v_vds_id UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    DELETE FROM vds_gluster
+    WHERE vds_id = v_vds_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION DeleteVdsGlusterByHostUUID(v_host_uuid UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    DELETE FROM vds_gluster
+    WHERE host_uuid = v_host_uuid;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION UpdateVdsGluster(v_id UUID,
+                                            v_vds_id UUID,
+                                            v_host_uuid UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    UPDATE vds_gluster
+    SET vds_id = v_vds_id,
+        host_uuid = v_host_uuid
+    WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+
+Create or replace FUNCTION UpdateVdsGlusterHostUUID(v_vds_id UUID,
+                                                    v_host_uuid UUID)
+RETURNS VOID
+AS $procedure$
+BEGIN
+    UPDATE vds_gluster
+    SET host_uuid = v_host_uuid
+    WHERE vds_id = v_vds_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/VdsGluster.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/VdsGluster.java
new file mode 100644
index 0000000..3520b1a
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/VdsGluster.java
@@ -0,0 +1,72 @@
+package org.ovirt.engine.core.common.businessentities.gluster;
+
+import org.ovirt.engine.core.common.businessentities.BusinessEntity;
+import org.ovirt.engine.core.common.utils.ObjectUtils;
+import org.ovirt.engine.core.compat.Guid;
+
+public class VdsGluster implements BusinessEntity<Guid> {
+
+    private static final long serialVersionUID = -1425566208615075937L;
+
+    private Guid id;
+
+    private Guid vdsId;
+
+    private Guid hostUuid;
+
+    public VdsGluster() {
+        id = Guid.NewGuid();
+    }
+
+    @Override
+    public Guid getId() {
+        return id;
+    }
+
+    @Override
+    public void setId(Guid id) {
+        this.id = id;
+    }
+
+    public Guid getVdsId() {
+        return vdsId;
+    }
+
+    public void setVdsId(Guid vdsId) {
+        this.vdsId = vdsId;
+    }
+
+    public Guid getHostUuid() {
+        return hostUuid;
+    }
+
+    public void setHostUuid(Guid hostUuid) {
+        this.hostUuid = hostUuid;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + getId().hashCode();
+        result = prime * result + ((vdsId == null) ? 0 : vdsId.hashCode());
+        result = prime * result + ((hostUuid == null) ? 0 : 
hostUuid.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof VdsGluster)) {
+            return false;
+        }
+
+        VdsGluster entity = (VdsGluster) obj;
+
+        if (!(ObjectUtils.objectsEqual(getId(), entity.getId())
+                && ObjectUtils.objectsEqual(vdsId, entity.getVdsId())
+                && ObjectUtils.objectsEqual(hostUuid, entity.getHostUuid()))) {
+            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 505aee1..2bf4206 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
@@ -98,6 +98,7 @@
 import org.ovirt.engine.core.dao.gluster.GlusterHooksDao;
 import org.ovirt.engine.core.dao.gluster.GlusterOptionDao;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
+import org.ovirt.engine.core.dao.gluster.VdsGlusterDao;
 import org.ovirt.engine.core.dao.network.InterfaceDao;
 import org.ovirt.engine.core.dao.network.NetworkClusterDao;
 import org.ovirt.engine.core.dao.network.NetworkDao;
@@ -874,6 +875,15 @@
         return getDao(GlusterHooksDao.class);
     }
 
+    /**
+     * Returns the singleton instance of {@link VdsGlusterDao}.
+     *
+     * @return the dao
+     */
+    public VdsGlusterDao getVdsGlusterDao() {
+        return getDao(VdsGlusterDao.class);
+    }
+
     public void setOnStartConnectionTimeout(int onStartConnectionTimeout) {
         this.onStartConnectionTimeout = onStartConnectionTimeout;
     }
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDao.java
new file mode 100644
index 0000000..a2225dc
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDao.java
@@ -0,0 +1,19 @@
+package org.ovirt.engine.core.dao.gluster;
+
+import org.ovirt.engine.core.common.businessentities.gluster.VdsGluster;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.DAO;
+import org.ovirt.engine.core.dao.MassOperationsDao;
+
+public interface VdsGlusterDao extends DAO, MassOperationsDao<VdsGluster, 
Guid> {
+
+    public void save(VdsGluster vdsGluster);
+
+    public VdsGluster getById(Guid id);
+
+    public VdsGluster getByVdsId(Guid vdsId);
+
+    public void remove(Guid id);
+
+    public void updateHostUuid(Guid vdsId, Guid hostUuid);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoDbFacadeImpl.java
new file mode 100644
index 0000000..4b8e56a
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoDbFacadeImpl.java
@@ -0,0 +1,88 @@
+package org.ovirt.engine.core.dao.gluster;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.core.common.businessentities.gluster.VdsGluster;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+public class VdsGlusterDaoDbFacadeImpl extends 
MassOperationsGenericDaoDbFacade<VdsGluster, Guid> implements VdsGlusterDao {
+
+    private static final RowMapper<VdsGluster> vdsGlusterRowMapper = new 
VdsGlusterRowMapper();
+
+    public VdsGlusterDaoDbFacadeImpl() {
+        super("VdsGluster");
+        setProcedureNameForGet("GetVdsGlusterById");
+    }
+
+    @Override
+    public void save(VdsGluster vdsGluster) {
+        getCallsHandler().executeModification("InsertVdsGluster", 
createFullParametersMapper(vdsGluster));
+    }
+
+    @Override
+    public VdsGluster getById(Guid id) {
+        return getCallsHandler().executeRead("GetVdsGlusterById", 
vdsGlusterRowMapper, createIdParameterMapper(id));
+    }
+
+    @Override
+    public VdsGluster getByVdsId(Guid vdsId) {
+        return getCallsHandler().executeRead("GetVdsGlusterByVdsId",
+                vdsGlusterRowMapper,
+                getCustomMapSqlParameterSource().addValue("vds_id", vdsId));
+    }
+
+    @Override
+    public void updateHostUuid(Guid vdsId, Guid hostUuid) {
+        getCallsHandler().executeModification("UpdateVdsGlusterHostUUID",
+                getCustomMapSqlParameterSource()
+                .addValue("vds_id", vdsId)
+                        .addValue("host_uuid", hostUuid));
+    }
+
+    @Override
+    public void remove(Guid id) {
+        getCallsHandler().executeModification("DeleteVdsGlusterById",
+                createIdParameterMapper(id));
+    }
+
+    @Override
+    public void removeAll(Collection<Guid> ids) {
+        getCallsHandler().executeModification("DeleteVdsGlusterByIds",
+                getCustomMapSqlParameterSource().addValue("ids", 
StringUtils.join(ids, ',')));
+    }
+
+    private static final class VdsGlusterRowMapper implements 
RowMapper<VdsGluster> {
+        @Override
+        public VdsGluster mapRow(ResultSet rs, int rowNum)
+                throws SQLException {
+            VdsGluster vdsGluster = new VdsGluster();
+            vdsGluster.setId(Guid.createGuidFromString(rs.getString("id")));
+            
vdsGluster.setVdsId(Guid.createGuidFromString(rs.getString("vds_id")));
+            
vdsGluster.setHostUuid(Guid.createGuidFromString(rs.getString("host_uuid")));
+            return vdsGluster;
+        }
+    }
+
+    @Override
+    protected MapSqlParameterSource createFullParametersMapper(VdsGluster 
entity) {
+        return createIdParameterMapper(entity.getId())
+                .addValue("vds_id", entity.getVdsId())
+                .addValue("host_uuid", entity.getHostUuid());
+    }
+
+    @Override
+    protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+        return getCustomMapSqlParameterSource().addValue("id", id);
+    }
+
+    @Override
+    protected RowMapper<VdsGluster> createEntityRowMapper() {
+        return vdsGlusterRowMapper;
+    }
+}
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 19de137..e5a4f2b 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
@@ -58,3 +58,4 @@
 NetworkViewDao=org.ovirt.engine.core.dao.network.NetworkViewDaoDbFacadeImpl
 
VmGuestAgentInterfaceDao=org.ovirt.engine.core.dao.VmGuestAgentInterfaceDaoDbFacadeImpl
 GlusterHooksDao=org.ovirt.engine.core.dao.gluster.GlusterHooksDaoDbFacadeImpl
+VdsGlusterDao=org.ovirt.engine.core.dao.gluster.VdsGlusterDaoDbFacadeImpl
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 59a2c25..7f829de 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
@@ -356,4 +356,18 @@
     public static final Guid NEW_HOOK_ID = new 
Guid("d2cb2f73-fab3-4a42-93f0-d5e4c069a43f");
 
     public static final Guid CLUSTER_ID = new 
Guid("ae956031-6be2-43d6-bb8f-5191c9253314");
+
+    /**
+     * Vds Gluster ID(s)
+     */
+
+    public static final Guid VDS_GLUSTER_ID1 = new 
Guid("d2cb2f73-fab3-4a42-93f0-d5e4c069a43e");
+
+    public static final Guid VDS_GLUSTER_ID2 = new 
Guid("d2cb2f73-fab3-4a42-93f0-d5e4c069a43f");
+
+    public static final Guid GLUSTER_HOST_UUID1 = new 
Guid("da9e2f09-2835-4530-9bf5-576c52b11941");
+
+    public static final Guid GLUSTER_HOST_UUID2 = new 
Guid("da9e2f09-2835-4530-9bf5-576c52b11942");
+
+    public static final Guid GLUSTER_HOST_UUID_NEW = new 
Guid("da9e2f09-2835-4530-9bf5-576c52b11943");
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoTest.java
new file mode 100644
index 0000000..e1a616b
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/VdsGlusterDaoTest.java
@@ -0,0 +1,83 @@
+package org.ovirt.engine.core.dao.gluster;
+
+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.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.ovirt.engine.core.common.businessentities.gluster.VdsGluster;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.BaseDAOTestCase;
+import org.ovirt.engine.core.dao.FixturesTool;
+
+
+public class VdsGlusterDaoTest extends BaseDAOTestCase {
+
+    private static final Guid SERVER_ID = new 
Guid("23f6d691-5dfb-472b-86dc-9e1d2d3c18f3");
+
+    private VdsGlusterDao dao;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        dao = dbFacade.getVdsGlusterDao();
+    }
+
+    @Test
+    public void testSave() {
+        VdsGluster newEntity = new VdsGluster();
+        newEntity.setVdsId(SERVER_ID);
+        newEntity.setHostUuid(FixturesTool.GLUSTER_HOST_UUID_NEW);
+
+        dao.save(newEntity);
+        VdsGluster entity = dao.getById(newEntity.getId());
+        assertTrue(newEntity.equals(entity));
+    }
+
+    @Test
+    public void testGetById() {
+        VdsGluster entity = dao.getById(FixturesTool.VDS_GLUSTER_ID1);
+        assertNotNull(entity);
+        assertEquals(FixturesTool.VDS_GLUSTER_ID1, entity.getId());
+    }
+
+    @Test
+    public void testGetByClusterId() {
+        VdsGluster entity = dao.getByVdsId(SERVER_ID);
+        assertNotNull(entity);
+        assertEquals(entity.getHostUuid(), FixturesTool.GLUSTER_HOST_UUID1);
+    }
+
+    @Test
+    public void testRemove() {
+        dao.remove(FixturesTool.VDS_GLUSTER_ID1);
+        VdsGluster entity = dao.getById(FixturesTool.VDS_GLUSTER_ID1);
+        assertNull(entity);
+    }
+
+    @Test
+    public void testRemoveAll() {
+        List<Guid> idsToRemove = new ArrayList<Guid>();
+        idsToRemove.add(FixturesTool.VDS_GLUSTER_ID1);
+        idsToRemove.add(FixturesTool.VDS_GLUSTER_ID2);
+        dao.removeAll(idsToRemove);
+
+        VdsGluster entity1 = dao.getById(FixturesTool.VDS_GLUSTER_ID2);
+        assertNull(entity1);
+
+        VdsGluster entity2 = dao.getById(FixturesTool.VDS_GLUSTER_ID2);
+        assertNull(entity2);
+    }
+
+    @Test
+    public void testUpdateHostUuid() {
+        dao.updateHostUuid(SERVER_ID, FixturesTool.GLUSTER_HOST_UUID2);
+        VdsGluster entity = dao.getById(FixturesTool.VDS_GLUSTER_ID1);
+        assertNotNull(entity);
+        assertEquals(entity.getHostUuid(), FixturesTool.GLUSTER_HOST_UUID2);
+    }
+}
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index d43b1a2..53558aa 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -4640,6 +4640,22 @@
         </row>
     </table>
 
+    <table name="vds_gluster">
+        <column>id</column>
+        <column>vds_id</column>
+        <column>host_uuid</column>
+        <row>
+            <value>d2cb2f73-fab3-4a42-93f0-d5e4c069a43e</value>
+            <value>23f6d691-5dfb-472b-86dc-9e1d2d3c18f3</value>
+            <value>da9e2f09-2835-4530-9bf5-576c52b11941</value>
+        </row>
+        <row>
+            <value>d2cb2f73-fab3-4a42-93f0-d5e4c069a43f</value>
+            <value>2001751e-549b-4e7a-aff6-32d36856c125</value>
+            <value>da9e2f09-2835-4530-9bf5-576c52b11942</value>
+        </row>
+    </table>
+
     <table name="object_column_white_list">
         <column>object_name</column>
         <column>column_name</column>


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

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

Reply via email to