cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From edi...@apache.org
Subject [13/18] git commit: updated refs/heads/object_store to c476d78
Date Thu, 16 May 2013 02:42:26 GMT
CLOUDSTACK-2116
Public IP addresses resource count of an account - number of ip addresses dedicated to an
account
plus the number of ip addresses belonging to the system that have been allocated to the account


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

Branch: refs/heads/object_store
Commit: fd354dbd7c9a6a25a0a3560b6db530fc7f5ece72
Parents: cf1fada
Author: Likitha Shetty <likitha.shetty@citrix.com>
Authored: Tue May 14 14:24:47 2013 +0530
Committer: Edison Su <sudison@gmail.com>
Committed: Wed May 15 19:41:49 2013 -0700

----------------------------------------------------------------------
 engine/schema/src/com/cloud/dc/dao/VlanDao.java    |    2 +
 .../schema/src/com/cloud/dc/dao/VlanDaoImpl.java   |   15 +++++++++
 .../configuration/ConfigurationManagerImpl.java    |   10 ++++++-
 .../src/com/cloud/network/NetworkManagerImpl.java  |   16 +++++-----
 .../resourcelimit/ResourceLimitManagerImpl.java    |   23 ++++++++++++++-
 5 files changed, 56 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd354dbd/engine/schema/src/com/cloud/dc/dao/VlanDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/VlanDao.java b/engine/schema/src/com/cloud/dc/dao/VlanDao.java
index 605fb20..39fa818 100755
--- a/engine/schema/src/com/cloud/dc/dao/VlanDao.java
+++ b/engine/schema/src/com/cloud/dc/dao/VlanDao.java
@@ -54,4 +54,6 @@ public interface VlanDao extends GenericDao<VlanVO, Long> {
         List<VlanVO> listZoneWideNonDedicatedVlans(long zoneId);
 
     List<VlanVO> listVlansByNetworkIdAndGateway(long networkid, String gateway);
+
+    List<VlanVO> listDedicatedVlans(long accountId);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd354dbd/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java b/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
index e8c68b1..eb3bde9 100755
--- a/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
+++ b/engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java
@@ -58,6 +58,7 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements
VlanDao
     protected SearchBuilder<VlanVO> PhysicalNetworkVlanSearch;
     protected SearchBuilder<VlanVO> ZoneWideNonDedicatedVlanSearch;
     protected SearchBuilder<VlanVO> VlanGatewaysearch;
+    protected SearchBuilder<VlanVO> DedicatedVlanSearch;
 
     protected SearchBuilder<AccountVlanMapVO> AccountVlanMapSearch;
 
@@ -213,6 +214,13 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements
VlanDao
         ZoneWideNonDedicatedVlanSearch.done();
         AccountVlanMapSearch.done();
 
+        DedicatedVlanSearch = createSearchBuilder();
+        AccountVlanMapSearch = _accountVlanMapDao.createSearchBuilder();
+        AccountVlanMapSearch.and("accountId", AccountVlanMapSearch.entity().getAccountId(),
SearchCriteria.Op.EQ);
+        DedicatedVlanSearch.join("AccountVlanMapSearch", AccountVlanMapSearch, DedicatedVlanSearch.entity().getId(),
AccountVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.LEFTOUTER);
+        DedicatedVlanSearch.done();
+        AccountVlanMapSearch.done();
+
         return result;
     }
 
@@ -343,4 +351,11 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements
VlanDao
         return listBy(sc);
     }
 
+    @Override
+    public List<VlanVO> listDedicatedVlans(long accountId) {
+        SearchCriteria<VlanVO> sc = DedicatedVlanSearch.create();
+        sc.setJoinParameters("AccountVlanMapSearch", "accountId", accountId);
+        return listBy(sc);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd354dbd/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 045c333..2837535 100755
--- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
+++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java
@@ -2852,6 +2852,8 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
                         ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(),
vlan.getVlanType().toString(),
                         ip.getSystem(), ip.getClass().getName(), ip.getUuid());
             }
+            // increment resource count for dedicated public ip's
+            _resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip,
new Long(ips.size()));
         } else if (podId != null) {
             // This VLAN is pod-wide, so create a PodVlanMapVO entry
             PodVlanMapVO podVlanMapVO = new PodVlanMapVO(podId, vlan.getId());
@@ -3122,6 +3124,10 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
                     ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(),
vlan.getVlanType().toString(),
                     ip.getSystem(), ip.getClass().getName(), ip.getUuid());
         }
+
+        // increment resource count for dedicated public ip's
+        _resourceLimitMgr.incrementResourceCount(vlanOwner.getId(), ResourceType.public_ip,
new Long(ips.size()));
+
         return vlan;
     }
 
@@ -3185,10 +3191,12 @@ public class ConfigurationManagerImpl extends ManagerBase implements
Configurati
         if (_accountVlanMapDao.remove(acctVln.get(0).getId())) {
             // generate usage events to remove dedication for every ip in the range
             for (IPAddressVO ip : ips) {
-                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getId(),
+                UsageEventUtils.publishUsageEvent(EventTypes.EVENT_NET_IP_RELEASE, acctVln.get(0).getAccountId(),
                         ip.getDataCenterId(), ip.getId(), ip.getAddress().toString(), ip.isSourceNat(),
vlan.getVlanType().toString(),
                         ip.getSystem(), ip.getClass().getName(), ip.getUuid());
             }
+            // decrement resource count for dedicated public ip's
+            _resourceLimitMgr.decrementResourceCount(acctVln.get(0).getAccountId(), ResourceType.public_ip,
new Long(ips.size()));
             return true;
         } else {
             return false;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd354dbd/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index d37f7c9..8834724 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -393,8 +393,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
                         addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(),
addr.isSourceNat(), guestType,
                         addr.getSystem(), addr.getClass().getName(), addr.getUuid());
             }
-            // don't increment resource count for direct ip addresses
-            if (addr.getAssociatedWithNetworkId() != null) {
+            // don't increment resource count for direct and dedicated ip addresses
+            if (addr.getAssociatedWithNetworkId() != null && !isIpDedicated(addr))
{
                 _resourceLimitMgr.incrementResourceCount(owner.getId(), ResourceType.public_ip);
             }
         }
@@ -639,10 +639,6 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
                 s_logger.debug("Associate IP address lock acquired");
             }
 
-            // Check that the maximum number of public IPs for the given
-            // accountId will not be exceeded
-            _resourceLimitMgr.checkResourceLimit(accountToLock, ResourceType.public_ip);
-
             txn.start();
 
             // If account has dedicated Public IP ranges, allocate IP from the dedicated
range
@@ -667,6 +663,10 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
             }
 
             if (!allocateFromDedicatedRange) {
+                // Check that the maximum number of public IPs for the given
+                // accountId will not be exceeded
+                _resourceLimitMgr.checkResourceLimit(accountToLock, ResourceType.public_ip);
+
                 List<VlanVO> nonDedicatedVlans = _vlanDao.listZoneWideNonDedicatedVlans(zone.getId());
                 for (VlanVO nonDedicatedVlan : nonDedicatedVlans) {
                     nonDedicatedVlanDbIds.add(nonDedicatedVlan.getId());
@@ -2963,8 +2963,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
         if (ip.getState() != State.Releasing) {
             txn.start();
 
-            // don't decrement resource count for direct ips
-            if (ip.getAssociatedWithNetworkId() != null) {
+            // don't decrement resource count for direct and dedicated ips
+            if (ip.getAssociatedWithNetworkId() != null && !isIpDedicated(ip)) {
                 _resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(),
ResourceType.public_ip);
             }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/fd354dbd/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
index d0d7f31..b5c060d 100755
--- a/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
+++ b/server/src/com/cloud/resourcelimit/ResourceLimitManagerImpl.java
@@ -48,6 +48,8 @@ import com.cloud.configuration.dao.ConfigurationDao;
 import com.cloud.configuration.dao.ResourceCountDao;
 import com.cloud.configuration.dao.ResourceLimitDao;
 import com.cloud.dao.EntityManager;
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.dao.VlanDao;
 import com.cloud.domain.Domain;
 import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
@@ -55,6 +57,7 @@ import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.exception.PermissionDeniedException;
 import com.cloud.exception.ResourceAllocationException;
 import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.projects.Project;
@@ -143,6 +146,8 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
     private ServiceOfferingDao _serviceOfferingDao;
     @Inject
     private TemplateDataStoreDao _vmTemplateStoreDao;
+    @Inject
+    private VlanDao _vlanDao;
 
     protected GenericSearchBuilder<TemplateDataStoreVO, SumCount> templateSizeSearch;
 
@@ -817,7 +822,7 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
         } else if (type == Resource.ResourceType.snapshot) {
             newCount = _snapshotDao.countSnapshotsForAccount(accountId);
         } else if (type == Resource.ResourceType.public_ip) {
-            newCount = _ipAddressDao.countAllocatedIPsForAccount(accountId);
+            newCount = calculatePublicIpForAccount(accountId);
         } else if (type == Resource.ResourceType.template) {
             newCount = _vmTemplateDao.countTemplatesForAccount(accountId);
         } else if (type == Resource.ResourceType.project) {
@@ -909,6 +914,22 @@ public class ResourceLimitManagerImpl extends ManagerBase implements
ResourceLim
         return totalVolumesSize + totalSnapshotsSize + totalTemplatesSize;
     }
 
+    private long calculatePublicIpForAccount(long accountId) {
+        Long dedicatedCount = 0L;
+        Long allocatedCount = 0L;
+
+        List<VlanVO> dedicatedVlans = _vlanDao.listDedicatedVlans(accountId);
+        for (VlanVO dedicatedVlan : dedicatedVlans) {
+            List<IPAddressVO> ips = _ipAddressDao.listByVlanId(dedicatedVlan.getId());
+            dedicatedCount += new Long(ips.size());
+        }
+        allocatedCount = _ipAddressDao.countAllocatedIPsForAccount(accountId);
+        if (dedicatedCount > allocatedCount)
+            return dedicatedCount;
+        else
+            return allocatedCount;
+    }
+
     @Override
     public long getResourceCount(Account account, ResourceType type) {
         return _resourceCountDao.getResourceCount(account.getId(), ResourceOwnerType.Account,
type);


Mime
View raw message