Arik Hadas has uploaded a new change for review.

Change subject: core: minor cleanup in VmPoolMonitor
......................................................................

core: minor cleanup in VmPoolMonitor

Change-Id: I7aaa8f37b5b4b4d872f374be8b5b8f7adacc5222
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
2 files changed, 9 insertions(+), 33 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/11635/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
index 0f1ee92..a0a24dc 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolCommandBase.java
@@ -145,20 +145,11 @@
      * @return True if can be attached, false otherwise.
      */
     protected static boolean canAttachPrestartedVmToUser(Guid vmId) {
-        boolean returnValue = true;
-        java.util.ArrayList<String> messages = new 
java.util.ArrayList<String>();
-
         // check that there isn't another user already attached to this VM:
-        if (vmAssignedToUser(vmId, messages)) {
-            returnValue = false;
-        }
+        boolean returnValue = !vmAssignedToUser(vmId, new 
java.util.ArrayList<String>());
 
         // Make sure the Vm is running stateless
-        if (returnValue) {
-            if (!vmIsRunningStateless(vmId)) {
-                returnValue = false;
-            }
-        }
+        returnValue = returnValue && vmIsRunningStateless(vmId);
 
         return returnValue;
     }
@@ -296,15 +287,6 @@
                 VdcObjectType.VmPool,
                 getActionType().getActionGroup()));
         return permissionList;
-    }
-
-    public static boolean isPrestartedVmForAssignment(Guid vm_guid) {
-        VmDynamic vmDynamic = 
DbFacade.getInstance().getVmDynamicDao().get(vm_guid);
-        if (vmDynamic != null && vmDynamic.getstatus() == VMStatus.Up && 
canAttachPrestartedVmToUser(vm_guid)) {
-            return true;
-        } else {
-            return false;
-        }
     }
 
     protected VmPoolDAO getVmPoolDAO() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
index f4c5d2f..6fa7e37 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmPoolMonitor.java
@@ -8,8 +8,8 @@
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
-import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.VmPoolMap;
+import org.ovirt.engine.core.common.businessentities.VmType;
 import org.ovirt.engine.core.common.businessentities.vm_pools;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
@@ -28,7 +28,7 @@
     @OnTimerMethodAnnotation("managePrestartedVmsInAllVmPools")
     public void managePrestartedVmsInAllVmPools() {
         List<vm_pools> vmPools = 
DbFacade.getInstance().getVmPoolDao().getAll();
-         for (vm_pools vmPool : vmPools) {
+        for (vm_pools vmPool : vmPools) {
             managePrestartedVmsInPool(vmPool);
         }
     }
@@ -39,20 +39,14 @@
      * @param vmPool
      */
     private void managePrestartedVmsInPool(vm_pools vmPool) {
-        int prestartedVms;
-        int missingPrestartedVms;
-        int numOfVmsToPrestart;
         Guid vmPoolId = vmPool.getvm_pool_id();
-        prestartedVms = 
VmPoolCommandBase.getNumOfPrestartedVmsInPool(vmPoolId);
-        missingPrestartedVms = vmPool.getPrestartedVms() - prestartedVms;
+        int prestartedVms = 
VmPoolCommandBase.getNumOfPrestartedVmsInPool(vmPoolId);
+        int missingPrestartedVms = vmPool.getPrestartedVms() - prestartedVms;
         if (missingPrestartedVms > 0) {
             // We do not want to start too many vms at once
-            int batchSize = Config.<Integer> 
GetValue(ConfigValues.VmPoolMonitorBatchSize);
-            if (missingPrestartedVms > batchSize) {
-                numOfVmsToPrestart = batchSize;
-            } else {
-                numOfVmsToPrestart = missingPrestartedVms;
-            }
+            int numOfVmsToPrestart =
+                    Math.min(missingPrestartedVms, Config.<Integer> 
GetValue(ConfigValues.VmPoolMonitorBatchSize));
+
             log.infoFormat("VmPool {0} is missing {1} prestarted Vms, 
attempting to prestart {2} Vms",
                     vmPoolId,
                     missingPrestartedVms,


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

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

Reply via email to