Search in sources :

Example 6 with SnapshotInfo

use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method syncSnapshotToRegionStore.

// push one individual snapshots currently on cache store to region store if it is not there already
private void syncSnapshotToRegionStore(final long snapshotId, final 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.
    final 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
        final SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId);
        if (srcSnapshot == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshotId + "  on cache store");
        }
        final AsyncCallFuture<SnapshotResult> future = syncToRegionStoreAsync(srcSnapshot, store);
        try {
            final 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());
            }
            // reduce reference count for template on cache, so it can recycled by schedule
            _cacheMgr.releaseCacheObject(srcSnapshot);
        } catch (final Exception ex) {
            throw new CloudRuntimeException("sync snapshot from cache to region wide store failed for image store " + store.getName());
        }
    }
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with SnapshotInfo

use of com.cloud.engine.subsystem.api.storage.SnapshotInfo 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 8 with SnapshotInfo

use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.

the class StorageSystemDataMotionStrategy method copyAsync.

@Override
public Void copyAsync(final DataObject srcData, final DataObject destData, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
    if (srcData instanceof SnapshotInfo) {
        final SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
        validate(snapshotInfo);
        final boolean canHandleSrc = canHandle(srcData.getDataStore());
        if (canHandleSrc && destData instanceof TemplateInfo && (destData.getDataStore().getRole() == DataStoreRole.Image || destData.getDataStore().getRole() == DataStoreRole.ImageCache)) {
            return handleCreateTemplateFromSnapshot(snapshotInfo, (TemplateInfo) destData, callback);
        }
        if (destData instanceof VolumeInfo) {
            final VolumeInfo volumeInfo = (VolumeInfo) destData;
            final boolean canHandleDest = canHandle(destData.getDataStore());
            if (canHandleSrc && canHandleDest) {
                return handleCreateVolumeFromSnapshotBothOnStorageSystem(snapshotInfo, volumeInfo, callback);
            }
            if (canHandleSrc) {
                throw new UnsupportedOperationException("This operation is not supported (DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT " + "not supported by destination storage plug-in).");
            }
            if (canHandleDest) {
                throw new UnsupportedOperationException("This operation is not supported (DataStoreCapabilities.STORAGE_SYSTEM_SNAPSHOT " + "not supported by source storage plug-in).");
            }
        }
    }
    throw new UnsupportedOperationException("This operation is not supported.");
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo)

Example 9 with SnapshotInfo

use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.

the class AncientDataMotionStrategy method copySnapshot.

protected Answer copySnapshot(final DataObject srcData, final DataObject destData) {
    final String value = configDao.getValue(Config.BackupSnapshotWait.toString());
    final int _backupsnapshotwait = NumbersUtil.parseInt(value, Integer.parseInt(Config.BackupSnapshotWait.getDefaultValue()));
    DataObject cacheData = null;
    final SnapshotInfo snapshotInfo = (SnapshotInfo) srcData;
    final Object payload = snapshotInfo.getPayload();
    Boolean fullSnapshot = true;
    if (payload != null) {
        fullSnapshot = (Boolean) payload;
    }
    final Map<String, String> options = new HashMap<>();
    options.put("fullSnapshot", fullSnapshot.toString());
    Answer answer = null;
    try {
        if (needCacheStorage(srcData, destData)) {
            final Scope selectedScope = pickCacheScopeForCopy(srcData, destData);
            cacheData = cacheMgr.getCacheObject(srcData, selectedScope);
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setCacheTO(cacheData.getTO());
            cmd.setOptions(options);
            final EndPoint ep = selector.select(srcData, destData);
            if (ep == null) {
                final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                s_logger.error(errMsg);
                answer = new Answer(cmd, false, errMsg);
            } else {
                answer = ep.sendMessage(cmd);
            }
        } else {
            final CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _backupsnapshotwait, VirtualMachineManager.ExecuteInSequence.value());
            cmd.setOptions(options);
            final EndPoint ep = selector.select(srcData, destData, StorageAction.BACKUPSNAPSHOT);
            if (ep == null) {
                final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
                s_logger.error(errMsg);
                answer = new Answer(cmd, false, errMsg);
            } else {
                answer = ep.sendMessage(cmd);
            }
        }
        // clean up cache entry
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        return answer;
    } catch (final Exception e) {
        s_logger.debug("copy snasphot failed: " + e.toString());
        if (cacheData != null) {
            cacheMgr.deleteCacheObject(cacheData);
        }
        throw new CloudRuntimeException(e.toString());
    }
}
Also used : HashMap(java.util.HashMap) CopyCommand(com.cloud.storage.command.CopyCommand) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) Answer(com.cloud.agent.api.Answer) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) ClusterScope(com.cloud.engine.subsystem.api.storage.ClusterScope) Scope(com.cloud.engine.subsystem.api.storage.Scope) ZoneScope(com.cloud.engine.subsystem.api.storage.ZoneScope) HostScope(com.cloud.engine.subsystem.api.storage.HostScope) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataObject(com.cloud.engine.subsystem.api.storage.DataObject)

Example 10 with SnapshotInfo

use of com.cloud.engine.subsystem.api.storage.SnapshotInfo in project cosmic by MissionCriticalCloud.

the class XenserverSnapshotStrategy method deleteSnapshot.

@Override
public boolean deleteSnapshot(final Long snapshotId) {
    final SnapshotVO snapshotVO = snapshotDao.findById(snapshotId);
    if (snapshotVO.getState() == Snapshot.State.Allocated) {
        snapshotDao.remove(snapshotId);
        return true;
    }
    if (snapshotVO.getState() == Snapshot.State.Destroyed) {
        return true;
    }
    if (Snapshot.State.Error.equals(snapshotVO.getState())) {
        final List<SnapshotDataStoreVO> storeRefs = snapshotStoreDao.findBySnapshotId(snapshotId);
        for (final SnapshotDataStoreVO ref : storeRefs) {
            snapshotStoreDao.expunge(ref.getId());
        }
        snapshotDao.remove(snapshotId);
        return true;
    }
    if (snapshotVO.getState() == Snapshot.State.CreatedOnPrimary) {
        s_logger.debug("delete snapshot on primary storage:");
        snapshotVO.setState(Snapshot.State.Destroyed);
        snapshotDao.update(snapshotId, snapshotVO);
        return true;
    }
    if (!Snapshot.State.BackedUp.equals(snapshotVO.getState()) && !Snapshot.State.Error.equals(snapshotVO.getState())) {
        throw new InvalidParameterValueException("Can't delete snapshotshot " + snapshotId + " due to it is in " + snapshotVO.getState() + " Status");
    }
    // first mark the snapshot as destroyed, so that ui can't see it, but we
    // may not destroy the snapshot on the storage, as other snapshots may
    // depend on it.
    final SnapshotInfo snapshotOnImage = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image);
    if (snapshotOnImage == null) {
        s_logger.debug("Can't find snapshot on backup storage, delete it in db");
        snapshotDao.remove(snapshotId);
        return true;
    }
    final SnapshotObject obj = (SnapshotObject) snapshotOnImage;
    try {
        obj.processEvent(Snapshot.Event.DestroyRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to set the state to destroying: ", e);
        return false;
    }
    try {
        final boolean result = deleteSnapshotChain(snapshotOnImage);
        obj.processEvent(Snapshot.Event.OperationSucceeded);
        if (result) {
            // snapshot is deleted on backup storage, need to delete it on primary storage
            final SnapshotDataStoreVO snapshotOnPrimary = snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Primary);
            if (snapshotOnPrimary != null) {
                snapshotOnPrimary.setState(State.Destroyed);
                snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary);
            }
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to delete snapshot: ", e);
        try {
            obj.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e.toString());
        }
        return false;
    }
    return true;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotVO(com.cloud.storage.SnapshotVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) SnapshotDataStoreVO(com.cloud.storage.datastore.db.SnapshotDataStoreVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)28 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)20 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 ExecutionException (java.util.concurrent.ExecutionException)10 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)9 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)9 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)9 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)8 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)8 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)7 DB (com.cloud.utils.db.DB)7 SnapshotVO (com.cloud.storage.SnapshotVO)6 SnapshotStrategy (com.cloud.engine.subsystem.api.storage.SnapshotStrategy)5 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4 VolumeVO (com.cloud.storage.VolumeVO)4 CommandResult (com.cloud.storage.command.CommandResult)4 ConfigurationException (javax.naming.ConfigurationException)4 Answer (com.cloud.agent.api.Answer)3 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)3