Skip to content

Commit 0dba08a

Browse files
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.
1 parent 1e24c6a commit 0dba08a

1 file changed

Lines changed: 61 additions & 36 deletions

File tree

‎server/src/com/cloud/alert/AlertManagerImpl.java‎

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -269,55 +269,80 @@ public void recalculateCapacity() {
269269
disk = sizes.second();
270270
_storageMgr.createCapacityEntry(pool, disk);
271271
}
272-
273-
// Calculate new Public IP capacity
274-
List<DataCenterVO> datacenters = _dcDao.listAllIncludingRemoved();
275-
for (DataCenterVO datacenter : datacenters) {
276-
long dcId = datacenter.getId();
277-
278-
//NOTE
279-
//What happens if we have multiple vlans? Dashboard currently shows stats
280-
//with no filter based on a vlan
281-
//ideal way would be to remove out the vlan param, and filter only on dcId
282-
//implementing the same
283-
int totalPublicIPs = _publicIPAddressDao.countIPsForDashboard(dcId, false);
284-
int allocatedPublicIPs = _publicIPAddressDao.countIPsForDashboard(dcId, true);
285-
286-
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, null, null, allocatedPublicIPs, totalPublicIPs, CapacityVO.CAPACITY_TYPE_PUBLIC_IP);
287-
newCapacities.add(newPublicIPCapacity);
288-
}
289-
290-
// Calculate new Private IP capacity
291-
List<HostPodVO> pods = _podDao.listAllIncludingRemoved();
292-
for (HostPodVO pod : pods) {
293-
long podId = pod.getId();
294-
long dcId = pod.getDataCenterId();
295-
296-
int totalPrivateIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
297-
int allocatedPrivateIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
298-
299-
CapacityVO newPrivateIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedPrivateIPs, totalPrivateIPs, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
300-
newCapacities.add(newPrivateIPCapacity);
301-
}
302272

303273
Transaction txn = Transaction.currentTxn();
304274
try {
305-
txn.start();
275+
txn.start();
276+
// Calculate new Public IP capacity
277+
List<DataCenterVO> datacenters = _dcDao.listAllIncludingRemoved();
278+
for (DataCenterVO datacenter : datacenters) {
279+
long dcId = datacenter.getId();
280+
281+
//NOTE
282+
//What happens if we have multiple vlans? Dashboard currently shows stats
283+
//with no filter based on a vlan
284+
//ideal way would be to remove out the vlan param, and filter only on dcId
285+
//implementing the same
306286

307-
_capacityDao.clearNonStorageCapacities2();
287+
s_logger.trace("Executing capacity update");
288+
createOrUpdateIpCapacity(dcId, null, CapacityVO.CAPACITY_TYPE_PUBLIC_IP);
289+
s_logger.trace("Done with capacity update");
290+
291+
}
292+
txn.commit();
308293

309-
for (CapacityVO newCapacity : newCapacities) {
294+
txn.start();
295+
// Calculate new Private IP capacity
296+
List<HostPodVO> pods = _podDao.listAllIncludingRemoved();
297+
for (HostPodVO pod : pods) {
298+
long podId = pod.getId();
299+
long dcId = pod.getDataCenterId();
300+
310301
s_logger.trace("Executing capacity update");
311-
_capacityDao.persist(newCapacity);
302+
createOrUpdateIpCapacity(dcId, podId, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
312303
s_logger.trace("Done with capacity update");
313-
}
314-
txn.commit();
304+
305+
}
306+
txn.commit();
315307
} catch (Exception ex) {
316308
txn.rollback();
317309
s_logger.error("Unable to start transaction for capacity update");
318310
}finally {
319311
txn.close();
320312
}
313+
}
314+
315+
public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType){
316+
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
317+
318+
List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
319+
capacitySC = _capacityDao.createSearchCriteria();
320+
capacitySC.addAnd("podId", SearchCriteria.Op.EQ, podId);
321+
capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, dcId);
322+
capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
323+
324+
int totalIPs;
325+
int allocatedIPs;
326+
capacities = _capacityDao.search(capacitySC, null);
327+
if (capacityType == CapacityVO.CAPACITY_TYPE_PRIVATE_IP){
328+
totalIPs = _privateIPAddressDao.countIPs(podId, dcId, false);
329+
allocatedIPs = _privateIPAddressDao.countIPs(podId, dcId, true);
330+
}else{
331+
totalIPs = _publicIPAddressDao.countIPsForDashboard(dcId, false);
332+
allocatedIPs = _publicIPAddressDao.countIPsForDashboard(dcId, true);
333+
}
334+
335+
if (capacities.size() == 0){
336+
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
337+
_capacityDao.persist(newPublicIPCapacity);
338+
}else if ( !(capacities.get(0).getUsedCapacity() == allocatedIPs
339+
&& capacities.get(0).getTotalCapacity() == totalIPs) ){
340+
CapacityVO capacity = capacities.get(0);
341+
capacity.setUsedCapacity(allocatedIPs);
342+
capacity.setTotalCapacity(totalIPs);
343+
_capacityDao.update(capacity.getId(), capacity);
344+
}
345+
321346
}
322347

323348
class CapacityChecker extends TimerTask {

0 commit comments

Comments
 (0)