use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotObject method processEvent.
@Override
public void processEvent(final ObjectInDataStoreStateMachine.Event event, final Answer answer) {
try {
final SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findByStoreSnapshot(getDataStore().getRole(), getDataStore().getId(), getId());
if (answer instanceof CreateObjectAnswer) {
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CreateObjectAnswer) answer).getData();
snapshotStore.setInstallPath(snapshotTO.getPath());
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
} else if (answer instanceof CopyCmdAnswer) {
final SnapshotObjectTO snapshotTO = (SnapshotObjectTO) ((CopyCmdAnswer) answer).getNewData();
snapshotStore.setInstallPath(snapshotTO.getPath());
if (snapshotTO.getPhysicalSize() != null) {
// For S3 delta snapshot, physical size is currently not set
snapshotStore.setPhysicalSize(snapshotTO.getPhysicalSize());
}
if (snapshotTO.getParentSnapshotPath() == null) {
snapshotStore.setParentSnapshotId(0L);
}
snapshotStoreDao.update(snapshotStore.getId(), snapshotStore);
// update side-effect of snapshot operation
if (snapshotTO.getVolume() != null && snapshotTO.getVolume().getPath() != null) {
final VolumeVO vol = volumeDao.findByUuid(snapshotTO.getVolume().getUuid());
if (vol != null) {
s_logger.info("Update volume path change due to snapshot operation, volume " + vol.getId() + " path: " + vol.getPath() + "->" + snapshotTO.getVolume().getPath());
vol.setPath(snapshotTO.getVolume().getPath());
volumeDao.update(vol.getId(), vol);
} else {
s_logger.error("Cound't find the original volume with uuid: " + snapshotTO.getVolume().getUuid());
}
}
} else {
throw new CloudRuntimeException("Unknown answer: " + answer.getClass());
}
} catch (final RuntimeException ex) {
if (event == ObjectInDataStoreStateMachine.Event.OperationFailed) {
objectInStoreMgr.deleteIfNotReady(this);
}
throw ex;
}
this.processEvent(event);
}
use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotObject method getChild.
@Override
public SnapshotInfo getChild() {
final 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());
final SnapshotDataStoreVO vo = sc.find();
if (vo == null) {
return null;
}
return snapshotFactory.getSnapshot(vo.getId(), store);
}
use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotServiceImpl method findSnapshotImageStore.
// if a snapshot has parent snapshot, the new snapshot should be stored in
// the same store as its parent since
// we are taking delta snapshot
private DataStore findSnapshotImageStore(final SnapshotInfo snapshot) {
Boolean fullSnapshot = true;
final Object payload = snapshot.getPayload();
if (payload != null) {
fullSnapshot = (Boolean) payload;
}
if (fullSnapshot) {
return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
} else {
final SnapshotInfo parentSnapshot = snapshot.getParent();
// Note that DataStore information in parentSnapshot is for primary
// data store here, we need to
// find the image store where the parent snapshot backup is located
SnapshotDataStoreVO parentSnapshotOnBackupStore = null;
if (parentSnapshot != null) {
parentSnapshotOnBackupStore = _snapshotStoreDao.findBySnapshot(parentSnapshot.getId(), DataStoreRole.Image);
}
if (parentSnapshotOnBackupStore == null) {
return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
}
return dataStoreMgr.getDataStore(parentSnapshotOnBackupStore.getDataStoreId(), parentSnapshotOnBackupStore.getRole());
}
}
use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotDataStoreDaoImpl method updateVolumeIds.
@Override
public void updateVolumeIds(final long oldVolId, final long newVolId) {
final SearchCriteria<SnapshotDataStoreVO> sc = volumeIdSearch.create();
sc.setParameters("volume_id", oldVolId);
final SnapshotDataStoreVO snapshot = createForUpdate();
snapshot.setVolumeId(newVolId);
final UpdateBuilder ub = getUpdateBuilder(snapshot);
update(ub, sc, null);
}
use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotDataStoreDaoImpl method updateStoreRoleToCache.
@Override
public void updateStoreRoleToCache(final long storeId) {
final SearchCriteria<SnapshotDataStoreVO> sc = storeSearch.create();
sc.setParameters("store_id", storeId);
sc.setParameters("destroyed", false);
final List<SnapshotDataStoreVO> snaps = listBy(sc);
if (snaps != null) {
s_logger.info("Update to cache store role for " + snaps.size() + " entries in snapshot_store_ref");
for (final SnapshotDataStoreVO snap : snaps) {
snap.setRole(DataStoreRole.ImageCache);
update(snap.getId(), snap);
}
}
}
Aggregations