Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Add "size" support to VMs
......................................................................

restapi: Add "size" support to VMs

This patch adds support for new "size" detail specifications for the VMs
collection.

When the "size" detail is requested the result will look like thiss:

  GET /vms;detail=+size HTTP/1.1
  All-Content: true

  <vms>
    <size>123</size>
    <vm id="..." href="...">
      ...
    </vm>
    ...
  </vms>

The "main" detail is intended to suppress output of the actual data, so that
only the size will be populated:

  GET /vms;detail=-main+size HTTP/1.1
  All-Content: true

  <vms>
    <size>123</size>
  </vms>

Change-Id: Ic089745a03e7f01d4c96e9267c0ff084bd913e0d
Bug-Url: https://bugzilla.redhat.com/1132247
Signed-off-by: Juan Hernandez <[email protected]>
---
M 
backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
1 file changed, 27 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/89/34589/1

diff --git 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
index 0ca1361..092171c 100644
--- 
a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
+++ 
b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendVmsResource.java
@@ -511,27 +511,38 @@
     }
 
     protected VMs 
mapCollection(List<org.ovirt.engine.core.common.businessentities.VM> entities, 
boolean isFiltered) {
-        // Fill VmInit for entities - the search query no join the VmInit to Vm
-        IdsQueryParameters params = new IdsQueryParameters();
-        List<Guid> ids = Entities.getIds(entities);
-        params.setId(ids);
-        VdcQueryReturnValue queryReturnValue = 
runQuery(VdcQueryType.GetVmsInit, params);
-        if (queryReturnValue.getSucceeded() && 
queryReturnValue.getReturnValue() != null) {
-            List<VmInit> vmInits = queryReturnValue.getReturnValue();
-            Map<Guid, VmInit> initMap = Entities.businessEntitiesById(vmInits);
-            for (org.ovirt.engine.core.common.businessentities.VM vm : 
entities) {
-                vm.setVmInit(initMap.get(vm.getId()));
+        Set<String> details = DetailHelper.getDetails(httpHeaders, uriInfo);
+        boolean includeData = details.contains(DetailHelper.MAIN);
+        boolean includeSize = details.contains("size");
+
+        if (includeData) {
+            // Fill VmInit for entities - the search query no join the VmInit 
to Vm
+            IdsQueryParameters params = new IdsQueryParameters();
+            List<Guid> ids = Entities.getIds(entities);
+            params.setId(ids);
+            VdcQueryReturnValue queryReturnValue = 
runQuery(VdcQueryType.GetVmsInit, params);
+            if (queryReturnValue.getSucceeded() && 
queryReturnValue.getReturnValue() != null) {
+                List<VmInit> vmInits = queryReturnValue.getReturnValue();
+                Map<Guid, VmInit> initMap = 
Entities.businessEntitiesById(vmInits);
+                for (org.ovirt.engine.core.common.businessentities.VM vm : 
entities) {
+                    vm.setVmInit(initMap.get(vm.getId()));
+                }
             }
         }
 
         VMs collection = new VMs();
-        for (org.ovirt.engine.core.common.businessentities.VM entity : 
entities) {
-            VM vm = map(entity);
-         // Filtered users are not allowed to view host related information
-            if (isFiltered) {
-                removeRestrictedInfoFromVM(vm);
+        if (includeData) {
+            for (org.ovirt.engine.core.common.businessentities.VM entity : 
entities) {
+                VM vm = map(entity);
+                // Filtered users are not allowed to view host related 
information
+                if (isFiltered) {
+                    removeRestrictedInfoFromVM(vm);
+                }
+                collection.getVMs().add(addLinks(populate(vm, entity)));
             }
-            collection.getVMs().add(addLinks(populate(vm, entity)));
+        }
+        if (includeSize) {
+            collection.setSize((long) entities.size());
         }
         return collection;
     }


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

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

Reply via email to