Gilad Chaplik has uploaded a new change for review.

Change subject: engine: Integrate cluster commands with new arch
......................................................................

engine: Integrate cluster commands with new arch

Adding cluster policy custom properties validation, and removing
old validation to selection algorithm parameters.

Change-Id: Icdd7bbfd825605de8c65bd8dcb7feeef431703ae
Signed-off-by: Gilad Chaplik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsGroupOperationCommandBase.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommandTest.java
4 files changed, 42 insertions(+), 47 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/16605/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java
index f1b2a90..6d63102 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsGroupCommand.java
@@ -3,6 +3,7 @@
 import java.util.Collections;
 import java.util.List;
 
+import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.bll.utils.VersionSupport;
 import org.ovirt.engine.core.common.AuditLogType;
@@ -18,9 +19,12 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported;
+import org.ovirt.engine.core.common.scheduling.ClusterPolicy;
 import org.ovirt.engine.core.common.validation.group.CreateEntity;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.NetworkUtils;
+import org.ovirt.engine.core.utils.customprop.SimpleCustomPropertiesUtil;
+import org.ovirt.engine.core.utils.customprop.ValidationError;
 import org.ovirt.engine.core.utils.linq.LinqUtils;
 import org.ovirt.engine.core.utils.linq.Predicate;
 
@@ -161,10 +165,6 @@
             }
         }
 
-        if (result) {
-            result = validateMetrics();
-        }
-
         if (getVdsGroup().supportsGlusterService()
                 && 
!GlusterFeatureSupported.gluster(getVdsGroup().getcompatibility_version())) {
             addCanDoActionMessage(VdcBllMessages.GLUSTER_NOT_SUPPORTED);
@@ -183,6 +183,18 @@
             }
         }
 
+        if (result) {
+            ClusterPolicy clusterPolicy = 
SchedulingManager.getInstance().getClusterPolicy(getVdsGroup().getClusterPolicyId());
+            List<ValidationError> validationErrors =
+                    
SimpleCustomPropertiesUtil.getInstance().validateProperties(SchedulingManager.getInstance()
+                            .getCustomPropertiesRegexMap(clusterPolicy),
+                            getVdsGroup().getClusterPolicyProperties());
+            if (!validationErrors.isEmpty()) {
+                
SimpleCustomPropertiesUtil.getInstance().handleCustomPropertiesError(validationErrors,
+                        getReturnValue().getCanDoActionMessages());
+                return false;
+            }
+        }
         return result;
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java
index 509eb09..20a27ce 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommand.java
@@ -261,9 +261,6 @@
                 }
             }
         }
-        if (result) {
-            result = validateMetrics();
-        }
 
         if (getVdsGroup().supportsGlusterService()
                 && 
!GlusterFeatureSupported.gluster(getVdsGroup().getcompatibility_version())) {
@@ -294,6 +291,9 @@
                 result = false;
             }
         }
+        if (result) {
+            result = validateClusterPolicy();
+        }
         return result;
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsGroupOperationCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsGroupOperationCommandBase.java
index a0de92e..43a3264 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsGroupOperationCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsGroupOperationCommandBase.java
@@ -1,12 +1,16 @@
 package org.ovirt.engine.core.bll;
 
+import java.util.List;
+
+import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
 import org.ovirt.engine.core.common.action.VdsGroupOperationParameters;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
-import org.ovirt.engine.core.common.businessentities.VdsSelectionAlgorithm;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
-import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.common.scheduling.ClusterPolicy;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.utils.customprop.SimpleCustomPropertiesUtil;
+import org.ovirt.engine.core.utils.customprop.ValidationError;
 
 public abstract class VdsGroupOperationCommandBase<T extends 
VdsGroupOperationParameters> extends
         VdsGroupCommandBase<T> {
@@ -43,45 +47,23 @@
         return cpuUtilization != GET_CPU_THRESHOLDS_FROM_CONFIGURATION;
     }
 
-    protected boolean validateMetrics() {
-        boolean result = true;
-
-        VdsSelectionAlgorithm selectionAlgorithm = 
getVdsGroup().getselection_algorithm();
-
-        if (result && selectionAlgorithm != null && 
!selectionAlgorithm.equals(VdsSelectionAlgorithm.None)) {
-
-            if (result
-                    && 
(!isCpuUtilizationValid(getVdsGroup().gethigh_utilization()) || 
!isCpuUtilizationValid(getVdsGroup().getlow_utilization()))) {
-                
addCanDoActionMessage(VdcBllMessages.VDS_GROUP_CPU_UTILIZATION_MUST_BE_IN_VALID_RANGE);
-                result = false;
-            }
-
-            if (result && getVdsGroup().getlow_utilization() > 
getVdsGroup().gethigh_utilization()) {
-                
addCanDoActionMessage(VdcBllMessages.VDS_GROUP_CPU_LOW_UTILIZATION_PERCENTAGE_MUST_BE_LOWER_THAN_HIGH_PERCENTAGE);
-                result = false;
-            }
-
-            if (result) {
-                if 
(selectionAlgorithm.equals(VdsSelectionAlgorithm.EvenlyDistribute)) {
-                    if 
(!isCpuUtilizationExist(getVdsGroup().gethigh_utilization())) {
-                        
addCanDoActionMessage(VdcBllMessages.VDS_GROUP_CPU_HIGH_UTILIZATION_PERCENTAGE_MUST_BE_DEFINED_WHEN_USING_EVENLY_DISTRIBUTED);
-                        result = false;
-                    }
-                } else if 
(selectionAlgorithm.equals(VdsSelectionAlgorithm.PowerSave)) {
-                    if 
(!isCpuUtilizationExist(getVdsGroup().gethigh_utilization())
-                            || 
!isCpuUtilizationExist(getVdsGroup().getlow_utilization())) {
-                        
addCanDoActionMessage(VdcBllMessages.VDS_GROUP_BOTH_LOW_AND_HIGH_CPU_UTILIZATION_PERCENTAGE_MUST_BE_DEFINED_WHEN_USING_POWER_SAVING);
-                        result = false;
-                    }
-                }
-            }
-        }
-
-        return result;
-    }
-
     protected boolean isAllowClusterWithVirtGluster() {
         Boolean allowVirGluster = Config.<Boolean> 
GetValue(ConfigValues.AllowClusterWithVirtGlusterEnabled);
         return allowVirGluster;
     }
+
+    protected boolean validateClusterPolicy() {
+        ClusterPolicy clusterPolicy =
+                
SchedulingManager.getInstance().getClusterPolicy(getVdsGroup().getClusterPolicyId());
+        List<ValidationError> validationErrors =
+                
SimpleCustomPropertiesUtil.getInstance().validateProperties(SchedulingManager.getInstance()
+                        .getCustomPropertiesRegexMap(clusterPolicy),
+                        getVdsGroup().getClusterPolicyProperties());
+        if (!validationErrors.isEmpty()) {
+            
SimpleCustomPropertiesUtil.getInstance().handleCustomPropertiesError(validationErrors,
+                    getReturnValue().getCanDoActionMessages());
+            return false;
+        }
+        return true;
+    }
 }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommandTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommandTest.java
index 98ad947..b703bfe 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommandTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/UpdateVdsGroupCommandTest.java
@@ -20,13 +20,13 @@
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
 import org.ovirt.engine.core.common.action.VdsGroupOperationParameters;
+import org.ovirt.engine.core.common.businessentities.StoragePool;
 import org.ovirt.engine.core.common.businessentities.StorageType;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VDSStatus;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VdsSelectionAlgorithm;
-import org.ovirt.engine.core.common.businessentities.StoragePool;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
@@ -299,6 +299,7 @@
         doReturn(storagePoolDAO).when(cmd).getStoragePoolDAO();
         doReturn(glusterVolumeDao).when(cmd).getGlusterVolumeDao();
         doReturn(vmDao).when(cmd).getVmDAO();
+        doReturn(true).when(cmd).validateClusterPolicy();
 
         
when(vdsGroupDAO.get(any(Guid.class))).thenReturn(createDefaultVdsGroup());
         
when(vdsGroupDAO.getByName(anyString())).thenReturn(createDefaultVdsGroup());


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

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

Reply via email to