From d47268815d0a07a95d21ac79267d123780d183d6 Mon Sep 17 00:00:00 2001 From: anthony Date: Fri, 7 Jan 2011 11:30:04 -0800 Subject: [PATCH] Revert "bug 5873: after this fix, in dashboard, "used" means it is really used now, no preservation." This reverts commit 638867201d76f999c4b0438e84d204b2cef788a4. --- .../impl/UserConcentratedAllocator.java | 2 +- .../src/com/cloud/alert/AlertManagerImpl.java | 4 +- server/src/com/cloud/vm/UserVmManager.java | 4 +- .../src/com/cloud/vm/UserVmManagerImpl.java | 52 ++++++++----------- 4 files changed, 27 insertions(+), 35 deletions(-) diff --git a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java index bc98dce57f5..e92c1b2ad51 100755 --- a/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java +++ b/server/src/com/cloud/agent/manager/allocator/impl/UserConcentratedAllocator.java @@ -170,7 +170,7 @@ public class UserConcentratedAllocator implements PodAllocator { // for CPU/Memory, we now switch to static allocation // if ((capacity.getTotalCapacity() - - _vmMgr.calcHostAllocatedCpuMemoryCapacity(capacity.getHostOrPoolId(), capacityType, true)) >= capacityNeeded) { + _vmMgr.calcHostAllocatedCpuMemoryCapacity(capacity.getHostOrPoolId(), capacityType)) >= capacityNeeded) { hostCandidate[0] = capacity.getHostOrPoolId(); enoughCapacity = true; diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 7f41db6b88b..a4e3f1f6227 100755 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -350,8 +350,8 @@ public class AlertManagerImpl implements AlertManager { if (host.getType() != Host.Type.Routing) { continue; } - long cpu = _vmMgr.calcHostAllocatedCpuMemoryCapacity(host.getId(), CapacityVO.CAPACITY_TYPE_CPU, false); - long usedMemory = _vmMgr.calcHostAllocatedCpuMemoryCapacity(host.getId(), CapacityVO.CAPACITY_TYPE_MEMORY, false); + long cpu = _vmMgr.calcHostAllocatedCpuMemoryCapacity(host.getId(), CapacityVO.CAPACITY_TYPE_CPU); + long usedMemory = _vmMgr.calcHostAllocatedCpuMemoryCapacity(host.getId(), CapacityVO.CAPACITY_TYPE_MEMORY); long totalMemory = host.getTotalMemory(); CapacityVO newMemoryCapacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), usedMemory, totalMemory, CapacityVO.CAPACITY_TYPE_MEMORY); diff --git a/server/src/com/cloud/vm/UserVmManager.java b/server/src/com/cloud/vm/UserVmManager.java index 9df729f5d86..a95e4814794 100755 --- a/server/src/com/cloud/vm/UserVmManager.java +++ b/server/src/com/cloud/vm/UserVmManager.java @@ -213,6 +213,6 @@ public interface UserVmManager extends Manager, VirtualMachineManager SnapshotVO createTemplateSnapshot(long userId, long volumeId); - long calcHostAllocatedCpuMemoryCapacity(long hostId, short capacityType, boolean preserve); - boolean skipCalculation(VMInstanceVO vm, boolean preserve); + long calcHostAllocatedCpuMemoryCapacity(long hostId, short capacityType); + boolean skipCalculation(VMInstanceVO vm); } diff --git a/server/src/com/cloud/vm/UserVmManagerImpl.java b/server/src/com/cloud/vm/UserVmManagerImpl.java index 84521784a04..9b8cf2a61b1 100755 --- a/server/src/com/cloud/vm/UserVmManagerImpl.java +++ b/server/src/com/cloud/vm/UserVmManagerImpl.java @@ -2935,35 +2935,27 @@ public class UserVmManagerImpl implements UserVmManager { } @Override - public boolean skipCalculation(VMInstanceVO vm, boolean preserve) { - if ( preserve ){ - if(vm.getState() == State.Expunging) { - if(s_logger.isDebugEnabled()) - s_logger.debug("Skip counting capacity for Expunging VM : " + vm.getInstanceName()); - return true; - } - - if(vm.getState() == State.Destroyed && vm.getType() != VirtualMachine.Type.User) - return true; - - if(vm.getState() == State.Stopped || vm.getState() == State.Destroyed) { - // for stopped/Destroyed VMs, we will skip counting it if it hasn't been used for a while - - long millisecondsSinceLastUpdate = DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime(); - if(millisecondsSinceLastUpdate > _hoursToSkipStoppedVMs*3600000L) { - if(s_logger.isDebugEnabled()) - s_logger.debug("Skip counting vm " + vm.getInstanceName() + " in capacity allocation as it has been stopped for " + millisecondsSinceLastUpdate/60000 + " minutes"); - return true; - } - } - return false; - } else { - if(vm.getState() == State.Expunging || vm.getState() == State.Destroyed || vm.getState() == State.Stopped ) { - return true; - } else { - return false; - } + public boolean skipCalculation(VMInstanceVO vm) { + if(vm.getState() == State.Expunging) { + if(s_logger.isDebugEnabled()) + s_logger.debug("Skip counting capacity for Expunging VM : " + vm.getInstanceName()); + return true; } + + if(vm.getState() == State.Destroyed && vm.getType() != VirtualMachine.Type.User) + return true; + + if(vm.getState() == State.Stopped || vm.getState() == State.Destroyed) { + // for stopped/Destroyed VMs, we will skip counting it if it hasn't been used for a while + + long millisecondsSinceLastUpdate = DateUtil.currentGMTTime().getTime() - vm.getUpdateTime().getTime(); + if(millisecondsSinceLastUpdate > _hoursToSkipStoppedVMs*3600000L) { + if(s_logger.isDebugEnabled()) + s_logger.debug("Skip counting vm " + vm.getInstanceName() + " in capacity allocation as it has been stopped for " + millisecondsSinceLastUpdate/60000 + " minutes"); + return true; + } + } + return false; } /** @@ -2973,13 +2965,13 @@ public class UserVmManagerImpl implements UserVmManager { * @return */ @Override - public long calcHostAllocatedCpuMemoryCapacity(long hostId, short capacityType, boolean preserve) { + public long calcHostAllocatedCpuMemoryCapacity(long hostId, short capacityType) { assert(capacityType == CapacityVO.CAPACITY_TYPE_MEMORY || capacityType == CapacityVO.CAPACITY_TYPE_CPU) : "Invalid capacity type passed in calcHostAllocatedCpuCapacity()"; List vms = _vmInstanceDao.listByLastHostId(hostId); long usedCapacity = 0; for (VMInstanceVO vm : vms) { - if(skipCalculation(vm, preserve)) + if(skipCalculation(vm)) continue; ServiceOffering so = null;