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

/api/clusters/../glustervolumes/{id}/profilestatistics[;nfsStatistics]

which returns output in format:
<volume_profileDetails>
 <brick_profileDetails>
  <brick_profileDetail>
    <brick><brick_dir>10.70.43.53:/bricks/b2</brick_dir></brick>
    <profile_detail>
      <profile_type>INTERVAL</profile_type>
      <duration>348</duration>
      <statistic id="fa...e"><name>total.bytes.read</name> ...</statistic>
       <block_statistic>
          <statistic id="c2...3"><name>block.size</name> ..</statistic>
          <statistic id="23...7"><name>bytes.read</name> ...</statistic>
          <statistic id="40...2"><name>bytes.write</name> ...</statistic>
       </block_statistic>
       <block_statistic>
       ...
       </block_statistic>
       <fop_statistic>
          <name>LOOKUP</name>
          <statistic id="1d...7"><name>min.latency</name>< ...</statistic>
          ...
       <fop_statistic>
    </profile_detail>
  </brick_profileDetail>
  ...
  <nfs_profileDetails>
     <nfs_profileDetail>
     <nfsServerIp>server-ip</nfsServerIp>
        <profile_detail> ... </profile_detail>
     </nfs_profileDetail>
  </nfs_profileDetails>
</volume_profileDetails>

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/interface/definition/src/main/resources/rsdl_metadata.yaml
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
8 files changed, 320 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/58/28358/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 ea8fd49..3354662 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;
@@ -367,6 +368,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 b61773b..3334af7 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
@@ -4117,6 +4117,92 @@
     </xs:complexContent>
   </xs:complexType>
 
+  <xs:element name="volume_profile_details" 
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_profile_details" minOccurs="0" maxOccurs="1"/>
+          <xs:element ref="nfs_profile_details" minOccurs="0" maxOccurs="1"/>
+         </xs:sequence>
+      </xs:extension>
+    </xs:complexContent>
+  </xs:complexType>
+
+  <xs:element name="brick_profile_details" type="BrickProfileDetails"/>
+  <xs:complexType name="BrickProfileDetails">
+    <xs:sequence>
+      <xs:element ref="brick_profile_detail" minOccurs="0" 
maxOccurs="unbounded" />
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="brick_profile_detail" 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_profile_details" type="NfsProfileDetails"/>
+  <xs:complexType name="NfsProfileDetails">
+    <xs:sequence>
+      <xs:element ref="nfs_profile_detail" minOccurs="0" maxOccurs="unbounded" 
/>
+    </xs:sequence>
+  </xs:complexType>
+
+  <xs:element name="entity_profile_detail" 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_profile_detail" type="NfsProfileDetail"/>
+  <xs:complexType name="NfsProfileDetail">
+    <xs:complexContent>
+      <xs:extension base="EntityProfileDetail">
+        <xs:sequence>
+          <xs:element name="nfs_server_ip" 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">
     <xs:sequence>
diff --git 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
index fd4bd16..540ca7a 100644
--- 
a/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
+++ 
b/backend/manager/modules/restapi/interface/definition/src/main/resources/rsdl_metadata.yaml
@@ -4377,6 +4377,15 @@
     headers:
       Content-Type: {value: application/xml|json, required: true}
       Correlation-Id: {value: 'any string', required: false}
+- name: 
/clusters/{cluster:id}/glustervolumes/{glustervolume:id}/profilestatistics|rel=get
+  description: get the profiling statistics once profiling is turned on for a 
volume
+  request:
+    body:
+      parameterType: null
+      signatures: []
+    urlparams:
+      nfsStatistics: {context: matrix, type: 'xs:boolean', value: true|false, 
required: false}
+    headers: {}
 - name: /clusters/{cluster:id}/glustervolumes/{glustervolume:id}/bricks|rel=get
   description: get the list of all bricks in the gluster volume attached to 
the cluster
   request:
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..4f3cbd2 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
@@ -1,17 +1,23 @@
 package org.ovirt.engine.api.restapi.resource.gluster;
 
+import java.util.HashMap;
+
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 
+import org.ovirt.engine.api.common.util.QueryHelper;
 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 +26,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;
 
 /**
@@ -30,6 +39,7 @@
 public class BackendGlusterVolumeResource
         extends AbstractBackendActionableResource<GlusterVolume, 
GlusterVolumeEntity>
         implements GlusterVolumeResource {
+    private static final String NFS_CONSTRAINT_PARAMETER = "nfsStatistics";
     private BackendGlusterVolumesResource parent;
 
     public BackendGlusterVolumeResource(String volumeId, 
BackendGlusterVolumesResource parent) {
@@ -156,4 +166,31 @@
                 guid,
                 query));
     }
+
+    @Override
+    public GlusterVolumeProfileDetails getProfileStatistics() {
+        boolean nfsStats = isNfsStatistics();
+        VdcQueryReturnValue result = 
runQuery(VdcQueryType.GetGlusterVolumeProfileInfo,
+                new 
GlusterVolumeProfileParameters(Guid.createGuidFromString(parent.getParent().get().getId()),
 guid, nfsStats));
+        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);
+        }
+    }
+
+    private Boolean isNfsStatistics() {
+        if (getUriInfo() != null && QueryHelper.hasMatrixParam(getUriInfo(), 
NFS_CONSTRAINT_PARAMETER)) {
+            HashMap<String, String> matrixConstraints = 
QueryHelper.getMatrixConstraints(getUriInfo(), NFS_CONSTRAINT_PARAMETER);
+            String maxString = matrixConstraints.get(NFS_CONSTRAINT_PARAMETER);
+                return Boolean.valueOf(maxString);
+        } else {
+            return false;
+        }
+    }
 }
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..777615e
--- /dev/null
+++ 
b/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/GlusterVolumeProfileInfoMapper.java
@@ -0,0 +1,119 @@
+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("block.bytes.read", "bytes read", GAUGE, BYTES, 
ValueType.INTEGER);
+    private final static Statistic BYTES_BLOCK_WRITE   = 
StatisticResourceUtils.create("block.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(clone(TOTAL_READ),
 statsInfo.getTotalRead()));
+            
profileDetail.getStatistic().add(StatisticResourceUtils.setDatum(clone(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(clone(MIN_LATENCY), 
fopStat.getMinLatency()));
+            
fStat.getStatistic().add(StatisticResourceUtils.setDatum(clone(MAX_LATENCY), 
fopStat.getMaxLatency()));
+            
fStat.getStatistic().add(StatisticResourceUtils.setDatum(clone(AVG_LATENCY), 
fopStat.getAvgLatency()));
+            
fStat.getStatistic().add(StatisticResourceUtils.setDatum(clone(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(clone(BLOCK_SIZE), 
blockStat.getSize()));
+            
bStat.getStatistic().add(StatisticResourceUtils.setDatum(clone(BYTES_BLOCK_READ),
 blockStat.getBlockRead()));
+            
bStat.getStatistic().add(StatisticResourceUtils.setDatum(clone(BYTES_BLOCK_WRITE),
 blockStat.getBlockWrite()));
+            profileDetail.getBlockStatistic().add(bStat);
+        }
+    }
+
+    public static Statistic clone(Statistic s) {
+        return StatisticResourceUtils.create(s.getName(), s.getDescription(), 
s.getType(), s.getUnit(), s.getValues().getType());
+    }
+
+}
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..d73a748
--- /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;
+    }
+
+    private 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/28358
To unsubscribe, visit http://gerrit.ovirt.org/settings

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

Reply via email to