Skip to content

Commit 14a0067

Browse files
committed
CLOUDSTACK-8285: check and update IP capacity states based on allocation state
- Backend should update if state was diabled and now has changed - UI's fetch latest does not actually fetch latest Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> (cherry picked from commit 985a616) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> Conflicts: server/src/com/cloud/storage/StorageManagerImpl.java
1 parent 0208de7 commit 14a0067

4 files changed

Lines changed: 33 additions & 44 deletions

File tree

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,16 @@ private void createOrUpdateVlanCapacity(long dcId, AllocationState capacityState
363363
int totalVlans = _dcDao.countZoneVlans(dcId, false);
364364
int allocatedVlans = _dcDao.countZoneVlans(dcId, true);
365365

366+
CapacityState vlanCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
366367
if (capacities.size() == 0) {
367368
CapacityVO newVlanCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN);
368-
if (capacityState == AllocationState.Disabled) {
369-
newVlanCapacity.setCapacityState(CapacityState.Disabled);
370-
}
369+
newVlanCapacity.setCapacityState(vlanCapacityState);
371370
_capacityDao.persist(newVlanCapacity);
372-
} else if (!(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans)) {
371+
} else if (!(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans && capacities.get(0).getCapacityState() == vlanCapacityState)) {
373372
CapacityVO capacity = capacities.get(0);
374373
capacity.setUsedCapacity(allocatedVlans);
375374
capacity.setTotalCapacity(totalVlans);
375+
capacity.setCapacityState(vlanCapacityState);
376376
_capacityDao.update(capacity.getId(), capacity);
377377
}
378378

@@ -401,19 +401,18 @@ public void createOrUpdateIpCapacity(Long dcId, Long podId, short capacityType,
401401
allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.DirectAttached);
402402
}
403403

404+
CapacityState ipCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
404405
if (capacities.size() == 0) {
405406
CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType);
406-
if (capacityState == AllocationState.Disabled) {
407-
newPublicIPCapacity.setCapacityState(CapacityState.Disabled);
408-
}
407+
newPublicIPCapacity.setCapacityState(ipCapacityState);
409408
_capacityDao.persist(newPublicIPCapacity);
410-
} else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs)) {
409+
} else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs && capacities.get(0).getCapacityState() == ipCapacityState)) {
411410
CapacityVO capacity = capacities.get(0);
412411
capacity.setUsedCapacity(allocatedIPs);
413412
capacity.setTotalCapacity(totalIPs);
413+
capacity.setCapacityState(ipCapacityState);
414414
_capacityDao.update(capacity.getId(), capacity);
415415
}
416-
417416
}
418417

419418
class CapacityChecker extends ManagedContextTimerTask {

‎server/src/com/cloud/server/ManagementServerImpl.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,11 +2369,16 @@ public List<CapacityVO> listTopConsumedResources(ListCapacityCmd cmd) {
23692369
Long zoneId = cmd.getZoneId();
23702370
Long podId = cmd.getPodId();
23712371
Long clusterId = cmd.getClusterId();
2372+
Boolean fetchLatest = cmd.getFetchLatest();
23722373

23732374
if (clusterId != null) {
23742375
throw new InvalidParameterValueException("Currently clusterId param is not suppoerted");
23752376
}
23762377
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId);
2378+
2379+
if (fetchLatest != null && fetchLatest) {
2380+
_alertMgr.recalculateCapacity();
2381+
}
23772382
List<SummedCapacity> summedCapacities = new ArrayList<SummedCapacity>();
23782383

23792384
if (zoneId == null && podId == null) {// Group by Zone, capacity type

‎server/src/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -894,39 +894,32 @@ public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, l
894894
}
895895

896896
s_logger.debug("Total over provisioned capacity of the pool " + storagePool.getName() + " id: " + storagePool.getId() + " is " + totalOverProvCapacity);
897+
CapacityState capacityState = CapacityState.Enabled;
898+
if (storagePool.getScope() == ScopeType.ZONE) {
899+
DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
900+
AllocationState allocationState = dc.getAllocationState();
901+
capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
902+
} else {
903+
if (storagePool.getClusterId() != null) {
904+
ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
905+
if (cluster != null) {
906+
AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
907+
capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
908+
}
909+
}
910+
}
897911
if (capacities.size() == 0) {
898912
CapacityVO capacity =
899913
new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity,
900914
capacityType);
901-
902-
if (storagePool.getScope() == ScopeType.ZONE) {
903-
DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId());
904-
AllocationState allocationState = dc.getAllocationState();
905-
CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
906-
capacity.setCapacityState(capacityState);
907-
} else {
908-
if (storagePool.getClusterId() != null) {
909-
ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId());
910-
if (cluster != null) {
911-
AllocationState allocationState = _configMgr.findClusterAllocationState(cluster);
912-
CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled;
913-
capacity.setCapacityState(capacityState);
914-
}
915-
}
916-
}
915+
capacity.setCapacityState(capacityState);
917916
_capacityDao.persist(capacity);
918917
} else {
919918
CapacityVO capacity = capacities.get(0);
920-
boolean update = false;
921-
if (capacity.getTotalCapacity() != totalOverProvCapacity) {
919+
if (capacity.getTotalCapacity() != totalOverProvCapacity || allocated != 0L || capacity.getCapacityState() != capacityState) {
922920
capacity.setTotalCapacity(totalOverProvCapacity);
923-
update = true;
924-
}
925-
if (allocated != 0) {
926921
capacity.setUsedCapacity(allocated);
927-
update = true;
928-
}
929-
if (update) {
922+
capacity.setCapacityState(capacityState);
930923
_capacityDao.update(capacity.getId(), capacity);
931924
}
932925
}

‎ui/scripts/dashboard.js‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,20 +141,12 @@
141141
});
142142
},
143143
capacity: function(data) {
144-
var latestData = null;
145144
if (window.fetchLatestflag == 1) {
146-
latestData = {
147-
148-
fetchLatest: true
149-
}
145+
data.fetchLastest = true;
150146
} else {
151-
latestData = {
152-
fetchLatest: false
153-
}
147+
data.fetchLastest = false;
154148
}
155-
156149
window.fetchLatestflag = 0;
157-
158150
dataFns.alerts(data);
159151
},
160152

@@ -210,7 +202,7 @@
210202
$.ajax({
211203
url: createURL('listCapacity'),
212204
data: {
213-
fetchLatest: false,
205+
fetchLatest: data.fetchLatest,
214206
sortBy: 'usage',
215207
page: 0,
216208
pagesize: 8

0 commit comments

Comments
 (0)