mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-3476:deleteDomain api should fail when release dedicated resource to that domain fails
This commit is contained in:
parent
36c0224142
commit
e8e207863c
@ -235,6 +235,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||||||
domain.setState(Domain.State.Inactive);
|
domain.setState(Domain.State.Inactive);
|
||||||
_domainDao.update(domain.getId(), domain);
|
_domainDao.update(domain.getId(), domain);
|
||||||
boolean rollBackState = false;
|
boolean rollBackState = false;
|
||||||
|
boolean hasDedicatedResources = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
long ownerId = domain.getAccountId();
|
long ownerId = domain.getAccountId();
|
||||||
@ -246,26 +247,20 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//don't delete the domain if there are accounts set for cleanup, or non-removed networks exist
|
//don't delete the domain if there are accounts set for cleanup, or non-removed networks exist, or domain has dedicated resources
|
||||||
List<Long> networkIds = _networkDomainDao.listNetworkIdsByDomain(domain.getId());
|
List<Long> networkIds = _networkDomainDao.listNetworkIdsByDomain(domain.getId());
|
||||||
List<AccountVO> accountsForCleanup = _accountDao.findCleanupsForRemovedAccounts(domain.getId());
|
List<AccountVO> accountsForCleanup = _accountDao.findCleanupsForRemovedAccounts(domain.getId());
|
||||||
if (accountsForCleanup.isEmpty() && networkIds.isEmpty()) {
|
List<DedicatedResourceVO> dedicatedResources = _dedicatedDao.listByDomainId(domain.getId());
|
||||||
|
if (dedicatedResources != null && !dedicatedResources.isEmpty()) {
|
||||||
|
s_logger.error("There are dedicated resources for the domain " + domain.getId());
|
||||||
|
hasDedicatedResources = true;
|
||||||
|
}
|
||||||
|
if (accountsForCleanup.isEmpty() && networkIds.isEmpty()&& !hasDedicatedResources) {
|
||||||
if (!_domainDao.remove(domain.getId())) {
|
if (!_domainDao.remove(domain.getId())) {
|
||||||
rollBackState = true;
|
rollBackState = true;
|
||||||
CloudRuntimeException e = new CloudRuntimeException("Delete failed on domain " + domain.getName() + " (id: " + domain.getId() + "); Please make sure all users and sub domains have been removed from the domain before deleting");
|
CloudRuntimeException e = new CloudRuntimeException("Delete failed on domain " + domain.getName() + " (id: " + domain.getId() + "); Please make sure all users and sub domains have been removed from the domain before deleting");
|
||||||
e.addProxyObject(domain.getUuid(), "domainId");
|
e.addProxyObject(domain.getUuid(), "domainId");
|
||||||
throw e;
|
throw e;
|
||||||
} else {
|
|
||||||
//release dedication if any, before deleting the domain
|
|
||||||
List<DedicatedResourceVO> dedicatedResources = _dedicatedDao.listByDomainId(domain.getId());
|
|
||||||
if (dedicatedResources != null && !dedicatedResources.isEmpty()) {
|
|
||||||
s_logger.debug("Releasing dedicated resources for domain" + domain.getId());
|
|
||||||
for (DedicatedResourceVO dr : dedicatedResources){
|
|
||||||
if (!_dedicatedDao.remove(dr.getId())) {
|
|
||||||
s_logger.warn("Fail to release dedicated resources for domain " + domain.getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rollBackState = true;
|
rollBackState = true;
|
||||||
@ -274,6 +269,8 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||||||
msg = accountsForCleanup.size() + " accounts to cleanup";
|
msg = accountsForCleanup.size() + " accounts to cleanup";
|
||||||
} else if (!networkIds.isEmpty()) {
|
} else if (!networkIds.isEmpty()) {
|
||||||
msg = networkIds.size() + " non-removed networks";
|
msg = networkIds.size() + " non-removed networks";
|
||||||
|
} else if (hasDedicatedResources) {
|
||||||
|
msg = "dedicated resources.";
|
||||||
}
|
}
|
||||||
|
|
||||||
CloudRuntimeException e = new CloudRuntimeException("Can't delete the domain yet because it has " + msg);
|
CloudRuntimeException e = new CloudRuntimeException("Can't delete the domain yet because it has " + msg);
|
||||||
@ -402,6 +399,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
|
|||||||
for (DedicatedResourceVO dr : dedicatedResources){
|
for (DedicatedResourceVO dr : dedicatedResources){
|
||||||
if (!_dedicatedDao.remove(dr.getId())) {
|
if (!_dedicatedDao.remove(dr.getId())) {
|
||||||
s_logger.warn("Fail to release dedicated resources for domain " + domainId);
|
s_logger.warn("Fail to release dedicated resources for domain " + domainId);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user