Search in sources :

Example 6 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 7 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 8 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)

Example 9 with SnapshotDataStoreVO

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

Example 10 with SnapshotDataStoreVO

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);
        }
    }
}
Also used : 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