CLOUDSTACK-2635: destroyed snapshots are still showing up from UI. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b4a996dd Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b4a996dd Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b4a996dd
Branch: refs/heads/object_store Commit: b4a996dd421a5fe2b01ddf4e908a242948b82ba2 Parents: 3a14d45 Author: Min Chen <[email protected]> Authored: Wed May 22 17:50:50 2013 -0700 Committer: Min Chen <[email protected]> Committed: Wed May 22 17:50:50 2013 -0700 ---------------------------------------------------------------------- .../storage/snapshot/SnapshotManagerImpl.java | 30 ++++++++------- 1 files changed, 16 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b4a996dd/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 index 142f58e..67b6062 100755 --- a/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java +++ b/server/src/com/cloud/storage/snapshot/SnapshotManagerImpl.java @@ -288,7 +288,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, throw new InvalidParameterValueException("Volume is not in ready state"); } - + boolean backedUp = false; // does the caller have the authority to act on this volume _accountMgr.checkAccess(UserContext.current().getCaller(), null, true, volume); @@ -351,7 +351,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, /* @Override public void downloadSnapshotsFromSwift(SnapshotVO ss) { - + long volumeId = ss.getVolumeId(); VolumeVO volume = _volsDao.findById(volumeId); Long dcId = volume.getDataCenterId(); @@ -581,7 +581,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, SearchBuilder<SnapshotVO> sb = _snapshotDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); - sb.and("status", sb.entity().getState(), SearchCriteria.Op.EQ); + sb.and("statusNEQ", sb.entity().getState(), SearchCriteria.Op.NEQ); //exclude those Destroyed snapshot, not showing on UI sb.and("volumeId", sb.entity().getVolumeId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.LIKE); sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); @@ -602,13 +602,15 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, if(zoneType != null) { SearchBuilder<DataCenterVO> zoneSb = _dcDao.createSearchBuilder(); - zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); + zoneSb.and("zoneNetworkType", zoneSb.entity().getNetworkType(), SearchCriteria.Op.EQ); sb.join("zoneSb", zoneSb, sb.entity().getDataCenterId(), zoneSb.entity().getId(), JoinBuilder.JoinType.INNER); } - + SearchCriteria<SnapshotVO> sc = sb.create(); _accountMgr.buildACLSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); + sc.setParameters("statusNEQ", Snapshot.State.Destroyed); + if (volumeId != null) { sc.setParameters("volumeId", volumeId); } @@ -624,9 +626,9 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, } if(zoneType != null) { - sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); + sc.setJoinParameters("zoneSb", "zoneNetworkType", zoneType); } - + if (name != null) { sc.setParameters("name", "%" + name + "%"); } @@ -925,8 +927,8 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, return null; } - - + + private boolean hostSupportSnapsthot(HostVO host) { if (host.getHypervisorType() != HypervisorType.KVM) { return true; @@ -944,14 +946,14 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, } return false; } - + private boolean supportedByHypervisor(VolumeInfo volume) { StoragePool storagePool = (StoragePool)volume.getDataStore(); ClusterVO cluster = _clusterDao.findById(storagePool.getClusterId()); if (cluster != null && cluster.getHypervisorType() == HypervisorType.Ovm) { throw new InvalidParameterValueException("Ovm won't support taking snapshot"); } - + if (volume.getHypervisorType().equals(HypervisorType.KVM)) { List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(cluster.getId()); if (hosts != null && !hosts.isEmpty()) { @@ -995,7 +997,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, Account snapshotOwner = payload.getAccount(); SnapshotInfo snapshot = this.snapshotFactory.getSnapshot(snapshotId, volume.getDataStore()); boolean processed = false; - + try { for (SnapshotStrategy strategy : snapshotStrategies) { if (strategy.canHandle(snapshot)) { @@ -1008,7 +1010,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, throw new CloudRuntimeException("Can't find snapshot strategy to deal with snapshot:" + snapshotId); } postCreateSnapshot(volume.getId(), snapshotId, payload.getSnapshotPolicyId()); - + UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_CREATE, snapshot.getAccountId(), snapshot.getDataCenterId(), snapshotId, snapshot.getName(), null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid()); @@ -1159,7 +1161,7 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager, HypervisorType hypervisorType = volume.getHypervisorType(); SnapshotVO snapshotVO = new SnapshotVO(volume.getDataCenterId(), volume.getAccountId(), volume.getDomainId(), volume.getId(), volume.getDiskOfferingId(), snapshotName, (short) snapshotType.ordinal(), snapshotType.name(), volume.getSize(), hypervisorType); - + SnapshotVO snapshot = _snapshotDao.persist(snapshotVO); if (snapshot == null) { throw new CloudRuntimeException("Failed to create snapshot for volume: " + volume.getId());
