Sahina Bose has uploaded a new change for review.

Change subject: restapi: API support to query gluster volume profile info
......................................................................

restapi: API support to query gluster volume profile info

Added an api to return volume profile information

Change-Id: Iff04cc30f01a7fbe9d6e48b8498d405d05c41c25
Bug-Url: https://bugzilla.redhat.com/1083583
Signed-off-by: Sahina Bose <[email protected]>
---
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterVolumeResource.java
M 
backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
M 
backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterVolumeResource.java
A 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GlusterVolumeProfileInfoMapper.java
A 
backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/StatisticResourceUtils.java
7 files changed, 292 insertions(+), 23 deletions(-)


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

diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterVolumeResource.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterVolumeResource.java
index 4f37d2d..05aab13 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterVolumeResource.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/resource/gluster/GlusterVolumeResource.java
@@ -12,6 +12,7 @@
 import org.ovirt.engine.api.model.Action;
 import org.ovirt.engine.api.model.Actionable;
 import org.ovirt.engine.api.model.GlusterVolume;
+import org.ovirt.engine.api.model.GlusterVolumeProfileDetails;
 import org.ovirt.engine.api.resource.ActionResource;
 import org.ovirt.engine.api.resource.ApiMediaType;
 import org.ovirt.engine.api.resource.MeasurableResource;
@@ -91,6 +92,11 @@
     @Path("stopprofile")
     public Response stopProfile(Action action);
 
+    @GET
+    @Formatted
+    @Path("profilestatistics")
+    public GlusterVolumeProfileDetails getProfileStatistics();
+
     /**
      * Sub-resource locator method, returns GlusterBricksResource on which the 
remainder of the URI is dispatched.
      *
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
index e2450cb..ebbc01c7 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/java/org/ovirt/engine/api/utils/LinkHelper.java
@@ -46,6 +46,7 @@
 import org.ovirt.engine.api.model.GlusterBrick;
 import org.ovirt.engine.api.model.GlusterHook;
 import org.ovirt.engine.api.model.GlusterVolume;
+import org.ovirt.engine.api.model.GlusterVolumeProfileDetails;
 import org.ovirt.engine.api.model.Group;
 import org.ovirt.engine.api.model.Hook;
 import org.ovirt.engine.api.model.Host;
@@ -361,6 +362,7 @@
 
         map = new ParentToCollectionMap(GlusterVolumeResource.class, 
GlusterVolumesResource.class, Cluster.class);
         TYPES.put(GlusterVolume.class, map);
+        TYPES.put(GlusterVolumeProfileDetails.class, map);
 
         map = new ParentToCollectionMap(GlusterBrickResource.class, 
GlusterBricksResource.class, GlusterVolume.class);
         TYPES.put(GlusterBrick.class, map);
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
index 58fcca8..528af0d 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/api.xsd
@@ -4049,6 +4049,92 @@
       </xs:extension>
     </xs:complexContent>
   </xs:complexType>
+  
+  <xs:element name="volume_profileDetails" type="GlusterVolumeProfileDetails"/>
+  <xs:complexType name="GlusterVolumeProfileDetails">
+    <xs:annotation>
+      <xs:appinfo>
+         <jaxb:class name="GlusterVolumeProfileDetails"/>
+      </xs:appinfo>
+    </xs:annotation>
+    <xs:complexContent>
+      <xs:extension base="BaseResource">
+        <xs:sequence>
+          <xs:element ref="brick_profileDetails" minOccurs="0" maxOccurs="1"/>
+          <xs:element ref="nfs_profileDetails" minOccurs="0" maxOccurs="1"/>
+         </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:element name="brick_profileDetails" type="BrickProfileDetails"/>
+  <xs:complexType name="BrickProfileDetails">
+    <xs:sequence>
+      <xs:element ref="brick_profileDetail" minOccurs="0" 
maxOccurs="unbounded" />
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="brick_profileDetail" type="BrickProfileDetail"/>
+  <xs:complexType name="BrickProfileDetail">
+  <xs:complexContent>
+     <xs:extension base="EntityProfileDetail">
+      <xs:sequence>
+         <xs:element ref="brick" minOccurs="0" maxOccurs="1"/>
+      </xs:sequence>
+      </xs:extension>
+     </xs:complexContent>
+  </xs:complexType>
+
+  <xs:element name="nfs_profileDetails" type="NfsProfileDetails"/>
+  <xs:complexType name="NfsProfileDetails">
+    <xs:sequence>
+      <xs:element ref="nfs_profileDetail" minOccurs="0" maxOccurs="unbounded" 
/>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="entity_profileDetail" type="EntityProfileDetail"/>
+  <xs:complexType name="EntityProfileDetail">
+   <xs:sequence>
+     <xs:element ref="profile_detail" minOccurs="0" maxOccurs="unbounded"/>
+   </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="nfs_profileDetail" type="NfsProfileDetail"/>
+   <xs:complexType name="NfsProfileDetail">
+    <xs:complexContent>
+     <xs:extension base="EntityProfileDetail">
+      <xs:sequence>
+        <xs:element name="nfsServerIp" type="xs:string" minOccurs="0" 
maxOccurs="1"/>
+      </xs:sequence>
+      </xs:extension>
+     </xs:complexContent>
+  </xs:complexType>
+
+  <xs:element name="profile_detail" type="ProfileDetail" />
+  <xs:complexType name="ProfileDetail">
+    <xs:sequence>
+      <xs:element name="profile_type" type="xs:string" minOccurs="1" 
maxOccurs="1" />
+      <xs:element name="duration" type="xs:int" minOccurs="0" maxOccurs="1" />
+      <xs:element ref="statistic" minOccurs="0" maxOccurs="2"/>
+      <xs:element ref="block_statistic" minOccurs="0" maxOccurs="unbounded"/>
+      <xs:element ref="fop_statistic" minOccurs="0" maxOccurs="unbounded"/>
+    </xs:sequence>
+   </xs:complexType>  
+
+  <xs:element name="block_statistic" type="BlockStatistic"/>
+  <xs:complexType name="BlockStatistic">
+   <xs:sequence>
+     <xs:element ref="statistic" minOccurs="0" maxOccurs="unbounded"/>
+   </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="fop_statistic" type="FopStatistic"/>
+  <xs:complexType name="FopStatistic">
+   <xs:sequence>
+     <xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1"/>
+     <xs:element ref="statistic" minOccurs="0" maxOccurs="unbounded"/>
+   </xs:sequence>
+  </xs:complexType>
 
   <xs:element name="pm_proxies" type="PmProxies"/>
   <xs:complexType name="PmProxies">
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java
index ec8c5c4..ea9f795 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/AbstractStatisticalQuery.java
@@ -1,19 +1,16 @@
 package org.ovirt.engine.api.restapi.resource;
 
 import java.math.BigDecimal;
-import java.math.MathContext;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.UUID;
 
 import org.ovirt.engine.api.model.BaseResource;
 import org.ovirt.engine.api.model.Statistic;
 import org.ovirt.engine.api.model.StatisticType;
 import org.ovirt.engine.api.model.StatisticUnit;
-import org.ovirt.engine.api.model.Value;
 import org.ovirt.engine.api.model.ValueType;
-import org.ovirt.engine.api.model.Values;
 import 
org.ovirt.engine.api.restapi.resource.BaseBackendResource.BackendFailureException;
+import org.ovirt.engine.api.restapi.utils.StatisticResourceUtils;
 import org.ovirt.engine.core.compat.Guid;
 
 /**
@@ -54,21 +51,19 @@
     }
 
     public Statistic setDatum(Statistic statistic, BigDecimal datum) {
-        statistic.getValues().getValues().get(0).setDatum(datum);
-        return statistic;
+        return StatisticResourceUtils.setDatum(statistic, datum);
     }
 
     public Statistic setDatum(Statistic statistic, String datum) {
-        statistic.getValues().getValues().get(0).setDetail(datum);
-        return statistic;
+        return StatisticResourceUtils.setDatum(statistic, datum);
     }
 
     public Statistic setDatum(Statistic statistic, long datum) {
-        return setDatum(statistic, new BigDecimal(datum));
+        return StatisticResourceUtils.setDatum(statistic, datum);
     }
 
     public Statistic setDatum(Statistic statistic, double datum) {
-        return setDatum(statistic, new BigDecimal(datum, new MathContext(2)));
+        return StatisticResourceUtils.setDatum(statistic, datum);
     }
 
     public abstract List<Statistic> getStatistics(E entity);
@@ -80,25 +75,13 @@
                                    StatisticType type,
                                    StatisticUnit unit,
                                    ValueType valueType) {
-        Statistic statistic = new Statistic();
-        statistic.setId(asId(name));
-        statistic.setName(name);
-        statistic.setDescription(description);
-        statistic.setType(type);
-        statistic.setUnit(unit);
-        statistic.setValues(new Values());
-        statistic.getValues().setType(valueType);
-        statistic.getValues().getValues().add(new Value());
-        return statistic;
+        return StatisticResourceUtils.create(name, description, type, unit, 
valueType);
     }
 
     public static Statistic clone(Statistic s) {
         return create(s.getName(), s.getDescription(), s.getType(), 
s.getUnit(), s.getValues().getType());
     }
 
-    public static String asId(String name) {
-        return UUID.nameUUIDFromBytes(name.getBytes()).toString();
-    }
 
     public List<Statistic> asList(Statistic...statistics) {
         List<Statistic> list = new ArrayList<Statistic>();
diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterVolumeResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterVolumeResource.java
index abb58c2..c5c5225 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterVolumeResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/gluster/BackendGlusterVolumeResource.java
@@ -5,13 +5,16 @@
 
 import org.ovirt.engine.api.model.Action;
 import org.ovirt.engine.api.model.GlusterVolume;
+import org.ovirt.engine.api.model.GlusterVolumeProfileDetails;
 import org.ovirt.engine.api.model.Option;
 import org.ovirt.engine.api.resource.StatisticsResource;
 import org.ovirt.engine.api.resource.gluster.GlusterBricksResource;
 import org.ovirt.engine.api.resource.gluster.GlusterVolumeResource;
+import org.ovirt.engine.api.restapi.logging.Messages;
 import org.ovirt.engine.api.restapi.resource.AbstractBackendActionableResource;
 import org.ovirt.engine.api.restapi.resource.BackendStatisticsResource;
 import org.ovirt.engine.api.restapi.resource.VolumeStatisticalQuery;
+import org.ovirt.engine.api.utils.LinkHelper;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import 
org.ovirt.engine.core.common.action.gluster.GlusterVolumeActionParameters;
 import 
org.ovirt.engine.core.common.action.gluster.GlusterVolumeOptionParameters;
@@ -20,8 +23,11 @@
 import 
org.ovirt.engine.core.common.action.gluster.ResetGlusterVolumeOptionsParameters;
 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.GlusterVolumeProfileInfo;
 import org.ovirt.engine.core.common.queries.IdQueryParameters;
+import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
+import 
org.ovirt.engine.core.common.queries.gluster.GlusterVolumeProfileParameters;
 import org.ovirt.engine.core.compat.Guid;
 
 /**
@@ -156,4 +162,20 @@
                 guid,
                 query));
     }
+
+    @Override
+    public GlusterVolumeProfileDetails getProfileStatistics() {
+        VdcQueryReturnValue result = 
runQuery(VdcQueryType.GetGlusterVolumeProfileInfo,
+                new 
GlusterVolumeProfileParameters(Guid.createGuidFromString(parent.getParent().get().getId()),
 guid));
+        if (result != null
+                && result.getSucceeded()
+                && result.getReturnValue() != null) {
+            return LinkHelper.addLinks(uriInfo, 
getMapper(GlusterVolumeProfileInfo.class,
+                    GlusterVolumeProfileDetails.class)
+            .map((GlusterVolumeProfileInfo)result.getReturnValue(), null));
+        } else {
+            //throw exception
+            throw new WebFaultException(null, 
localize(Messages.BACKEND_FAILED), Response.Status.INTERNAL_SERVER_ERROR);
+        }
+    }
 }
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GlusterVolumeProfileInfoMapper.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GlusterVolumeProfileInfoMapper.java
new file mode 100644
index 0000000..db35621
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GlusterVolumeProfileInfoMapper.java
@@ -0,0 +1,115 @@
+package org.ovirt.engine.api.restapi.types;
+
+import static org.ovirt.engine.api.model.StatisticType.GAUGE;
+import static org.ovirt.engine.api.model.StatisticUnit.BYTES;
+import static org.ovirt.engine.api.model.StatisticUnit.SECONDS;
+
+import java.util.List;
+
+import org.ovirt.engine.api.model.BlockStatistic;
+import org.ovirt.engine.api.model.BrickProfileDetail;
+import org.ovirt.engine.api.model.BrickProfileDetails;
+import org.ovirt.engine.api.model.EntityProfileDetail;
+import org.ovirt.engine.api.model.FopStatistic;
+import org.ovirt.engine.api.model.GlusterBrick;
+import org.ovirt.engine.api.model.GlusterVolumeProfileDetails;
+import org.ovirt.engine.api.model.NfsProfileDetail;
+import org.ovirt.engine.api.model.NfsProfileDetails;
+import org.ovirt.engine.api.model.ProfileDetail;
+import org.ovirt.engine.api.model.Statistic;
+import org.ovirt.engine.api.model.StatisticUnit;
+import org.ovirt.engine.api.model.ValueType;
+import org.ovirt.engine.api.restapi.utils.StatisticResourceUtils;
+import org.ovirt.engine.core.common.businessentities.gluster.BlockStats;
+import org.ovirt.engine.core.common.businessentities.gluster.FopStats;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeProfileInfo;
+import org.ovirt.engine.core.common.businessentities.gluster.StatsInfo;
+
+public class GlusterVolumeProfileInfoMapper {
+    private final static Statistic BYTES_BLOCK_READ   = 
StatisticResourceUtils.create("byted.read", "bytes read", GAUGE, BYTES, 
ValueType.INTEGER);
+    private final static Statistic BYTES_BLOCK_WRITE   = 
StatisticResourceUtils.create("bytes.write", "bytes written", GAUGE, BYTES, 
ValueType.INTEGER);
+    private final static Statistic BLOCK_SIZE   = 
StatisticResourceUtils.create("block.size", "block size", GAUGE, BYTES, 
ValueType.INTEGER);
+    private final static Statistic TOTAL_READ   = 
StatisticResourceUtils.create("total.bytes.read", "total bytes read", GAUGE, 
BYTES, ValueType.INTEGER);
+    private final static Statistic TOTAL_WRITE   = 
StatisticResourceUtils.create("total.bytes.write", "blockSize", GAUGE, BYTES, 
ValueType.INTEGER);
+    private final static Statistic MIN_LATENCY   = 
StatisticResourceUtils.create("min.latency", "minimum latency", GAUGE, SECONDS, 
ValueType.INTEGER);
+    private final static Statistic MAX_LATENCY   = 
StatisticResourceUtils.create("max.latency", "maximum latency", GAUGE, SECONDS, 
ValueType.INTEGER);
+    private final static Statistic AVG_LATENCY   = 
StatisticResourceUtils.create("avg.latency", "average latency", GAUGE, SECONDS, 
ValueType.INTEGER);
+    private final static Statistic HITS   = 
StatisticResourceUtils.create("hits", "number of hits", GAUGE, 
StatisticUnit.NONE, ValueType.INTEGER);
+
+
+    @Mapping (from=GlusterVolumeProfileDetails.class, 
to=GlusterVolumeProfileInfo.class)
+    public static GlusterVolumeProfileInfo map(GlusterVolumeProfileDetails 
model, GlusterVolumeProfileInfo toEntity) {
+        //GlusterVolumeProfileInfo is  read only from server and no support 
for setting these.
+        //Hence mapping from REST model to Business entity not required.
+        GlusterVolumeProfileInfo entity = (toEntity == null) ? new 
GlusterVolumeProfileInfo() : toEntity;
+        return entity;
+    }
+
+    @Mapping (from=GlusterVolumeProfileInfo.class, 
to=GlusterVolumeProfileDetails.class)
+    public static GlusterVolumeProfileDetails map(GlusterVolumeProfileInfo 
fromEntity, GlusterVolumeProfileDetails toModel) {
+        GlusterVolumeProfileDetails model = new GlusterVolumeProfileDetails();
+        BrickProfileDetails brickprofileDetails = new BrickProfileDetails();
+        if (fromEntity.getBrickProfileDetails() != null) {
+            for 
(org.ovirt.engine.core.common.businessentities.gluster.BrickProfileDetails 
brickDetailEntity:
+                fromEntity.getBrickProfileDetails()) {
+                BrickProfileDetail brickprofileDetail = new 
BrickProfileDetail();
+                brickprofileDetail.setBrick(new GlusterBrick());
+                
brickprofileDetail.getBrick().setBrickDir(brickDetailEntity.getBrickName());
+                mapProfileDetails(brickDetailEntity.getStatsInfo(), 
brickprofileDetail);
+                
brickprofileDetails.getBrickProfileDetail().add(brickprofileDetail);
+            }
+        }
+        model.setBrickProfileDetails(brickprofileDetails);
+
+        NfsProfileDetails nfsprofileDetails = new NfsProfileDetails();
+        if (fromEntity.getNfsProfileDetails() != null) {
+            for 
(org.ovirt.engine.core.common.businessentities.gluster.NfsProfileDetails 
nfsDetailEntity:
+                fromEntity.getNfsProfileDetails()) {
+                NfsProfileDetail nfsprofileDetail = new NfsProfileDetail();
+                
nfsprofileDetail.setNfsServerIp(nfsDetailEntity.getNfsServerIp());
+                mapProfileDetails(nfsDetailEntity.getStatsInfo(), 
nfsprofileDetail);
+                nfsprofileDetails.getNfsProfileDetail().add(nfsprofileDetail);
+            }
+        }
+        model.setNfsProfileDetails(nfsprofileDetails);
+        return model;
+    }
+
+    private static void mapProfileDetails(List<StatsInfo> statsInfoList,
+            EntityProfileDetail entityprofileDetail) {
+        for (StatsInfo statsInfo: statsInfoList) {
+            ProfileDetail profileDetail = new ProfileDetail();
+            
profileDetail.setProfileType(statsInfo.getProfileStatsType().name());
+            profileDetail.setDuration(statsInfo.getDuration());
+            
profileDetail.getStatistic().add(StatisticResourceUtils.setDatum(TOTAL_READ, 
statsInfo.getTotalRead()));
+            
profileDetail.getStatistic().add(StatisticResourceUtils.setDatum(TOTAL_WRITE, 
statsInfo.getTotalWrite()));
+            mapBlockStats(profileDetail, statsInfo);
+            mapFopStats(profileDetail, statsInfo);
+            entityprofileDetail.getProfileDetail().add(profileDetail);
+
+        }
+    }
+
+    private static void mapFopStats(ProfileDetail profileDetail, StatsInfo 
statsInfo) {
+        for (FopStats fopStat: statsInfo.getFopStats()) {
+            FopStatistic fStat = new FopStatistic();
+            fStat.setName(fopStat.getName());
+            
fStat.getStatistic().add(StatisticResourceUtils.setDatum(MIN_LATENCY, 
fopStat.getMinLatency()));
+            
fStat.getStatistic().add(StatisticResourceUtils.setDatum(MAX_LATENCY, 
fopStat.getMaxLatency()));
+            
fStat.getStatistic().add(StatisticResourceUtils.setDatum(AVG_LATENCY, 
fopStat.getAvgLatency()));
+            fStat.getStatistic().add(StatisticResourceUtils.setDatum(HITS, 
fopStat.getHits()));
+            profileDetail.getFopStatistic().add(fStat);
+        }
+    }
+
+    private static void mapBlockStats(ProfileDetail profileDetail, StatsInfo 
statsInfo) {
+        for (BlockStats blockStat: statsInfo.getBlockStats()) {
+            BlockStatistic bStat = new BlockStatistic();
+            
bStat.getStatistic().add(StatisticResourceUtils.setDatum(BLOCK_SIZE, 
blockStat.getSize()));
+            
bStat.getStatistic().add(StatisticResourceUtils.setDatum(BYTES_BLOCK_READ, 
blockStat.getBlockRead()));
+            
bStat.getStatistic().add(StatisticResourceUtils.setDatum(BYTES_BLOCK_WRITE, 
blockStat.getBlockWrite()));
+            profileDetail.getBlockStatistic().add(bStat);
+        }
+    }
+
+}
diff --git 
a/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/StatisticResourceUtils.java
 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/StatisticResourceUtils.java
new file mode 100644
index 0000000..49339ce
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/utils/StatisticResourceUtils.java
@@ -0,0 +1,55 @@
+package org.ovirt.engine.api.restapi.utils;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.util.UUID;
+
+import org.ovirt.engine.api.model.Statistic;
+import org.ovirt.engine.api.model.StatisticType;
+import org.ovirt.engine.api.model.StatisticUnit;
+import org.ovirt.engine.api.model.Value;
+import org.ovirt.engine.api.model.ValueType;
+import org.ovirt.engine.api.model.Values;
+
+public class StatisticResourceUtils {
+
+    public static Statistic create(String name,
+            String description,
+            StatisticType type,
+            StatisticUnit unit,
+            ValueType valueType) {
+        Statistic statistic = new Statistic();
+        statistic.setId(asId(name));
+        statistic.setName(name);
+        statistic.setDescription(description);
+        statistic.setType(type);
+        statistic.setUnit(unit);
+        statistic.setValues(new Values());
+        statistic.getValues().setType(valueType);
+        statistic.getValues().getValues().add(new Value());
+        return statistic;
+    }
+
+    public static String asId(String name) {
+        return UUID.nameUUIDFromBytes(name.getBytes()).toString();
+    }
+
+    public static Statistic setDatum(Statistic statistic, BigDecimal datum) {
+        statistic.getValues().getValues().get(0).setDatum(datum);
+        return statistic;
+    }
+
+    public static Statistic setDatum(Statistic statistic, String datum) {
+        statistic.getValues().getValues().get(0).setDetail(datum);
+        return statistic;
+    }
+
+    public static Statistic setDatum(Statistic statistic, long datum) {
+        return setDatum(statistic, new BigDecimal(datum));
+    }
+
+    public static Statistic setDatum(Statistic statistic, double datum) {
+        return setDatum(statistic, new BigDecimal(datum, new MathContext(2)));
+    }
+
+}


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

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

Reply via email to