cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sate...@apache.org
Subject [30/50] [abbrv] git commit: updated refs/heads/vmware-storage-motion to 406785b
Date Thu, 30 May 2013 11:23:01 GMT
CLOUDSTACK-2366: Anti-Affinity - DeleteAffinityGroup API should allow for deletion of Afffinity
group even when VMs are associated with it.

Changes:
- Allowing group to be deleted even when VMs are associated to it.


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

Branch: refs/heads/vmware-storage-motion
Commit: 34943adfc69f406ba78b7cae17b92abcc1c147e9
Parents: 68275fb
Author: Prachi Damle <prachi@cloud.com>
Authored: Wed May 29 17:58:49 2013 -0700
Committer: Prachi Damle <prachi@cloud.com>
Committed: Wed May 29 17:59:32 2013 -0700

----------------------------------------------------------------------
 .../cloudstack/affinity/AffinityGroupService.java  |    5 +---
 .../user/affinitygroup/DeleteAffinityGroupCmd.java |   18 +++++----------
 .../affinity/AffinityGroupServiceImpl.java         |   13 ++++++++--
 .../cloudstack/affinity/AffinityApiUnitTest.java   |   17 ++-----------
 4 files changed, 20 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34943adf/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
index 26c32c8..7423c48 100644
--- a/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
+++ b/api/src/org/apache/cloudstack/affinity/AffinityGroupService.java
@@ -18,7 +18,6 @@ package org.apache.cloudstack.affinity;
 
 import java.util.List;
 
-import com.cloud.exception.ResourceInUseException;
 import com.cloud.uservm.UserVm;
 import com.cloud.utils.Pair;
 
@@ -45,10 +44,8 @@ public interface AffinityGroupService {
      * @param account
      * @param domainId
      * @param affinityGroupName
-     * @throws ResourceInUseException
      */
-    boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String
affinityGroupName)
-            throws ResourceInUseException;
+    boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId, String
affinityGroupName);
 
     /** Lists Affinity Groups in your account
      * @param account

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34943adf/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
index ea4a010..f80e176 100644
--- a/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
+++ b/api/src/org/apache/cloudstack/api/command/user/affinitygroup/DeleteAffinityGroupCmd.java
@@ -30,7 +30,6 @@ import org.apache.log4j.Logger;
 import com.cloud.async.AsyncJob;
 import com.cloud.event.EventTypes;
 import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceInUseException;
 import com.cloud.user.Account;
 import com.cloud.user.UserContext;
 
@@ -123,17 +122,12 @@ public class DeleteAffinityGroupCmd extends BaseAsyncCmd {
 
     @Override
     public void execute(){
-        try{
-            boolean result = _affinityGroupService.deleteAffinityGroup(id, accountName, domainId,
name);
-            if (result) {
-                SuccessResponse response = new SuccessResponse(getCommandName());
-                this.setResponseObject(response);
-            } else {
-                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete
affinity group");
-            }
-        } catch (ResourceInUseException ex) {
-            s_logger.warn("Exception: ", ex);
-            throw new ServerApiException(ApiErrorCode.RESOURCE_IN_USE_ERROR, ex.getMessage());
+        boolean result = _affinityGroupService.deleteAffinityGroup(id, accountName, domainId,
name);
+        if (result) {
+            SuccessResponse response = new SuccessResponse(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete affinity
group");
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34943adf/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
----------------------------------------------------------------------
diff --git a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
index efe18c3..5211279 100644
--- a/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
+++ b/server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java
@@ -125,8 +125,7 @@ public class AffinityGroupServiceImpl extends ManagerBase implements AffinityGro
     @DB
     @Override
     @ActionEvent(eventType = EventTypes.EVENT_AFFINITY_GROUP_DELETE, eventDescription = "Deleting
affinity group")
-    public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId,
String affinityGroupName)
-            throws ResourceInUseException {
+    public boolean deleteAffinityGroup(Long affinityGroupId, String account, Long domainId,
String affinityGroupName) {
 
         Account caller = UserContext.current().getCaller();
         Account owner = _accountMgr.finalizeOwner(caller, account, domainId, null);
@@ -164,7 +163,15 @@ public class AffinityGroupServiceImpl extends ManagerBase implements
AffinityGro
 
         List<AffinityGroupVMMapVO> affinityGroupVmMap = _affinityGroupVMMapDao.listByAffinityGroup(affinityGroupId);
         if (!affinityGroupVmMap.isEmpty()) {
-            throw new ResourceInUseException("Cannot delete affinity group when it's in use
by virtual machines");
+            SearchBuilder<AffinityGroupVMMapVO> listByAffinityGroup = _affinityGroupVMMapDao.createSearchBuilder();
+            listByAffinityGroup.and("affinityGroupId", listByAffinityGroup.entity().getAffinityGroupId(),
+                    SearchCriteria.Op.EQ);
+            listByAffinityGroup.done();
+            SearchCriteria<AffinityGroupVMMapVO> sc = listByAffinityGroup.create();
+            sc.setParameters("affinityGroupId", affinityGroupId);
+
+            _affinityGroupVMMapDao.lockRows(sc, null, true);
+            _affinityGroupVMMapDao.remove(sc);
         }
 
         _affinityGroupDao.expunge(affinityGroupId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/34943adf/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
----------------------------------------------------------------------
diff --git a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
index 484b044..24c5d3d 100644
--- a/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
+++ b/server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
@@ -17,6 +17,7 @@
 package org.apache.cloudstack.affinity;
 
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.anyBoolean;
 import static org.mockito.Matchers.anyLong;
 import static org.mockito.Matchers.anyObject;
@@ -64,6 +65,8 @@ import com.cloud.user.AccountVO;
 import com.cloud.user.UserContext;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.component.ComponentContext;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.UserVmDao;
@@ -172,20 +175,6 @@ public class AffinityApiUnitTest {
         _affinityService.deleteAffinityGroup(null, "user", domainId, null);
     }
 
-    @Test(expected = ResourceInUseException.class)
-    public void deleteAffinityGroupInUse() throws ResourceInUseException {
-        List<AffinityGroupVMMapVO> affinityGroupVmMap = new ArrayList<AffinityGroupVMMapVO>();
-        AffinityGroupVMMapVO mapVO = new AffinityGroupVMMapVO(20L, 10L);
-        affinityGroupVmMap.add(mapVO);
-        when(_affinityGroupVMMapDao.listByAffinityGroup(20L)).thenReturn(affinityGroupVmMap);
-
-        AffinityGroupVO groupVO = new AffinityGroupVO();
-        when(_groupDao.findById(20L)).thenReturn(groupVO);
-        when(_groupDao.lockRow(20L, true)).thenReturn(groupVO);
-
-        _affinityService.deleteAffinityGroup(20L, "user", domainId, null);
-    }
-
     @Test(expected = InvalidParameterValueException.class)
     public void updateAffinityGroupVMRunning() throws ResourceInUseException {
 


Mime
View raw message