Ramesh N has uploaded a new change for review.

Change subject: gluster: dao changes for volume capacity info
......................................................................

gluster: dao changes for volume capacity info

  Adding volume capacity information as part of the
volumes tables. Necessary DAO changed are made to update/read
the capacity information.
:
Change-Id: I7d67b7ee22f4cb6839d0f14d3f27f3e22149ff22
Signed-off-by: Ramesh Nachimuthu <rnach...@redhat.com>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeSizeInfo.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M packaging/dbscripts/create_views.sql
M packaging/dbscripts/gluster_volumes_sp.sql
A 
packaging/dbscripts/upgrade/03_04_0350_add_volume_capacity_info_to_gluster_volumes.sql
8 files changed, 149 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/10/23010/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeSizeInfo.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeSizeInfo.java
index 4014956..306c6d6 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeSizeInfo.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/gluster/GlusterVolumeSizeInfo.java
@@ -1,7 +1,9 @@
 package org.ovirt.engine.core.common.businessentities.gluster;
 
 import java.io.Serializable;
+import java.util.Date;
 
+import org.ovirt.engine.core.common.utils.ObjectUtils;
 import org.ovirt.engine.core.compat.Guid;
 
 public class GlusterVolumeSizeInfo implements Serializable {
@@ -12,14 +14,16 @@
     private Long totalSize;
     private Long freeSize;
     private Long usedSize;
+    private Date updatedAt;
 
     public GlusterVolumeSizeInfo() {
     }
 
-    public GlusterVolumeSizeInfo(Long totalSize, Long freeSize, Long usedSize) 
{
+    public GlusterVolumeSizeInfo(Long totalSize, Long freeSize, Long usedSize, 
Date updatedAt) {
         this.totalSize = totalSize;
         this.freeSize = freeSize;
         this.usedSize = usedSize;
+        this.updatedAt = updatedAt;
     }
 
     public Guid getVolumeId() {
@@ -53,6 +57,14 @@
         this.usedSize = usedSize;
     }
 
+    public Date getUpdatedAt() {
+        return updatedAt;
+    }
+
+    public void setUpdatedAt(Date updatedAt) {
+        this.updatedAt = updatedAt;
+    }
+
     @Override
     public int hashCode() {
         final int prime = 31;
@@ -62,6 +74,7 @@
         result = prime * result + ((totalSize == null) ? 0 : 
totalSize.hashCode());
         result = prime * result + ((freeSize == null) ? 0 : 
freeSize.hashCode());
         result = prime * result + ((usedSize == null) ? 0 : 
usedSize.hashCode());
+        result = prime * result + ((updatedAt == null) ? 0 : 
updatedAt.hashCode());
         return result;
     }
 
@@ -70,25 +83,29 @@
         if (!(obj instanceof GlusterVolumeSizeInfo)) {
             return false;
         }
-        GlusterVolumeSizeInfo sizeInfo = (GlusterVolumeSizeInfo)obj;
+        GlusterVolumeSizeInfo sizeInfo = (GlusterVolumeSizeInfo) obj;
 
-        if (!(volumeId.equals(sizeInfo.getVolumeName()))) {
+        if (!ObjectUtils.objectsEqual(volumeName, sizeInfo.getVolumeName())) {
             return false;
         }
 
-        if (!(volumeId.equals(sizeInfo.getVolumeId()))) {
+        if (!ObjectUtils.objectsEqual(volumeId, sizeInfo.getVolumeId())) {
             return false;
         }
 
-        if (totalSize != sizeInfo.getTotalSize()) {
+        if (!ObjectUtils.objectsEqual(updatedAt, sizeInfo.getUpdatedAt())) {
             return false;
         }
 
-        if (freeSize != sizeInfo.getFreeSize()) {
+        if (!ObjectUtils.objectsEqual(totalSize, sizeInfo.getTotalSize())) {
             return false;
         }
 
-        if (usedSize != sizeInfo.getUsedSize()) {
+        if (!ObjectUtils.objectsEqual(freeSize, sizeInfo.getFreeSize())) {
+            return false;
+        }
+
+        if (!ObjectUtils.objectsEqual(usedSize, sizeInfo.getUsedSize())) {
             return false;
         }
 
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
index 9825c31..d44bb8a 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDao.java
@@ -6,6 +6,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.AccessProtocol;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSizeInfo;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
 import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
 import org.ovirt.engine.core.compat.Guid;
@@ -70,6 +71,8 @@
 
     public void updateGlusterVolume(GlusterVolumeEntity volume);
 
+    public void updateVolumeCapacityInfo(GlusterVolumeSizeInfo 
volumeCapacityInfo);
+
     public void updateVolumeTask(Guid volumeId, Guid taskId);
 
     public GlusterVolumeEntity getVolumeByGlusterTask(Guid taskId);
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
index b5ccd90..76808f5 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoDbFacadeImpl.java
@@ -14,6 +14,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSizeInfo;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
 import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
 import org.ovirt.engine.core.common.job.JobExecutionStatus;
@@ -36,6 +37,8 @@
     private static final RowMapper<AccessProtocol> accessProtocolRowMapper = 
new AccessProtocolRowMapper();
     private static final RowMapper<TransportType> transportTypeRowMapper = new 
TransportTypeRowMapper();
     private static final RowMapper<GlusterAsyncTask> glusterAsyncTaskRowMapper 
= new GlusterAsyncTaskRowMapper();
+    private static final RowMapper<GlusterVolumeSizeInfo> 
glusterVolumeSizeInfoRowMapper =
+            new GlusterVolumeSizeInfoRowMapper();
 
     public GlusterVolumeDaoDbFacadeImpl() {
         super("GlusterVolume");
@@ -241,7 +244,7 @@
                 glusterAsyncTaskRowMapper,
                 createVolumeIdParams(volumeId));
 
-        if(glusterAsyncTasks != null && !glusterAsyncTasks.isEmpty()) {
+        if (glusterAsyncTasks != null && !glusterAsyncTasks.isEmpty()) {
             return glusterAsyncTasks.get(0);
         }
         return null;
@@ -316,13 +319,14 @@
             
volume.setOptions(dbFacade.getGlusterOptionDao().getOptionsOfVolume(volume.getId()));
             volume.setAccessProtocols(new 
HashSet<AccessProtocol>(getAccessProtocolsOfVolume(volume.getId())));
             volume.setTransportTypes(new 
HashSet<TransportType>(getTransportTypesOfVolume(volume.getId())));
+            volume.setCapacityDetails(fetchCapacityDatails(volume.getId()));
             GlusterAsyncTask asyncTask = getAsyncTaskOfVolume(volume.getId());
             if (asyncTask != null) {
                 volume.setAsyncTask(asyncTask);
             }
             List<GlusterBrickEntity> bricks = 
dbFacade.getGlusterBrickDao().getBricksOfVolume(volume.getId());
             if (volume.getAsyncTask() != null && 
volume.getAsyncTask().getTaskId() != null) {
-                for (GlusterBrickEntity brick: bricks) {
+                for (GlusterBrickEntity brick : bricks) {
                     if (brick.getAsyncTask() != null && 
brick.getAsyncTask().getTaskId() != null &&
                             
brick.getAsyncTask().getTaskId().equals(volume.getAsyncTask().getTaskId())) {
                         brick.setAsyncTask(volume.getAsyncTask());
@@ -331,6 +335,14 @@
             }
             volume.setBricks(bricks);
         }
+    }
+
+    private GlusterVolumeSizeInfo fetchCapacityDatails(Guid id) {
+        GlusterVolumeSizeInfo glusterVolumeSizeInfo = 
getCallsHandler().executeRead(
+                "GetGlusterVolumeCapacityInfoById",
+                glusterVolumeSizeInfoRowMapper,
+                createVolumeIdParams(id));
+        return glusterVolumeSizeInfo;
     }
 
     private static final class GlusterVolumeRowMapper implements 
RowMapper<GlusterVolumeEntity> {
@@ -365,26 +377,46 @@
             return TransportType.valueOf(rs.getString("transport_type"));
         }
     }
+
     private static final class GlusterAsyncTaskRowMapper implements 
RowMapper<GlusterAsyncTask> {
         @Override
         public GlusterAsyncTask mapRow(ResultSet rs, int rowNum)
                 throws SQLException {
             GlusterAsyncTask asyncTask = new GlusterAsyncTask();
             asyncTask.setTaskId(getGuid(rs, "external_id"));
-            String jobStatus =rs.getString("job_status");
+            String jobStatus = rs.getString("job_status");
             if (asyncTask.getTaskId() != null || 
JobExecutionStatus.STARTED.name().equalsIgnoreCase(jobStatus)) {
                 asyncTask.setJobId(getGuid(rs, "job_job_id"));
                 asyncTask.setJobStatus(JobExecutionStatus.valueOf(jobStatus));
             }
-            String stepStatus =rs.getString("status");
+            String stepStatus = rs.getString("status");
             String stepType = rs.getString("step_type");
-            if(stepType != null && !stepType.isEmpty()){
+            if (stepType != null && !stepType.isEmpty()) {
                 
asyncTask.setType(GlusterTaskType.forValue(StepEnum.valueOf(stepType)));
             }
-            if(stepStatus != null && !stepStatus.isEmpty()){
+            if (stepStatus != null && !stepStatus.isEmpty()) {
                 asyncTask.setStatus(JobExecutionStatus.valueOf(stepStatus));
             }
             return asyncTask;
+        }
+    }
+
+    private static final class GlusterVolumeSizeInfoRowMapper implements 
RowMapper<GlusterVolumeSizeInfo> {
+        @Override
+        public GlusterVolumeSizeInfo mapRow(ResultSet rs, int rowNum)
+                throws SQLException {
+            GlusterVolumeSizeInfo capacityInfo = new GlusterVolumeSizeInfo();
+            capacityInfo.setVolumeId(getGuid(rs, "id"));
+            capacityInfo.setTotalSize(rs.getLong("total_space"));
+            capacityInfo.setUsedSize(rs.getLong("used_space"));
+            capacityInfo.setFreeSize(rs.getLong("free_space"));
+            capacityInfo.setUpdatedAt(rs.getDate("capacity_info_updated_at"));
+
+            if (capacityInfo.getTotalSize() == 0) {
+                return null;
+            }
+
+            return capacityInfo;
         }
     }
 
@@ -411,6 +443,16 @@
     }
 
     @Override
+    public void updateVolumeCapacityInfo(GlusterVolumeSizeInfo 
volumeCapacityInfo) {
+        
getCallsHandler().executeModification("UpdateGlusterVolumeCapacityInfo",
+                getCustomMapSqlParameterSource()
+                        .addValue("id", volumeCapacityInfo.getVolumeId())
+                        .addValue("total_space", 
volumeCapacityInfo.getTotalSize())
+                        .addValue("used_space", 
volumeCapacityInfo.getUsedSize())
+                        .addValue("free_space", 
volumeCapacityInfo.getFreeSize()));
+    }
+
+    @Override
     protected MapSqlParameterSource 
createFullParametersMapper(GlusterVolumeEntity volume) {
         return getCustomMapSqlParameterSource()
                 .addValue("id", volume.getId())
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
index 5fb0e92..67402c6 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/gluster/GlusterVolumeDaoTest.java
@@ -84,6 +84,16 @@
     }
 
     @Test
+    public void testGetCapacityInfo() {
+        GlusterVolumeEntity volume = dao.getById(EXISTING_VOL_DIST_ID);
+        assertNotNull("volume capacity info is not available", 
volume.getCapacityDetails());
+        assertTrue(volume.getCapacityDetails().getTotalSize() == 50000);
+        assertTrue(volume.getCapacityDetails().getUsedSize() == 5000);
+        assertTrue(volume.getCapacityDetails().getFreeSize() == 45000);
+        assertNotNull(volume.getCapacityDetails().getUpdatedAt());
+    }
+
+    @Test
     public void testGetAllWithQuery() {
         List<GlusterVolumeEntity> volumes =
                 dao.getAllWithQuery("select * from gluster_volumes_view where 
vol_type = '"
@@ -387,6 +397,7 @@
         assertEquals(volumeAfter, existingReplVol);
     }
 
+
     private GlusterVolumeEntity insertTestVolume() {
         Guid volumeId = Guid.newGuid();
 
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index c11f7ef..54fe4ad 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -5179,6 +5179,10 @@
         <column>stripe_count</column>
         <column>_create_date</column>
         <column>_update_date</column>
+        <column>total_space</column>
+        <column>used_space</column>
+        <column>free_space</column>
+        <column>capacity_info_updated_at</column>
         <row>
             <value>0c3f45f6-3fe9-4b35-a30c-be0d1a835ea8</value>
             <value>ae956031-6be2-43d6-bb8f-5191c9253314</value>
@@ -5188,6 +5192,10 @@
             <value>0</value>
             <value>0</value>
             <value>2010-10-21 03:38:22</value>
+            <value>2010-11-29 15:57:10</value>
+            <value>50000</value>
+            <value>5000</value>
+            <value>45000</value>
             <value>2010-11-29 15:57:10</value>
         </row>
         <row>
@@ -5200,6 +5208,10 @@
             <value>0</value>
             <value>2010-10-21 03:38:22</value>
             <value>2010-11-29 15:57:10</value>
+            <value>90000</value>
+            <value>50000</value>
+            <value>40000</value>
+            <value>2010-11-29 15:57:10</value>
         </row>
     </table>
 
diff --git a/packaging/dbscripts/create_views.sql 
b/packaging/dbscripts/create_views.sql
index bee24c6..817c2bd 100644
--- a/packaging/dbscripts/create_views.sql
+++ b/packaging/dbscripts/create_views.sql
@@ -1601,6 +1601,15 @@
 FROM gluster_volumes
 INNER JOIN vds_groups ON gluster_volumes.cluster_id = vds_groups.vds_group_id;
 
+CREATE OR REPLACE VIEW gluster_volumes_capacity_view
+AS
+SELECT gluster_volumes.id,
+       gluster_volumes.total_space,
+       gluster_volumes.used_space,
+       gluster_volumes.free_space,
+       gluster_volumes.capacity_info_updated_at
+FROM gluster_volumes;
+
 CREATE OR REPLACE VIEW gluster_volume_bricks_view
 AS
 SELECT gluster_volume_bricks.*,
diff --git a/packaging/dbscripts/gluster_volumes_sp.sql 
b/packaging/dbscripts/gluster_volumes_sp.sql
index be0946d..75112c9 100644
--- a/packaging/dbscripts/gluster_volumes_sp.sql
+++ b/packaging/dbscripts/gluster_volumes_sp.sql
@@ -83,6 +83,21 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+Create or replace FUNCTION GetGlusterVolumeCapacityInfoById(v_volume_id UUID)
+    RETURNS SETOF gluster_volumes_capacity_view STABLE
+    AS $procedure$
+BEGIN
+    RETURN QUERY SELECT 
+       gluster_volumes.id,
+       gluster_volumes.total_space,
+       gluster_volumes.used_space,
+       gluster_volumes.free_space,
+       gluster_volumes.capacity_info_updated_at
+    FROM gluster_volumes
+    WHERE gluster_volumes.id = v_volume_id;
+END; $procedure$
+LANGUAGE plpgsql;
+
 Create or replace FUNCTION GetGlusterVolumesByOption(v_cluster_id UUID,
                                                        v_status VARCHAR(32),
                                                        v_option_key 
VARCHAR(8192),
@@ -394,6 +409,22 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+Create or replace FUNCTION UpdateGlusterVolumeCapacityInfo(v_id UUID,
+                                                v_total_space bigint,
+                                                v_used_space bigint,
+                                                v_free_space bigint)
+    RETURNS VOID
+    AS $procedure$
+BEGIN
+    UPDATE gluster_volumes
+    SET 
+        total_space = v_total_space,
+        used_space = v_used_space,
+        free_space = v_free_space,
+        capacity_info_updated_at = LOCALTIMESTAMP
+    WHERE id = v_id;
+END; $procedure$
+LANGUAGE plpgsql;
 
 Create or replace FUNCTION UpdateGlusterVolumeBrick(v_id UUID,
                                                     v_new_id UUID,
diff --git 
a/packaging/dbscripts/upgrade/03_04_0350_add_volume_capacity_info_to_gluster_volumes.sql
 
b/packaging/dbscripts/upgrade/03_04_0350_add_volume_capacity_info_to_gluster_volumes.sql
new file mode 100644
index 0000000..1fc4cf4
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_04_0350_add_volume_capacity_info_to_gluster_volumes.sql
@@ -0,0 +1,11 @@
+-- adding total_space column to gluster volumes used to store the total 
capacity of the volume
+SELECT fn_db_add_column('gluster_volumes', 'total_space', 'bigint');
+
+-- adding used_space column to gluster volumes used to store the used space in 
the volume
+SELECT fn_db_add_column('gluster_volumes', 'used_space', 'bigint');
+
+-- adding free_space column to gluster volumes used to store the free space 
left in the volume
+SELECT fn_db_add_column('gluster_volumes', 'free_space', 'bigint');
+
+-- adding capacity_info_updated_at field to store when the capacity info was 
updated
+SELECT fn_db_add_column('gluster_volumes', 'capacity_info_updated_at', 
'timestamp'); 


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

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

Reply via email to