From 28bcbc3bddc34b371097057c2e2b8d6204a58548 Mon Sep 17 00:00:00 2001 From: Kris McQueen Date: Tue, 26 Oct 2010 16:47:07 -0700 Subject: [PATCH] bug 6732: there is no longer a manual policy, so add in special handling for deleting manual snapshots. Also, in the process of deleting the snapshot, the snapshot might need to be retrieved from the database, so be sure to find including removed. status 6732: resolved fixed --- .../storage/snapshot/SnapshotManagerImpl.java | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index a52ea1087e1..b9bf1cb70e6 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -280,8 +280,9 @@ public class SnapshotManagerImpl implements SnapshotManager { SnapshotVO preSnapshotVO = null; if( preId != 0) { preSnapshotVO = _snapshotDao.findById(preId); - preSnapshotPath = preSnapshotVO.getPath(); - + if (preSnapshotVO != null) { + preSnapshotPath = preSnapshotVO.getPath(); + } } ManageSnapshotCommand cmd = new ManageSnapshotCommand(id, volume.getPath(), preSnapshotPath, snapshotName, vmName); @@ -697,15 +698,24 @@ public class SnapshotManagerImpl implements SnapshotManager { userId = Long.valueOf(1); } - List policies = listPoliciesforVolume(snapshotCheck.getVolumeId()); - boolean status = true; - for (SnapshotPolicyVO policy : policies) { - status = deleteSnapshotInternal(snapshotId, policy.getId(), userId); - + if (SnapshotType.MANUAL.ordinal() == (int)snapshotCheck.getSnapshotType()) { + status = deleteSnapshotInternal(snapshotId, Snapshot.MANUAL_POLICY_ID, userId); + if (!status) { - s_logger.warn("Failed to delete snapshot"); - throw new ServerApiException(BaseCmd.INTERNAL_ERROR,"Failed to delete snapshot:"+snapshotId); + s_logger.warn("Failed to delete snapshot"); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR,"Failed to delete snapshot:"+snapshotId); + } + } else { + List policies = listPoliciesforVolume(snapshotCheck.getVolumeId()); + + for (SnapshotPolicyVO policy : policies) { + status = deleteSnapshotInternal(snapshotId, policy.getId(), userId); + + if (!status) { + s_logger.warn("Failed to delete snapshot"); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR,"Failed to delete snapshot:"+snapshotId); + } } } @@ -727,7 +737,7 @@ public class SnapshotManagerImpl implements SnapshotManager { break; lastId = lastSnapshot.getId(); } - lastSnapshot = _snapshotDao.findById(lastId); + lastSnapshot = _snapshotDao.findByIdIncludingRemoved(lastId); while( lastSnapshot.getRemoved() != null ) { String BackupSnapshotId = lastSnapshot.getBackupSnapshotId(); if( BackupSnapshotId != null ) { @@ -757,7 +767,7 @@ public class SnapshotManagerImpl implements SnapshotManager { public boolean destroySnapshotBackUp(long userId, long snapshotId, long policyId) { boolean success = false; String details = null; - SnapshotVO snapshot = _snapshotDao.findById(snapshotId); + SnapshotVO snapshot = _snapshotDao.findByIdIncludingRemoved(snapshotId); VolumeVO volume = _volsDao.findById(snapshot.getVolumeId()); String primaryStoragePoolNameLabel = _storageMgr.getPrimaryStorageNameLabel(volume); @@ -812,7 +822,7 @@ public class SnapshotManagerImpl implements SnapshotManager { Transaction txn = Transaction.currentTxn(); txn.start(); - SnapshotVO snapshot = _snapshotDao.findById(snapshotId); + SnapshotVO snapshot = _snapshotDao.findByIdIncludingRemoved(snapshotId); _snapshotDao.expunge(snapshotId); // If this is a manual delete, decrement the count of snapshots for this account if (policyId == Snapshot.MANUAL_POLICY_ID) {