Arik Hadas has uploaded a new change for review.

Change subject: extract initVds
......................................................................

extract initVds

Change-Id: I6c839f26561173ea3d11a8c87ed741a48f663e30
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java
2 files changed, 21 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/22642/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index b72ed5f..9512320 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -87,6 +87,10 @@
         RESUME,
         CREATE_STATELESS_IMAGES,
         REMOVE_STATELESS_IMAGES;
+
+        boolean isVdsm() {
+            return this == RUN || this == RESUME;
+        }
     }
 
     private boolean disksFetched;
@@ -196,7 +200,6 @@
     }
 
     private void resumeVm() {
-        initVds();
         VDSReturnValue result = getBackend().getResourceManager()
                 .RunAsyncVdsCommand(
                         VDSCommandType.Resume,
@@ -209,17 +212,6 @@
 
     protected void runVm() {
         setActionReturnValue(VMStatus.Down);
-
-        try {
-            initVds();
-        }
-        catch (Exception e) {
-            failedToRunVm();
-            setSucceeded(false);
-            _isRerun = false;
-            // TODO: re-throw the exception
-            return;
-        }
 
         VMStatus status = null;
         try {
@@ -262,6 +254,7 @@
         setActionReturnValue(VMStatus.Down);
 
         initVm();
+        initVds();
         perform();
     }
 
@@ -646,9 +639,22 @@
     }
 
     protected Guid initVds() {
-        Guid selectedVdsId = getFlow() == Flow.RESUME ? getVm().getRunOnVds() 
: schedule();
-        initVds(selectedVdsId);
-        return selectedVdsId;
+        if (!getFlow().isVdsm()) {
+            return null;
+        }
+
+        try {
+            Guid selectedVdsId =
+                    getFlow() == Flow.RESUME ? getVm().getRunOnVds() : 
schedule();
+            initVds(selectedVdsId);
+            return selectedVdsId;
+        }
+        catch (Exception e) {
+            failedToRunVm();
+            setSucceeded(false);
+            _isRerun = false;
+            throw e;
+        }
     }
 
     protected void initVds(Guid vdsId) {
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java
index 9f65404..df4ea24 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/RunVmCommandTest.java
@@ -41,7 +41,6 @@
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmPayload;
 import org.ovirt.engine.core.common.config.ConfigValues;
-import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.interfaces.VDSBrokerFrontend;
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
@@ -333,13 +332,6 @@
         doReturn(new VDSGroup()).when(command).getVdsGroup();
         assertTrue(command.canDoAction());
         
assertTrue(command.getReturnValue().getCanDoActionMessages().isEmpty());
-    }
-
-    @Test(expected = VdcBLLException.class)
-    public void testGetVdsToRunOn() {
-        doReturn(null).when(command).getDestinationVds();
-        doReturn(null).when(command).schedule();
-        command.initVds();
     }
 
     /**


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c839f26561173ea3d11a8c87ed741a48f663e30
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