Arik Hadas has uploaded a new change for review.

Change subject: core: minor improvements in StopVmCommandBase
......................................................................

core: minor improvements in StopVmCommandBase

- set StopVmCommandBase#suspendedVm only if the VM status is suspended
  (it is currently being set if the VM has hibernation volumes and
  different status as well)

- rename StopVmCommandBase#stopSuspendedVm method to
  removeHibernationVolumes as it is used to remove the hibernation
  volumes from VMs that are not suspended as well.

- removed usages of DBFacade class

Change-Id: Ie347eb6b9df6284038dd5b9028f3d39d81e04f64
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
1 file changed, 28 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/73/17473/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
index fa90ef5..235bb5a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
@@ -21,7 +21,6 @@
 import 
org.ovirt.engine.core.common.vdscommands.UpdateVmDynamicDataVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.compat.Guid;
-import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
@@ -80,11 +79,17 @@
     @Override
     protected void executeVmCommand() {
         getParameters().setEntityInfo(new EntityInfo(VdcObjectType.VM, 
getVm().getId()));
-        if (getVm().getStatus() == VMStatus.Suspended
-                || StringUtils.isNotEmpty(getVm().getHibernationVolHandle())) {
+
+        boolean removedHibernationVolumes = false;
+        if (StringUtils.isNotEmpty(getVm().getHibernationVolHandle())) {
+            removedHibernationVolumes = removeHibernationVolumes();
+        }
+
+        if (getVm().getStatus() == VMStatus.Suspended) {
             suspendedVm = true;
-            setSucceeded(stopSuspendedVm());
-        } else {
+            setSucceeded(removedHibernationVolumes);
+        }
+        else {
             super.executeVmCommand();
         }
     }
@@ -96,25 +101,27 @@
      * @return True - Operation succeeded <BR/>
      *         False - Operation failed.
      */
-    private boolean stopSuspendedVm() {
-        boolean returnVal = false;
-
+    private boolean removeHibernationVolumes() {
         // Set the Vm to null, for getting the recent VM from the DB, instead 
from the cache.
         setVm(null);
-        VMStatus vmStatus = getVm().getStatus();
+        final VMStatus vmStatus = getVm().getStatus();
 
         // Check whether stop VM procedure didn't started yet (Status is not 
imageLocked), by another transaction.
-        if (getVm().getStatus() != VMStatus.ImageLocked) {
-            // Set the VM to image locked to decrease race condition.
-            updateVmStatus(VMStatus.ImageLocked);
-            if (StringUtils.isNotEmpty(getVm().getHibernationVolHandle())
-                    && removeMemoryVolumes(getVm().getHibernationVolHandle(), 
getActionType(), false)) {
-                returnVal = true;
-            } else {
-                updateVmStatus(vmStatus);
-            }
+        if (vmStatus == VMStatus.ImageLocked) {
+            return false;
         }
-        return returnVal;
+
+        // Set the VM to image locked to decrease race condition.
+        updateVmStatus(VMStatus.ImageLocked);
+
+        // We call removeMemoryVolumes with startPollingTasks = false because 
this call
+        // is part of the exeuction stage so the task polling will be made 
anyway..
+        if (!removeMemoryVolumes(getVm().getHibernationVolHandle(), 
getActionType(), false)) {
+            updateVmStatus(vmStatus);
+            return false;
+        }
+
+        return true;
     }
 
     private void updateVmStatus(VMStatus newStatus) {
@@ -142,7 +149,7 @@
                             new 
UpdateVmDynamicDataVDSCommandParameters(getVm().getRunOnVds(),
                                     vmDynamicData));
         } else {
-            DbFacade.getInstance().getVmDynamicDao().update(vmDynamicData);
+            getVmDynamicDao().update(vmDynamicData);
         }
     }
 
@@ -154,7 +161,7 @@
             getVm().setStatus(VMStatus.Down);
             getVm().setHibernationVolHandle(null);
 
-            
DbFacade.getInstance().getVmDynamicDao().update(getVm().getDynamicData());
+            getVmDynamicDao().update(getVm().getDynamicData());
         }
 
         else {


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie347eb6b9df6284038dd5b9028f3d39d81e04f64
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <aha...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to