Ramesh N has uploaded a new change for review.

Change subject: gluster: caculate volume capacity from brick capacity
......................................................................

gluster: caculate volume capacity from brick capacity

Calculating gluster volume capacity from bricks capacity
information.

In case of replicated bricks, brick with less capacity in the
replica pairs will be used to compute the volume capacity.

Change-Id: I91bed10764599154bf28f7be93b6ebe6565480b1
Signed-off-by: Ramesh Nachimuthu <[email protected]>
---
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumeStatusReturnForXmlRpc.java
1 file changed, 46 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/98/28498/1

diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumeStatusReturnForXmlRpc.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumeStatusReturnForXmlRpc.java
index 5e2a5bb..9dea354 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumeStatusReturnForXmlRpc.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/gluster/GlusterVolumeStatusReturnForXmlRpc.java
@@ -96,18 +96,62 @@
             GlusterVolumeSizeInfo capacityInfo = null;
 
             // Fetch the volume capacity detail
+            capacityInfo = null;
             if (statusInfo.containsKey(VOLUME_STATUS_INFO)) {
                 Map<String, Object> volumeStatusInfo = (Map<String, Object>) 
statusInfo.get("volumeStatsInfo");
                 capacityInfo = new GlusterVolumeSizeInfo();
-                capacityInfo.setVolumeId(volume.getId());
                 capacityInfo.setTotalSize(Long.valueOf((String) 
volumeStatusInfo.get(DETAIL_SIZE_TOTAL)));
                 capacityInfo.setUsedSize(Long.valueOf((String) 
volumeStatusInfo.get(DETAIL_SIZE_USED)));
                 capacityInfo.setFreeSize(Long.valueOf((String) 
volumeStatusInfo.get(DETAIL_SIZE_FREE)));
-                volumeAdvancedDetails.setCapacityInfo(capacityInfo);
+            } else {
+                capacityInfo = calculateVolumeCapacityFromBricks(brickDetails, 
volume.getReplicaCount());
             }
+            capacityInfo.setVolumeId(volume.getId());
+            volumeAdvancedDetails.setCapacityInfo(capacityInfo);
+
         }
     }
 
+    private GlusterVolumeSizeInfo 
calculateVolumeCapacityFromBricks(List<BrickDetails> brickDetails,
+            int replicaCount) {
+        GlusterVolumeSizeInfo capacityInfo = new GlusterVolumeSizeInfo();
+        if (replicaCount == 0){
+            replicaCount = 1;
+        }
+
+        long totalSize = 0;
+        long freeSize = 0;
+        long usedSize = 0;
+
+        int brickIndex = 0;
+        int replicaIndex = 0;
+        while (brickIndex < brickDetails.size()) {
+            replicaIndex = 1;
+            double brickTotalSize = 
brickDetails.get(brickIndex).getBrickProperties().getTotalSize();
+            double brickFreeSize = 
brickDetails.get(brickIndex).getBrickProperties().getFreeSize();
+            // If replica count is more than 1, then find the min of totalSize 
and FreeSize in replicated bricks
+            while (++replicaIndex <= replicaCount) {
+                brickIndex++;
+                if 
(brickDetails.get(brickIndex).getBrickProperties().getTotalSize() < 
brickTotalSize){
+                    brickTotalSize = 
brickDetails.get(brickIndex).getBrickProperties().getTotalSize();
+                }
+
+                if 
(brickDetails.get(brickIndex).getBrickProperties().getFreeSize() < 
brickFreeSize) {
+                    brickFreeSize = 
brickDetails.get(brickIndex).getBrickProperties().getFreeSize();
+                }
+
+            }
+            totalSize += brickTotalSize;
+            freeSize += brickFreeSize;
+            brickIndex++;
+        }
+
+        capacityInfo.setTotalSize(totalSize);
+        capacityInfo.setFreeSize(freeSize);
+        capacityInfo.setUsedSize(totalSize - freeSize);
+        return capacityInfo;
+    }
+
     private List<GlusterServerService> prepareServiceInfo(Map<String, Object> 
statusInfo) {
         List<GlusterServerService> serviceInfoList = new 
ArrayList<GlusterServerService>();
         prepareServiceInfo(statusInfo, serviceInfoList, NFS_KEY);


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I91bed10764599154bf28f7be93b6ebe6565480b1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Ramesh N <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to