Hello Noam Slomianko,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/18570

to review the following change.

Change subject: core: scheduler: handle external scheduler parameters
......................................................................

core: scheduler: handle external scheduler parameters

For loaded external scheduling plugin fixing saving
description and custom properties.

Signed-off-by: Noam Slomianko <[email protected]>
Change-Id: Ibaa3e1396ba0ec61ebce33d08a1174b93b97c56d
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryResult.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryThread.java
2 files changed, 30 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/18570/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryResult.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryResult.java
index c009c61..ca010ec 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryResult.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryResult.java
@@ -4,6 +4,8 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
+import org.ovirt.engine.core.utils.customprop.SimpleCustomPropertiesUtil;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
@@ -41,13 +43,21 @@
                     return false;
                 }
             // list of module names as keys and [description, regex] as value
-            for (String moduleName : typeMap.keySet()) {
-                Object[] singleModule = typeMap.get(moduleName);
+                for (String moduleName : typeMap.keySet()) {
+                    Object[] singleModule = typeMap.get(moduleName);
+                    // check custom properties format.
+                    String customPropertiesRegex = singleModule[1].toString();
+                    if (!StringUtils.isEmpty(customPropertiesRegex) && 
SimpleCustomPropertiesUtil.getInstance()
+                            .syntaxErrorInProperties(customPropertiesRegex)) {
+                        log.error("module " + moduleName + " will not be 
loaded, wrong custom properties format ("
+                                + customPropertiesRegex + ")");
+                        continue;
+                    }
                     ExternalSchedulerDiscoveryUnit currentUnit = new 
ExternalSchedulerDiscoveryUnit(moduleName,
-                        singleModule[0].toString(),
-                        singleModule[1].toString());
+                            singleModule[0].toString(),
+                            customPropertiesRegex);
                     currentList.add(currentUnit);
-            }
+                }
         }
         return true;
         } catch (Exception e) {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryThread.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryThread.java
index 4296a63..a85630f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryThread.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/external/ExternalSchedulerDiscoveryThread.java
@@ -1,6 +1,6 @@
 package org.ovirt.engine.core.bll.scheduling.external;
 
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
@@ -85,27 +85,26 @@
                 continue;
             }
 
-            try{
-                Map<String, String> discoveryPropMap = 
SimpleCustomPropertiesUtil.getInstance().convertProperties(discoveryUnit.getRegex());
-                if 
(!policyUnit.getParameterRegExMap().equals(discoveryPropMap)) {
-                    sendToDb(discoveryUnit, true, type);
-                }
-            } catch (Exception e) {
-                // TODO: handle exception? log?
+            Map<String, String> discoveryPropMap =
+                    StringUtils.isEmpty(discoveryUnit.getRegex()) ? new 
LinkedHashMap<String, String>() :
+                    
SimpleCustomPropertiesUtil.getInstance().convertProperties(discoveryUnit.getRegex());
+            if (!discoveryPropMap.equals(policyUnit.getParameterRegExMap()) ||
+                    
!discoveryUnit.getDescription().equals(policyUnit.getDescription()) ||
+                    !policyUnit.isEnabled()) {
+                sendToDb(discoveryUnit, policyUnit.getId(), type);
             }
-
-            // TODO: when policy unit description is merged, compare it as well
 
             return policyUnit;
 
         }
-        sendToDb(discoveryUnit, false, type);
+        sendToDb(discoveryUnit, null, type);
         return null;
     }
 
-    private void sendToDb(ExternalSchedulerDiscoveryUnit discovery, boolean 
isUpdate, PolicyUnitType type) {
+    private void sendToDb(ExternalSchedulerDiscoveryUnit discovery, Guid 
policyUnitId, PolicyUnitType type) {
         PolicyUnit policy = createFromDiscoveryUnit(discovery, type);
-        if (isUpdate) {
+        if (policyUnitId != null) {
+            policy.setId(policyUnitId);
             getPolicyUnitDao().update(policy);
         } else {
             policy.setId(Guid.newGuid());
@@ -118,13 +117,13 @@
         policy.setInternal(false);
         policy.setName(discoveryUnit.getName());
         policy.setPolicyUnitType(type);
-        if(!StringUtils.isBlank(discoveryUnit.getRegex())) {
+        policy.setDescription(discoveryUnit.getDescription());
+        if (!StringUtils.isEmpty(discoveryUnit.getRegex())) {
             
policy.setParameterRegExMap(SimpleCustomPropertiesUtil.getInstance()
                     .convertProperties(discoveryUnit.getRegex()));
         } else {
-            policy.setParameterRegExMap(new HashMap<String, String>());
+            policy.setParameterRegExMap(new LinkedHashMap<String, String>());
         }
-        // TODO: when policy unit description is merged, set it
         return policy;
     }
 


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

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

Reply via email to