@Override public long getAccountId() { return snapshot.getAccountId(); }
@Override public long getId() { return snapshot.getId(); }
@Override public State getState() { return snapshot.getState(); }
@Override public boolean start() { //destroy snapshots in destroying state List<SnapshotVO> snapshots = _snapshotDao.listAllByStatus(Snapshot.State.Destroying); for (SnapshotVO snapshotVO : snapshots) { try { if (!deleteSnapshot(snapshotVO.getId())) { s_logger.debug("Failed to delete snapshot in destroying state with id " + snapshotVO.getUuid()); } } catch (Exception e) { s_logger.debug("Failed to delete snapshot in destroying state with id " + snapshotVO.getUuid()); } } return true; }
@Override public boolean updateState(State currentState, Event event, State nextState, SnapshotVO snapshot, Object data) { TransactionLegacy txn = TransactionLegacy.currentTxn(); txn.start(); SnapshotVO snapshotVO = snapshot; snapshotVO.setState(nextState); super.update(snapshotVO.getId(), snapshotVO); txn.commit(); return true; }
_accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); 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); sb.and("idIN", sb.entity().getId(), SearchCriteria.Op.IN); sb.and("snapshotTypeEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.IN); sb.and("snapshotTypeNEQ", sb.entity().getsnapshotType(), SearchCriteria.Op.NEQ); sb.and("dataCenterId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ); sb.groupBy(sb.entity().getId()); sb.join("tagSearch", tagSearch, sb.entity().getId(), tagSearch.entity().getResourceId(), JoinBuilder.JoinType.INNER); Type snapshotType = SnapshotVO.getSnapshotType(snapshotTypeStr); if (snapshotType == null) { throw new InvalidParameterValueException("Unsupported snapshot type " + snapshotTypeStr); Type type = SnapshotVO.getSnapshotType(intervalTypeStr); if (type == null) { throw new InvalidParameterValueException("Unsupported snapstho interval type " + intervalTypeStr);
if (snapshotCheck.getState() == Snapshot.State.Destroyed) { throw new InvalidParameterValueException("Snapshot with id: " + snapshotId + " is already destroyed"); if (snapshotCheck.getState() == Snapshot.State.BackedUp) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_DELETE, snapshotCheck.getAccountId(), snapshotCheck.getDataCenterId(), snapshotId, snapshotCheck.getName(), null, null, 0L, snapshotCheck.getClass().getName(), snapshotCheck.getUuid()); if (snapshotCheck.getState() != Snapshot.State.Error && snapshotCheck.getState() != Snapshot.State.Destroyed) { _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.snapshot); if (snapshotCheck.getState() == Snapshot.State.BackedUp) { if (snapshotStoreRef != null) { _resourceLimitMgr.decrementResourceCount(snapshotCheck.getAccountId(), ResourceType.secondary_storage, new Long(snapshotStoreRef.getPhysicalSize())); s_logger.debug("Failed to delete snapshot: " + snapshotCheck.getId() + ":" + e.toString());
@PostConstruct protected void init() { VolumeIdSearch = createSearchBuilder(); VolumeIdSearch.and("volumeId", VolumeIdSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdSearch.done(); VolumeIdTypeSearch.and("volumeId", VolumeIdTypeSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdTypeSearch.and("type", VolumeIdTypeSearch.entity().getsnapshotType(), SearchCriteria.Op.EQ); VolumeIdTypeSearch.done(); 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.and("volumeId", VolumeIdVersionSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); VolumeIdVersionSearch.and("version", VolumeIdVersionSearch.entity().getVersion(), SearchCriteria.Op.EQ); VolumeIdVersionSearch.done(); AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountIdSearch.done(); StatusSearch.and("volumeId", StatusSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); StatusSearch.and("status", StatusSearch.entity().getState(), SearchCriteria.Op.IN); StatusSearch.done(); notInStatusSearch.and("volumeId", notInStatusSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); notInStatusSearch.and("status", notInStatusSearch.entity().getState(), SearchCriteria.Op.NOTIN); notInStatusSearch.done();
if (snapshotCheck.getState() != Snapshot.State.BackedUp) { throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.State.BackedUp + " state yet and can't be used for volume creation"); parentVolume = _volsDao.findByIdIncludingRemoved(snapshotCheck.getVolumeId()); diskOfferingId = snapshotCheck.getDiskOfferingId(); diskOffering = _diskOfferingDao.findById(diskOfferingId); if (zoneId == null) { zoneId = snapshotCheck.getDataCenterId(); size = snapshotCheck.getSize(); // ; disk offering is used for tags minIops = snapshotCheck.getMinIops(); maxIops = snapshotCheck.getMaxIops();
SnapshotStrategy snapshotStrategy = _storageStrategyFactory.getSnapshotStrategy(snapshot, SnapshotOperation.DELETE); if (snapshotStrategy == null) { s_logger.error("Unable to find snaphot strategy to handle snapshot with id '" + snapshot.getId() + "'"); continue; SnapshotDataStoreVO snapshotStoreRef = _snapshotStoreDao.findBySnapshot(snapshot.getId(), DataStoreRole.Image); if (snapshotStrategy.deleteSnapshot(snapshot.getId())) { if (Type.MANUAL == snapshot.getRecurringType()) { _resourceLimitMgr.decrementResourceCount(accountId, ResourceType.snapshot); if (snapshotStoreRef != null) { UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_DELETE, snapshot.getAccountId(), volume.getDataCenterId(), snapshot.getId(), snapshot.getName(), null, null, volume.getSize(), snapshot.getClass().getName(), snapshot.getUuid());
volume = _volumeDao.findByIdIncludingRemoved(snapshot.getVolumeId()); if (snapshot.getState() != Snapshot.State.BackedUp) { throw new InvalidParameterValueException("Snapshot id=" + snapshotId + " is not in " + Snapshot.State.BackedUp + " state yet and can't be used for template creation"); hyperType = snapshot.getHypervisorType(); _resourceLimitMgr.checkResourceLimit(templateOwner, ResourceType.secondary_storage, new Long(volume != null ? volume.getSize() : snapshot.getSize()).longValue()); new Long(volume != null ? volume.getSize() : snapshot.getSize()));
private void postCreateRecurringSnapshotForPolicy(long userId, long volumeId, long snapshotId, long policyId) { // Use count query SnapshotVO spstVO = _snapshotDao.findById(snapshotId); Type type = spstVO.getRecurringType(); int maxSnaps = type.getMax(); List<SnapshotVO> snaps = listSnapsforVolumeTypeNotDestroyed(volumeId, type); SnapshotPolicyVO policy = _snapshotPolicyDao.findById(policyId); if (policy != null && policy.getMaxSnaps() < maxSnaps) { maxSnaps = policy.getMaxSnaps(); } while (snaps.size() > maxSnaps && snaps.size() > 1) { SnapshotVO oldestSnapshot = snaps.get(0); long oldSnapId = oldestSnapshot.getId(); if (policy != null) { s_logger.debug("Max snaps: " + policy.getMaxSnaps() + " exceeded for snapshot policy with Id: " + policyId + ". Deleting oldest snapshot: " + oldSnapId); } if (deleteSnapshot(oldSnapId)) { //log Snapshot delete event ActionEventUtils.onCompletedActionEvent(User.UID_SYSTEM, oldestSnapshot.getAccountId(), EventVO.LEVEL_INFO, EventTypes.EVENT_SNAPSHOT_DELETE, "Successfully deleted oldest snapshot: " + oldSnapId, 0); } snaps.remove(oldestSnapshot); } }
VolumeVO volume = _volsDao.findById(snapshot.getVolumeId()); if (volume.getState() != Volume.State.Ready) { throw new InvalidParameterValueException("The volume is not in Ready state."); if (result) { _resourceLimitMgr.decrementResourceCount(snapshot.getAccountId(), ResourceType.primary_storage, new Long(volume.getSize() - snapshot.getSize())); volume.setSize(snapshot.getSize()); _volsDao.update(volume.getId(), volume); return snapshotInfo;
@Override public long getVolumeId() { return snapshot.getVolumeId(); }
volumeId = snapshot.getVolumeId(); List<SnapshotVO> lstSnapshots = getNonDestroyedSnapshots(snapshot.getVolumeId()); if (snapshotVo.getId() != csSnapshotId) { snapshotDetails = snapshotDetailsDao.findDetail(snapshotVo.getId(), SolidFireUtil.SNAPSHOT_ID);
snapshotSizeSearch.and("storeRole", snapshotSizeSearch.entity().getRole(), Op.EQ); SearchBuilder<SnapshotVO> join2 = _snapshotDao.createSearchBuilder(); join2.and("accountId", join2.entity().getAccountId(), Op.EQ); snapshotSizeSearch.join("snapshots", join2, snapshotSizeSearch.entity().getSnapshotId(), join2.entity().getId(), JoinBuilder.JoinType.INNER); snapshotSizeSearch.done();
throw new InvalidParameterValueException("Creating snapshot failed due to snapshot : " + parentSnap.getUuid() + " is created from the same vm snapshot"); SnapshotDataStoreVO snapshotOnPrimaryStore = this._snapshotStoreDao.findBySnapshot(snapshot.getId(), store.getRole()); snapshotOnPrimaryStore.setState(ObjectInDataStoreStateMachine.State.Ready); snapshotOnPrimaryStore.setInstallPath(vmSnapshot.getName()); _snapshotStoreDao.update(snapshotOnPrimaryStore.getId(), snapshotOnPrimaryStore); snapshot.setState(Snapshot.State.CreatedOnPrimary); _snapshotDao.update(snapshot.getId(), snapshot);
SnapshotVO snapshotVO = snapshotDao.findById(snapshotId); if (snapshotVO.getState() == Snapshot.State.Allocated) { snapshotDao.remove(snapshotId); return true; if (snapshotVO.getState() == Snapshot.State.Destroyed) { return true; if (Snapshot.State.Error.equals(snapshotVO.getState())) { List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId); for (SnapshotDataStoreVO ref : storeRefs) { if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) { snapshotVO.setState(Snapshot.State.Destroyed); snapshotDao.update(snapshotId, snapshotVO); return true; if (!Snapshot.State.BackedUp.equals(snapshotVO.getState()) && !Snapshot.State.Error.equals(snapshotVO.getState()) && !Snapshot.State.Destroying.equals(snapshotVO.getState())) { throw new InvalidParameterValueException("Can't delete snapshotshot " + snapshotId + " due to it is in " + snapshotVO.getState() + " Status");
@Override public HypervisorType getHypervisorType() { return snapshot.getHypervisorType(); }
@Override public short getsnapshotType() { return snapshot.getsnapshotType(); }