Skip to content

Commit ce334b4

Browse files
sedukullDaanHoogland
authored andcommitted
CLOUDSTACK-6791 Fixed the issue
(cherry picked from commit 62cc238)
1 parent 1c17df8 commit ce334b4

1 file changed

Lines changed: 31 additions & 20 deletions

File tree

‎server/src/com/cloud/network/guru/DirectNetworkGuru.java‎

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import javax.ejb.Local;
2222
import javax.inject.Inject;
2323

24+
import com.cloud.utils.exception.CloudRuntimeException;
2425
import org.apache.log4j.Logger;
2526

2627
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@@ -47,10 +48,6 @@
4748
import com.cloud.network.Networks.BroadcastDomainType;
4849
import com.cloud.network.Networks.Mode;
4950
import com.cloud.network.Networks.TrafficType;
50-
import com.cloud.network.dao.IPAddressDao;
51-
import com.cloud.network.dao.IPAddressVO;
52-
import com.cloud.network.dao.NetworkVO;
53-
import com.cloud.network.dao.UserIpv6AddressDao;
5451
import com.cloud.offering.NetworkOffering;
5552
import com.cloud.offerings.dao.NetworkOfferingDao;
5653
import com.cloud.user.Account;
@@ -70,6 +67,11 @@
7067
import com.cloud.vm.VirtualMachineProfile;
7168
import com.cloud.vm.dao.NicDao;
7269
import com.cloud.vm.dao.NicSecondaryIpDao;
70+
import com.cloud.network.dao.IPAddressDao;
71+
import com.cloud.network.dao.IPAddressVO;
72+
import com.cloud.network.dao.NetworkVO;
73+
import com.cloud.network.dao.UserIpv6AddressDao;
74+
7375

7476
@Local(value = {NetworkGuru.class})
7577
public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@@ -323,24 +325,33 @@ public void shutdown(NetworkProfile network, NetworkOffering offering) {
323325
@DB
324326
public boolean trash(Network network, NetworkOffering offering) {
325327
//Have to remove all placeholder nics
326-
final List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(network.getId());
327-
Transaction.execute(new TransactionCallbackNoReturn() {
328-
@Override
329-
public void doInTransactionWithoutResult(TransactionStatus status) {
330-
for (Nic nic : nics) {
331-
if (nic.getIp4Address() != null) {
332-
s_logger.debug("Releasing ip " + nic.getIp4Address() + " of placeholder nic " + nic);
333-
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
334-
_ipAddrMgr.markIpAsUnavailable(ip.getId());
335-
_ipAddressDao.unassignIpAddress(ip.getId());
336-
s_logger.debug("Removing placeholder nic " + nic);
337-
_nicDao.remove(nic.getId());
328+
try {
329+
long id = network.getId();
330+
final List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(id);
331+
if (nics != null) {
332+
Transaction.execute(new TransactionCallbackNoReturn() {
333+
@Override
334+
public void doInTransactionWithoutResult(TransactionStatus status) {
335+
for (Nic nic : nics) {
336+
if (nic.getIp4Address() != null) {
337+
s_logger.debug("Releasing ip " + nic.getIp4Address() + " of placeholder nic " + nic);
338+
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
339+
if (ip != null) {
340+
_ipAddrMgr.markIpAsUnavailable(ip.getId());
341+
_ipAddressDao.unassignIpAddress(ip.getId());
342+
s_logger.debug("Removing placeholder nic " + nic);
343+
_nicDao.remove(nic.getId());
344+
}
345+
}
346+
}
338347
}
339-
}
348+
});
340349
}
341-
});
342-
343-
return true;
350+
return true;
351+
}catch (Exception e) {
352+
s_logger.error("trash. Exception:" + e.getMessage());
353+
throw new CloudRuntimeException("trash. Exception:" + e.getMessage(),e);
354+
}
344355
}
345356

346357
@Override

0 commit comments

Comments
 (0)