diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java b/server/src/com/cloud/alert/AlertManagerImpl.java index 3f599a19f6a..86530699675 100644 --- a/server/src/com/cloud/alert/AlertManagerImpl.java +++ b/server/src/com/cloud/alert/AlertManagerImpl.java @@ -364,16 +364,16 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi int totalVlans = _dcDao.countZoneVlans(dcId, false); int allocatedVlans = _dcDao.countZoneVlans(dcId, true); + CapacityState vlanCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; if (capacities.size() == 0) { CapacityVO newVlanCapacity = new CapacityVO(null, dcId, null, null, allocatedVlans, totalVlans, Capacity.CAPACITY_TYPE_VLAN); - if (capacityState == AllocationState.Disabled) { - newVlanCapacity.setCapacityState(CapacityState.Disabled); - } + newVlanCapacity.setCapacityState(vlanCapacityState); _capacityDao.persist(newVlanCapacity); - } else if (!(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans)) { + } else if (!(capacities.get(0).getUsedCapacity() == allocatedVlans && capacities.get(0).getTotalCapacity() == totalVlans && capacities.get(0).getCapacityState() == vlanCapacityState)) { CapacityVO capacity = capacities.get(0); capacity.setUsedCapacity(allocatedVlans); capacity.setTotalCapacity(totalVlans); + capacity.setCapacityState(vlanCapacityState); _capacityDao.update(capacity.getId(), capacity); } @@ -402,19 +402,18 @@ public class AlertManagerImpl extends ManagerBase implements AlertManager, Confi allocatedIPs = _publicIPAddressDao.countIPsForNetwork(dcId, true, VlanType.DirectAttached); } + CapacityState ipCapacityState = (capacityState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; if (capacities.size() == 0) { CapacityVO newPublicIPCapacity = new CapacityVO(null, dcId, podId, null, allocatedIPs, totalIPs, capacityType); - if (capacityState == AllocationState.Disabled) { - newPublicIPCapacity.setCapacityState(CapacityState.Disabled); - } + newPublicIPCapacity.setCapacityState(ipCapacityState); _capacityDao.persist(newPublicIPCapacity); - } else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs)) { + } else if (!(capacities.get(0).getUsedCapacity() == allocatedIPs && capacities.get(0).getTotalCapacity() == totalIPs && capacities.get(0).getCapacityState() == ipCapacityState)) { CapacityVO capacity = capacities.get(0); capacity.setUsedCapacity(allocatedIPs); capacity.setTotalCapacity(totalIPs); + capacity.setCapacityState(ipCapacityState); _capacityDao.update(capacity.getId(), capacity); } - } class CapacityChecker extends ManagedContextTimerTask { diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index aa158b45b16..eabaf231405 100644 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -2390,11 +2390,16 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe Long zoneId = cmd.getZoneId(); Long podId = cmd.getPodId(); Long clusterId = cmd.getClusterId(); + Boolean fetchLatest = cmd.getFetchLatest(); if (clusterId != null) { throw new InvalidParameterValueException("Currently clusterId param is not suppoerted"); } zoneId = _accountMgr.checkAccessAndSpecifyAuthority(CallContext.current().getCallingAccount(), zoneId); + + if (fetchLatest != null && fetchLatest) { + _alertMgr.recalculateCapacity(); + } List summedCapacities = new ArrayList(); if (zoneId == null && podId == null) {// Group by Zone, capacity type diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index bfaa461aa84..d72cc691807 100644 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -927,39 +927,32 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C } s_logger.debug("Total over provisioned capacity of the pool " + storagePool.getName() + " id: " + storagePool.getId() + " is " + totalOverProvCapacity); + CapacityState capacityState = CapacityState.Enabled; + if (storagePool.getScope() == ScopeType.ZONE) { + DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId()); + AllocationState allocationState = dc.getAllocationState(); + capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; + } else { + if (storagePool.getClusterId() != null) { + ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId()); + if (cluster != null) { + AllocationState allocationState = _configMgr.findClusterAllocationState(cluster); + capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; + } + } + } if (capacities.size() == 0) { CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType); - - if (storagePool.getScope() == ScopeType.ZONE) { - DataCenterVO dc = ApiDBUtils.findZoneById(storagePool.getDataCenterId()); - AllocationState allocationState = dc.getAllocationState(); - CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; - capacity.setCapacityState(capacityState); - } else { - if (storagePool.getClusterId() != null) { - ClusterVO cluster = ApiDBUtils.findClusterById(storagePool.getClusterId()); - if (cluster != null) { - AllocationState allocationState = _configMgr.findClusterAllocationState(cluster); - CapacityState capacityState = (allocationState == AllocationState.Disabled) ? CapacityState.Disabled : CapacityState.Enabled; - capacity.setCapacityState(capacityState); - } - } - } + capacity.setCapacityState(capacityState); _capacityDao.persist(capacity); } else { CapacityVO capacity = capacities.get(0); - boolean update = false; - if (capacity.getTotalCapacity() != totalOverProvCapacity) { + if (capacity.getTotalCapacity() != totalOverProvCapacity || allocated != 0L || capacity.getCapacityState() != capacityState) { capacity.setTotalCapacity(totalOverProvCapacity); - update = true; - } - if (allocated != 0) { capacity.setUsedCapacity(allocated); - update = true; - } - if (update) { + capacity.setCapacityState(capacityState); _capacityDao.update(capacity.getId(), capacity); } } diff --git a/ui/scripts/dashboard.js b/ui/scripts/dashboard.js index 15e5e528e9b..dff6a91a9e8 100644 --- a/ui/scripts/dashboard.js +++ b/ui/scripts/dashboard.js @@ -183,20 +183,12 @@ }); }, capacity: function(data) { - var latestData = null; if (window.fetchLatestflag == 1) { - latestData = { - - fetchLatest: true - } + data.fetchLastest = true; } else { - latestData = { - fetchLatest: false - } + data.fetchLastest = false; } - window.fetchLatestflag = 0; - dataFns.alerts(data); }, @@ -252,7 +244,7 @@ $.ajax({ url: createURL('listCapacity'), data: { - fetchLatest: false, + fetchLatest: data.fetchLatest, sortBy: 'usage', page: 0, pageSize: (pageSize > 8? 8: pageSize)