Roy Golan has uploaded a new change for review.

Change subject: core: expand VDS monitoring with cluster emulation modes
......................................................................

core: expand VDS monitoring with cluster emulation modes

This patch follows the wiki on
http://wiki.ovirt.org/Cluster_emulation_modes

Added the logic to match the host supported emulated machine flags
against the config vals or the cluster property.

Added logic to transit the host to NON-OPERATIONAL when it
doesn't match the cluster/config values.

Added logic to set the cluser emulated machine value from the first host
that matches the config values.

Change-Id: I0caf343d4d883a1e420ca2b4fc24c678436599cb
Signed-off-by: Roy Golan <rgo...@redhat.com>
---
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/GlusterMonitoringStrategy.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MonitoringStrategy.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MultipleServicesMonitoringStrategy.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VirtMonitoringStrategy.java
7 files changed, 110 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/15868/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 2854e0f..eb3db3d 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
@@ -1,6 +1,7 @@
 package org.ovirt.engine.core.common.utils;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
@@ -129,4 +130,19 @@
         return addedElements;
     }
 
+    /**
+     * @param src    The list on which we iterate to match against the lookup.
+     * @param lookup A list with the lookup entries. only one match against 
and entry here is sufficient.
+     * @return the first match between a value in src against the lookup.
+     */
+    public static String firstMatch(List<String> src, String... lookup) {
+        Arrays.sort(lookup);
+        for (String s : src) {
+            int matchedIndex = Arrays.binarySearch(lookup, s);
+            if (matchedIndex >= 0) {
+                return lookup[matchedIndex];
+            }
+        }
+        return null;
+    }
 }
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 6ad8a0d..7f14427 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
@@ -89,4 +89,12 @@
         assertTrue(addedElements.size() == 1);
         assertTrue(addedElements.contains("string4"));
     }
+
+    @Test
+    public void testFirstMatch() {
+        List<String> source = Arrays.asList("zero", "one", "two ", "three");
+
+        Assert.assertEquals("one", ListUtils.firstMatch(source, "one", "two"));
+        Assert.assertEquals("one", ListUtils.firstMatch(source, "two", "one"));
+    }
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/GlusterMonitoringStrategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/GlusterMonitoringStrategy.java
index 0a4773f..f8c8674 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/GlusterMonitoringStrategy.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/GlusterMonitoringStrategy.java
@@ -18,6 +18,11 @@
     }
 
     @Override
+    public boolean hostCompliesWithClusterEmulationMode(VDS vds) {
+        return true; // non issue here as emulation mode is related to VM 
migration
+    }
+
+    @Override
     public void processSoftwareCapabilities(VDS vds) {
     }
 
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MonitoringStrategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MonitoringStrategy.java
index 9d586b5..54ebb26 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MonitoringStrategy.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MonitoringStrategy.java
@@ -31,4 +31,8 @@
      */
     public boolean isMonitoringNeeded(VDS vds);
 
+    /**
+     * Process cluster wide compatibility with this host emulated machine 
flags.
+     */
+    public boolean hostCompliesWithClusterEmulationMode(VDS vds);
 }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MultipleServicesMonitoringStrategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MultipleServicesMonitoringStrategy.java
index 27e6779..7f145be 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MultipleServicesMonitoringStrategy.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/MultipleServicesMonitoringStrategy.java
@@ -53,6 +53,16 @@
     }
 
     @Override
+    public boolean hostCompliesWithClusterEmulationMode(VDS vds) {
+        for (MonitoringStrategy strategy : strategies) {
+            if (!strategy.hostCompliesWithClusterEmulationMode(vds)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
     public boolean processHardwareCapabilitiesNeeded(VDS oldVds, VDS newVds) {
         // In this case, if one of the services needs hardware capabilities 
processing then we return true
         for ( MonitoringStrategy monitoringStrategy : strategies ) {
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
index e2db5f5..a06eedc 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsManager.java
@@ -2,6 +2,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -570,6 +571,7 @@
             // We process the software capabilities.
             VDSStatus oldStatus = vds.getStatus();
             monitoringStrategy.processSoftwareCapabilities(vds);
+
             returnStatus = vds.getStatus();
 
             if (returnStatus != oldStatus && returnStatus == 
VDSStatus.NonOperational) {
@@ -578,6 +580,22 @@
 
             
processHardwareCapsNeeded.set(monitoringStrategy.processHardwareCapabilitiesNeeded(oldVDS,
 vds));
 
+            if (!monitoringStrategy.hostCompliesWithClusterEmulationMode(vds)) 
{
+                setIsSetNonOperationalExecuted(true);
+
+                Map<String, String> customLogValues = new HashMap<>();
+                customLogValues.put("hostSupportedEmulatedMachines", 
vds.getSupportedEmulatedMachines());
+                customLogValues.put("clusterEmulatedMachines", 
Config.<String>GetValue(ConfigValues.ClusterEmulatedMachines));
+
+                
ResourceManager.getInstance().getEventListener().vdsNonOperational(
+                        vds.getId(),
+                        
NonOperationalReason.EMULATED_MACHINES_INCOMPATIBLE_WITH_CLUSTER,
+                        true,
+                        true,
+                        Guid.Empty,
+                        customLogValues);
+                vds.setStatus(VDSStatus.NonOperational);
+            }
             return returnStatus;
         } else if (vdsBrokerCommand.getVDSReturnValue().getExceptionObject() 
!= null) {
             // if exception is VDSNetworkException then call to
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 682d096..09d7c3b 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
@@ -1,10 +1,19 @@
 package org.ovirt.engine.core.vdsbroker;
 
+import java.util.Arrays;
+import java.util.List;
+
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.NonOperationalReason;
 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.config.Config;
+import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.common.utils.ListUtils;
 import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dao.VdsGroupDAO;
 
 /**
  * This class defines virt strategy entry points, which are needed in host 
monitoring phase
@@ -21,6 +30,46 @@
     public boolean isMonitoringNeeded(VDS vds) {
         // No need to update the run-time info for hosts that don't run VMs
         return (vds.getStatus() != VDSStatus.NonOperational || 
vds.getVmCount() > 0);
+    }
+
+    @Override
+    public boolean hostCompliesWithClusterEmulationMode(VDS vds) {
+
+        String clusterEmulatedMachine = 
getEmulatedMachine(vds.getVdsGroupId());
+        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);
+        } else {
+            // the cluster has the emulated machine flag set. match the host 
on it.
+            return 
Arrays.asList(hostSupportedEmulatedMachines).contains(clusterEmulatedMachine);
+        }
+    }
+
+    private boolean hostEmulationModeMatchesTheConfigValues(VDS vds, String[] 
hostSupportedEmulatedMachines) {
+        // match this host against the config flags by order
+        String matchedEmulatedMachine = ListUtils.firstMatch(
+                
Config.<List<String>>GetValue(ConfigValues.ClusterEmulatedMachines),
+                hostSupportedEmulatedMachines);
+
+        if (matchedEmulatedMachine != null && 
!matchedEmulatedMachine.isEmpty()) {
+            setClusterEmulatedMachine(vds, matchedEmulatedMachine);
+            return true;
+        }
+        return false;
+    }
+
+    private void setClusterEmulatedMachine(VDS vds, String 
matchedEmulatedMachine) {
+        // host matches and its value will set the cluster emulated machine
+        
DbFacade.getInstance().getVdsGroupDao().setEmulatedMachine(vds.getVdsGroupId(), 
matchedEmulatedMachine);
+    }
+
+    private String getEmulatedMachine(Guid vdsGroupId) {
+        VdsGroupDAO vdsGroupDao = DbFacade.getInstance().getVdsGroupDao();
+        VDSGroup vdsGroup = vdsGroupDao.get(vdsGroupId);
+        return vdsGroup.getEmulatedMachine();
     }
 
     @Override
@@ -52,4 +101,3 @@
         return !StringUtils.equals(oldVds.getCpuFlags(), newVds.getCpuFlags());
     }
 }
-


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0caf343d4d883a1e420ca2b4fc24c678436599cb
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to