Gilad Chaplik has uploaded a new change for review.

Change subject: core: scheduling: handle cpu load duration
......................................................................

core: scheduling: handle cpu load duration

Move the logic into SchedulerManager.

Change-Id: I231aa54ccc0cadbd9456b090fe08ae85dd926957
Bug-Url: https://bugzilla.redhat.com/1031353
Signed-off-by: Gilad Chaplik <gchap...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SlaValidator.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
7 files changed, 44 insertions(+), 74 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/50/22350/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
index 4f7ccff..db9fc0b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
@@ -13,6 +13,7 @@
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.bll.job.ExecutionHandler;
+import org.ovirt.engine.core.bll.scheduling.SchedulingManager;
 import org.ovirt.engine.core.bll.storage.StoragePoolStatusHandler;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.AddVmFromScratchParameters;
@@ -347,5 +348,11 @@
         }
     }
 
+    @Override
+    public void updateSchedulingStats(VDS vds) {
+        SchedulingManager.getInstance().updateHostSchedulingStats(vds);
+    }
+
     private static Log log = LogFactory.getLog(VdsEventListener.class);
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
index f565a4d..c23e0ac 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SchedulingManager.java
@@ -5,6 +5,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -17,6 +18,7 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
 import 
org.ovirt.engine.core.bll.scheduling.external.ExternalSchedulerDiscoveryThread;
 import org.ovirt.engine.core.bll.scheduling.external.ExternalSchedulerFactory;
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
@@ -61,6 +63,9 @@
         }
         return instance;
     }
+
+    private static final String HIGH_UTILIZATION = "HighUtilization";
+    private static final String LOW_UTILIZATION = "LowUtilization";
 
     /**
      * <policy id, policy> map
@@ -790,4 +795,27 @@
         policyUnits.remove(policyUnitId);
     }
 
+    /**
+     * update host scheduling statistics:
+     * * CPU load duration interval over/under policy threshold
+     * @param vds
+     */
+    public void updateHostSchedulingStats(VDS vds) {
+        if (vds.getUsageCpuPercent() != null) {
+            VDSGroup vdsGroup = getVdsGroupDao().get(vds.getVdsGroupId());
+            if (vds.getUsageCpuPercent() >= 
NumberUtils.toInt(vdsGroup.getClusterPolicyProperties()
+                    .get(HIGH_UTILIZATION),
+                    Config.<Integer> 
GetValue(ConfigValues.HighUtilizationForEvenlyDistribute))
+                    || vds.getUsageCpuPercent() <= 
NumberUtils.toInt(vdsGroup.getClusterPolicyProperties()
+                            .get(LOW_UTILIZATION),
+                            Config.<Integer> 
GetValue(ConfigValues.LowUtilizationForEvenlyDistribute))) {
+                if (vds.getCpuOverCommitTimestamp() == null) {
+                    vds.setCpuOverCommitTimestamp(new Date());
+                }
+            } else {
+                vds.setCpuOverCommitTimestamp(null);
+            }
+        }
+    }
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SlaValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SlaValidator.java
index b384037..9c9c28b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SlaValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SlaValidator.java
@@ -39,36 +39,6 @@
         return retVal;
     }
 
-    /**
-     * Check if the given host has enough CPU to run the VM, without exceeding 
the high utilization threshold.
-     *
-     * @param vds
-     *            The host to check.
-     * @param vm
-     *            The VM to check.
-     * @return Does this host has enough CPU (without exceeding the threshold) 
to run the VM.
-     */
-    public boolean hasCpuToRunVM(VDS vds, VM vm) {
-        if (vds.getUsageCpuPercent() == null || vm.getUsageCpuPercent() == 
null) {
-            return false;
-        }
-        // The predicted CPU is actually the CPU that the VM will take 
considering how many cores it has and now many
-        // cores the host has. This is why we take both parameters into 
consideration.
-        int predictedVmCpu = (vm.getUsageCpuPercent() * vm.getNumOfCpus()) / 
getEffectiveCpuCores(vds);
-        boolean result = vds.getUsageCpuPercent() + predictedVmCpu <= 
vds.getHighUtilization();
-        if (log.isDebugEnabled()) {
-            log.debugFormat("Host {0} has {1}% CPU load; VM {2} is predicted 
to have {3}% CPU load; " +
-                    "High threshold is {4}%. Host is {5}suitable in terms of 
CPU.",
-                    vds.getName(),
-                    vds.getUsageCpuPercent(),
-                    vm.getName(),
-                    predictedVmCpu,
-                    vds.getHighUtilization(),
-                    (result ? "" : "not "));
-        }
-        return result;
-    }
-
     public static Integer getEffectiveCpuCores(VDS vds) {
         VDSGroup vdsGroup = 
DbFacade.getInstance().getVdsGroupDao().get(vds.getVdsGroupId());
         return getEffectiveCpuCores(vds, vdsGroup != null ? 
vdsGroup.getCountThreadsAsCores() : false);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
index db8093f..616fbe2 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/IVdsEventListener.java
@@ -2,6 +2,7 @@
 
 import java.util.List;
 import java.util.Map;
+
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.eventqueue.EventResult;
@@ -60,4 +61,11 @@
     boolean restartVds(Guid vdsId);
 
     void addExternallyManagedVms(List<VmStatic> externalVmList);
+
+    /**
+     * update host's scheduling related properties
+     *
+     * @param vds
+     */
+    void updateSchedulingStats(VDS vds); // BLL
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
index 952478e..64ab139 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VDS.java
@@ -45,9 +45,6 @@
         result = prime * result + ((mVdsStatic == null) ? 0 : 
mVdsStatic.hashCode());
         result = prime * result + ((cpuName == null) ? 0 : cpuName.hashCode());
         result = prime * result + ((_spm_status == null) ? 0 : 
_spm_status.hashCode());
-        result = prime * result + cpuOverCommitDurationMinutes;
-        result = prime * result + highUtilization;
-        result = prime * result + lowUtilization;
         result = prime * result + ((mImagesLastCheck == null) ? 0 : 
mImagesLastCheck.hashCode());
         result = prime * result + ((mImagesLastDelay == null) ? 0 : 
mImagesLastDelay.hashCode());
         result = prime * result + ((mInterfaceList == null) ? 0 : 
mInterfaceList.hashCode());
@@ -82,9 +79,6 @@
         return (ObjectUtils.objectsEqual(mVdsStatic, other.mVdsStatic)
                 && ObjectUtils.objectsEqual(cpuName, other.cpuName)
                 && _spm_status == other._spm_status
-                && cpuOverCommitDurationMinutes == 
other.cpuOverCommitDurationMinutes
-                && highUtilization == other.highUtilization
-                && lowUtilization == other.lowUtilization
                 && ObjectUtils.objectsEqual(mImagesLastCheck, 
other.mImagesLastCheck)
                 && ObjectUtils.objectsEqual(mImagesLastDelay, 
other.mImagesLastDelay)
                 && ObjectUtils.objectsEqual(mInterfaceList, 
other.mInterfaceList)
@@ -798,36 +792,6 @@
 
     public void setVdsStrength(int value) {
         this.mVdsStatic.setVdsStrength(value);
-    }
-
-    private int highUtilization;
-
-    public int getHighUtilization() {
-        return this.highUtilization;
-    }
-
-    public void setHighUtilization(int value) {
-        this.highUtilization = value;
-    }
-
-    private int lowUtilization;
-
-    public int getLowUtilization() {
-        return this.lowUtilization;
-    }
-
-    public void setLowUtilization(int value) {
-        this.lowUtilization = value;
-    }
-
-    private int cpuOverCommitDurationMinutes;
-
-    public int getCpuOverCommitDurationMinutes() {
-        return this.cpuOverCommitDurationMinutes;
-    }
-
-    public void setCpuOverCommitDurationMinutes(int value) {
-        this.cpuOverCommitDurationMinutes = value;
     }
 
     private Guid storagePoolId;
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
index f550cb6..f1443ae 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/VdsUpdateRunTimeInfo.java
@@ -512,6 +512,7 @@
         GetStatsVDSCommand<VdsIdAndVdsVDSCommandParametersBase> 
vdsBrokerCommand =
                 new 
GetStatsVDSCommand<VdsIdAndVdsVDSCommandParametersBase>(new 
VdsIdAndVdsVDSCommandParametersBase(_vds));
         vdsBrokerCommand.execute();
+        
ResourceManager.getInstance().getEventListener().updateSchedulingStats(_vds);
         if (!vdsBrokerCommand.getVDSReturnValue().getSucceeded()
                 && vdsBrokerCommand.getVDSReturnValue().getExceptionObject() 
!= null) {
             VDSNetworkException ex =
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
index bfc5820..3af0f2d 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VdsBrokerObjectsBuilder.java
@@ -582,14 +582,6 @@
         vds.setCpuUser(AssignDoubleValue(xmlRpcStruct, 
VdsProperties.cpu_user));
         if (vds.getCpuSys() != null && vds.getCpuUser() != null) {
             vds.setUsageCpuPercent((int) (vds.getCpuSys() + vds.getCpuUser()));
-            if (vds.getUsageCpuPercent() >= vds.getHighUtilization()
-                    || vds.getUsageCpuPercent() <= vds.getLowUtilization()) {
-                if (vds.getCpuOverCommitTimestamp() == null) {
-                    vds.setCpuOverCommitTimestamp(new Date());
-                }
-            } else {
-                vds.setCpuOverCommitTimestamp(null);
-            }
         }
         // CPU load reported by VDSM is in uptime-style format, i.e. normalized
         // to unity, so that say an 8% load is reported as 0.08


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I231aa54ccc0cadbd9456b090fe08ae85dd926957
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.3
Gerrit-Owner: Gilad Chaplik <gchap...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to