Roy Golan has uploaded a new change for review.

Change subject: core: simplify emulated machine matching code
......................................................................

core: simplify emulated machine matching code

Change-Id: Id61cbd7ab74d809ba66071d9d1807f8b4f8c985c
Signed-off-by: Roy Golan <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
M 
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VirtMonitoringStrategy.java
3 files changed, 14 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/42/19042/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
index 2c0db43..c497b3e 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ListUtils.java
@@ -134,9 +134,16 @@
      * @param src    The list on which we iterate to match against the lookup.
      * @param lookup The list being matched against an entry for the 
source.<br>
      * </br> The first match breaks the loop and is sufficient.
-     * @return the first match between a value in src against the lookup.
+     * @return :
+     * - the first match between a value in src against the lookup.
+     * - null if the lookup is null
+     * - null if there's no match
      */
     public static String firstMatch(List<String> src, String... lookup) {
+        if (lookup == null) {
+            return null;
+        }
+
         Arrays.sort(lookup);
         for (String s : src) {
             int matchedIndex = Arrays.binarySearch(lookup, s);
diff --git 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
index 7f14427..b73f8a9 100644
--- 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
+++ 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ListUtilsTest.java
@@ -96,5 +96,6 @@
 
         Assert.assertEquals("one", ListUtils.firstMatch(source, "one", "two"));
         Assert.assertEquals("one", ListUtils.firstMatch(source, "two", "one"));
+        Assert.assertEquals(null, ListUtils.firstMatch(source, null));
     }
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VirtMonitoringStrategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VirtMonitoringStrategy.java
index 9c0e528..9d636b1 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VirtMonitoringStrategy.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VirtMonitoringStrategy.java
@@ -87,25 +87,23 @@
     private boolean hostCompliesWithClusterEmulationMode(VDS vds, VDSGroup 
vdsGroup) {
 
         String clusterEmulatedMachine = vdsGroup.getEmulatedMachine();
-        String[] hostSupportedEmulatedMachines =
-                vds.getSupportedEmulatedMachines() != null ? 
vds.getSupportedEmulatedMachines().split(",") : new String[]{""};
 
         // the initial cluster emulated machine value is set by the first host 
that complies.
         if (clusterEmulatedMachine == null || 
clusterEmulatedMachine.isEmpty()) {
-            return hostEmulationModeMatchesTheConfigValues(vds, 
hostSupportedEmulatedMachines);
+            return hostEmulationModeMatchesTheConfigValues(vds);
         } else {
-            // the cluster has the emulated machine flag set. match the host 
on it.
-            return 
Arrays.asList(hostSupportedEmulatedMachines).contains(clusterEmulatedMachine);
+            // the cluster has the emulated machine flag set. match the host 
against it.
+            return vds.getSupportedEmulatedMachines() != null ? 
Arrays.asList(vds.getSupportedEmulatedMachines().split(",")).contains(clusterEmulatedMachine)
 : false;
         }
     }
 
-    private boolean hostEmulationModeMatchesTheConfigValues(VDS vds, String[] 
hostSupportedEmulatedMachines) {
+    private boolean hostEmulationModeMatchesTheConfigValues(VDS vds) {
         // match this host against the config flags by order
         String matchedEmulatedMachine =
                 ListUtils.firstMatch(
                         Config.<List<String>> 
GetValue(ConfigValues.ClusterEmulatedMachines,
                                 
vds.getVdsGroupCompatibilityVersion().getValue()),
-                        hostSupportedEmulatedMachines);
+                        vds.getSupportedEmulatedMachines().split(","));
 
         if (matchedEmulatedMachine != null && 
!matchedEmulatedMachine.isEmpty()) {
             setClusterEmulatedMachine(vds, matchedEmulatedMachine);


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

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

Reply via email to