mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
bug 10422: Correctly populating the used and reserved capacity in ComputeCapacityListener Status 10422: resolved fixed
This commit is contained in:
parent
1eb8e61c43
commit
91e016114e
@ -79,94 +79,7 @@ public class ComputeCapacityListener implements Listener {
|
||||
if (!(startup instanceof StartupRoutingCommand)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_capacityMgr.updateCapacityForHost(server);
|
||||
SearchCriteria<CapacityVO> capacityCPU = _capacityDao
|
||||
.createSearchCriteria();
|
||||
capacityCPU.addAnd("hostOrPoolId", SearchCriteria.Op.EQ,
|
||||
server.getId());
|
||||
capacityCPU.addAnd("dataCenterId", SearchCriteria.Op.EQ,
|
||||
server.getDataCenterId());
|
||||
capacityCPU
|
||||
.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId());
|
||||
capacityCPU.addAnd("capacityType", SearchCriteria.Op.EQ,
|
||||
CapacityVO.CAPACITY_TYPE_CPU);
|
||||
List<CapacityVO> capacityVOCpus = _capacityDao.search(capacityCPU,
|
||||
null);
|
||||
|
||||
if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) {
|
||||
CapacityVO CapacityVOCpu = capacityVOCpus.get(0);
|
||||
long newTotalCpu = (server.getCpus().longValue()
|
||||
* server.getSpeed().longValue());
|
||||
if ((CapacityVOCpu.getTotalCapacity() <= newTotalCpu)
|
||||
|| ((CapacityVOCpu.getUsedCapacity() + CapacityVOCpu
|
||||
.getReservedCapacity()) <= newTotalCpu)) {
|
||||
CapacityVOCpu.setTotalCapacity(newTotalCpu);
|
||||
} else if ((CapacityVOCpu.getUsedCapacity()
|
||||
+ CapacityVOCpu.getReservedCapacity() > newTotalCpu)
|
||||
&& (CapacityVOCpu.getUsedCapacity() < newTotalCpu)) {
|
||||
CapacityVOCpu.setReservedCapacity(0);
|
||||
CapacityVOCpu.setTotalCapacity(newTotalCpu);
|
||||
} else {
|
||||
s_logger.debug("What? new cpu is :" + newTotalCpu
|
||||
+ ", old one is " + CapacityVOCpu.getUsedCapacity()
|
||||
+ "," + CapacityVOCpu.getReservedCapacity() + ","
|
||||
+ CapacityVOCpu.getTotalCapacity());
|
||||
}
|
||||
_capacityDao.update(CapacityVOCpu.getId(), CapacityVOCpu);
|
||||
} else {
|
||||
CapacityVO capacity = new CapacityVO(
|
||||
server.getId(),
|
||||
server.getDataCenterId(),
|
||||
server.getPodId(),
|
||||
server.getClusterId(),
|
||||
0L,
|
||||
(server.getCpus().longValue()
|
||||
* server.getSpeed().longValue()),
|
||||
CapacityVO.CAPACITY_TYPE_CPU);
|
||||
_capacityDao.persist(capacity);
|
||||
}
|
||||
|
||||
SearchCriteria<CapacityVO> capacityMem = _capacityDao
|
||||
.createSearchCriteria();
|
||||
capacityMem.addAnd("hostOrPoolId", SearchCriteria.Op.EQ,
|
||||
server.getId());
|
||||
capacityMem.addAnd("dataCenterId", SearchCriteria.Op.EQ,
|
||||
server.getDataCenterId());
|
||||
capacityMem
|
||||
.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId());
|
||||
capacityMem.addAnd("capacityType", SearchCriteria.Op.EQ,
|
||||
CapacityVO.CAPACITY_TYPE_MEMORY);
|
||||
List<CapacityVO> capacityVOMems = _capacityDao.search(capacityMem,
|
||||
null);
|
||||
|
||||
if (capacityVOMems != null && !capacityVOMems.isEmpty()) {
|
||||
CapacityVO CapacityVOMem = capacityVOMems.get(0);
|
||||
long newTotalMem = server.getTotalMemory();
|
||||
if (CapacityVOMem.getTotalCapacity() <= newTotalMem
|
||||
|| (CapacityVOMem.getUsedCapacity()
|
||||
+ CapacityVOMem.getReservedCapacity() <= newTotalMem)) {
|
||||
CapacityVOMem.setTotalCapacity(newTotalMem);
|
||||
} else if (CapacityVOMem.getUsedCapacity()
|
||||
+ CapacityVOMem.getReservedCapacity() > newTotalMem
|
||||
&& CapacityVOMem.getUsedCapacity() < newTotalMem) {
|
||||
CapacityVOMem.setReservedCapacity(0);
|
||||
CapacityVOMem.setTotalCapacity(newTotalMem);
|
||||
} else {
|
||||
s_logger.debug("What? new cpu is :" + newTotalMem
|
||||
+ ", old one is " + CapacityVOMem.getUsedCapacity()
|
||||
+ "," + CapacityVOMem.getReservedCapacity() + ","
|
||||
+ CapacityVOMem.getTotalCapacity());
|
||||
}
|
||||
_capacityDao.update(CapacityVOMem.getId(), CapacityVOMem);
|
||||
} else {
|
||||
CapacityVO capacity = new CapacityVO(server.getId(),
|
||||
server.getDataCenterId(), server.getPodId(), server.getClusterId(), 0L,
|
||||
server.getTotalMemory(),
|
||||
CapacityVO.CAPACITY_TYPE_MEMORY);
|
||||
_capacityDao.persist(capacity);
|
||||
}
|
||||
|
||||
_capacityMgr.updateCapacityForHost(server);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user