Omer Frenkel has uploaded a new change for review.

Change subject: core: minor refactor for custom props validation
......................................................................

core: minor refactor for custom props validation

instead of calling one method to check the properties and then another
to check the result, now calling one method to do both.

Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1166632
Change-Id: I444f374d0c1bb4c495b3c2b1c26c92bc466e19c9
Signed-off-by: Omer Frenkel <ofren...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/customprop/VmPropertiesUtils.java
7 files changed, 21 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/22/35422/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
index c5d9e3e..640c006 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVmCommand.java
@@ -80,7 +80,6 @@
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
-import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
 import org.ovirt.engine.core.common.validation.group.CreateVm;
 import org.ovirt.engine.core.compat.Guid;
@@ -286,9 +285,7 @@
             return false;
         }
 
-        List<ValidationError> validationErrors = 
validateCustomProperties(vmStaticFromParams);
-        if (!validationErrors.isEmpty()) {
-            
VmPropertiesUtils.getInstance().handleCustomPropertiesError(validationErrors, 
reasons);
+        if (!validateCustomProperties(vmStaticFromParams, reasons)) {
             return false;
         }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
index 3792dbb..8e03c54 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVmCommand.java
@@ -61,7 +61,6 @@
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.utils.Pair;
-import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
 import org.ovirt.engine.core.common.validation.group.UpdateVm;
 import org.ovirt.engine.core.compat.DateTime;
@@ -474,10 +473,7 @@
             }
         }
 
-        List<ValidationError> validationErrors = 
validateCustomProperties(vmFromParams.getStaticData());
-        if (!validationErrors.isEmpty()) {
-            
VmPropertiesUtils.getInstance().handleCustomPropertiesError(validationErrors,
-                    getReturnValue().getCanDoActionMessages());
+        if (!validateCustomProperties(vmFromParams.getStaticData(), 
getReturnValue().getCanDoActionMessages())) {
             return false;
         }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
index 5bd96b4..36368fc 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmCommand.java
@@ -33,7 +33,6 @@
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
-import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
 import 
org.ovirt.engine.core.common.vdscommands.DeleteImageGroupVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -397,10 +396,11 @@
         return Config.<Integer> 
getValue(ConfigValues.InitStorageSparseSizeInGB).intValue();
     }
 
-    protected List<ValidationError> validateCustomProperties(VmStatic 
vmStaticFromParams) {
+    protected boolean validateCustomProperties(VmStatic vmStaticFromParams, 
List<String> reasons) {
         return VmPropertiesUtils.getInstance().validateVmProperties(
                 getVdsGroup().getcompatibility_version(),
-                vmStaticFromParams.getCustomProperties());
+                vmStaticFromParams.getCustomProperties(),
+                reasons);
     }
 
     /**
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
index 502b288..576a87f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/RunVmValidator.java
@@ -41,7 +41,6 @@
 import org.ovirt.engine.core.common.queries.VdcQueryReturnValue;
 import org.ovirt.engine.core.common.queries.VdcQueryType;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
-import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.common.utils.customprop.VmPropertiesUtils;
 import 
org.ovirt.engine.core.common.vdscommands.IsVmDuringInitiatingVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -175,17 +174,10 @@
     protected boolean validateVmProperties(VM vm, String 
runOnceCustomProperties, List<String> messages) {
         String customProperties = runOnceCustomProperties != null ?
                 runOnceCustomProperties : vm.getCustomProperties();
-        List<ValidationError> validationErrors =
-                getVmPropertiesUtils().validateVmProperties(
+        return getVmPropertiesUtils().validateVmProperties(
                         vm.getVdsGroupCompatibilityVersion(),
-                        customProperties);
-
-        if (!validationErrors.isEmpty()) {
-            
getVmPropertiesUtils().handleCustomPropertiesError(validationErrors, messages);
-            return false;
-        }
-
-        return true;
+                        customProperties,
+                        messages);
     }
 
     protected ValidationResult validateBootSequence(VM vm, BootSequence 
runOnceBootSequence,
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
index b72cde4..4a000f4 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/AddVmCommandTest.java
@@ -172,7 +172,7 @@
         final int domainSizeGB = 20;
         final int sizeRequired = 5;
         AddVmCommand<VmManagementParametersBase> cmd = 
setupCanAddVmTests(domainSizeGB, sizeRequired);
-        
doReturn(Collections.emptyList()).when(cmd).validateCustomProperties(any(VmStatic.class));
+        doReturn(true).when(cmd).validateCustomProperties(any(VmStatic.class), 
any(ArrayList.class));
         doReturn(true).when(cmd).validateSpaceRequirements();
         assertTrue("vm could not be added", cmd.canAddVm(reasons, 
Arrays.asList(createStorageDomain(domainSizeGB))));
     }
@@ -362,7 +362,7 @@
         AddVmFromTemplateCommand<AddVmFromTemplateParameters> result = 
spy(concrete);
         doReturn(true).when(result).checkNumberOfMonitors();
         doReturn(createVmTemplate()).when(result).getVmTemplate();
-        
doReturn(Collections.emptyList()).when(result).validateCustomProperties(any(VmStatic.class));
+        
doReturn(true).when(result).validateCustomProperties(any(VmStatic.class), 
any(ArrayList.class));
         mockDAOs(result);
         mockBackend(result);
         initCommandMethods(result);
@@ -703,7 +703,7 @@
         final int domainSizeGB = 20;
         final int sizeRequired = 5;
         AddVmCommand<VmManagementParametersBase> cmd = 
setupCanAddVmTests(domainSizeGB, sizeRequired);
-        
doReturn(Collections.emptyList()).when(cmd).validateCustomProperties(any(VmStatic.class));
+        doReturn(true).when(cmd).validateCustomProperties(any(VmStatic.class), 
any(ArrayList.class));
         doReturn(true).when(cmd).validateSpaceRequirements();
 
         cmd.getParameters().setBalloonEnabled(true);
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
index 4a91765..d35fce4 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVmCommandTest.java
@@ -44,7 +44,6 @@
 import org.ovirt.engine.core.common.osinfo.OsRepository;
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
-import org.ovirt.engine.core.common.utils.customprop.ValidationError;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dao.DiskDao;
@@ -369,7 +368,7 @@
     }
 
     private void mockValidateCustomProperties() {
-        doReturn(Collections.<ValidationError> 
emptyList()).when(command).validateCustomProperties(any(VmStatic.class));
+        
doReturn(true).when(command).validateCustomProperties(any(VmStatic.class), 
any(ArrayList.class));
     }
 
     private void mockValidatePciAndIdeLimit() {
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/customprop/VmPropertiesUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/customprop/VmPropertiesUtils.java
index 7b3fb3c..4c1ad82 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/customprop/VmPropertiesUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/customprop/VmPropertiesUtils.java
@@ -215,4 +215,13 @@
     public String getVmPropSpec() {
         return VALIDATION_STR;
     }
+
+    public boolean validateVmProperties(Version version, String properties, 
List<String> message) {
+        List<ValidationError> validationErrors = validateVmProperties(version, 
properties);
+        if (!validationErrors.isEmpty()) {
+            handleCustomPropertiesError(validationErrors, message);
+            return false;
+        }
+        return true;
+    }
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I444f374d0c1bb4c495b3c2b1c26c92bc466e19c9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5
Gerrit-Owner: Omer Frenkel <ofren...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to