cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raj...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 1d1b503
Date Tue, 21 Feb 2017 00:16:38 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 3582c653f -> 1d1b503de


CLOUDSTACK-9766 : Executing deleteSnapshot api with already deleted snapshot does not throw
any exception or failure message


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

Branch: refs/heads/master
Commit: f8ad3e8115f50f5de8511a80937a40723bbe4971
Parents: 17787a1
Author: Nitesh Sarda <nitesh_sarda@accelerite.com>
Authored: Wed Feb 1 11:59:45 2017 +0530
Committer: Nitesh Sarda <nitesh_sarda@accelerite.com>
Committed: Wed Feb 1 11:59:45 2017 +0530

----------------------------------------------------------------------
 .../src/com/cloud/storage/dao/SnapshotDao.java      |  2 ++
 .../src/com/cloud/storage/dao/SnapshotDaoImpl.java  | 16 ++++++++++++++++
 .../cloud/storage/snapshot/SnapshotManagerImpl.java | 10 +++++++---
 .../cloud/storage/snapshot/SnapshotManagerTest.java |  5 ++---
 4 files changed, 27 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8ad3e81/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java b/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
old mode 100644
new mode 100755
index ff2e445..fe63558
--- a/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
+++ b/engine/schema/src/com/cloud/storage/dao/SnapshotDao.java
@@ -37,6 +37,8 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long>,
StateDao<Snap
 
     List<SnapshotVO> listByVolumeIdType(long volumeId, Type type);
 
+    List<SnapshotVO> listByVolumeIdTypeNotDestroyed(long volumeId, Type type);
+
     List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId);
 
     List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8ad3e81/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java b/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
old mode 100644
new mode 100755
index 9483f1c..a6941cf
--- a/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
+++ b/engine/schema/src/com/cloud/storage/dao/SnapshotDaoImpl.java
@@ -62,6 +62,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
 
     private SearchBuilder<SnapshotVO> VolumeIdSearch;
     private SearchBuilder<SnapshotVO> VolumeIdTypeSearch;
+    private SearchBuilder<SnapshotVO> VolumeIdTypeNotDestroyedSearch;
     private SearchBuilder<SnapshotVO> ParentIdSearch;
     private SearchBuilder<SnapshotVO> backupUuidSearch;
     private SearchBuilder<SnapshotVO> VolumeIdVersionSearch;
@@ -96,6 +97,15 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
     }
 
     @Override
+    public List<SnapshotVO> listByVolumeIdTypeNotDestroyed(long volumeId, Type type)
{
+        SearchCriteria<SnapshotVO> sc = VolumeIdTypeNotDestroyedSearch.create();
+        sc.setParameters("volumeId", volumeId);
+        sc.setParameters("type", type.ordinal());
+        sc.setParameters("status", State.Destroyed);
+        return listBy(sc, null);
+    }
+
+    @Override
     public List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version) {
         return listByVolumeIdVersion(null, volumeId, version);
     }
@@ -147,6 +157,12 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long>
implements
         VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ);
         VolumeIdTypeSearch.done();
 
+        VolumeIdTypeNotDestroyedSearch = createSearchBuilder();
+        VolumeIdTypeNotDestroyedSearch.and("volumeId", VolumeIdTypeNotDestroyedSearch.entity().getVolumeId(),
SearchCriteria.Op.EQ);
+        VolumeIdTypeNotDestroyedSearch.and("type", VolumeIdTypeNotDestroyedSearch.entity().getsnapshotType(),
SearchCriteria.Op.EQ);
+        VolumeIdTypeNotDestroyedSearch.and("status", VolumeIdTypeNotDestroyedSearch.entity().getState(),
SearchCriteria.Op.NEQ);
+        VolumeIdTypeNotDestroyedSearch.done();
+
         VolumeIdVersionSearch = createSearchBuilder();
         VolumeIdVersionSearch.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(),
SearchCriteria.Op.EQ);
         VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(),
SearchCriteria.Op.EQ);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8ad3e81/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
old mode 100644
new mode 100755
index d9a93c3..5bc56b7
--- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
+++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java
@@ -481,7 +481,7 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase
implement
         Type type = spstVO.getRecurringType();
         int maxSnaps = type.getMax();
 
-        List<SnapshotVO> snaps = listSnapsforVolumeType(volumeId, type);
+        List<SnapshotVO> snaps = listSnapsforVolumeTypeNotDestroyed(volumeId, type);
         SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId);
         if (policy != null && policy.getMaxSnaps() < maxSnaps) {
             maxSnaps = policy.getMaxSnaps();
@@ -514,6 +514,10 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase
implement
             throw new InvalidParameterValueException("unable to find a snapshot with id "
+ snapshotId);
         }
 
+        if (snapshotCheck.getState() == Snapshot.State.Destroyed) {
+            throw new InvalidParameterValueException("Snapshot with id: " + snapshotId +
" is already destroyed");
+        }
+
         _accountMgr.checkAccess(caller, null, true, snapshotCheck);
 
         SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshotCheck,
SnapshotOperation.DELETE);
@@ -898,8 +902,8 @@ public class SnapshotManagerImpl extends MutualExclusiveIdsManagerBase
implement
         return _snapshotDao.listByVolumeId(volumeId);
     }
 
-    private List<SnapshotVO> listSnapsforVolumeType(long volumeId, Type type) {
-        return _snapshotDao.listByVolumeIdType(volumeId, type);
+    private List<SnapshotVO> listSnapsforVolumeTypeNotDestroyed(long volumeId, Type
type) {
+        return _snapshotDao.listByVolumeIdTypeNotDestroyed(volumeId, type);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f8ad3e81/server/test/com/cloud/storage/snapshot/SnapshotManagerTest.java
----------------------------------------------------------------------
diff --git a/server/test/com/cloud/storage/snapshot/SnapshotManagerTest.java b/server/test/com/cloud/storage/snapshot/SnapshotManagerTest.java
old mode 100644
new mode 100755
index 58ee2e7..685f495
--- a/server/test/com/cloud/storage/snapshot/SnapshotManagerTest.java
+++ b/server/test/com/cloud/storage/snapshot/SnapshotManagerTest.java
@@ -248,14 +248,13 @@ public class SnapshotManagerTest {
         _snapshotMgr.allocSnapshot(TEST_VOLUME_ID, Snapshot.MANUAL_POLICY_ID, null, null);
     }
 
-    @Test
+    @Test(expected = InvalidParameterValueException.class)
     public void testDeleteSnapshotF1() {
         when(snapshotStrategy.deleteSnapshot(TEST_SNAPSHOT_ID)).thenReturn(true);
         when(snapshotMock.getState()).thenReturn(Snapshot.State.Destroyed);
         when(snapshotMock.getAccountId()).thenReturn(2L);
         when(snapshotMock.getDataCenterId()).thenReturn(2L);
-        boolean result =_snapshotMgr.deleteSnapshot(TEST_SNAPSHOT_ID);
-        Assert.assertTrue(result);
+        _snapshotMgr.deleteSnapshot(TEST_SNAPSHOT_ID);
     }
 
     // vm state not stopped


Mime
View raw message