bug 7881: fixed publicIpAllocation to an account.

status 7881: resolved fixed

Also fixed the issue with account delete when nonSourceNat ip addresses were not being released
This commit is contained in:
alena 2011-01-21 21:45:43 -08:00
parent 1ff8d98d4c
commit 6304a92c23
10 changed files with 560 additions and 632 deletions

View File

@ -29,6 +29,7 @@ import com.cloud.api.response.VlanIpRangeResponse;
import com.cloud.dc.Vlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
@Implementation(description="Creates a VLAN IP range.", responseObject=VlanIpRangeResponse.class)
public class CreateVlanIpRangeCmd extends BaseCmd {
@ -132,7 +133,7 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
}
@Override
public void execute(){
public void execute() throws ResourceUnavailableException{
try {
Vlan result = _configService.createVlanAndPublicIpRange(this);
if (result != null) {
@ -148,6 +149,6 @@ public class CreateVlanIpRangeCmd extends BaseCmd {
} catch (InsufficientCapacityException ex) {
s_logger.info(ex);
throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
}
}
}
}

View File

@ -28,6 +28,8 @@ import com.cloud.dc.Vlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering;
import com.cloud.offering.ServiceOffering;
@ -174,7 +176,7 @@ public interface ConfigurationService {
* @throws
* @return The new Vlan object
*/
Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException, ResourceUnavailableException;
boolean deleteVlanIpRange(DeleteVlanIpRangeCmd cmd);
@ -191,5 +193,7 @@ public interface ConfigurationService {
Integer getNetworkRate(long networkOfferingId);
Account getVlanAccount(long vlanId);
List<? extends NetworkOffering> listNetworkOfferings(TrafficType trafficType, boolean systemOnly);
}

View File

@ -25,10 +25,10 @@ import com.cloud.dc.DataCenterVO;
import com.cloud.dc.HostPodVO;
import com.cloud.dc.Vlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Networks.TrafficType;
import com.cloud.offering.DiskOffering;
import com.cloud.offering.NetworkOffering.Availability;
@ -111,17 +111,6 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
* @throws
*/
DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2, String internalDns1, String internalDns2, String vnetRange, String guestCidr, String domain, Long domainId, NetworkType zoneType);
/**
* Associates an ip address list to an account. The list of ip addresses are all addresses associated with the given vlan id.
* @param userId
* @param accountId
* @param zoneId
* @param vlanId
* @throws InsufficientAddressCapacityException
* @throws
*/
public void associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId) throws InsufficientAddressCapacityException, ConcurrentOperationException;
/**
* Deletes a VLAN from the database, along with all of its IP addresses. Will not delete VLANs that have allocated IP addresses.
@ -180,9 +169,11 @@ public interface ConfigurationManager extends ConfigurationService, Manager {
*/
NetworkOfferingVO createNetworkOffering(long userId, String name, String displayText, TrafficType trafficType, String tags, Integer maxConnections, boolean specifyVlan, Availability availability);
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException, ResourceUnavailableException;
void createDefaultNetworks(long zoneId) throws ConcurrentOperationException;
DataCenterVO getZone(long id);
boolean deleteAccountSpecificVirtualRanges(long accountId);
}

View File

@ -21,13 +21,11 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.ejb.Local;
import javax.naming.ConfigurationException;
@ -82,12 +80,11 @@ import com.cloud.domain.DomainVO;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.dao.EventDao;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.network.IPAddressVO;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestIpType;
import com.cloud.network.NetworkManager;
@ -123,14 +120,12 @@ import com.cloud.utils.db.Filter;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.ConsoleProxyVO;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.SecondaryStorageVmVO;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.dao.ConsoleProxyDao;
import com.cloud.vm.dao.DomainRouterDao;
import com.cloud.vm.dao.SecondaryStorageVmDao;
@ -1583,7 +1578,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
}
@Override
public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException {
public Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException, ResourceUnavailableException {
Long zoneId = cmd.getZoneId();
Long podId = cmd.getPodId();
String startIP = cmd.getStartIp();
@ -1687,7 +1682,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
@Override
public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException{
public Vlan createVlanAndPublicIpRange(Long userId, Long zoneId, Long podId, String startIP, String endIP, String vlanGateway, String vlanNetmask, boolean forVirtualNetwork, String vlanId, Account account, Long networkId) throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException, ResourceUnavailableException{
// Check that the pod ID is valid
if (podId != null && ((_podDao.findById(podId)) == null)) {
@ -1773,7 +1768,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Direct Attached IP ranges for a pod must be untagged.");
}
// Make sure there aren't any account VLANs in this zone
List<AccountVlanMapVO> accountVlanMaps = _accountVlanMapDao.listAllIncludingRemoved();
for (AccountVlanMapVO accountVlanMap : accountVlanMaps) {
@ -1880,14 +1874,7 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
VlanVO vlan = new VlanVO(vlanType, vlanId, vlanGateway, vlanNetmask, zone.getId(), ipRange, networkId);
vlan = _vlanDao.persist(vlan);
// Persist the IP range
if (account != null && vlanType.equals(VlanType.VirtualNetwork)){
if(!savePublicIPRangeForAccount(startIP, endIP, zoneId, vlan.getId(), account.getId(), account.getDomainId())) {
deletePublicIPRange(vlan.getId());
_vlanDao.expunge(vlan.getId());
throw new CloudRuntimeException("Failed to save IP range. Please contact Cloud Support."); //It can be Direct IP or Public IP.
}
}else if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId())) {
if (!savePublicIPRange(startIP, endIP, zoneId, vlan.getId())) {
deletePublicIPRange(vlan.getId());
_vlanDao.expunge(vlan.getId());
throw new CloudRuntimeException("Failed to save IP range. Please contact Cloud Support."); //It can be Direct IP or Public IP.
@ -1910,81 +1897,13 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
eventMsg += ".";
if (associateIpRangeToAccount) {
// if this is an account VLAN, now associate the IP Addresses to the account
associateIpAddressListToAccount(userId, account.getId(), zoneId, vlan.getId());
long ipCount = _publicIpAddressDao.countIPs(zoneId, vlan.getId(), false);
_accountMgr.incrementResourceCount(account.getId(), ResourceType.public_ip, ipCount);
s_logger.trace("Updated " + ResourceType.public_ip + " resource count on " + ipCount + " for account " + account);
_networkMgr.associateIpAddressListToAccount(userId, account.getId(), zoneId, vlan.getId());
}
return vlan;
}
@Override @DB
public void associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId) throws InsufficientAddressCapacityException,
ConcurrentOperationException {
Transaction txn = Transaction.currentTxn();
AccountVO account = null;
try {
//Acquire Lock
account = _accountDao.acquireInLockTable(accountId);
if (account == null) {
s_logger.warn("Unable to lock account: " + accountId);
throw new ConcurrentOperationException("Unable to acquire account lock");
}
s_logger.debug("Associate IP address lock acquired");
//Get Router
DomainRouterVO router = _domrDao.findBy(accountId, zoneId);
if (router == null) {
s_logger.debug("No router found for account: " + account.getAccountName() + ".");
return;
}
if (router.getState() == State.Running) {
//Get Vlans associated with the account
List<VlanVO> vlansForAccount = new ArrayList<VlanVO>();
if (vlanId == null){
vlansForAccount.addAll(_vlanDao.listVlansForAccountByType(zoneId, account.getId(), VlanType.VirtualNetwork));
s_logger.debug("vlansForAccount "+ vlansForAccount);
}else{
vlansForAccount.add(_vlanDao.findById(vlanId));
}
// Creating a list of all the ips that can be assigned to this account
txn.start();
List<String> ipAddrsList = new ArrayList<String>();
for (VlanVO vlan : vlansForAccount){
ipAddrsList.addAll(_publicIpAddressDao.assignAcccountSpecificIps(accountId, account.getDomainId(), vlan.getId(), false));
long size = ipAddrsList.size();
_accountMgr.incrementResourceCount(accountId, ResourceType.public_ip, size);
s_logger.debug("Assigning new ip addresses " +ipAddrsList);
}
if(ipAddrsList.isEmpty()) {
return;
}
// Associate the IP's to DomR
boolean success = _networkMgr.associateIP(router,ipAddrsList, true, 0);
String errorMsg = "Unable to assign public IP address pool";
if (!success) {
s_logger.debug(errorMsg);
throw new CloudRuntimeException(errorMsg);
}
txn.commit();
}
} catch (CloudRuntimeException iee) {
s_logger.error("Associate IP threw an CloudRuntimeException.", iee);
throw iee;
} catch (Throwable t) {
s_logger.error("Associate IP address threw an exception.", t);
throw new CloudRuntimeException("Associate IP address exception");
} finally {
if (account != null) {
_accountDao.releaseFromLockTable(accountId);
s_logger.debug("Associate IP address lock released");
}
}
}
@Override
public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId) throws InvalidParameterValueException {
@ -1993,16 +1912,11 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
throw new InvalidParameterValueException("Please specify a valid IP range id.");
}
// Check if the VLAN has any allocated public IPs
if (_publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true) > 0) {
throw new InvalidParameterValueException("The IP range can't be deleted because it has allocated public IP addresses.");
}
// Check if the VLAN is being used by any domain router
if (_domrDao.listByVlanDbId(vlanDbId).size() > 0) {
throw new InvalidParameterValueException("The IP range can't be deleted because it is being used by a domain router.");
}
// Check if the VLAN has any allocated public IPs
if (_publicIpAddressDao.countIPs(vlan.getDataCenterId(), vlanDbId, true) > 0) {
throw new InvalidParameterValueException("The IP range can't be deleted because it has allocated public IP addresses.");
}
// Delete all public IPs in the VLAN
if (!deletePublicIPRange(vlanDbId)) {
return false;
@ -2143,33 +2057,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return true;
}
@DB
protected boolean savePublicIPRangeForAccount(String startIP, String endIP, long zoneId, long vlanDbId, long accountId, long domainId) {
IPRangeConfig config = new IPRangeConfig();
Transaction txn = Transaction.currentTxn();
txn.start();
long startIPLong = NetUtils.ip2Long(startIP);
long endIPLong = NetUtils.ip2Long(endIP);
Vector<String> ips = config.savePublicIPRange(txn, startIPLong, endIPLong, zoneId, vlanDbId);
List<Long> skip = new ArrayList<Long>(ips.size());
for (String ip : ips) {
skip.add(NetUtils.ip2Long(ip));
}
for (long ip = startIPLong; ip <= endIPLong; ip++) {
if (skip.contains(ip)) {
continue;
}
IPAddressVO addr = _publicIpAddressDao.findById(new Ip(ip));
addr.setAllocatedInDomainId(domainId);
addr.setAllocatedTime(new Date());
addr.setAllocatedToAccountId(accountId);
_publicIpAddressDao.update(addr.getAddress(), addr);
}
txn.commit();
return true;
}
@DB
protected List<String> savePrivateIPRange(String startIP, String endIP, long podId, long zoneId) {
Transaction txn = Transaction.currentTxn();
@ -2474,10 +2361,6 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
if (vlan == null) {
throw new InvalidParameterValueException("Please specify a valid IP range id.");
}
// if (vlan.getNetworkId() != null) {
// throw new InvalidParameterValueException("Fail to delete a vlan range as there are networks associated with it");
// }
return deleteVlanAndPublicIpRange(userId, vlanDbId);
@ -2789,4 +2672,39 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura
return _accountMgr.getAccount(accountId);
}
@Override
public List<? extends NetworkOffering> listNetworkOfferings(TrafficType trafficType, boolean systemOnly) {
Filter searchFilter = new Filter(NetworkOfferingVO.class, "created", false, null, null);
SearchCriteria<NetworkOfferingVO> sc = _networkOfferingDao.createSearchCriteria();
if (trafficType != null) {
sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType);
}
sc.addAnd("systemOnly", SearchCriteria.Op.EQ, systemOnly);
return _networkOfferingDao.search(sc, searchFilter);
}
@Override @DB
public boolean deleteAccountSpecificVirtualRanges(long accountId) {
List<AccountVlanMapVO> maps = _accountVlanMapDao.listAccountVlanMapsByAccount(accountId);
boolean result = true;
if (maps != null && !maps.isEmpty()) {
Transaction txn = Transaction.currentTxn();
txn.start();
for (AccountVlanMapVO map : maps) {
if (!deleteVlanAndPublicIpRange(_accountMgr.getSystemUser().getId(), map.getVlanDbId())) {
result = false;
}
}
if (result) {
txn.commit();
} else {
s_logger.error("Failed to delete account specific virtual ip ranges for account id=" + accountId);
}
} else {
s_logger.trace("Account id=" + accountId + " has no account specific virtual ip ranges, nothing to delete");
}
return result;
}
}

View File

@ -20,6 +20,7 @@ package com.cloud.network;
import java.util.List;
import java.util.Map;
import com.cloud.api.commands.CreateNetworkCmd;
import com.cloud.dc.Vlan;
import com.cloud.dc.Vlan.VlanType;
import com.cloud.deploy.DeployDestination;
@ -27,6 +28,8 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Service;
@ -40,7 +43,6 @@ import com.cloud.user.Account;
import com.cloud.user.AccountVO;
import com.cloud.utils.Pair;
import com.cloud.utils.net.Ip;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.Nic;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@ -89,16 +91,6 @@ public interface NetworkManager extends NetworkService {
*/
public boolean releasePublicIpAddress(Ip ipAddress, long ownerId, long userId);
/**
* Associates or disassociates a list of public IP address for a router.
* @param router router object to send the association to
* @param ipAddrList list of public IP addresses
* @param add true if associate, false if disassociate
* @param vmId
* @return
*/
boolean associateIP(DomainRouterVO router, List<String> ipAddrList, boolean add, long vmId) throws ConcurrentOperationException;
/**
* Lists IP addresses that belong to VirtualNetwork VLANs
* @param accountId - account that the IP address should belong to
@ -149,5 +141,18 @@ public interface NetworkManager extends NetworkService {
void shutdownNetwork(long networkId);
boolean destroyNetwork(long networkId, long callerUserId);
Network createNetwork(long networkOfferingId, String name, String displayText, Boolean isShared, Boolean isDefault, Long zoneId, String gateway, String startIP, String endIP, String netmask, String vlanId, String networkDomain, Account owner) throws InvalidParameterValueException, PermissionDeniedException;
/**
* Associates an ip address list to an account. The list of ip addresses are all addresses associated with the given vlan id.
* @param userId
* @param accountId
* @param zoneId
* @param vlanId
* @throws InsufficientAddressCapacityException
* @throws
*/
boolean associateIpAddressListToAccount(long userId, long accountId, long zoneId, Long vlanId) throws InsufficientAddressCapacityException,
ConcurrentOperationException, ResourceUnavailableException;
}

File diff suppressed because it is too large Load Diff

View File

@ -34,15 +34,13 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Ip> {
List<IPAddressVO> listByDcIdIpAddress(long dcId, String ipAddress);
List<IPAddressVO> listByNetwork(long networkId);
List<IPAddressVO> listByAssociatedNetwork(long networkId);
int countIPs(long dcId, long vlanDbId, boolean onlyCountAllocated);
int countIPs(long dcId, Long accountId, String vlanId, String vlanGateway, String vlanNetmask);
boolean mark(long dcId, Ip ip);
List<String> assignAcccountSpecificIps(long accountId, long longValue, Long vlanDbId, boolean sourceNat);
int countIPsForDashboard(long dcId, boolean onlyCountAllocated);
}

View File

@ -109,35 +109,6 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Ip> implements
return update(vo, sc) >= 1;
}
@Override
@DB
public List<String> assignAcccountSpecificIps(long accountId, long domainId, Long vlanDbId, boolean sourceNat) {
Transaction txn = Transaction.currentTxn();
txn.start();
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
sc.setParameters("vlan", vlanDbId);
sc.setParameters("sourceNat", sourceNat);
List<IPAddressVO> ipList = lockRows(sc, null, true);
List<String> ipStringList = new ArrayList<String>();
for (IPAddressVO ip : ipList) {
ip.setAllocatedToAccountId(accountId);
ip.setAllocatedTime(new Date());
ip.setAllocatedInDomainId(domainId);
ip.setSourceNat(sourceNat);
ip.setState(State.Allocated);
if (!update(ip.getAddress(), ip)) {
throw new CloudRuntimeException("Unable to update a locked ip address " + ip.getAddress());
}
ipStringList.add(ip.getAddress().toString());
}
txn.commit();
return ipStringList;
}
/**
* @deprecated This method is now deprecated because vlan has been
* added. The actual method is now within NetworkManager.
@ -203,7 +174,7 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Ip> implements
}
@Override
public List<IPAddressVO> listByNetwork(long networkId) {
public List<IPAddressVO> listByAssociatedNetwork(long networkId) {
SearchCriteria<IPAddressVO> sc = AllFieldsSearch.create();
sc.setParameters("network", networkId);

View File

@ -73,9 +73,6 @@ import com.cloud.dc.dao.VlanDao;
import com.cloud.deploy.DataCenterDeployment;
import com.cloud.deploy.DeployDestination;
import com.cloud.domain.dao.DomainDao;
import com.cloud.event.EventTypes;
import com.cloud.event.EventUtils;
import com.cloud.event.EventVO;
import com.cloud.event.dao.EventDao;
import com.cloud.exception.AgentUnavailableException;
import com.cloud.exception.ConcurrentOperationException;
@ -156,7 +153,6 @@ import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.net.Ip;
import com.cloud.utils.net.NetUtils;
import com.cloud.vm.DomainRouterVO;
import com.cloud.vm.NicProfile;

View File

@ -49,6 +49,7 @@ import com.cloud.api.commands.UpdateAccountCmd;
import com.cloud.api.commands.UpdateResourceLimitCmd;
import com.cloud.api.commands.UpdateUserCmd;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
import com.cloud.configuration.ResourceCount.ResourceType;
import com.cloud.configuration.ResourceLimitVO;
import com.cloud.configuration.dao.ConfigurationDao;
@ -131,6 +132,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
@Inject private StorageManager _storageMgr;
@Inject private TemplateManager _tmpltMgr;
@Inject private VirtualNetworkApplianceManager _routerMgr;
@Inject private ConfigurationManager _configMgr;
private final ScheduledExecutorService _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("AccountChecker"));
@ -857,21 +859,32 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
s_logger.info("deleteAccount: Deleted " + numRemoved + " network groups for account " + accountId);
//Delete all the networks
boolean networksDeleted = true;
s_logger.debug("Deleting networks for account " + account.getId());
List<NetworkVO> networks = _networkDao.listByOwner(accountId);
if (networks != null) {
for (NetworkVO network : networks) {
if (!_networkMgr.deleteNetwork(network.getId())) {
s_logger.warn("Unable to destroy network " + network + " as a part of account cleanup");
s_logger.warn("Unable to destroy network " + network + " as a part of account id=" + accountId +" cleanup.");
accountCleanupNeeded = true;
}
s_logger.debug("Network " + network.getId() + " successfully deleted.");
networksDeleted = false;
} else {
s_logger.debug("Network " + network.getId() + " successfully deleted as a part of account id=" + accountId + " cleanup.");
}
}
}
//delete account specific vlans - only when networks are cleaned up successfully
if (networksDeleted) {
if (!_configMgr.deleteAccountSpecificVirtualRanges(accountId)){
accountCleanupNeeded = true;
} else {
s_logger.debug("Account specific Virtual IP ranges " + " are successfully deleted as a part of account id=" + accountId + " cleanup.");
}
}
return true;
} finally {
s_logger.info("Cleanup for account " + account.getId() + (accountCleanupNeeded ? " is needed." : " is not needed."));
if (accountCleanupNeeded) {
_accountDao.markForCleanup(accountId);
}