Search in sources :

Example 16 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotServiceImpl method syncSnapshotCallBack.

protected Void syncSnapshotCallBack(AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, CopySnapshotContext<CommandResult> context) {
    CopyCommandResult result = callback.getResult();
    SnapshotInfo destSnapshot = context.destSnapshot;
    SnapshotResult res = new SnapshotResult(destSnapshot, null);
    AsyncCallFuture<SnapshotResult> future = context.future;
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
        // no change to existing snapshot_store_ref, will try to re-sync later if other call triggers this sync operation
        } else {
            // this will update install path properly, next time it will not sync anymore.
            destSnapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (Exception e) {
        s_logger.debug("Failed to process sync snapshot callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 17 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotServiceImpl method revertSnapshot.

@Override
public boolean revertSnapshot(SnapshotInfo snapshot) {
    SnapshotInfo snapshotOnPrimaryStore = _snapshotFactory.getSnapshot(snapshot.getId(), DataStoreRole.Primary);
    if (snapshotOnPrimaryStore == null) {
        throw new CloudRuntimeException("Cannot find an entry for snapshot " + snapshot.getId() + " on primary storage pools");
    }
    PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<CommandResult>(null, snapshot, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().revertSnapshotCallback(null, null)).setContext(context);
    ((PrimaryDataStoreDriver) store.getDriver()).revertSnapshot(snapshot, snapshotOnPrimaryStore, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (InterruptedException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    } catch (ExecutionException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)

Example 18 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

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(SnapshotInfo snapshot) {
    Boolean fullSnapshot = true;
    Object payload = snapshot.getPayload();
    if (payload != null) {
        fullSnapshot = (Boolean) payload;
    }
    if (fullSnapshot) {
        return dataStoreMgr.getImageStore(snapshot.getDataCenterId());
    } else {
        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(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotDataStoreVO(org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)

Example 19 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

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(long snapshotId, 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.
    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
        SnapshotInfo srcSnapshot = _snapshotFactory.getReadySnapshotOnCache(snapshotId);
        if (srcSnapshot == null) {
            throw new CloudRuntimeException("Cannot find snapshot " + snapshotId + "  on cache store");
        }
        AsyncCallFuture<SnapshotResult> future = syncToRegionStoreAsync(srcSnapshot, store);
        try {
            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 (Exception ex) {
            throw new CloudRuntimeException("sync snapshot from cache to region wide store failed for image store " + store.getName());
        }
    }
}
Also used : SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(org.apache.cloudstack.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 20 with SnapshotInfo

use of org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo in project cloudstack by apache.

the class SnapshotServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<SnapshotResult> syncToRegionStoreAsync(SnapshotInfo snapshot, DataStore store) {
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    // no need to create entry on snapshot_store_ref here, since entries are already created when updateCloudToUseObjectStore is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    SnapshotInfo snapshotOnStore = _snapshotFactory.getSnapshot(snapshot, store);
    String installPath = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshot.getAccountId() + "/" + snapshot.getVolumeId();
    ((SnapshotObject) snapshotOnStore).setPath(installPath);
    CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnStore, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncSnapshotCallBack(null, null)).setContext(context);
    motionSrv.copyAsync(snapshot, snapshotOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)40 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)17 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)16 SnapshotVO (com.cloud.storage.SnapshotVO)15 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)11 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)11 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)10 ExecutionException (java.util.concurrent.ExecutionException)10 SnapshotDataStoreVO (org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO)10 SnapshotStrategy (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotStrategy)9 DB (com.cloud.utils.db.DB)8 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)8 VolumeVO (com.cloud.storage.VolumeVO)7 TemplateInfo (org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo)6 CommandResult (org.apache.cloudstack.storage.command.CommandResult)6 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)5 Answer (com.cloud.agent.api.Answer)4 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)4 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)4