You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by al...@apache.org on 2013/07/17 20:25:54 UTC

git commit: updated refs/heads/4.2 to 1933960

Updated Branches:
  refs/heads/4.2 5d390ec7a -> 1933960dd


CLOUDSTACK-3476:deleteDomain api should fail when release dedicated resource to that domain fails


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/1933960d
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/1933960d
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/1933960d

Branch: refs/heads/4.2
Commit: 1933960ddac755756db4a510e6ce53e29548a340
Parents: 5d390ec
Author: Saksham Srivastava <sa...@citrix.com>
Authored: Fri Jul 12 19:21:16 2013 +0530
Committer: Alena Prokharchyk <al...@citrix.com>
Committed: Wed Jul 17 11:18:24 2013 -0700

----------------------------------------------------------------------
 .../src/com/cloud/user/DomainManagerImpl.java   | 24 +++++++++-----------
 1 file changed, 11 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/1933960d/server/src/com/cloud/user/DomainManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/user/DomainManagerImpl.java b/server/src/com/cloud/user/DomainManagerImpl.java
index aad5787..1117ff0 100644
--- a/server/src/com/cloud/user/DomainManagerImpl.java
+++ b/server/src/com/cloud/user/DomainManagerImpl.java
@@ -233,6 +233,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
         domain.setState(Domain.State.Inactive);
         _domainDao.update(domain.getId(), domain);
         boolean rollBackState = false;
+        boolean hasDedicatedResources = false;
 
         try {
             long ownerId = domain.getAccountId();
@@ -244,26 +245,20 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
                     throw e;
                 }
             } 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<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())) {
                         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");
                         e.addProxyObject(domain.getUuid(), "domainId");
                         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 {
                     rollBackState = true;
@@ -272,6 +267,8 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
                         msg = accountsForCleanup.size() + " accounts to cleanup";
                     } else if (!networkIds.isEmpty()) {
                         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);
@@ -400,6 +397,7 @@ public class DomainManagerImpl extends ManagerBase implements DomainManager, Dom
                 for (DedicatedResourceVO dr : dedicatedResources){
                     if (!_dedicatedDao.remove(dr.getId())) {
                         s_logger.warn("Fail to release dedicated resources for domain " + domainId);
+                        return false;
                     }
                 }
             }