From 28cfa24bd2eff22bee2a2945eb2ac085d300ba26 Mon Sep 17 00:00:00 2001 From: anthony Date: Fri, 18 Mar 2011 15:19:57 -0700 Subject: [PATCH] only 2.1 snapshot depends on template, if there is no 2.1 snapshot, template can be removed --- .../com/cloud/storage/dao/SnapshotDao.java | 1 + .../cloud/storage/dao/SnapshotDaoImpl.java | 19 +++++++++++++++++++ .../storage/snapshot/SnapshotManagerImpl.java | 8 +++++--- .../cloud/template/TemplateManagerImpl.java | 4 ++-- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/server/src/com/cloud/storage/dao/SnapshotDao.java b/server/src/com/cloud/storage/dao/SnapshotDao.java index 4220e691e62..e5731b00359 100644 --- a/server/src/com/cloud/storage/dao/SnapshotDao.java +++ b/server/src/com/cloud/storage/dao/SnapshotDao.java @@ -34,5 +34,6 @@ public interface SnapshotDao extends GenericDao { List listByVolumeIdIncludingRemoved(long volumeId); List listByBackupUuid(long volumeId, String backupUuid); long updateSnapshotVersion(long volumeId, String from, String to); + List listByVolumeIdVersion(long volumeId, String version); } diff --git a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java index 3ad6cd1514f..ba4773f4970 100644 --- a/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java +++ b/server/src/com/cloud/storage/dao/SnapshotDaoImpl.java @@ -44,6 +44,7 @@ public class SnapshotDaoImpl extends GenericDaoBase implements private final SearchBuilder VolumeIdTypeSearch; private final SearchBuilder ParentIdSearch; private final SearchBuilder backupUuidSearch; + private final SearchBuilder VolumeIdVersionSearch; @Override public SnapshotVO findNextSnapshot(long snapshotId) { @@ -63,6 +64,12 @@ public class SnapshotDaoImpl extends GenericDaoBase implements public List listByVolumeIdType(long volumeId, Type type ) { return listByVolumeIdType(null, volumeId, type); } + + + @Override + public List listByVolumeIdVersion(long volumeId, String version ) { + return listByVolumeIdVersion(null, volumeId, version); + } @Override public List listByVolumeId(long volumeId) { @@ -89,6 +96,13 @@ public class SnapshotDaoImpl extends GenericDaoBase implements sc.setParameters("type", type.ordinal()); return listBy(sc, filter); } + + public List listByVolumeIdVersion(Filter filter, long volumeId, String version ) { + SearchCriteria sc = VolumeIdVersionSearch.create(); + sc.setParameters("volumeId", volumeId); + sc.setParameters("version", version); + return listBy(sc, filter); + } protected SnapshotDaoImpl() { VolumeIdSearch = createSearchBuilder(); @@ -100,6 +114,11 @@ public class SnapshotDaoImpl extends GenericDaoBase implements VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ); VolumeIdTypeSearch.done(); + VolumeIdVersionSearch = createSearchBuilder(); + VolumeIdVersionSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); + VolumeIdVersionSearch.and("version", VolumeIdTypeSearch.entity().getVersion(), SearchCriteria.Op.EQ); + VolumeIdVersionSearch.done(); + ParentIdSearch = createSearchBuilder(); ParentIdSearch.and("prevSnapshotId", ParentIdSearch.entity().getPrevSnapshotId(), SearchCriteria.Op.EQ); ParentIdSearch.done(); diff --git a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java index 07843f0c47d..68a33cda6b7 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -487,9 +487,11 @@ public class SnapshotManagerImpl implements SnapshotManager, SnapshotService, Ma long prevSnapshotId = snapshot.getPrevSnapshotId(); if (prevSnapshotId > 0) { prevSnapshot = _snapshotDao.findByIdIncludingRemoved(prevSnapshotId); - prevBackupUuid = prevSnapshot.getBackupSnapshotId(); - if (prevBackupUuid != null) { - prevSnapshotUuid = prevSnapshot.getPath(); + if (prevSnapshot.getVersion() != null && prevSnapshot.getVersion().equals("2.2") ) { + prevBackupUuid = prevSnapshot.getBackupSnapshotId(); + if (prevBackupUuid != null) { + prevSnapshotUuid = prevSnapshot.getPath(); + } } } diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 94676db53a6..8523955e535 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -1149,9 +1149,9 @@ public class TemplateManagerImpl implements TemplateManager, Manager, TemplateSe // Check if there are any snapshots for the template in the template host ref's zone List volumes = _volumeDao.findByTemplateAndZone(templateId, zoneId); for (VolumeVO volume : volumes) { - List snapshots = _snapshotDao.listByVolumeId(volume.getId()); + List snapshots = _snapshotDao.listByVolumeIdVersion(volume.getId(), "2.1"); if (!snapshots.isEmpty()) { - s_logger.debug("Template " + template.getName() + " in zone " + zone.getName() + " is not deleteable because there are snapshots using this template."); + s_logger.debug("Template " + template.getName() + " in zone " + zone.getName() + " is not deleteable because there are 2.1 snapshots using this template."); return false; } }