Gilad Chaplik has uploaded a new change for review.

Change subject: engine: move static method
......................................................................

engine: move static method

getEffectiveCpuCores from vdsSelector to SchedulingValidator util class

Change-Id: I447eec70ecb06daf4e8208f49e4478e4786b1cd0
Signed-off-by: Gilad Chaplik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/EvenlyDistributeComparer.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/SlaValidator.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsCpuVdsLoadBalancingAlgorithm.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsSelector.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VmCountVdsLoadBalancingAlgorithm.java
5 files changed, 25 insertions(+), 24 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/06/16106/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/EvenlyDistributeComparer.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/EvenlyDistributeComparer.java
index 799152f..90099d9 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/EvenlyDistributeComparer.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/EvenlyDistributeComparer.java
@@ -11,7 +11,7 @@
         int vcpu = Config.<Integer> 
GetValue(ConfigValues.VcpuConsumptionPercentage);
         int spmCpu = (vds.getSpmStatus() == VdsSpmStatus.None) ? 0 : Config
                 .<Integer> GetValue(ConfigValues.SpmVCpuConsumption);
-        int hostCores = VdsSelector.getEffectiveCpuCores(vds);
+        int hostCores = SlaValidator.getEffectiveCpuCores(vds);
         double hostCpu = vds.getUsageCpuPercent();
         double pendingVcpus = vds.getPendingVcpusCount();
 
@@ -20,8 +20,8 @@
 
     @Override
     public boolean isBetter(VDS x, VDS y, VM vm) {
-        if (VdsSelector.getEffectiveCpuCores(x) == null
-                || VdsSelector.getEffectiveCpuCores(y) == null
+        if (SlaValidator.getEffectiveCpuCores(x) == null
+                || SlaValidator.getEffectiveCpuCores(y) == null
                 || x.getUsageCpuPercent() == null
                 || y.getUsageCpuPercent() == null
                 || x.getPendingVcpusCount() == 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 ddd7f30..928b0eb 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
@@ -1,7 +1,9 @@
 package org.ovirt.engine.core.bll.scheduling;
 
 import org.ovirt.engine.core.common.businessentities.VDS;
+import org.ovirt.engine.core.common.businessentities.VDSGroup;
 import org.ovirt.engine.core.common.businessentities.VM;
+import org.ovirt.engine.core.dal.dbbroker.DbFacade;
 import org.ovirt.engine.core.utils.log.Log;
 import org.ovirt.engine.core.utils.log.LogFactory;
 
@@ -52,7 +54,7 @@
         }
         // 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()) / 
VdsSelector.getEffectiveCpuCores(vds);
+        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; " +
@@ -67,4 +69,16 @@
         return result;
     }
 
+    public static Integer getEffectiveCpuCores(VDS vds) {
+        VDSGroup vdsGroup = 
DbFacade.getInstance().getVdsGroupDao().get(vds.getVdsGroupId());
+
+        if (vds.getCpuThreads() != null
+                && vdsGroup != null
+                && Boolean.TRUE.equals(vdsGroup.getCountThreadsAsCores())) {
+            return vds.getCpuThreads();
+        } else {
+            return vds.getCpuCores();
+        }
+    }
+
 }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsCpuVdsLoadBalancingAlgorithm.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsCpuVdsLoadBalancingAlgorithm.java
index a5199d7..952a3be 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsCpuVdsLoadBalancingAlgorithm.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsCpuVdsLoadBalancingAlgorithm.java
@@ -35,7 +35,7 @@
             public boolean eval(VDS p) {
                 return p.getUsageCpuPercent() >= p.getHighUtilization()
                         && p.getCpuOverCommitTimestamp() != null
-                        && (new Date().getTime() - 
p.getCpuOverCommitTimestamp().getTime()) >= (long)p
+                        && (new Date().getTime() - 
p.getCpuOverCommitTimestamp().getTime()) >= p
                                 .getCpuOverCommitDurationMinutes() * 1000L * 
60L;
             }
         });
@@ -172,7 +172,7 @@
         }
 
         private int calculateCpuUsage(VDS o1) {
-            return o1.getUsageCpuPercent() * 
VdsSelector.getEffectiveCpuCores(o1) / o1.getVdsStrength();
+            return o1.getUsageCpuPercent() * 
SlaValidator.getEffectiveCpuCores(o1) / o1.getVdsStrength();
         }
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsSelector.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsSelector.java
index 28fea45..c798b87 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsSelector.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VdsSelector.java
@@ -10,7 +10,6 @@
 import org.ovirt.engine.core.common.businessentities.Entities;
 import org.ovirt.engine.core.common.businessentities.MigrationSupport;
 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.VMStatus;
@@ -191,18 +190,6 @@
         VdcBllMessages validate(VDS vds, StringBuilder sb, boolean isMigrate, 
List<Guid> vdsBlackList);
     }
 
-    public static Integer getEffectiveCpuCores(VDS vds) {
-        VDSGroup vdsGroup = 
DbFacade.getInstance().getVdsGroupDao().get(vds.getVdsGroupId());
-
-        if (vds.getCpuThreads() != null
-                && vdsGroup != null
-                && Boolean.TRUE.equals(vdsGroup.getCountThreadsAsCores())) {
-            return vds.getCpuThreads();
-        } else {
-            return vds.getCpuCores();
-        }
-    }
-
     @SuppressWarnings("serial")
     final List<HostValidator> hostValidators = 
Collections.unmodifiableList(new ArrayList<HostValidator>(){
         {
@@ -246,7 +233,7 @@
             add(new HostValidator() {
                 @Override
                 public VdcBllMessages validate(VDS vds, StringBuilder sb, 
boolean isMigrate, List<Guid> vdsBlackList) {
-                    Integer cores = getEffectiveCpuCores(vds);
+                    Integer cores = SlaValidator.getEffectiveCpuCores(vds);
                     if (cores != null && getVm().getNumOfCpus() > cores) {
                         sb.append("has less cores(").append(cores).append(") 
than ").append(getVm().getNumOfCpus());
                         return VdcBllMessages.ACTION_TYPE_FAILED_VDS_VM_CPUS;
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VmCountVdsLoadBalancingAlgorithm.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VmCountVdsLoadBalancingAlgorithm.java
index 8e69ec2..d864f93 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VmCountVdsLoadBalancingAlgorithm.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/scheduling/VmCountVdsLoadBalancingAlgorithm.java
@@ -40,7 +40,7 @@
         List<VDS> vdses = LinqUtils.filter(getAllRelevantVdss(), new 
Predicate<VDS>() {
             @Override
             public boolean eval(VDS p) {
-                return p.getVmCount() > vmCountTemp * 
VdsSelector.getEffectiveCpuCores(p);
+                return p.getVmCount() > vmCountTemp * 
SlaValidator.getEffectiveCpuCores(p);
             }
         });
         Collections.sort(vdses, new Comparator<VDS>() {
@@ -86,7 +86,7 @@
         List<VDS> vdses = LinqUtils.filter(getAllRelevantVdss(), new 
Predicate<VDS>() {
             @Override
             public boolean eval(VDS p) {
-                return p.getVmCount() < vmCountTemp * 
VdsSelector.getEffectiveCpuCores(p);
+                return p.getVmCount() < vmCountTemp * 
SlaValidator.getEffectiveCpuCores(p);
             }
         });
         Collections.sort(vdses, new Comparator<VDS>() {
@@ -132,8 +132,8 @@
         List<VDS> vdses = LinqUtils.filter(getAllRelevantVdss(), new 
Predicate<VDS>() {
             @Override
             public boolean eval(VDS p) {
-                return p.getVmCount() < highVdsCountTemp * 
VdsSelector.getEffectiveCpuCores(p)
-                        && p.getVmCount() >= lowVdsCountTemp * 
VdsSelector.getEffectiveCpuCores(p);
+                return p.getVmCount() < highVdsCountTemp * 
SlaValidator.getEffectiveCpuCores(p)
+                        && p.getVmCount() >= lowVdsCountTemp * 
SlaValidator.getEffectiveCpuCores(p);
             }
         });
         setReadyToMigrationServers(LinqUtils.toMap(vdses, new 
DefaultMapper<VDS, Guid>() {


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I447eec70ecb06daf4e8208f49e4478e4786b1cd0
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