Don't update resource count for system account

This commit is contained in:
alena 2011-09-13 16:27:32 -07:00
parent de9856f1c4
commit 45c595d558
2 changed files with 23 additions and 18 deletions

View File

@ -2950,28 +2950,23 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
if (ip.getState() != State.Releasing) {
txn.start();
Account owner = _accountMgr.getAccount(ip.getAccountId());
// don't decrement resource count for direct ips
if (ip.getAssociatedWithNetworkId() != null) {
_accountMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAccountId(), ResourceType.public_ip);
}
long isSourceNat = (ip.isSourceNat()) ? 1 : 0;
// Save usage event
if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
// don't decrement resource count for direct ips
if (ip.getAssociatedWithNetworkId() != null) {
_accountMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAccountId(), ResourceType.public_ip);
}
long isSourceNat = (ip.isSourceNat()) ? 1 : 0;
if (ip.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
NetworkVO network = _networksDao.findByIdIncludingRemoved(ip.getSourceNetworkId());
String guestType = "";
if( (network != null) && (network.getGuestType() != null)){
guestType = network.getGuestType().toString();
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), isSourceNat, guestType);
_usageEventDao.persist(usageEvent);
if (ip.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
NetworkVO network = _networksDao.findByIdIncludingRemoved(ip.getSourceNetworkId());
String guestType = "";
if( (network != null) && (network.getGuestType() != null)){
guestType = network.getGuestType().toString();
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), isSourceNat, guestType);
_usageEventDao.persist(usageEvent);
}
ip = _ipAddressDao.markAsUnavailable(addrId);

View File

@ -258,6 +258,11 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
@Override
public void incrementResourceCount(long accountId, ResourceType type, Long... delta) {
//don't upgrade resource count for system account
if (accountId == Account.ACCOUNT_ID_SYSTEM) {
s_logger.trace("Not incrementing resource count for system accounts, returning");
return;
}
long numToIncrement = (delta.length == 0) ? 1 : delta[0].longValue();
if (!updateResourceCount(accountId, type, true, numToIncrement)) {
@ -268,6 +273,11 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
@Override
public void decrementResourceCount(long accountId, ResourceType type, Long... delta) {
//don't upgrade resource count for system account
if (accountId == Account.ACCOUNT_ID_SYSTEM) {
s_logger.trace("Not decrementing resource count for system accounts, returning");
return;
}
long numToDecrement = (delta.length == 0) ? 1 : delta[0].longValue();
if (!updateResourceCount(accountId, type, false, numToDecrement)) {