mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 10520: CAPACITY_TYPE_PUBLIC_IP and CAPACITY_TYPE_PRIVATE_IP - Change from remove and insert to the to the insert and update model. It doesnt seem like they are referenced for the allocators while creating a vm. Next might change them to calculating them on the fly.
This commit is contained in:
parent
1e24c6a745
commit
0dba08a431
@ -270,6 +270,9 @@ public class AlertManagerImpl implements AlertManager {
|
||||
_storageMgr.createCapacityEntry(pool, disk);
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
txn.start();
|
||||
// Calculate new Public IP capacity
|
||||
List<DataCenterVO> datacenters = _dcDao.listAllIncludingRemoved();
|
||||
for (DataCenterVO datacenter : datacenters) {
|
||||
@ -280,36 +283,25 @@ public class AlertManagerImpl implements AlertManager {
|
||||
//with no filter based on a vlan
|
||||
//ideal way would be to remove out the vlan param, and filter only on dcId
|
||||
//implementing the same
|
||||
int totalPublicIPs = _publicIPAddressDao.countIPsForDashboard(dcId, false);
|
||||
int allocatedPublicIPs = _publicIPAddressDao.countIPsForDashboard(dcId, true);
|
||||
|
||||
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, null, null, allocatedPublicIPs, totalPublicIPs, CapacityVO.CAPACITY_TYPE_PUBLIC_IP);
|
||||
newCapacities.add(newPublicIPCapacity);
|
||||
s_logger.trace("Executing capacity update");
|
||||
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_PUBLIC_IP);
|
||||
s_logger.trace("Done with capacity update");
|
||||
|
||||
}
|
||||
txn.commit();
|
||||
|
||||
txn.start();
|
||||
// Calculate new Private IP capacity
|
||||
List<HostPodVO> pods = _podDao.listAllIncludingRemoved();
|
||||
for (HostPodVO pod : pods) {
|
||||
long podId = pod.getId();
|
||||
long dcId = pod.getDataCenterId();
|
||||
|
||||
int totalPrivateIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
|
||||
int allocatedPrivateIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
|
||||
|
||||
CapacityVO newPrivateIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedPrivateIPs, totalPrivateIPs, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
|
||||
newCapacities.add(newPrivateIPCapacity);
|
||||
}
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
txn.start();
|
||||
|
||||
_capacityDao.clearNonStorageCapacities2();
|
||||
|
||||
for (CapacityVO newCapacity : newCapacities) {
|
||||
s_logger.trace("Executing capacity update");
|
||||
_capacityDao.persist(newCapacity);
|
||||
createOrUpdateIpCapacity(dcId, podId, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
|
||||
s_logger.trace("Done with capacity update");
|
||||
|
||||
}
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
@ -320,6 +312,39 @@ public class AlertManagerImpl implements AlertManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType){
|
||||
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
|
||||
|
||||
List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
|
||||
capacitySC = _capacityDao.createSearchCriteria();
|
||||
capacitySC.addAnd("podId", SearchCriteria.Op.EQ, podId);
|
||||
capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
|
||||
capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
|
||||
|
||||
int totalIPs;
|
||||
int allocatedIPs;
|
||||
capacities = _capacityDao.search(capacitySC, null);
|
||||
if (capacityType == CapacityVO.CAPACITY_TYPE_PRIVATE_IP){
|
||||
totalIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
|
||||
allocatedIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
|
||||
}else{
|
||||
totalIPs = _publicIPAddressDao.countIPsForDashboard(dcId, false);
|
||||
allocatedIPs = _publicIPAddressDao.countIPsForDashboard(dcId, true);
|
||||
}
|
||||
|
||||
if (capacities.size() == 0){
|
||||
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
|
||||
_capacityDao.persist(newPublicIPCapacity);
|
||||
}else if ( !(capacities.get(0).getUsedCapacity() == allocatedIPs
|
||||
&& capacities.get(0).getTotalCapacity() == totalIPs) ){
|
||||
CapacityVO capacity = capacities.get(0);
|
||||
capacity.setUsedCapacity(allocatedIPs);
|
||||
capacity.setTotalCapacity(totalIPs);
|
||||
_capacityDao.update(capacity.getId(), capacity);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CapacityChecker extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user