Repository: cloudstack
Updated Branches:
  refs/heads/4.4 0208de721 -> 14a00679b


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 <[email protected]>
(cherry picked from commit 985a61652eb5dc97503c002e9fc3c3a7ca39b70c)
Signed-off-by: Rohit Yadav <[email protected]>

Conflicts:
        server/src/com/cloud/storage/StorageManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/14a00679
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/14a00679
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/14a00679

Branch: refs/heads/4.4
Commit: 14a00679bda40c77c3c99be770da61d854be6e53
Parents: 0208de7
Author: Rohit Yadav <[email protected]>
Authored: Wed Feb 25 15:52:57 2015 +0530
Committer: Rohit Yadav <[email protected]>
Committed: Wed Feb 25 16:48:54 2015 +0530

----------------------------------------------------------------------
 .../src/com/cloud/alert/AlertManagerImpl.java   | 17 ++++----
 .../com/cloud/server/ManagementServerImpl.java  |  5 +++
 .../com/cloud/storage/StorageManagerImpl.java   | 41 ++++++++------------
 ui/scripts/dashboard.js                         | 14 ++-----
 4 files changed, 33 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/14a00679/server/src/com/cloud/alert/AlertManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/alert/AlertManagerImpl.java 
b/server/src/com/cloud/alert/AlertManagerImpl.java
index fc5b5fd..e8257d1 100755
--- a/server/src/com/cloud/alert/AlertManagerImpl.java
+++ b/server/src/com/cloud/alert/AlertManagerImpl.java
@@ -363,16 +363,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);
         }
 
@@ -401,19 +401,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 {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/14a00679/server/src/com/cloud/server/ManagementServerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/server/ManagementServerImpl.java 
b/server/src/com/cloud/server/ManagementServerImpl.java
index ff9b339..07ea4b4 100755
--- a/server/src/com/cloud/server/ManagementServerImpl.java
+++ b/server/src/com/cloud/server/ManagementServerImpl.java
@@ -2369,11 +2369,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<SummedCapacity> summedCapacities = new 
ArrayList<SummedCapacity>();
 
         if (zoneId == null && podId == null) {// Group by Zone, capacity type

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/14a00679/server/src/com/cloud/storage/StorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java 
b/server/src/com/cloud/storage/StorageManagerImpl.java
index fafd002..898f069 100755
--- a/server/src/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/com/cloud/storage/StorageManagerImpl.java
@@ -894,39 +894,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);
             }
         }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/14a00679/ui/scripts/dashboard.js
----------------------------------------------------------------------
diff --git a/ui/scripts/dashboard.js b/ui/scripts/dashboard.js
index 249e769..438e6ee 100644
--- a/ui/scripts/dashboard.js
+++ b/ui/scripts/dashboard.js
@@ -141,20 +141,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);
                     },
 
@@ -210,7 +202,7 @@
                         $.ajax({
                             url: createURL('listCapacity'),
                             data: {
-                                fetchLatest: false,
+                                fetchLatest: data.fetchLatest,
                                 sortBy: 'usage',
                                 page: 0,
                                 pagesize: 8

Reply via email to