cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [cloudstack] branch master updated: CLOUDSTACK-8939: VM Snapshot size with memory correctly calculated in cloud.usage_event (XenServer) (#914)
Date Fri, 01 Sep 2017 09:00:59 GMT
This is an automated email from the ASF dual-hosted git repository.

bhaisaab pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/master by this push:
     new 0d81e88  CLOUDSTACK-8939: VM Snapshot size with memory correctly calculated in cloud.usage_event
(XenServer) (#914)
0d81e88 is described below

commit 0d81e88601f015b23217832bca05fbed6d754f82
Author: subhash yedugundla <venkata.yedugundla@accelerite.com>
AuthorDate: Fri Sep 1 14:30:55 2017 +0530

    CLOUDSTACK-8939: VM Snapshot size with memory correctly calculated in cloud.usage_event
(XenServer) (#914)
    
    Fixing the error  with snapshot size calculation  in a vm with memory
---
 .../xenserver/resource/CitrixResourceBase.java     | 42 +++++++++++++---------
 .../CitrixCreateVMSnapshotCommandWrapper.java      |  8 +++--
 .../CitrixDeleteVMSnapshotCommandWrapper.java      |  9 +++--
 3 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
index 10c4307..f960b9f 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java
@@ -3333,7 +3333,7 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
         return _instance;
     }
 
-    public long getVMSnapshotChainSize(final Connection conn, final VolumeObjectTO volumeTo,
final String vmName) throws BadServerResponse, XenAPIException, XmlRpcException {
+    public long getVMSnapshotChainSize(final Connection conn, final VolumeObjectTO volumeTo,
final String vmName, final String vmSnapshotName) throws BadServerResponse, XenAPIException,
XmlRpcException {
         if (volumeTo.getVolumeType() == Volume.Type.DATADISK) {
             final VDI dataDisk = VDI.getByUuid(conn, volumeTo.getPath());
             if (dataDisk != null) {
@@ -3364,25 +3364,33 @@ public abstract class CitrixResourceBase implements ServerResource,
HypervisorRe
             }
         }
         if (volumeTo.getVolumeType() == Volume.Type.ROOT) {
-            final Map<VM, VM.Record> allVMs = VM.getAllRecords(conn);
-            // add size of memory snapshot vdi
-            if (allVMs != null && allVMs.size() > 0) {
-                for (final VM vmr : allVMs.keySet()) {
-                    try {
-                        final String vName = vmr.getNameLabel(conn);
-                        if (vName != null && vName.contains(vmName) && vmr.getIsASnapshot(conn))
{
-                            final VDI memoryVDI = vmr.getSuspendVDI(conn);
-                            if (!isRefNull(memoryVDI)) {
-                                size = size + memoryVDI.getPhysicalUtilisation(conn);
-                                final VDI pMemoryVDI = memoryVDI.getParent(conn);
-                                if (!isRefNull(pMemoryVDI)) {
-                                    size = size + pMemoryVDI.getPhysicalUtilisation(conn);
+            VM vm = getVM(conn, vmName);
+            if(vm != null){
+                Set<VM> vmSnapshots=vm.getSnapshots(conn);
+                if(vmSnapshots != null){
+                    for(VM vmsnap: vmSnapshots){
+                        try {
+                            final String vmSnapName = vmsnap.getNameLabel(conn);
+                            s_logger.debug("snapname " + vmSnapName);
+                            if (vmSnapName != null && vmSnapName.contains(vmSnapshotName)
&& vmsnap.getIsASnapshot(conn)) {
+                                s_logger.debug("snapname " + vmSnapName + "isASnapshot");
+                                VDI memoryVDI = vmsnap.getSuspendVDI(conn);
+                                if (!isRefNull(memoryVDI)) {
+                                    size = size + memoryVDI.getPhysicalUtilisation(conn);
+                                    s_logger.debug("memoryVDI size :"+size);
+                                    String parentUuid = memoryVDI.getSmConfig(conn).get("vhd-parent");
+                                    VDI pMemoryVDI = VDI.getByUuid(conn, parentUuid);
+                                    if (!isRefNull(pMemoryVDI)) {
+                                        size = size + pMemoryVDI.getPhysicalUtilisation(conn);
+                                    }
+                                    s_logger.debug("memoryVDI size+parent :"+size);
                                 }
                             }
+                           } catch (Exception e) {
+                            s_logger.debug("Exception occurs when calculate snapshot capacity
for memory: due to " + e.toString());
+                            continue;
                         }
-                    } catch (final Exception e) {
-                        s_logger.debug("Exception occurs when calculate snapshot capacity
for memory: due to " + e.toString());
-                        continue;
+
                     }
                 }
             }
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java
index 4550cf8..6bd843d 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixCreateVMSnapshotCommandWrapper.java
@@ -23,6 +23,7 @@ import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
+import com.cloud.utils.exception.CloudRuntimeException;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.log4j.Logger;
 
@@ -142,8 +143,11 @@ public final class CitrixCreateVMSnapshotCommandWrapper extends CommandWrapper<C
             }
             // calculate used capacity for this VM snapshot
             for (final VolumeObjectTO volumeTo : command.getVolumeTOs()) {
-                final long size = citrixResourceBase.getVMSnapshotChainSize(conn, volumeTo,
command.getVmName());
-                volumeTo.setSize(size);
+                try {
+                    final long size = citrixResourceBase.getVMSnapshotChainSize(conn, volumeTo,
command.getVmName(), vmSnapshotName);
+                    volumeTo.setSize(size);
+                } catch (final CloudRuntimeException cre) {
+                }
             }
 
             success = true;
diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java
b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java
index a341c76..3aeeb42 100644
--- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java
+++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixDeleteVMSnapshotCommandWrapper.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
 
+import com.cloud.utils.exception.CloudRuntimeException;
 import org.apache.cloudstack.storage.to.VolumeObjectTO;
 import org.apache.log4j.Logger;
 
@@ -79,8 +80,12 @@ public final class CitrixDeleteVMSnapshotCommandWrapper extends CommandWrapper<D
             }
             // re-calculate used capacify for this VM snapshot
             for (final VolumeObjectTO volumeTo : command.getVolumeTOs()) {
-                final long size = citrixResourceBase.getVMSnapshotChainSize(conn, volumeTo,
command.getVmName());
-                volumeTo.setSize(size);
+                try {
+                    final long size = citrixResourceBase.getVMSnapshotChainSize(conn, volumeTo,
command.getVmName(), snapshotName);
+                    volumeTo.setSize(size);
+                } catch (final CloudRuntimeException cre) {
+
+                }
             }
 
             return new DeleteVMSnapshotAnswer(command, command.getVolumeTOs());

-- 
To stop receiving notification emails like this one, please contact
['"commits@cloudstack.apache.org" <commits@cloudstack.apache.org>'].

Mime
View raw message