CLOUDSTACK-6791 Fixed the issue

(cherry picked from commit 62cc238e12)
This commit is contained in:
Santhosh Edukulla 2014-06-12 16:22:32 +05:30 committed by Daan Hoogland
parent 1c17df853f
commit ce334b4ee5
1 changed files with 31 additions and 20 deletions

View File

@ -21,6 +21,7 @@ import java.util.List;
import javax.ejb.Local;
import javax.inject.Inject;
import com.cloud.utils.exception.CloudRuntimeException;
import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
@ -47,10 +48,6 @@ import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.Mode;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.UserIpv6AddressDao;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingDao;
import com.cloud.user.Account;
@ -70,6 +67,11 @@ import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.dao.NicDao;
import com.cloud.vm.dao.NicSecondaryIpDao;
import com.cloud.network.dao.IPAddressDao;
import com.cloud.network.dao.IPAddressVO;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.UserIpv6AddressDao;
@Local(value = {NetworkGuru.class})
public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@ -323,24 +325,33 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
@DB
public boolean trash(Network network, NetworkOffering offering) {
//Have to remove all placeholder nics
final List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(network.getId());
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
for (Nic nic : nics) {
if (nic.getIp4Address() != null) {
s_logger.debug("Releasing ip " + nic.getIp4Address() + " of placeholder nic " + nic);
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
s_logger.debug("Removing placeholder nic " + nic);
_nicDao.remove(nic.getId());
try {
long id = network.getId();
final List<NicVO> nics = _nicDao.listPlaceholderNicsByNetworkId(id);
if (nics != null) {
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
for (Nic nic : nics) {
if (nic.getIp4Address() != null) {
s_logger.debug("Releasing ip " + nic.getIp4Address() + " of placeholder nic " + nic);
IPAddressVO ip = _ipAddressDao.findByIpAndSourceNetworkId(nic.getNetworkId(), nic.getIp4Address());
if (ip != null) {
_ipAddrMgr.markIpAsUnavailable(ip.getId());
_ipAddressDao.unassignIpAddress(ip.getId());
s_logger.debug("Removing placeholder nic " + nic);
_nicDao.remove(nic.getId());
}
}
}
}
}
});
}
});
return true;
return true;
}catch (Exception e) {
s_logger.error("trash. Exception:" + e.getMessage());
throw new CloudRuntimeException("trash. Exception:" + e.getMessage(),e);
}
}
@Override