Shubhendu Tripathi has uploaded a new change for review.

Change subject: gluster: DAO for volume snapshot maintenance
......................................................................

gluster: DAO for volume snapshot maintenance

Introduced DAO for gluster volume snapshot maintenance.

Change-Id: Id60902aad02b852773ad398aaac9bad8ed7793ab
Signed-off-by: Shubhendu Tripathi <[email protected]>
---
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/GlusterVolumeSnapshotDao.java
A 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoDbFacadeImpl.java
M backend/manager/modules/dal/src/main/jdbc-resources/engine-daos.properties
A 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
A packaging/dbscripts/gluster_volume_snapshot_sp.sql
7 files changed, 583 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/39270/1

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 85a4211..b2f1049 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
@@ -871,6 +871,15 @@
     }
 
     /**
+     * Returns the singleton instance of {@link GlusterVolumeSnapshotDao}
+     *
+     * @return the dao
+     */
+    public GlusterVolumeSnapshotDao getGlusterVolumeSnapshotDao() {
+        return getDao(GlusterVolumeSnapshotDao.class);
+    }
+
+    /**
      * Returns the singleton instance of {@link GlusterVolumeDao}.
      *
      * @return the dao
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDao.java
new file mode 100644
index 0000000..a0b6ae0
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDao.java
@@ -0,0 +1,41 @@
+package org.ovirt.engine.core.dao.gluster;
+
+import java.util.Collection;
+import java.util.List;
+
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterSnapshotStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.DAO;
+import org.ovirt.engine.core.dao.SearchDAO;
+
+public interface GlusterVolumeSnapshotDao extends DAO, 
SearchDAO<GlusterVolumeSnapshotEntity> {
+    public void save(GlusterVolumeSnapshotEntity snapshot);
+
+    public void saveAll(List<GlusterVolumeSnapshotEntity> snapshots);
+
+    public GlusterVolumeSnapshotEntity getById(Guid id);
+
+    public GlusterVolumeSnapshotEntity getByName(Guid volumeId, String 
snapshotName);
+
+    public List<GlusterVolumeSnapshotEntity> getAllByVolumeId(Guid volumeId);
+
+    public List<GlusterVolumeSnapshotEntity> getAllByClusterId(Guid clusterId);
+
+    @Override
+    public List<GlusterVolumeSnapshotEntity> getAllWithQuery(String query);
+
+    public void remove(Guid id);
+
+    public void removeAll(Collection<Guid> ids);
+
+    public void removeAllByVolumeId(Guid volumeId);
+
+    public void removeByName(Guid volumeId, String snapshotName);
+
+    public void updateSnapshotStatus(Guid snapshotId, GlusterSnapshotStatus 
status);
+
+    public void updateSnapshotStatusByName(Guid volumeId, String snapshotName, 
GlusterSnapshotStatus status);
+
+    public void updateAllInBatch(List<GlusterVolumeSnapshotEntity> snapshots);
+}
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoDbFacadeImpl.java
new file mode 100644
index 0000000..bf3137b
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoDbFacadeImpl.java
@@ -0,0 +1,188 @@
+package org.ovirt.engine.core.dao.gluster;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterSnapshotStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity;
+import org.ovirt.engine.core.common.utils.EnumUtils;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.MapSqlParameterMapper;
+import org.ovirt.engine.core.dao.MassOperationsGenericDaoDbFacade;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+
+public class GlusterVolumeSnapshotDaoDbFacadeImpl extends 
MassOperationsGenericDaoDbFacade<GlusterVolumeSnapshotEntity, Guid> implements 
GlusterVolumeSnapshotDao {
+    private static final RowMapper<GlusterVolumeSnapshotEntity> 
snapshotRowMapper =
+            new GlusterVolumeSnapshotRowMapper();
+
+    public GlusterVolumeSnapshotDaoDbFacadeImpl() {
+        super("GlusterVolumeSnapshot");
+        setProcedureNameForGet("GetGlusterVolumeSnapshotById");
+
+    }
+
+    @Override
+    public void save(GlusterVolumeSnapshotEntity snapshot) {
+        getCallsHandler().executeModification("InsertGlusterVolumeSnapshot", 
createFullParametersMapper(snapshot));
+    }
+
+    @Override
+    public void saveAll(List<GlusterVolumeSnapshotEntity> snapshots) {
+        for (GlusterVolumeSnapshotEntity entity : snapshots) {
+            save(entity);
+        }
+    }
+
+    @Override
+    public GlusterVolumeSnapshotEntity getById(Guid id) {
+        GlusterVolumeSnapshotEntity snapshot =
+                getCallsHandler().executeRead("GetGlusterVolumeSnapshotById",
+                        snapshotRowMapper,
+                        createSnapshotIdParams(id));
+        return snapshot;
+    }
+
+    @Override
+    public GlusterVolumeSnapshotEntity getByName(Guid volumeId, String 
snapshotName) {
+        GlusterVolumeSnapshotEntity snapshot =
+                getCallsHandler().executeRead("GetGlusterVolumeSnapshotByName",
+                        snapshotRowMapper,
+                        getCustomMapSqlParameterSource()
+                                .addValue("volume_id", volumeId)
+                                .addValue("snapshot_name", snapshotName));
+
+        return snapshot;
+    }
+
+    @Override
+    public List<GlusterVolumeSnapshotEntity> getAllByVolumeId(Guid volumeId) {
+        List<GlusterVolumeSnapshotEntity> snapshots =
+                
getCallsHandler().executeReadList("GetGlusterVolumeSnapshotsByVolumeId", 
snapshotRowMapper,
+                        getCustomMapSqlParameterSource()
+                                .addValue("volume_id", volumeId));
+        return snapshots;
+    }
+
+    @Override
+    public List<GlusterVolumeSnapshotEntity> getAllByClusterId(Guid clusterId) 
{
+        List<GlusterVolumeSnapshotEntity> snapshots =
+                
getCallsHandler().executeReadList("GetGlusterVolumeSnapshotsByClusterId",
+                        snapshotRowMapper,
+                        
getCustomMapSqlParameterSource().addValue("cluster_Id", clusterId));
+        return snapshots;
+    }
+
+    @Override
+    public void remove(Guid id) {
+        
getCallsHandler().executeModification("DeleteGlusterVolumeSnapshotByGuid", 
createSnapshotIdParams(id));
+    }
+
+    @Override
+    public void removeAllByVolumeId(Guid volumeId) {
+        
getCallsHandler().executeModification("DeleteGlusterVolumeSnapshotsByVolumeId",
+                getCustomMapSqlParameterSource()
+                        .addValue("volume_id", volumeId));
+    }
+
+    @Override
+    public void removeByName(Guid volumeId, String snapshotName) {
+        
getCallsHandler().executeModification("DeleteGlusterVolumeSnapshotByName",
+                getCustomMapSqlParameterSource()
+                        .addValue("volume_id", volumeId)
+                        .addValue("snapshot_name", snapshotName));
+    }
+
+    @Override
+    public void removeAll(Collection<Guid> ids) {
+        
getCallsHandler().executeModification("DeleteGlusterVolumesSnapshotByIds",
+                getCustomMapSqlParameterSource().addValue("snapshot_ids", 
StringUtils.join(ids, ',')));
+    }
+
+    @Override
+    public void updateSnapshotStatus(Guid snapshotId, GlusterSnapshotStatus 
status) {
+        
getCallsHandler().executeModification("UpdateGlusterVolumeSnapshotStatus",
+                createSnapshotIdParams(snapshotId).addValue("status", 
EnumUtils.nameOrNull(status)));
+    }
+
+    @Override
+    public void updateSnapshotStatusByName(Guid volumeId, String snapshotName, 
GlusterSnapshotStatus status) {
+        
getCallsHandler().executeModification("UpdateGlusterVolumeSnapshotStatusByName",
+                getCustomMapSqlParameterSource()
+                        .addValue("volume_id", volumeId)
+                        .addValue("snapshot_name", snapshotName)
+                        .addValue("status", EnumUtils.nameOrNull(status)));
+    }
+
+    @Override
+    public List<GlusterVolumeSnapshotEntity> getAllWithQuery(String query) {
+        List<GlusterVolumeSnapshotEntity> snapshots = 
jdbcTemplate.query(query, snapshotRowMapper);
+        return snapshots;
+    }
+
+    @Override
+    protected MapSqlParameterSource 
createFullParametersMapper(GlusterVolumeSnapshotEntity snapshot) {
+        return getCustomMapSqlParameterSource()
+                .addValue("snapshot_id", snapshot.getSnapshotId())
+                .addValue("snapshot_name", snapshot.getSnapshotName())
+                .addValue("volume_id", snapshot.getVolumeId())
+                .addValue("description", snapshot.getDescription())
+                .addValue("status", 
EnumUtils.nameOrNull(snapshot.getStatus()));
+    }
+
+    private MapSqlParameterSource createSnapshotIdParams(Guid id) {
+        return getCustomMapSqlParameterSource().addValue("snapshot_id", id);
+    }
+
+    @Override
+    protected MapSqlParameterSource createIdParameterMapper(Guid id) {
+        return createSnapshotIdParams(id);
+    }
+
+    @Override
+    protected RowMapper<GlusterVolumeSnapshotEntity> createEntityRowMapper() {
+        return snapshotRowMapper;
+    }
+
+    @Override
+    public void updateAllInBatch(List<GlusterVolumeSnapshotEntity> snapshots) {
+        updateAllInBatch("UpdateGlusterVolumeSnapshotStatus", snapshots, 
getBatchMapper());
+    }
+
+    private static final class GlusterVolumeSnapshotRowMapper implements 
RowMapper<GlusterVolumeSnapshotEntity> {
+        @Override
+        public GlusterVolumeSnapshotEntity mapRow(ResultSet rs, int rowNum)
+                throws SQLException {
+            GlusterVolumeSnapshotEntity entity = new 
GlusterVolumeSnapshotEntity();
+            entity.setSnapshotId(getGuidDefaultEmpty(rs, "snapshot_id"));
+            entity.setClusterId(getGuidDefaultEmpty(rs, "cluster_id"));
+            entity.setVolumeId(getGuidDefaultEmpty(rs, "volume_id"));
+            entity.setSnapshotName(rs.getString("snapshot_name"));
+            entity.setCreatedAt(rs.getTimestamp("_create_date"));
+            entity.setDescription(rs.getString("description"));
+            
entity.setStatus(GlusterSnapshotStatus.from(rs.getString("status")));
+            return entity;
+        }
+    }
+
+    @Override
+    public MapSqlParameterMapper<GlusterVolumeSnapshotEntity> getBatchMapper() 
{
+        return new MapSqlParameterMapper<GlusterVolumeSnapshotEntity>() {
+            @Override
+            public MapSqlParameterSource map(GlusterVolumeSnapshotEntity 
entity) {
+                MapSqlParameterSource paramValue =
+                        new MapSqlParameterSource()
+                                .addValue("snapshot_id", entity.getId())
+                                .addValue("snapshot_name", 
entity.getSnapshotName())
+                                .addValue("volume_id", entity.getVolumeId())
+                                .addValue("description", 
entity.getDescription())
+                                .addValue("status", 
EnumUtils.nameOrNull(entity.getStatus()))
+                                .addValue("_create_date", 
entity.getCreatedAt());
+                return paramValue;
+            }
+        };
+    }
+}
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 63e7518..b8aa233 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
@@ -57,6 +57,7 @@
 StepDao=org.ovirt.engine.core.dao.StepDaoDbFacadeImpl
 GlusterVolumeDao=org.ovirt.engine.core.dao.gluster.GlusterVolumeDaoDbFacadeImpl
 GlusterBrickDao=org.ovirt.engine.core.dao.gluster.GlusterBrickDaoDbFacadeImpl
+GlusterVolumeSnapshotDao=org.ovirt.engine.core.dao.gluster.GlusterVolumeSnapshotDaoDbFacadeImpl
 GlusterOptionDao=org.ovirt.engine.core.dao.gluster.GlusterOptionDaoDbFacadeImpl
 
ImageStorageDomainMapDao=org.ovirt.engine.core.dao.ImageStorageDomainMapDaoDbFacadeImpl
 
VmAndTemplatesGenerationsDAO=org.ovirt.engine.core.dao.VmAndTemplatesGenerationsDbFacadeImpl
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoTest.java
new file mode 100644
index 0000000..420ac7b
--- /dev/null
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeSnapshotDaoTest.java
@@ -0,0 +1,185 @@
+package org.ovirt.engine.core.dao.gluster;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+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.GlusterSnapshotStatus;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.BaseDAOTestCase;
+
+public class GlusterVolumeSnapshotDaoTest extends BaseDAOTestCase {
+    private static final Guid VOLUME_ID = new 
Guid("0c3f45f6-3fe9-4b35-a30c-be0d1a835ea8");
+    private static final Guid CLUSTER_ID = new 
Guid("ae956031-6be2-43d6-bb8f-5191c9253314");
+    private static final Guid EXISTING_SNAPSHOT_ID = new 
Guid("0c3f45f6-3fe9-4b35-a30c-be0d1a835ea6");
+    private static final Guid EXISTING_SNAPSHOT_ID_1 = new 
Guid("0c3f45f6-3fe9-4b35-a30c-be0d1a835ea7");
+    private static final String EXISTING_SNAPSHOT_NAME_1 = 
"test-vol-distribute-1-snap2";
+    private static final String NEW_SNAPSHOT_NAME = 
"test-vol-distribute-1-snap3";
+    private GlusterVolumeSnapshotDao dao;
+    private GlusterVolumeSnapshotEntity existingSnapshot;
+    private GlusterVolumeSnapshotEntity existingSnapshot1;
+    private GlusterVolumeSnapshotEntity newSnapshot;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        dao = dbFacade.getGlusterVolumeSnapshotDao();
+        existingSnapshot = dao.getById(EXISTING_SNAPSHOT_ID);
+        existingSnapshot1 = dao.getById(EXISTING_SNAPSHOT_ID_1);
+    }
+
+    @Test
+    public void testSaveAndGetById() {
+        GlusterVolumeSnapshotEntity snapshot = dao.getByName(VOLUME_ID, 
NEW_SNAPSHOT_NAME);
+        assertNull(snapshot);
+
+        newSnapshot = insertTestSnapshot();
+        snapshot = dao.getById(newSnapshot.getId());
+
+        assertNotNull(snapshot);
+        assertEquals(newSnapshot, snapshot);
+    }
+
+    @Test
+    public void testGetByName() {
+        newSnapshot = insertTestSnapshot();
+        GlusterVolumeSnapshotEntity snapshot = dao.getByName(VOLUME_ID, 
NEW_SNAPSHOT_NAME);
+
+        assertNotNull(snapshot);
+        assertEquals(newSnapshot, snapshot);
+    }
+
+    @Test
+    public void testGetByVolumeId() {
+        List<GlusterVolumeSnapshotEntity> snapshots = 
dao.getAllByVolumeId(VOLUME_ID);
+
+        assertTrue(snapshots != null);
+        assertTrue(snapshots.size() == 2);
+        assertTrue(snapshots.contains(existingSnapshot));
+    }
+
+    @Test
+    public void testGetByClusterId() {
+        List<GlusterVolumeSnapshotEntity> snapshots = 
dao.getAllByClusterId(CLUSTER_ID);
+
+        assertNotNull(snapshots);
+        assertTrue(snapshots.size() == 2);
+        assertTrue(snapshots.contains(existingSnapshot));
+    }
+
+    @Test
+    public void testGetAllWithQuery() {
+        List<GlusterVolumeSnapshotEntity> snapshots =
+                dao.getAllWithQuery("select * from 
gluster_volume_snapshots_view");
+
+        assertTrue(snapshots != null);
+        assertTrue(snapshots.size() == 2);
+    }
+
+    @Test
+    public void testRemove() {
+        dao.remove(EXISTING_SNAPSHOT_ID);
+        List<GlusterVolumeSnapshotEntity> snapshots = 
dao.getAllByVolumeId(VOLUME_ID);
+
+        assertTrue(snapshots.size() == 1);
+        assertFalse(snapshots.contains(existingSnapshot));
+    }
+
+    @Test
+    public void testRemoveMultiple() {
+        List<Guid> idsToRemove = new ArrayList<Guid>();
+        idsToRemove.add(EXISTING_SNAPSHOT_ID);
+        idsToRemove.add(EXISTING_SNAPSHOT_ID_1);
+
+        dao.removeAll(idsToRemove);
+        List<GlusterVolumeSnapshotEntity> snapshots = 
dao.getAllByVolumeId(VOLUME_ID);
+
+        assertTrue(snapshots.isEmpty());
+    }
+
+    @Test
+    public void testRemoveByName() {
+        dao.removeByName(VOLUME_ID, EXISTING_SNAPSHOT_NAME_1);
+        List<GlusterVolumeSnapshotEntity> snapshots = 
dao.getAllByVolumeId(VOLUME_ID);
+
+        assertTrue(snapshots.size() == 1);
+        assertTrue(snapshots.contains(existingSnapshot));
+        assertFalse(snapshots.contains(existingSnapshot1));
+    }
+
+    @Test
+    public void testRemoveAllByVolumeId() {
+        dao.removeAllByVolumeId(VOLUME_ID);
+        List<GlusterVolumeSnapshotEntity> snapshots = 
dao.getAllByVolumeId(VOLUME_ID);
+        assertTrue(snapshots.isEmpty());
+    }
+
+    @Test
+    public void testUpdateSnapshotStatus() {
+        dao.updateSnapshotStatus(existingSnapshot.getSnapshotId(), 
GlusterSnapshotStatus.STOPPED);
+        GlusterVolumeSnapshotEntity snapshot = 
dao.getById(existingSnapshot.getSnapshotId());
+
+        assertNotNull(snapshot);
+
+        assertFalse(snapshot.equals(existingSnapshot));
+        existingSnapshot.setStatus(GlusterSnapshotStatus.STOPPED);
+        assertEquals(existingSnapshot, snapshot);
+    }
+
+    @Test
+    public void testUpdateSnapshotStatusByName() {
+        dao.updateSnapshotStatusByName(existingSnapshot.getVolumeId(),
+                existingSnapshot.getSnapshotName(),
+                GlusterSnapshotStatus.STOPPED);
+        GlusterVolumeSnapshotEntity snapshot = 
dao.getById(existingSnapshot.getSnapshotId());
+
+        assertNotNull(snapshot);
+
+        assertFalse(snapshot.equals(existingSnapshot));
+        existingSnapshot.setStatus(GlusterSnapshotStatus.STOPPED);
+        assertEquals(existingSnapshot, snapshot);
+    }
+
+    @Test
+    public void testUpdateAllInBatch() {
+        existingSnapshot = dao.getById(EXISTING_SNAPSHOT_ID);
+        existingSnapshot1 = dao.getById(EXISTING_SNAPSHOT_ID_1);
+
+        existingSnapshot.setStatus(GlusterSnapshotStatus.STOPPED);
+        existingSnapshot1.setStatus(GlusterSnapshotStatus.STOPPED);
+
+        List<GlusterVolumeSnapshotEntity> snapshots = new ArrayList<>();
+        snapshots.add(existingSnapshot);
+        snapshots.add(existingSnapshot1);
+
+        dao.updateAllInBatch(snapshots);
+
+        GlusterVolumeSnapshotEntity tmpSnapshot = 
dao.getById(EXISTING_SNAPSHOT_ID);
+        GlusterVolumeSnapshotEntity tmpSnapshot1 = 
dao.getById(EXISTING_SNAPSHOT_ID_1);
+
+        assertEquals(tmpSnapshot.getStatus(), GlusterSnapshotStatus.STOPPED);
+        assertEquals(tmpSnapshot1.getStatus(), GlusterSnapshotStatus.STOPPED);
+    }
+
+    private GlusterVolumeSnapshotEntity insertTestSnapshot() {
+        Guid snapshotId = Guid.newGuid();
+
+        GlusterVolumeSnapshotEntity snapshot = new 
GlusterVolumeSnapshotEntity();
+        snapshot.setSnapshotId(snapshotId);
+        snapshot.setClusterId(CLUSTER_ID);
+        snapshot.setSnapshotName(NEW_SNAPSHOT_NAME);
+        snapshot.setVolumeId(VOLUME_ID);
+        snapshot.setDescription("test-description");
+        snapshot.setStatus(GlusterSnapshotStatus.STARTED);
+
+        dao.save(snapshot);
+        return snapshot;
+    }
+}
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index d381760..5b2f767 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -6536,6 +6536,28 @@
         </row>
     </table>
 
+    <table name="gluster_volume_snapshots">
+        <column>snapshot_id</column>
+        <column>volume_id</column>
+        <column>snapshot_name</column>
+        <column>description</column>
+        <column>status</column>
+        <row>
+            <value>0c3f45f6-3fe9-4b35-a30c-be0d1a835ea6</value>
+            <value>0c3f45f6-3fe9-4b35-a30c-be0d1a835ea8</value>
+            <value>test-vol-distribute-1-snap1</value>
+            <value></value>
+            <value>STARTED</value>
+        </row>
+        <row>
+            <value>0c3f45f6-3fe9-4b35-a30c-be0d1a835ea7</value>
+            <value>0c3f45f6-3fe9-4b35-a30c-be0d1a835ea8</value>
+            <value>test-vol-distribute-1-snap2</value>
+            <value></value>
+            <value>STARTED</value>
+        </row>
+    </table>
+
     <table name="gluster_volume_bricks">
         <column>id</column>
         <column>volume_id</column>
diff --git a/packaging/dbscripts/gluster_volume_snapshot_sp.sql 
b/packaging/dbscripts/gluster_volume_snapshot_sp.sql
new file mode 100644
index 0000000..e6f55a0
--- /dev/null
+++ b/packaging/dbscripts/gluster_volume_snapshot_sp.sql
@@ -0,0 +1,137 @@
+/* ----------------------------------------------------------------
+ Stored procedures for database operations on Gluster Volume Snapshot
+ related tables:
+      - gluster_volume_snapshots
+      - gluster_volume_snapshot_config
+----------------------------------------------------------------*/
+
+Create or replace FUNCTION InsertGlusterVolumeSnapshot(v_snapshot_id UUID,
+                                                v_snapshot_name VARCHAR(1000),
+                                                v_volume_id UUID,
+                                                v_description VARCHAR(1024),
+                                                v_status VARCHAR(32))
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    INSERT INTO gluster_volume_snapshots (snapshot_id, snapshot_name, 
volume_id,
+        description, status)
+    VALUES (v_snapshot_id,  v_snapshot_name, v_volume_id,
+        v_description, v_status);
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetGlusterVolumeSnapshotById(v_snapshot_id UUID)
+    RETURNS SETOF gluster_volume_snapshots_view STABLE
+    AS $procedure$
+BEGIN
+    RETURN QUERY SELECT *
+    FROM  gluster_volume_snapshots_view
+    WHERE snapshot_id = v_snapshot_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetGlusterVolumeSnapshotsByVolumeId(v_volume_id 
UUID)
+RETURNS SETOF gluster_volume_snapshots_view STABLE
+AS $procedure$
+BEGIN
+    RETURN QUERY SELECT *
+    FROM  gluster_volume_snapshots_view
+    WHERE volume_id = v_volume_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetGlusterVolumeSnapshotsByClusterId(v_cluster_id 
UUID)
+RETURNS SETOF gluster_volume_snapshots_view STABLE
+AS $procedure$
+BEGIN
+    RETURN QUERY SELECT *
+    FROM  gluster_volume_snapshots_view
+    WHERE cluster_id = v_cluster_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION GetGlusterVolumeSnapshotByName(v_volume_id UUID,
+                                            v_snapshot_name VARCHAR(1000))
+RETURNS SETOF gluster_volume_snapshots_view STABLE
+    AS $procedure$
+BEGIN
+    RETURN QUERY SELECT *
+    FROM gluster_volume_snapshots_view
+    WHERE volume_id = v_volume_id and snapshot_name = v_snapshot_name;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteGlusterVolumeSnapshotByGuid(v_snapshot_id 
UUID)
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    DELETE FROM gluster_volume_snapshots
+    WHERE snapshot_id = v_snapshot_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteGlusterVolumeSnapshotsByVolumeId(v_volume_id 
UUID)
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    DELETE FROM gluster_volume_snapshots
+    WHERE volume_id = v_volume_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteGlusterVolumeSnapshotByName(v_volume_id UUID,
+                                                    v_snapshot_name 
VARCHAR(1000))
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    DELETE FROM gluster_volume_snapshots
+    WHERE volume_id = v_volume_id
+    AND   snapshot_name = v_snapshot_name;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION DeleteGlusterVolumesSnapshotByIds(v_snapshot_ids 
VARCHAR(5000))
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+DELETE FROM gluster_volume_snapshots
+WHERE snapshot_id in (select * from fnSplitterUuid(v_snapshot_ids));
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION UpdateGlusterVolumeSnapshotStatus(v_snapshot_id 
UUID,
+                                                        v_status VARCHAR(32))
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    UPDATE  gluster_volume_snapshots
+    SET     status = v_status,
+            _update_date = LOCALTIMESTAMP
+    WHERE   snapshot_id = v_snapshot_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
+
+Create or replace FUNCTION UpdateGlusterVolumeSnapshotStatusByName(v_volume_id 
UUID,
+                                                        v_snapshot_name 
VARCHAR(1000),
+                                                        v_status VARCHAR(32))
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    UPDATE  gluster_volume_snapshots
+    SET     status = v_status,
+            _update_date = LOCALTIMESTAMP
+    WHERE   volume_id = v_volume_id
+    AND     snapshot_name = v_snapshot_name;
+END; $procedure$
+LANGUAGE plpgsql;
+


-- 
To view, visit https://gerrit.ovirt.org/39270
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id60902aad02b852773ad398aaac9bad8ed7793ab
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5-gluster
Gerrit-Owner: Shubhendu Tripathi <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to