anmolbabu has uploaded a new change for review.

Change subject: engine : Refactored gluster volume profile query
......................................................................

engine : Refactored gluster volume profile query

This patch refactors the volume profile query
to take an additional boolean parameter nfs which
helps to query the vds for 2 types of stats
nfs and brick profile stats

Change-Id: I41d80dbb8b6865f67fcadf78baed2a813c423d03
Signed-off-by: Anmol Babu <anb...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeProfileInfoQuery.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/gluster/GlusterVolumeProfileParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/SizeConverter.java
3 files changed, 76 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/27468/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeProfileInfoQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeProfileInfoQuery.java
index 9fad7f9..31e9195 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeProfileInfoQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GetGlusterVolumeProfileInfoQuery.java
@@ -1,9 +1,15 @@
 package org.ovirt.engine.core.bll.gluster;
 
+import java.util.List;
+
+import 
org.ovirt.engine.core.common.businessentities.gluster.BrickProfileDetails;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeProfileInfo;
+import 
org.ovirt.engine.core.common.queries.gluster.GlusterVolumeProfileParameters;
 import 
org.ovirt.engine.core.common.queries.gluster.GlusterVolumeQueriesParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeProfileInfoVDSParameters;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 
 
 /**
@@ -20,7 +26,17 @@
         VDSReturnValue returnValue = 
runVdsCommand(VDSCommandType.GetGlusterVolumeProfileInfo,
                 new 
GlusterVolumeProfileInfoVDSParameters(getParameters().getClusterId(),
                         getUpServerId(getParameters().getClusterId()),
-                        getGlusterVolumeName(getParameters().getVolumeId())));
-        getQueryReturnValue().setReturnValue(returnValue.getReturnValue());
+                        getGlusterVolumeName(getParameters().getVolumeId()),
+                        
((GlusterVolumeProfileParameters)getParameters()).isNfs()));
+
+        
getQueryReturnValue().setReturnValue((((GlusterVolumeProfileParameters)getParameters()).isNfs())
 ? (GlusterVolumeProfileInfo) returnValue.getReturnValue() : 
setBrickNames((GlusterVolumeProfileInfo) returnValue.getReturnValue()));
+    }
+
+    protected GlusterVolumeProfileInfo setBrickNames(GlusterVolumeProfileInfo 
profileInfo) {
+        List<BrickProfileDetails> brickProfiles= 
profileInfo.getBrickProfileDetails();
+        for(int i = 0; i < brickProfiles.size(); i++) {
+            
brickProfiles.get(i).setBrickName(DbFacade.getInstance().getGlusterBrickDao().getById(brickProfiles.get(i).getBrickId()).getQualifiedName());
+        }
+        return profileInfo;
     }
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/gluster/GlusterVolumeProfileParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/gluster/GlusterVolumeProfileParameters.java
new file mode 100644
index 0000000..f08eb21
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/gluster/GlusterVolumeProfileParameters.java
@@ -0,0 +1,35 @@
+package org.ovirt.engine.core.common.queries.gluster;
+
+import org.ovirt.engine.core.compat.Guid;
+
+
+public class GlusterVolumeProfileParameters extends 
GlusterVolumeQueriesParameters {
+
+    /**
+     *
+     */
+    private static final long serialVersionUID = 1L;
+
+    private boolean nfs;
+
+    public boolean isNfs() {
+        return nfs;
+    }
+
+    public void setNfs(boolean nfs) {
+        this.nfs = nfs;
+    }
+
+    public GlusterVolumeProfileParameters() {
+
+    }
+    public GlusterVolumeProfileParameters(Guid clusterId, Guid volumeId) {
+        super(clusterId, volumeId);
+        this.nfs = false;
+    }
+
+    public GlusterVolumeProfileParameters(Guid clusterId, Guid volumeId, 
boolean nfs) {
+        super(clusterId, volumeId);
+        this.nfs = nfs;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/SizeConverter.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/SizeConverter.java
index d081064..58cadf0 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/SizeConverter.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/SizeConverter.java
@@ -68,4 +68,27 @@
         }
         return new Pair<SizeConverter.SizeUnit, Double>(SizeUnit.BYTES, 
(double)size);
     }
+
+    /*
+     * This method converts the input long value Size from the input unit to a 
maximum expressable unit such that its magnitude > 0.
+     * And also,the value returned by this method is a string containing a 
precise non-decimal sequence of magnitude-unit string pairs.
+     * For ex : 1269760000 bytes =  1 GB 186 MB 960 KB
+     *                           = (1 * 1024 (MB) * 1024 (KB) * 1024 (Bytes)) 
+ (186 * 1024 (KB) * 1024 (Bytes)) + (960 * 1024 (Bytes))
+     * This method achieves this iteratively by,
+     * 1. Convert the size into highest expressable unit using the above 
autoConvert method
+     * 2. Concat to convertedSize string the converted size and its unit
+     * 3. Set the size to reminder
+     */
+
+    public static String autoPreciseConvert(long size, SizeUnit inUnit) {
+        String convertedSize = "";
+        while(size > 1024) {
+            Pair<SizeUnit, Double> result = SizeConverter.autoConvert(size, 
inUnit);
+            convertedSize = convertedSize.concat(result.getSecond().intValue() 
+ " " + result.getFirst().toString() + " ");
+            long reminder = size - 
SizeConverter.convert(result.getSecond().longValue(), result.getFirst(), 
inUnit).longValue();
+            size = reminder;
+        }
+        convertedSize = convertedSize.concat((((convertedSize != "") && (size 
> 0)) || ((convertedSize == "") && (size == 0))) ? (size + " " + inUnit) : "");
+        return convertedSize;
+    }
 }


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

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

Reply via email to