Omer Frenkel has uploaded a new change for review.

Change subject: core: minor run vm canDoAction refactor
......................................................................

core: minor run vm canDoAction refactor

make canDoAction return on error instead of if-else code

Change-Id: I62b362e855bd252e44b0bb7c9c9ee33dbd9b6696
Signed-off-by: Omer Frenkel <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java
2 files changed, 23 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/75/17475/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 e2e7c7b..a3f1b66 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
@@ -767,8 +767,7 @@
         List<String> messages = getReturnValue().getCanDoActionMessages();
         List<Disk> vmDisks = getDiskDao().getAllForVm(vm.getId(), true);
         VDS destVds = getDestinationVds();
-        boolean canDoAction =
-                getRunVmValidator().canRunVm(vm,
+        if (!getRunVmValidator().canRunVm(vm,
                         messages,
                         vmDisks,
                         getParameters().getBootSequence(),
@@ -780,24 +779,24 @@
                         getRunVdssList(),
                         destVds == null ? null : destVds.getId(),
                         getVdsGroup()) &&
-                        validateNetworkInterfaces();
-
-        // check for Vm Payload
-        if (canDoAction && getParameters().getVmPayload() != null) {
-            canDoAction = checkPayload(getParameters().getVmPayload(),
-                    getParameters().getDiskPath());
-
-            if (canDoAction && 
!StringUtils.isEmpty(getParameters().getFloppyPath()) &&
-                    getParameters().getVmPayload().getType() == 
VmDeviceType.FLOPPY) {
-                
addCanDoActionMessage(VdcBllMessages.VMPAYLOAD_FLOPPY_EXCEEDED);
-                canDoAction = false;
-            }
-            else {
-                getVm().setVmPayload(getParameters().getVmPayload());
-            }
+                        validateNetworkInterfaces()) {
+            return false;
         }
 
-        return canDoAction;
+        // check for Vm Payload
+        if (getParameters().getVmPayload() != null) {
+            boolean isPayloadValid = 
checkPayload(getParameters().getVmPayload(),
+                    getParameters().getDiskPath());
+
+            if (isPayloadValid && 
!StringUtils.isEmpty(getParameters().getFloppyPath()) &&
+                    getParameters().getVmPayload().getType() == 
VmDeviceType.FLOPPY) {
+                return 
failCanDoAction(VdcBllMessages.VMPAYLOAD_FLOPPY_EXCEEDED);
+            }
+
+            getVm().setVmPayload(getParameters().getVmPayload());
+        }
+
+        return true;
     }
 
     protected VmValidator getVmValidator(VM vm) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java
index 3bf0c05..c5227a5 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmOnceCommand.java
@@ -23,17 +23,17 @@
 
     @Override
     protected boolean canDoAction() {
-        boolean returnValue = super.canDoAction();
+        if (!super.canDoAction()) {
+            return false;
+        }
 
         // the condition allows to get only user and password which are both 
set (even with empty string) or both aren't
         // set (null), the action will fail if only one of those parameters is 
null.
-        if (returnValue
-                && (getParameters().getSysPrepUserName() == null ^ 
getParameters().getSysPrepPassword() == null)) {
-            
addCanDoActionMessage(VdcBllMessages.VM_CANNOT_RUN_ONCE_WITH_ILLEGAL_SYSPREP_PARAM);
-            returnValue = false;
+        if (getParameters().getSysPrepUserName() == null ^ 
getParameters().getSysPrepPassword() == null) {
+            return 
failCanDoAction(VdcBllMessages.VM_CANNOT_RUN_ONCE_WITH_ILLEGAL_SYSPREP_PARAM);
         }
 
-        return returnValue;
+        return true;
     }
 
     /**


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

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

Reply via email to