Repository: cloudstack
Updated Branches:
  refs/heads/4.9 9a8841d0d -> 2ebf94928


CLOUDSTACK-9535: [API] listVMSnapshots improvement


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f4a42ab0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f4a42ab0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f4a42ab0

Branch: refs/heads/4.9
Commit: f4a42ab0d7aa559e007e263b54e67d4ce9a0e2ad
Parents: 9a8841d
Author: nvazquez <nicolas.m.vazq...@gmail.com>
Authored: Mon Oct 3 15:56:32 2016 -0300
Committer: nvazquez <nicolas.m.vazq...@gmail.com>
Committed: Wed Oct 5 17:42:14 2016 -0300

----------------------------------------------------------------------
 .../com/cloud/vm/snapshot/VMSnapshotService.java    |  3 ++-
 .../command/user/vmsnapshot/ListVMSnapshotCmd.java  |  7 ++++---
 server/src/com/cloud/api/ApiResponseHelper.java     | 16 ++++++++++++++++
 .../cloud/vm/snapshot/VMSnapshotManagerImpl.java    |  5 +++--
 4 files changed, 25 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f4a42ab0/api/src/com/cloud/vm/snapshot/VMSnapshotService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/vm/snapshot/VMSnapshotService.java 
b/api/src/com/cloud/vm/snapshot/VMSnapshotService.java
index 839da73..12767b3 100644
--- a/api/src/com/cloud/vm/snapshot/VMSnapshotService.java
+++ b/api/src/com/cloud/vm/snapshot/VMSnapshotService.java
@@ -27,11 +27,12 @@ import 
com.cloud.exception.InsufficientServerCapacityException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.exception.ResourceUnavailableException;
 import com.cloud.uservm.UserVm;
+import com.cloud.utils.Pair;
 import com.cloud.vm.VirtualMachine;
 
 public interface VMSnapshotService {
 
-    List<? extends VMSnapshot> listVMSnapshots(ListVMSnapshotCmd cmd);
+    Pair<List<? extends VMSnapshot>, Integer> 
listVMSnapshots(ListVMSnapshotCmd cmd);
 
     VMSnapshot getVMSnapshotById(Long id);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f4a42ab0/api/src/org/apache/cloudstack/api/command/user/vmsnapshot/ListVMSnapshotCmd.java
----------------------------------------------------------------------
diff --git 
a/api/src/org/apache/cloudstack/api/command/user/vmsnapshot/ListVMSnapshotCmd.java
 
b/api/src/org/apache/cloudstack/api/command/user/vmsnapshot/ListVMSnapshotCmd.java
index ad5126e..9b2634d 100644
--- 
a/api/src/org/apache/cloudstack/api/command/user/vmsnapshot/ListVMSnapshotCmd.java
+++ 
b/api/src/org/apache/cloudstack/api/command/user/vmsnapshot/ListVMSnapshotCmd.java
@@ -28,6 +28,7 @@ import org.apache.cloudstack.api.response.ListResponse;
 import org.apache.cloudstack.api.response.UserVmResponse;
 import org.apache.cloudstack.api.response.VMSnapshotResponse;
 
+import com.cloud.utils.Pair;
 import com.cloud.vm.snapshot.VMSnapshot;
 
 @APICommand(name = "listVMSnapshot", description = "List virtual machine 
snapshot by conditions", responseObject = VMSnapshotResponse.class, since = 
"4.2.0", entityType = {VMSnapshot.class},
@@ -69,15 +70,15 @@ public class ListVMSnapshotCmd extends 
BaseListTaggedResourcesCmd {
 
     @Override
     public void execute() {
-        List<? extends VMSnapshot> result = 
_vmSnapshotService.listVMSnapshots(this);
+        Pair<List<? extends VMSnapshot>,Integer> result = 
_vmSnapshotService.listVMSnapshots(this);
         ListResponse<VMSnapshotResponse> response = new 
ListResponse<VMSnapshotResponse>();
         List<VMSnapshotResponse> snapshotResponses = new 
ArrayList<VMSnapshotResponse>();
-        for (VMSnapshot r : result) {
+        for (VMSnapshot r : result.first()) {
             VMSnapshotResponse vmSnapshotResponse = 
_responseGenerator.createVMSnapshotResponse(r);
             vmSnapshotResponse.setObjectName("vmSnapshot");
             snapshotResponses.add(vmSnapshotResponse);
         }
-        response.setResponses(snapshotResponses);
+        response.setResponses(snapshotResponses, result.second());
         response.setResponseName(getCommandName());
         setResponseObject(response);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f4a42ab0/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java 
b/server/src/com/cloud/api/ApiResponseHelper.java
index 66b8faa..6a7f0ab 100644
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -194,6 +194,7 @@ import com.cloud.configuration.ResourceLimit;
 import com.cloud.dc.ClusterDetailsDao;
 import com.cloud.dc.ClusterVO;
 import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenterVO;
 import com.cloud.dc.HostPodVO;
 import com.cloud.dc.Pod;
 import com.cloud.dc.StorageNetworkIpRange;
@@ -201,6 +202,7 @@ import com.cloud.dc.Vlan;
 import com.cloud.dc.Vlan.VlanType;
 import com.cloud.dc.VlanVO;
 import com.cloud.domain.Domain;
+import com.cloud.domain.DomainVO;
 import com.cloud.event.Event;
 import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
@@ -552,6 +554,10 @@ public class ApiResponseHelper implements 
ResponseGenerator {
         UserVm vm = ApiDBUtils.findUserVmById(vmSnapshot.getVmId());
         if (vm != null) {
             vmSnapshotResponse.setVirtualMachineid(vm.getUuid());
+            DataCenterVO datacenter = 
ApiDBUtils.findZoneById(vm.getDataCenterId());
+            if (datacenter != null) {
+                vmSnapshotResponse.setZoneId(datacenter.getUuid());
+            }
         }
         if (vmSnapshot.getParent() != null) {
             VMSnapshot vmSnapshotParent = 
ApiDBUtils.getVMSnapshotById(vmSnapshot.getParent());
@@ -565,6 +571,16 @@ public class ApiResponseHelper implements 
ResponseGenerator {
             vmSnapshotResponse.setProjectId(project.getUuid());
             vmSnapshotResponse.setProjectName(project.getName());
         }
+        Account account = 
ApiDBUtils.findAccountById(vmSnapshot.getAccountId());
+        if (account != null) {
+            vmSnapshotResponse.setAccountName(account.getAccountName());
+        }
+        DomainVO domain = ApiDBUtils.findDomainById(vmSnapshot.getDomainId());
+        if (domain != null) {
+            vmSnapshotResponse.setDomainId(domain.getUuid());
+            vmSnapshotResponse.setDomainName(domain.getName());
+        }
+
         vmSnapshotResponse.setCurrent(vmSnapshot.getCurrent());
         vmSnapshotResponse.setType(vmSnapshot.getType().toString());
         vmSnapshotResponse.setObjectName("vmsnapshot");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f4a42ab0/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java 
b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
index d8f4596..bb1536d 100644
--- a/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
+++ b/server/src/com/cloud/vm/snapshot/VMSnapshotManagerImpl.java
@@ -163,7 +163,7 @@ public class VMSnapshotManagerImpl extends 
MutualExclusiveIdsManagerBase impleme
     }
 
     @Override
-    public List<VMSnapshotVO> listVMSnapshots(ListVMSnapshotCmd cmd) {
+    public Pair<List<? extends VMSnapshot>, Integer> 
listVMSnapshots(ListVMSnapshotCmd cmd) {
         Account caller = getCaller();
         List<Long> permittedAccounts = new ArrayList<Long>();
 
@@ -243,7 +243,8 @@ public class VMSnapshotManagerImpl extends 
MutualExclusiveIdsManagerBase impleme
             sc.setParameters("id", id);
         }
 
-        return _vmSnapshotDao.search(sc, searchFilter);
+        Pair<List<VMSnapshotVO>,Integer> searchAndCount = 
_vmSnapshotDao.searchAndCount(sc, searchFilter);
+        return new Pair<List<? extends VMSnapshot>, 
Integer>(searchAndCount.first(), searchAndCount.second());
 
     }
 

Reply via email to