Arik Hadas has uploaded a new change for review.

Change subject: core: cleanup in hibernate command
......................................................................

core: cleanup in hibernate command

- rename _storageDomainId to cachedStorageDomainId and do not initialize
  it to Empty guid but use 'null' value instead

- remove redundant reload of the VM in the 'perform' method, as the VM
  is already locked, thus no multi-requests for hibernation is possible

- use getStoragePoolId instead of getVm().getStoragePoolId, since it is
  the same

Change-Id: Ib714ea598fdd8da26ae077efc3298cd0861fb02f
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HibernateVmCommand.java
1 file changed, 12 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/83/36883/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HibernateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HibernateVmCommand.java
index d4dcbb7..ffe5dbb 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HibernateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HibernateVmCommand.java
@@ -47,7 +47,9 @@
 
     private static final String SAVE_IMAGE_TASK_KEY = "SAVE_IMAGE_TASK_KEY";
     private static final String SAVE_RAM_STATE_TASK_KEY = 
"SAVE_RAM_STATE_TASK_KEY";
+
     private boolean isHibernateVdsProblematic = false;
+    private Guid cachedStorageDomainId;
 
     /**
      * Constructor for command creation when compensation is applied on startup
@@ -71,8 +73,6 @@
         return lockProperties.withScope(Scope.Execution);
     }
 
-    private Guid _storageDomainId = Guid.Empty;
-
     @Override
     protected void insertAsyncTaskPlaceHolders() {
         persistAsyncTaskPlaceHolder(getParameters().getParentCommand(), 
SAVE_IMAGE_TASK_KEY);
@@ -89,22 +89,20 @@
      */
     @Override
     public Guid getStorageDomainId() {
-        if (_storageDomainId.equals(Guid.Empty) && getVm() != null) {
-            List<DiskImage> diskDummiesForMemSize = 
MemoryUtils.createDiskDummies(getVm().getTotalMemorySizeInBytes(),
+        if (cachedStorageDomainId == null) {
+            List<DiskImage> diskDummiesForMemSize = 
MemoryUtils.createDiskDummies(
+                    getVm().getTotalMemorySizeInBytes(),
                     MemoryUtils.META_DATA_SIZE_IN_BYTES);
-            StorageDomain storageDomain = 
VmHandler.findStorageDomainForMemory(getVm().getStoragePoolId(), 
diskDummiesForMemSize);
+            StorageDomain storageDomain = 
VmHandler.findStorageDomainForMemory(getStoragePoolId(), diskDummiesForMemSize);
             if (storageDomain != null) {
-                _storageDomainId = storageDomain.getId();
+                cachedStorageDomainId = storageDomain.getId();
             }
         }
-        return _storageDomainId;
+        return cachedStorageDomainId;
     }
 
     @Override
     protected void perform() {
-        // Set the VM to null, to fetch it again from the DB ,instead from the 
cache.
-        // We want to get the VM state from the DB, to avoid multi requests 
for VM hibernation.
-        setVm(null);
         if (getVm().isRunning()) {
 
             TransactionSupport.executeInNewTransaction(
@@ -132,7 +130,7 @@
                     runVdsCommand(
                                     VDSCommandType.CreateImage,
                                     new CreateImageVDSCommandParameters(
-                                            getVm().getStoragePoolId(),
+                                            getStoragePoolId(),
                                             getStorageDomainId(),
                                             image1GroupId,
                                             
getVm().getTotalMemorySizeInBytes(),
@@ -170,7 +168,7 @@
             VDSReturnValue ret2 =
                     runVdsCommand(
                                     VDSCommandType.CreateImage,
-                                    new 
CreateImageVDSCommandParameters(getVm().getStoragePoolId(),
+                                    new 
CreateImageVDSCommandParameters(getStoragePoolId(),
                                             getStorageDomainId(),
                                             image2GroupId,
                                             
MemoryUtils.META_DATA_SIZE_IN_BYTES,
@@ -187,7 +185,7 @@
 
             getSnapshotDAO().updateHibernationMemory(getVmId(),
                     MemoryUtils.createMemoryStateString(
-                            getStorageDomainId(), getVm().getStoragePoolId(),
+                            getStorageDomainId(), getStoragePoolId(),
                             image1GroupId, hiberVol1, image2GroupId, 
hiberVol2));
 
             getParameters().setVdsmTaskIds(new 
ArrayList<Guid>(getReturnValue().getVdsmTaskIdList()));
@@ -260,7 +258,7 @@
             return 
failCanDoAction(VdcBllMessages.VM_CANNOT_SUSPEND_STATELESS_VM);
         }
 
-        if (getStorageDomainId().equals(Guid.Empty)) {
+        if (getStorageDomainId() == null) {
             return 
failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_NO_SUITABLE_DOMAIN_FOUND);
         }
 


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

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

Reply via email to