mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
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
This commit is contained in:
parent
6d6887533f
commit
f893aa8a78
@ -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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2853,6 +2853,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());
|
||||
@ -3124,6 +3126,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;
|
||||
}
|
||||
|
||||
@ -3187,10 +3193,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;
|
||||
|
||||
@ -394,8 +394,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);
|
||||
}
|
||||
}
|
||||
@ -640,10 +640,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
|
||||
@ -668,6 +664,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());
|
||||
@ -2964,8 +2964,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);
|
||||
}
|
||||
|
||||
|
||||
@ -46,6 +46,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;
|
||||
@ -53,6 +55,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;
|
||||
@ -141,6 +144,8 @@ public class ResourceLimitManagerImpl extends ManagerBase implements ResourceLim
|
||||
private ServiceOfferingDao _serviceOfferingDao;
|
||||
@Inject
|
||||
private VMTemplateHostDao _vmTemplateHostDao;
|
||||
@Inject
|
||||
private VlanDao _vlanDao;
|
||||
|
||||
protected GenericSearchBuilder<VMTemplateHostVO, SumCount> templateSizeSearch;
|
||||
|
||||
@ -814,7 +819,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) {
|
||||
@ -906,6 +911,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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user