diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java index c4435c8074e..2f5458acfee 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 getAccountNetworkMapByNetworkId(long networkId); } diff --git a/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java b/engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java index 09479056f14..913d677f462 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 implements NetworkAccountDao { - public NetworkAccountDaoImpl() { + final SearchBuilder AllFieldsSearch; + + protected NetworkAccountDaoImpl() { super(); + + AllFieldsSearch = createSearchBuilder(); + AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ); + AllFieldsSearch.done(); + } + + @Override + public NetworkAccountVO getAccountNetworkMapByNetworkId(long networkId) { + SearchCriteria sc = AllFieldsSearch.create(); + sc.setParameters("networkId", networkId); + return findOneBy(sc); } } diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 8368f9507b0..187717a85cb 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 _networkGurus; public List 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());