Repository: cloudstack
Updated Branches:
  refs/heads/master b074fc70d -> e8ade2dd9


Bug-Id: CS-27335: public_ip type resource count for an account is not 
decremented upon IP range deletion

Reviewed-By: Kishan/Bharat

Signed-off-by: Maneesha.P <[email protected]>


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

Branch: refs/heads/master
Commit: 865623fd1edd0d2a5adb9c6be2cd9c9eab9b32db
Parents: 3df847d
Author: Damodar <[email protected]>
Authored: Tue Nov 18 17:12:28 2014 +0530
Committer: Maneesha.P <[email protected]>
Committed: Thu Aug 6 14:39:27 2015 +0530

----------------------------------------------------------------------
 .../src/com/cloud/configuration/ConfigurationManagerImpl.java | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/865623fd/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java 
b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
index 50e120a..fc7bff9 100644
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -3312,6 +3312,7 @@ public class ConfigurationManagerImpl extends ManagerBase 
implements Configurati
         // Check if the VLAN has any allocated public IPs
         final List<IPAddressVO> ips = 
_publicIpAddressDao.listByVlanId(vlanDbId);
         if (isAccountSpecific) {
+            int resourceCountToBeDecrement = 0;
             try {
                 vlanRange = _vlanDao.acquireInLockTable(vlanDbId, 30);
                 if (vlanRange == null) {
@@ -3338,19 +3339,23 @@ public class ConfigurationManagerImpl extends 
ManagerBase implements Configurati
                         throw new InvalidParameterValueException("Can't delete 
account specific vlan " + vlanDbId + " as ip " + ip
                                 + " belonging to the range has firewall rules 
applied. Cleanup the rules first");
                     }
-                    if(ip.getAllocatedTime() != null) {// This means IP is 
allocated
+                    if (ip.getAllocatedTime() != null) {// This means IP is 
allocated
                         // release public ip address here
                         success = 
_ipAddrMgr.disassociatePublicIpAddress(ip.getId(), userId, caller);
                     }
                     if (!success) {
                         s_logger.warn("Some ip addresses failed to be released 
as a part of vlan " + vlanDbId + " removal");
                     } else {
+                        resourceCountToBeDecrement++;
                         
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, 
acctVln.get(0).getAccountId(), ip.getDataCenterId(), ip.getId(),
                                 ip.getAddress().toString(), ip.isSourceNat(), 
vlanRange.getVlanType().toString(), ip.getSystem(), ip.getClass().getName(), 
ip.getUuid());
                     }
                 }
             } finally {
                 _vlanDao.releaseFromLockTable(vlanDbId);
+                if (resourceCountToBeDecrement > 0) {  //Making sure to 
decrement the count of only success operations above. For any reaason if 
disassociation fails then this number will vary from original range length.
+                    
_resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), 
ResourceType.public_ip, new Long(resourceCountToBeDecrement));
+                }
             }
         } else {   // !isAccountSpecific
             final NicIpAliasVO ipAlias = 
_nicIpAliasDao.findByGatewayAndNetworkIdAndState(vlanRange.getVlanGateway(), 
vlanRange.getNetworkId(), NicIpAlias.state.active);

Reply via email to