mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-02 11:52:28 +01:00
only 2.1 snapshot depends on template, if there is no 2.1 snapshot, template can be removed
This commit is contained in:
parent
5bbffcaa97
commit
28cfa24bd2
@ -34,5 +34,6 @@ public interface SnapshotDao extends GenericDao<SnapshotVO, Long> {
|
||||
List<SnapshotVO> listByVolumeIdIncludingRemoved(long volumeId);
|
||||
List<SnapshotVO> listByBackupUuid(long volumeId, String backupUuid);
|
||||
long updateSnapshotVersion(long volumeId, String from, String to);
|
||||
List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version);
|
||||
|
||||
}
|
||||
|
||||
@ -44,6 +44,7 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
private final SearchBuilder<SnapshotVO> VolumeIdTypeSearch;
|
||||
private final SearchBuilder<SnapshotVO> ParentIdSearch;
|
||||
private final SearchBuilder<SnapshotVO> backupUuidSearch;
|
||||
private final SearchBuilder<SnapshotVO> VolumeIdVersionSearch;
|
||||
|
||||
@Override
|
||||
public SnapshotVO findNextSnapshot(long snapshotId) {
|
||||
@ -63,6 +64,12 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
public List<SnapshotVO> listByVolumeIdType(long volumeId, Type type ) {
|
||||
return listByVolumeIdType(null, volumeId, type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listByVolumeIdVersion(long volumeId, String version ) {
|
||||
return listByVolumeIdVersion(null, volumeId, version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SnapshotVO> listByVolumeId(long volumeId) {
|
||||
@ -89,6 +96,13 @@ public class SnapshotDaoImpl extends GenericDaoBase<SnapshotVO, Long> implements
|
||||
sc.setParameters("type", type.ordinal());
|
||||
return listBy(sc, filter);
|
||||
}
|
||||
|
||||
public List<SnapshotVO> listByVolumeIdVersion(Filter filter, long volumeId, String version ) {
|
||||
SearchCriteria<SnapshotVO> 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<SnapshotVO, Long> 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();
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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<VolumeVO> volumes = _volumeDao.findByTemplateAndZone(templateId, zoneId);
|
||||
for (VolumeVO volume : volumes) {
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listByVolumeId(volume.getId());
|
||||
List<SnapshotVO> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user