@Override public Snapshot backupSnapshot(Long snapshotId) { SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Image); if (snapshot != null) { throw new CloudRuntimeException("Already in the backup snapshot:" + snapshotId); } return snapshotSrv.backupSnapshot(snapshot); }
private void syncSnapshotToRegionStore(long snapshotId, DataStore store){ // if snapshot is already on region wide object store, check if it is really downloaded there (by checking install_path). Sync snapshot to region // wide store if it is not there physically. SnapshotInfo snapOnStore = _snapshotFactory.getSnapshot(snapshotId, store); if (snapOnStore == null) { throw new CloudRuntimeException("Cannot find an entry in snapshot_store_ref for snapshot " + snapshotId + " on region store: " + store.getName()); } if (snapOnStore.getPath() == null || snapOnStore.getPath().length() == 0) { if (s_logger.isDebugEnabled()) { s_logger.debug("sync snapshot " + snapshotId + " from cache to object store..."); } // snapshot is not on region store yet, sync to region store SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId); if (srcSnapshot == null) { throw new CloudRuntimeException("Cannot find snapshot " + snapshotId + " on cache store"); } AsyncCallFuture<SnapshotResult> future = syncToRegionStoreAsync(srcSnapshot, store); try { SnapshotResult result = future.get(); if (result.isFailed()) { throw new CloudRuntimeException("sync snapshot from cache to region wide store failed for image store " + store.getName() + ":" + result.getResult()); } _cacheMgr.releaseCacheObject(srcSnapshot); // reduce reference count for template on cache, so it can recycled by schedule } catch (Exception ex) { throw new CloudRuntimeException("sync snapshot from cache to region wide store failed for image store " + store.getName()); } } }
@Override public void cleanupSnapshotsByVolume(Long volumeId) { List<SnapshotInfo> infos = snapshotFactory.getSnapshots(volumeId, DataStoreRole.Primary); for(SnapshotInfo info: infos) { try { if(info != null) { snapshotSrv.deleteSnapshot(info); } } catch(CloudRuntimeException e) { String msg = "Cleanup of Snapshot with uuid " + info.getUuid() + " in primary storage is failed. Ignoring"; s_logger.warn(msg); } } }
if (r) { List<SnapshotInfo> cacheSnaps = snapshotDataFactory.listSnapshotOnCache(snapshot.getId()); for (SnapshotInfo cacheSnap : cacheSnaps) { s_logger.debug("Delete snapshot " + snapshot.getId() + " from image cache store: " + cacheSnap.getDataStore().getName());
@Override public SnapshotInfo getParent() { SnapshotDataStoreVO snapStoreVO = snapshotStoreDao.findByStoreSnapshot(store.getRole(), store.getId(), snapshot.getId()); Long parentId = null; if (snapStoreVO != null) { parentId = snapStoreVO.getParentSnapshotId(); if (parentId != null && parentId != 0) { return snapshotFactory.getSnapshot(parentId, store); } } return null; }
@Override public DataObject get(DataObject dataObj, DataStore store) { if (dataObj.getType() == DataObjectType.TEMPLATE) { return imageFactory.getTemplate(dataObj, store); } else if (dataObj.getType() == DataObjectType.VOLUME) { return volumeFactory.getVolume(dataObj, store); } else if (dataObj.getType() == DataObjectType.SNAPSHOT) { return snapshotFactory.getSnapshot(dataObj, store); } throw new CloudRuntimeException("unknown type"); }
SnapshotObject snapshotObj = (SnapshotObject)snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Primary);
for (SnapshotDataStoreVO destroyedSnapshotStoreVO : destroyedSnapshotStoreVOs) { SnapshotInfo snap = snapshotFactory.getSnapshot(destroyedSnapshotStoreVO.getSnapshotId(), store); if (snap.getChild() != null) { s_logger.debug("Skip snapshot on store: " + destroyedSnapshotStoreVO + " , because it has child");
SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotDetailsVO.getResourceId(), DataStoreRole.Primary); snapshotSrv.processEventOnSnapshotObject(snapshot, Snapshot.Event.OperationFailed); _snapshotDetailsDao.removeDetail(snapshotDetailsVO.getResourceId(), AsyncJob.Constants.MS_ID);
@Override public boolean revertSnapshot(SnapshotInfo snapshot) { SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary); if (snapshotOnPrimaryStore == null) { throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools"); } PrimaryDataStore store = (PrimaryDataStore)snapshotOnPrimaryStore.getDataStore(); AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>(); RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future); AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this); caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context); ((PrimaryDataStoreDriver)store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller); SnapshotResult result = null; try { result = future.get(); if (result.isFailed()) { throw new CloudRuntimeException(result.getResult()); } return true; } catch (InterruptedException e) { s_logger.debug("revert snapshot is failed: " + e.toString()); } catch (ExecutionException e) { s_logger.debug("revert snapshot is failed: " + e.toString()); } return false; }
private AsyncCallFuture<SnapshotResult> syncToRegionStoreAsync(SnapshotInfo snapshot, DataStore store) { AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>(); // no need to create entry on snapshot_store_ref here, since entries are already created when updateCloudToUseObjectStore is invoked. // But we need to set default install path so that sync can be done in the right s3 path SnapshotInfo snapshotOnStore = _snapshotFactory.getSnapshot(snapshot, store); String installPath = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshot.getAccountId() + "/" + snapshot.getVolumeId(); ((SnapshotObject)snapshotOnStore).setPath(installPath); CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnStore, future); AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher .create(this); caller.setCallback(caller.getTarget().syncSnapshotCallBack(null, null)).setContext(context); motionSrv.copyAsync(snapshot, snapshotOnStore, caller); return future; }
@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; }
DataStore store = dataStoreMgr.getDataStore(pool.getId(), DataStoreRole.Primary); DataStoreRole dataStoreRole = getDataStoreRole(snapshot); SnapshotInfo snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole); snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary); snapInfo = snapshotFactory.getSnapshot(snapshot.getId(), dataStoreRole); if (snapInfo == null) { throw new CloudRuntimeException("Cannot find snapshot " + snapshot.getId() + " on secondary and could not create backup");
SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary); if(snapshot == null)
SnapshotInfo snapshot = snapshotFactory.getSnapshot(snapshotId, volume.getDataStore()); snapshot.addPayload(payload); try {
SnapshotInfo snapshotOnImage = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image); if (snapshotOnImage == null) { s_logger.debug("Can't find snapshot on backup storage, delete it in db"); SnapshotInfo snapshotOnPrimaryInfo = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Primary); long volumeId = snapshotOnPrimary.getVolumeId(); VolumeVO volumeVO = volumeDao.findById(volumeId);
destSnapshot.processEvent(Event.OperationSuccessed, copyCmdAnswer); srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded); snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), copyCmdAnswer); future.complete(snapResult); } catch (Exception e) {
SnapshotInfo snapshotInfo = snapshotFactory.getSnapshot(snapshotId, dataStoreRole); if (snapshotInfo == null) { throw new CloudRuntimeException("snapshot:" + snapshotId + " not exist in data store");
@Override public SnapshotInfo getChild() { QueryBuilder<SnapshotDataStoreVO> sc = QueryBuilder.create(SnapshotDataStoreVO.class); sc.and(sc.entity().getDataStoreId(), Op.EQ, store.getId()); sc.and(sc.entity().getRole(), Op.EQ, store.getRole()); sc.and(sc.entity().getState(), Op.NIN, State.Destroying, State.Destroyed, State.Error); sc.and(sc.entity().getParentSnapshotId(), Op.EQ, getId()); SnapshotDataStoreVO vo = sc.find(); if (vo == null) { return null; } return snapshotFactory.getSnapshot(vo.getId(), store); }
DataStoreRole dataStoreRole = ApiResponseHelper.getDataStoreRole(snapshot, _snapshotStoreDao, _dataStoreMgr); SnapshotInfo snapInfo = _snapshotFactory.getSnapshot(snapshotId, dataStoreRole); snapInfo = _snapshotFactory.getSnapshot(snapshotId, DataStoreRole.Primary); if(snapInfo == null) { throw new CloudRuntimeException("Cannot find snapshot "+snapshotId); snapInfo = _snapshotFactory.getSnapshot(snapshotId, dataStoreRole); if(snapInfo == null) { throw new CloudRuntimeException("Cannot find snapshot " + snapshotId + " on secondary and could not create backup");