Search in sources :

Example 1 with SnapshotDataStoreVO

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;
}
Also used : SnapshotVO(com.cloud.storage.SnapshotVO) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 2 with SnapshotDataStoreVO

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;
}
Also used : SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 3 with SnapshotDataStoreVO

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);
}
Also used : SnapshotObjectTO(com.cloud.storage.to.SnapshotObjectTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) CreateObjectAnswer(com.cloud.storage.command.CreateObjectAnswer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 4 with SnapshotDataStoreVO

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);
}
Also used : SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Example 5 with SnapshotDataStoreVO

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());
    }
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO)

Aggregations

SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)34 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)12 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)10 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)9 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)9 SnapshotVO (com.cloud.storage.SnapshotVO)8 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)8 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Date (java.util.Date)5 ConfigurationException (javax.naming.ConfigurationException)5 SnapshotStrategy (com.cloud.engine.subsystem.api.storage.SnapshotStrategy)4 DB (com.cloud.utils.db.DB)4 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 VMTemplateStoragePoolVO (com.cloud.storage.VMTemplateStoragePoolVO)3 VolumeVO (com.cloud.storage.VolumeVO)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)2