Arik Hadas has uploaded a new change for review.

Change subject: core: extract balloon validation in import vm
......................................................................

core: extract balloon validation in import vm

It is better to extract the validation from the canDoAction command for
2 reasons:
1. Readability - to make the canDoAction method more readable
2. Testability - to make the command more testable

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


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/35087/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
index 1fcad3f..e68d63c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -217,23 +218,36 @@
             }
         }
 
-        boolean hasBalloon = false;
+        if (!validateBallonDevice()) {
+            return false;
+        }
 
-        for (VmDevice vmDevice : getVm().getManagedVmDeviceMap().values()) {
-            if (VmDeviceCommonUtils.isMemoryBalloon(vmDevice)) {
-                hasBalloon = true;
-                break;
-            }
+        return canDoActionAfterCloneVm(domainsMap);
+    }
+
+    protected boolean validateBallonDevice() {
+        if (!isBalloonDeviceExists(getVm().getManagedVmDeviceMap().values())) {
+            return true;
         }
 
         OsRepository osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
-        if (hasBalloon && 
!osRepository.isBalloonEnabled(getVm().getStaticData().getOsId(),
+        if (!osRepository.isBalloonEnabled(getVm().getStaticData().getOsId(),
                 getVdsGroup().getcompatibility_version())) {
             addCanDoActionMessageVariable("clusterArch", 
getVdsGroup().getArchitecture());
             return 
failCanDoAction(VdcBllMessages.BALLOON_REQUESTED_ON_NOT_SUPPORTED_ARCH);
         }
 
-        return canDoActionAfterCloneVm(domainsMap);
+        return true;
+    }
+
+    private boolean isBalloonDeviceExists(Collection<VmDevice> devices) {
+        for (VmDevice vmDevice : getVm().getManagedVmDeviceMap().values()) {
+            if (VmDeviceCommonUtils.isMemoryBalloon(vmDevice)) {
+                return true;
+            }
+        }
+
+        return false;
     }
 
     @Override


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

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