Gilad Chaplik has uploaded a new change for review.

Change subject: core: move static util method to static util class (15/15)
......................................................................

core: move static util method to static util class (15/15)

vdsSelector.getEffectiveCpuCores(vds)

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


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/17/13217/1

diff --git 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/EvenlyDistributeComparer.java
 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/EvenlyDistributeComparer.java
index a64db2c..440a8bb 100644
--- 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/EvenlyDistributeComparer.java
+++ 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/EvenlyDistributeComparer.java
@@ -9,7 +9,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 = SlaStaticValidation.getEffectiveCpuCores(vds);
         double hostCpu = vds.getUsageCpuPercent();
         double pendingVcpus = vds.getPendingVcpusCount();
 
@@ -18,8 +18,8 @@
 
     @Override
     public boolean IsBetter(VDS x, VDS y, VM vm) {
-        if (VdsSelector.getEffectiveCpuCores(x) == null
-                || VdsSelector.getEffectiveCpuCores(y) == null
+        if (SlaStaticValidation.getEffectiveCpuCores(x) == null
+                || SlaStaticValidation.getEffectiveCpuCores(y) == null
                 || x.getUsageCpuPercent() == null
                 || y.getUsageCpuPercent() == null
                 || x.getPendingVcpusCount() == null
diff --git 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/SlaStaticValidation.java
 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/SlaStaticValidation.java
index 22fb841..a079d43 100644
--- 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/SlaStaticValidation.java
+++ 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/SlaStaticValidation.java
@@ -1,7 +1,9 @@
 package org.ovirt.engine.core.sla;
 
 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;
 
@@ -23,7 +25,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()) / 
SlaStaticValidation.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; " +
@@ -62,4 +64,16 @@
         return retVal;
     }
 
+    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/sla/src/main/java/org/ovirt/engine/core/sla/VdsCpuVdsLoadBalancingAlgorithm.java
 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsCpuVdsLoadBalancingAlgorithm.java
index 5f6cb73..79386ac 100644
--- 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsCpuVdsLoadBalancingAlgorithm.java
+++ 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsCpuVdsLoadBalancingAlgorithm.java
@@ -172,7 +172,7 @@
         }
 
         private int calculateCpuUsage(VDS o1) {
-            return o1.getUsageCpuPercent() * 
VdsSelector.getEffectiveCpuCores(o1) / o1.getVdsStrength();
+            return o1.getUsageCpuPercent() * 
SlaStaticValidation.getEffectiveCpuCores(o1) / o1.getVdsStrength();
         }
     }
 
diff --git 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsSelector.java
 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsSelector.java
index 975638f..d3630a5 100644
--- 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsSelector.java
+++ 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VdsSelector.java
@@ -9,7 +9,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.VDSType;
 import org.ovirt.engine.core.common.businessentities.VM;
@@ -161,18 +160,6 @@
         VdcBllMessages validate(VDS vds, StringBuilder sb, boolean isMigrate);
     }
 
-    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>(){
         {
@@ -216,7 +203,7 @@
             add(new HostValidator() {
                 @Override
                 public VdcBllMessages validate(VDS vds, StringBuilder sb, 
boolean isMigrate) {
-                    Integer cores = getEffectiveCpuCores(vds);
+                    Integer cores = 
SlaStaticValidation.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;
@@ -284,7 +271,7 @@
      * @return <c>true</c> if [is VM swap value legal] [the specified VDS];
      *         otherwise, <c>false</c>.
      */
-    private static boolean isVMSwapValueLegal(VDS vds) {
+    private boolean isVMSwapValueLegal(VDS vds) {
         if (!Config.<Boolean> GetValue(ConfigValues.EnableSwapCheck)) {
             return true;
         }
diff --git 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VmCountVdsLoadBalancingAlgorithm.java
 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VmCountVdsLoadBalancingAlgorithm.java
index f921c75..b0de46a 100644
--- 
a/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/VmCountVdsLoadBalancingAlgorithm.java
+++ 
b/backend/manager/modules/sla/src/main/java/org/ovirt/engine/core/sla/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 * 
SlaStaticValidation.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 * 
SlaStaticValidation.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 * 
SlaStaticValidation.getEffectiveCpuCores(p)
+                        && p.getVmCount() >= lowVdsCountTemp * 
SlaStaticValidation.getEffectiveCpuCores(p);
             }
         });
         setReadyToMigrationServers(LinqUtils.toMap(vdses, new 
DefaultMapper<VDS, Guid>() {


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

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