Revert "bug 5873: after this fix, in dashboard, "used" means it is really used now, no preservation."

This reverts commit 638867201d.
This commit is contained in:
anthony 2011-01-07 11:30:04 -08:00
parent 255f1a7316
commit d47268815d
4 changed files with 27 additions and 35 deletions

View File

@ -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;

View File

@ -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);

View File

@ -213,6 +213,6 @@ public interface UserVmManager extends Manager, VirtualMachineManager<UserVmVO>
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);
}

View File

@ -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<VMInstanceVO> vms = _vmInstanceDao.listByLastHostId(hostId);
long usedCapacity = 0;
for (VMInstanceVO vm : vms) {
if(skipCalculation(vm, preserve))
if(skipCalculation(vm))
continue;
ServiceOffering so = null;