Skip to content

Commit a71810f

Browse files
author
Likitha Shetty
committed
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
1 parent 743d35c commit a71810f

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎engine/schema/src/com/cloud/network/dao/NetworkAccountDao.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
import com.cloud.utils.db.GenericDao;
2020

2121
public interface NetworkAccountDao extends GenericDao<NetworkAccountVO, Long> {
22+
NetworkAccountVO getAccountNetworkMapByNetworkId(long networkId);
2223
}

‎engine/schema/src/com/cloud/network/dao/NetworkAccountDaoImpl.java‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,27 @@
1818

1919
import org.springframework.stereotype.Component;
2020

21-
import com.cloud.utils.db.GenericDao;
2221
import com.cloud.utils.db.GenericDaoBase;
22+
import com.cloud.utils.db.SearchBuilder;
23+
import com.cloud.utils.db.SearchCriteria;
24+
import com.cloud.utils.db.SearchCriteria.Op;
2325

2426
@Component
2527
public class NetworkAccountDaoImpl extends GenericDaoBase<NetworkAccountVO, Long> implements NetworkAccountDao {
26-
public NetworkAccountDaoImpl() {
28+
final SearchBuilder<NetworkAccountVO> AllFieldsSearch;
29+
30+
protected NetworkAccountDaoImpl() {
2731
super();
32+
33+
AllFieldsSearch = createSearchBuilder();
34+
AllFieldsSearch.and("networkId", AllFieldsSearch.entity().getNetworkId(), Op.EQ);
35+
AllFieldsSearch.done();
36+
}
37+
38+
@Override
39+
public NetworkAccountVO getAccountNetworkMapByNetworkId(long networkId) {
40+
SearchCriteria<NetworkAccountVO> sc = AllFieldsSearch.create();
41+
sc.setParameters("networkId", networkId);
42+
return findOneBy(sc);
2843
}
2944
}

‎server/src/com/cloud/network/NetworkManagerImpl.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@
119119
import com.cloud.network.dao.IPAddressDao;
120120
import com.cloud.network.dao.IPAddressVO;
121121
import com.cloud.network.dao.LoadBalancerDao;
122+
import com.cloud.network.dao.NetworkAccountDao;
123+
import com.cloud.network.dao.NetworkAccountVO;
122124
import com.cloud.network.dao.NetworkDao;
123125
import com.cloud.network.dao.NetworkDomainDao;
126+
import com.cloud.network.dao.NetworkDomainVO;
124127
import com.cloud.network.dao.NetworkServiceMapDao;
125128
import com.cloud.network.dao.NetworkServiceMapVO;
126129
import com.cloud.network.dao.NetworkVO;
@@ -261,6 +264,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager, L
261264
AccountGuestVlanMapDao _accountGuestVlanMapDao;
262265
@Inject
263266
DataCenterVnetDao _datacenterVnetDao;
267+
@Inject
268+
NetworkAccountDao _networkAccountDao;
264269

265270
List<NetworkGuru> _networkGurus;
266271
public List<NetworkGuru> getNetworkGurus() {
@@ -2891,7 +2896,15 @@ public boolean destroyNetwork(long networkId, ReservationContext context) {
28912896
} catch (NoTransitionException e) {
28922897
s_logger.debug(e.getMessage());
28932898
}
2894-
_networksDao.remove(network.getId());
2899+
if (_networksDao.remove(network.getId())) {
2900+
NetworkDomainVO networkDomain = _networkDomainDao.getDomainNetworkMapByNetworkId(network.getId());
2901+
if (networkDomain != null)
2902+
_networkDomainDao.remove(networkDomain.getId());
2903+
2904+
NetworkAccountVO networkAccount = _networkAccountDao.getAccountNetworkMapByNetworkId(network.getId());
2905+
if (networkAccount != null)
2906+
_networkAccountDao.remove(networkAccount.getId());
2907+
}
28952908

28962909
NetworkOffering ntwkOff = _configMgr.getNetworkOffering(network.getNetworkOfferingId());
28972910
boolean updateResourceCount = resourceCountNeedsUpdate(ntwkOff, network.getAclType());

0 commit comments

Comments
 (0)