Updated Branches: refs/heads/4.2 743d35cae -> a71810f70
CLOUDSTACK-3735. Domain deletion fails even when the networks within the domain have been destroyed. When a network is destroyed remove the corresponding network entry from domain_network_ref and account_network_ref table Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a71810f7 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a71810f7 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a71810f7 Branch: refs/heads/4.2 Commit: a71810f705d5f8dd15d81aba67597ab67d57cd96 Parents: 743d35c Author: Likitha Shetty <[email protected]> Authored: Wed Jul 24 19:37:16 2013 +0530 Committer: Likitha Shetty <[email protected]> Committed: Wed Jul 24 20:02:15 2013 +0530 ---------------------------------------------------------------------- .../com/cloud/network/dao/NetworkAccountDao.java | 1 + .../cloud/network/dao/NetworkAccountDaoImpl.java | 19 +++++++++++++++++-- .../com/cloud/network/NetworkManagerImpl.java | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a71810f7/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java index c4435c8..2f5458a 100644 --- a/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java +++ b/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java @@ -19,4 +19,5 @@ package com.cloud.network.dao; import com.cloud.utils.db.GenericDao; public interface NetworkAccountDao extends GenericDao<NetworkAccountVO, Long> { + NetworkAccountVO getAccountNetworkMapByNetworkId(long networkId); } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a71810f7/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java ---------------------------------------------------------------------- diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java index 0947905..913d677 100644 --- a/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java +++ b/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java @@ -18,12 +18,27 @@ package com.cloud.network.dao; import org.springframework.stereotype.Component; -import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; @Component public class NetworkAccountDaoImpl extends GenericDaoBase<NetworkAccountVO, Long> implements NetworkAccountDao { - public NetworkAccountDaoImpl() { + final SearchBuilder<NetworkAccountVO> AllFieldsSearch; + + protected NetworkAccountDaoImpl() { super(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.done(); + } + + @Override + public NetworkAccountVO getAccountNetworkMapByNetworkId(long networkId) { + SearchCriteria<NetworkAccountVO> sc = AllFieldsSearch.create(); + sc.setParameters("networkId", networkId); + return findOneBy(sc); } } http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a71810f7/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 8368f95..187717a 100755 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -119,8 +119,11 @@ import com.cloud.network.dao.FirewallRulesDao; import com.cloud.network.dao.IPAddressDao; import com.cloud.network.dao.IPAddressVO; import com.cloud.network.dao.LoadBalancerDao; +import com.cloud.network.dao.NetworkAccountDao; +import com.cloud.network.dao.NetworkAccountVO; import com.cloud.network.dao.NetworkDao; import com.cloud.network.dao.NetworkDomainDao; +import com.cloud.network.dao.NetworkDomainVO; import com.cloud.network.dao.NetworkServiceMapDao; import com.cloud.network.dao.NetworkServiceMapVO; import com.cloud.network.dao.NetworkVO; @@ -261,6 +264,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L AccountGuestVlanMapDao _accountGuestVlanMapDao; @Inject DataCenterVnetDao _datacenterVnetDao; + @Inject + NetworkAccountDao _networkAccountDao; List<NetworkGuru> _networkGurus; public List<NetworkGuru> getNetworkGurus() { @@ -2891,7 +2896,15 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L } catch (NoTransitionException e) { s_logger.debug(e.getMessage()); } - _networksDao.remove(network.getId()); + if (_networksDao.remove(network.getId())) { + NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(network.getId()); + if (networkDomain != null) + _networkDomainDao.remove(networkDomain.getId()); + + NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(network.getId()); + if (networkAccount != null) + _networkAccountDao.remove(networkAccount.getId()); + } NetworkOffering ntwkOff = _configMgr.getNetworkOffering(network.getNetworkOfferingId()); boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, network.getAclType());
