@Override protected Snapshot retrieve() { return _snapshotDao.findById(_snapshotId); } }
private List<SnapshotVO> listSnapsforVolume(long volumeId) { return _snapshotDao.listByVolumeId(volumeId); }
@Override public boolean canOperateOnVolume(Volume volume) { List<SnapshotVO> snapshots = _snapshotDao.listByStatus(volume.getId(), Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp); if (snapshots.size() > 0) { return false; } return true; }
private void updateLocationTypeInDb(SnapshotInfo snapshotInfo) { Object objPayload = snapshotInfo.getPayload(); if (objPayload instanceof CreateSnapshotPayload) { CreateSnapshotPayload payload = (CreateSnapshotPayload)objPayload; SnapshotVO snapshot = snapshotDao.findById(snapshotInfo.getId()); snapshot.setLocationType(payload.getLocationType()); snapshotDao.update(snapshotInfo.getId(), snapshot); } }
@Override public void cleanupVolumeDuringSnapshotFailure(Long volumeId, Long snapshotId) { SnapshotVO snaphsot = _snapshotDao.findById(snapshotId); if (snaphsot != null) { if (snaphsot.getState() != Snapshot.State.BackedUp) { List<SnapshotDataStoreVO> snapshotDataStoreVOs = _snapshotStoreDao.findBySnapshotId(snapshotId); for (SnapshotDataStoreVO snapshotDataStoreVO : snapshotDataStoreVOs) { s_logger.debug("Remove snapshot " + snapshotId + ", status " + snapshotDataStoreVO.getState() + " on snapshot_store_ref table with id: " + snapshotDataStoreVO.getId()); _snapshotStoreDao.remove(snapshotDataStoreVO.getId()); } s_logger.debug("Remove snapshot " + snapshotId + " status " + snaphsot.getState() + " from snapshot table"); _snapshotDao.remove(snapshotId); } } }
@Override public boolean deleteSnapshot(Long snapshotId) { SnapshotVO snapshotVO = snapshotDao.findById(snapshotId); snapshotDao.remove(snapshotId); return true; snapshotStoreDao.expunge(ref.getId()); snapshotDao.remove(snapshotId); return true; snapshotDao.update(snapshotId, snapshotVO); return true; if (snapshotOnImage == null) { s_logger.debug("Can't find snapshot on backup storage, delete it in db"); snapshotDao.remove(snapshotId); return true;
} else { if (!_snapshotDao.listByVolumeId(vol.getId()).isEmpty()) { _snapshotDao.updateVolumeIds(vol.getId(), result.getVolume().getId()); _snapshotDataStoreDao.updateVolumeIds(vol.getId(), result.getVolume().getId());
@Override public Snapshot archiveSnapshot(Long snapshotId) { SnapshotInfo snapshotOnPrimary = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary); if (snapshotOnPrimary == null || !snapshotOnPrimary.getStatus().equals(ObjectInDataStoreStateMachine.State.Ready)) { throw new CloudRuntimeException("Can only archive snapshots present on primary storage. " + "Cannot find snapshot " + snapshotId + " on primary storage"); } SnapshotInfo snapshotOnSecondary = snapshotSrv.backupSnapshot(snapshotOnPrimary); SnapshotVO snapshotVO = _snapshotDao.findById(snapshotOnSecondary.getId()); snapshotVO.setLocationType(Snapshot.LocationType.SECONDARY); _snapshotDao.persist(snapshotVO); try { snapshotSrv.deleteSnapshot(snapshotOnPrimary); } catch (Exception e) { throw new CloudRuntimeException("Snapshot archived to Secondary Storage but there was an error deleting " + " the snapshot on Primary Storage. Please manually delete the primary snapshot " + snapshotId, e); } return snapshotOnSecondary; }
SearchBuilder<SnapshotVO> sb = _snapshotDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); SearchCriteria<SnapshotVO> ssc = _snapshotDao.createSearchCriteria(); ssc.addOr("name", SearchCriteria.Op.LIKE, "%" + keyword + "%"); sc.addAnd("name", SearchCriteria.Op.SC, ssc); Pair<List<SnapshotVO>, Integer> result = _snapshotDao.searchAndCount(sc, searchFilter); return new Pair<List<? extends Snapshot>, Integer>(result.first(), result.second());
s_logger.debug("Can't find snapshot; deleting it in DB"); snapshotDao.remove(snapshotId);
snapshotSizeSearch.and("state", snapshotSizeSearch.entity().getState(), Op.EQ); 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);
_accountMgr.checkAccess(caller, null, true, vmSnapshot); SnapshotVO snapshot = _snapshotDao.findById(snapshotId); if (snapshot == null) { throw new InvalidParameterValueException("Creating snapshot failed due to snapshot:" + snapshotId + " doesn't exist"); if (parentSnapshotDataStoreVO != null) { SnapshotVO parentSnap = _snapshotDao.findById(parentSnapshotDataStoreVO.getSnapshotId()); if (parentSnap != null && parentSnapshotDataStoreVO.getInstallPath() != null && parentSnapshotDataStoreVO.getInstallPath().equals(vmSnapshot.getName())) { throw new InvalidParameterValueException("Creating snapshot failed due to snapshot : " + parentSnap.getUuid() + " is created from the same vm snapshot"); _snapshotStoreDao.update(snapshotOnPrimaryStore.getId(), snapshotOnPrimaryStore); snapshot.setState(Snapshot.State.CreatedOnPrimary); _snapshotDao.update(snapshot.getId(), snapshot);
@Override public boolean deleteSnapshot(Long snapshotId) { Preconditions.checkArgument(snapshotId != null, "'snapshotId' cannot be 'null'."); SnapshotVO snapshotVO = snapshotDao.findById(snapshotId); if (Snapshot.State.Destroyed.equals(snapshotVO.getState())) { return true; } if (Snapshot.State.Error.equals(snapshotVO.getState())) { snapshotDao.remove(snapshotId); return true; } if (!Snapshot.State.BackedUp.equals(snapshotVO.getState())) { throw new InvalidParameterValueException("Unable to delete snapshot '" + snapshotId + "' because it is in the following state: " + snapshotVO.getState()); } return cleanupSnapshotOnPrimaryStore(snapshotId); }
if (!_snapshotDao.listByVolumeId(srcVolumeInfo.getId()).isEmpty()) { _snapshotDao.updateVolumeIds(srcVolumeInfo.getId(), destVolumeInfo.getId()); _snapshotDataStoreDao.updateVolumeIds(srcVolumeInfo.getId(), destVolumeInfo.getId());
@Override public void doInTransactionWithoutResult(TransactionStatus status) { try { SnapshotObject srcSnapshot = (SnapshotObject)snapshot; srcSnapshot.processEvent(Event.DestroyRequested); srcSnapshot.processEvent(Event.OperationSuccessed); srcSnapshot.processEvent(Snapshot.Event.OperationFailed); _snapshotDetailsDao.removeDetail(srcSnapshot.getId(), AsyncJob.Constants.MS_ID); _snapshotDao.remove(srcSnapshot.getId()); } catch (NoTransitionException ex) { s_logger.debug("Failed to create backup " + ex.toString()); throw new CloudRuntimeException("Failed to backup snapshot" + snapshot.getId()); } } });
parentSnapshotSearch.done(); snapshotVOSearch = _snapshotDao.createSearchBuilder(); snapshotVOSearch.and("volume_id", snapshotVOSearch.entity().getVolumeId(), SearchCriteria.Op.EQ); snapshotVOSearch.done();
@Override public SnapshotInfo getSnapshot(long snapshotId, DataStore store) { SnapshotVO snapshot = snapshotDao.findById(snapshotId); SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store); return so; }
private List<SnapshotVO> getNonDestroyedSnapshots(long csVolumeId) { List<SnapshotVO> lstSnapshots = snapshotDao.listByVolumeId(csVolumeId); if (lstSnapshots == null) { lstSnapshots = new ArrayList<>(); } List<SnapshotVO> lstSnapshots2 = new ArrayList<>(); for (SnapshotVO snapshot : lstSnapshots) { if (!Snapshot.State.Destroyed.equals(snapshot.getState())) { lstSnapshots2.add(snapshot); } } return lstSnapshots2; }
private boolean checkStatusOfVolumeSnapshots(long vmId, Volume.Type type) { List<VolumeVO> listVolumes = null; if (type == Volume.Type.ROOT) { listVolumes = _volsDao.findByInstanceAndType(vmId, type); } else if (type == Volume.Type.DATADISK) { listVolumes = _volsDao.findByInstanceAndType(vmId, type); } else { listVolumes = _volsDao.findByInstance(vmId); } s_logger.debug("Found "+listVolumes.size()+" no. of volumes of type "+type+" for vm with VM ID "+vmId); for (VolumeVO volume : listVolumes) { Long volumeId = volume.getId(); s_logger.debug("Checking status of snapshots for Volume with Volume Id: "+volumeId); List<SnapshotVO> ongoingSnapshots = _snapshotDao.listByStatus(volumeId, Snapshot.State.Creating, Snapshot.State.CreatedOnPrimary, Snapshot.State.BackingUp); int ongoingSnapshotsCount = ongoingSnapshots.size(); s_logger.debug("The count of ongoing Snapshots for VM with ID "+vmId+" and disk type "+type+" is "+ongoingSnapshotsCount); if (ongoingSnapshotsCount > 0) { s_logger.debug("Found "+ongoingSnapshotsCount+" no. of snapshots, on volume of type "+type+", which snapshots are not yet backed up"); return true; } } return false; }
_snapshotDao.remove(destroyedSnapshotStoreVO.getSnapshotId()); SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary); if (snapshotOnPrimary != null) {