diff --git a/server/src/com/cloud/api/ApiDBUtils.java b/server/src/com/cloud/api/ApiDBUtils.java index 4e86b306e3f..3224374902c 100755 --- a/server/src/com/cloud/api/ApiDBUtils.java +++ b/server/src/com/cloud/api/ApiDBUtils.java @@ -329,6 +329,10 @@ public class ApiDBUtils { public static DomainVO findDomainById(Long domainId) { return _domainDao.findById(domainId); } + + public static DomainVO findDomainByIdIncludingRemoved(Long domainId) { + return _domainDao.findByIdIncludingRemoved(domainId); + } public static DomainRouterVO findDomainRouterById(Long routerId) { return _domainRouterDao.findById(routerId); diff --git a/server/src/com/cloud/server/ManagementServerImpl.java b/server/src/com/cloud/server/ManagementServerImpl.java index 0eaf6d3100c..255170bec68 100755 --- a/server/src/com/cloud/server/ManagementServerImpl.java +++ b/server/src/com/cloud/server/ManagementServerImpl.java @@ -2981,6 +2981,7 @@ public class ManagementServerImpl implements ManagementServer { } else { throw new InvalidParameterValueException("Failed to delete domain nable " + domainId + ", domain not found"); } + cleanupDomainOfferings(domainId); return true; } catch (InvalidParameterValueException ex) { throw ex; @@ -2990,6 +2991,19 @@ public class ManagementServerImpl implements ManagementServer { } } + private void cleanupDomainOfferings(Long domainId) { + //delete the service and disk offerings associated with this domain + List diskOfferingsForThisDomain = _diskOfferingDao.listByDomainId(domainId); + for(DiskOfferingVO diskOffering : diskOfferingsForThisDomain) { + _diskOfferingDao.remove(diskOffering.getId()); + } + + List serviceOfferingsForThisDomain = _offeringsDao.findServiceOfferingByDomainId(domainId); + for(ServiceOfferingVO serviceOffering : serviceOfferingsForThisDomain) { + _offeringsDao.remove(serviceOffering.getId()); + } + } + private boolean cleanupDomain(Long domainId, Long ownerId) throws ConcurrentOperationException, ResourceUnavailableException{ boolean success = true; { @@ -3012,7 +3026,7 @@ public class ManagementServerImpl implements ManagementServer { success = (success && _accountMgr.cleanupAccount(account, UserContext.current().getCallerUserId(), UserContext.current().getCaller())); } } - + // delete the domain itself boolean deleteDomainSuccess = _domainDao.remove(domainId);