diff --git a/core/src/com/cloud/dc/dao/DataCenterIpAddressDao.java b/core/src/com/cloud/dc/dao/DataCenterIpAddressDao.java index 73b0952941a..c30d7386ae9 100644 --- a/core/src/com/cloud/dc/dao/DataCenterIpAddressDao.java +++ b/core/src/com/cloud/dc/dao/DataCenterIpAddressDao.java @@ -26,6 +26,7 @@ public interface DataCenterIpAddressDao extends GenericDao listByPodIdDcIdIpAddress(long podId, long dcId, String ipAddress); + List listByPodIdDcId(long podId, long dcId); int countIPs(long podId, long dcId, boolean onlyCountAllocated); boolean deleteIpAddressByPod(long podId); diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 9d6da9d8747..eae74424666 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -52,6 +52,7 @@ import com.cloud.configuration.ResourceCount.ResourceType; import com.cloud.configuration.dao.ConfigurationDao; import com.cloud.dc.AccountVlanMapVO; import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenterIpAddressVO; import com.cloud.dc.DataCenterVO; import com.cloud.dc.HostPodVO; import com.cloud.dc.Pod; @@ -62,6 +63,7 @@ import com.cloud.dc.VlanVO; import com.cloud.dc.dao.AccountVlanMapDao; import com.cloud.dc.dao.DataCenterDao; import com.cloud.dc.dao.DataCenterIpAddressDao; +import com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl; import com.cloud.dc.dao.HostPodDao; import com.cloud.dc.dao.PodVlanMapDao; import com.cloud.dc.dao.VlanDao; @@ -97,6 +99,7 @@ import com.cloud.user.dao.AccountDao; import com.cloud.user.dao.UserDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.component.Adapters; +import com.cloud.utils.component.ComponentLocator; import com.cloud.utils.component.Inject; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; @@ -140,6 +143,9 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura @Inject NetworkManager _networkMgr; @Inject(adapter=SecurityChecker.class) Adapters _secChecker; + + //FIXME - why don't we have interface for DataCenterLinkLocalIpAddressDao? + protected static final DataCenterLinkLocalIpAddressDaoImpl _LinkLocalIpAllocDao = ComponentLocator.inject(DataCenterLinkLocalIpAddressDaoImpl.class); private int _maxVolumeSizeInGb; @@ -437,14 +443,27 @@ public class ConfigurationManagerImpl implements ConfigurationManager, Configura HostPodVO pod = _podDao.findById(podId); DataCenterVO zone = _zoneDao.findById(pod.getDataCenterId()); + + //Delete private ip addresses for the pod if there are any + List privateIps = _privateIpAddressDao.listByPodIdDcId(Long.valueOf(podId), pod.getDataCenterId()); + if (privateIps != null && privateIps.size() != 0) { + if (!(_privateIpAddressDao.deleteIpAddressByPod(podId))) { + throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); + } + } + + //Delete link local ip addresses for the pod + if (!(_LinkLocalIpAllocDao.deleteIpAddressByPod(podId))) { + throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId); + } - //Delete the pod and private IP addresses in the pod - if (_podDao.expunge(podId) && _privateIpAddressDao.deleteIpAddressByPod(podId)) { - saveConfigurationEvent(userId, null, EventTypes.EVENT_POD_DELETE, "Successfully deleted pod with name: " + pod.getName() + " in zone: " + zone.getName() + ".", "podId=" + podId, "dcId=" + zone.getId()); - return true; - } else { - return false; + //Delete the pod + if (!(_podDao.expunge(podId))) { + throw new CloudRuntimeException("Failed to delete pod " + podId); } + + saveConfigurationEvent(userId, null, EventTypes.EVENT_POD_DELETE, "Successfully deleted pod with name: " + pod.getName() + " in zone: " + zone.getName() + ".", "podId=" + podId, "dcId=" + zone.getId()); + return true; } @Override