use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotDataFactoryImpl method getSnapshot.
@Override
public SnapshotInfo getSnapshot(final long snapshotId, final DataStoreRole role) {
final SnapshotVO snapshot = snapshotDao.findById(snapshotId);
SnapshotDataStoreVO snapshotStore = snapshotStoreDao.findBySnapshot(snapshotId, role);
if (snapshotStore == null) {
snapshotStore = snapshotStoreDao.findByVolume(snapshot.getVolumeId(), role);
if (snapshotStore == null) {
return null;
}
}
final DataStore store = storeMgr.getDataStore(snapshotStore.getDataStoreId(), role);
final SnapshotObject so = SnapshotObject.getSnapshotObject(snapshot, store);
return so;
}
use of com.cloud.storage.datastore.db.SnapshotDataStoreVO in project cosmic by MissionCriticalCloud.
the class SnapshotObject method getParent.
@Override
public SnapshotInfo getParent() {
final 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;
}
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());
}
}
Aggregations