Search in sources :

Example 6 with SnapshotResult

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

the class SnapshotServiceImpl method copySnapshotAsyncCallback.

protected Void copySnapshotAsyncCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, final CopySnapshotContext<CommandResult> context) {
    final CopyCommandResult result = callback.getResult();
    final SnapshotInfo destSnapshot = context.destSnapshot;
    final SnapshotObject srcSnapshot = (SnapshotObject) context.srcSnapshot;
    final AsyncCallFuture<SnapshotResult> future = context.future;
    SnapshotResult snapResult = new SnapshotResult(destSnapshot, result.getAnswer());
    if (result.isFailed()) {
        try {
            destSnapshot.processEvent(Event.OperationFailed);
            // if backup snapshot failed, mark srcSnapshot in snapshot_store_ref as failed also
            srcSnapshot.processEvent(Event.DestroyRequested);
            srcSnapshot.processEvent(Event.OperationSuccessed);
            srcSnapshot.processEvent(Snapshot.Event.OperationFailed);
            _snapshotDao.remove(srcSnapshot.getId());
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to update state: " + e.toString());
        }
        snapResult.setResult(result.getResult());
        future.complete(snapResult);
        return null;
    }
    try {
        final CopyCmdAnswer copyCmdAnswer = (CopyCmdAnswer) result.getAnswer();
        destSnapshot.processEvent(Event.OperationSuccessed, copyCmdAnswer);
        srcSnapshot.processEvent(Snapshot.Event.OperationSucceeded);
        snapResult = new SnapshotResult(_snapshotFactory.getSnapshot(destSnapshot.getId(), destSnapshot.getDataStore()), copyCmdAnswer);
        future.complete(snapResult);
    } catch (final Exception e) {
        s_logger.debug("Failed to update snapshot state", e);
        snapResult.setResult(e.toString());
        future.complete(snapResult);
    }
    return null;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with SnapshotResult

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

the class SnapshotServiceImpl method revertSnapshot.

@Override
public boolean revertSnapshot(final SnapshotInfo snapshot) {
    final 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");
    }
    final PrimaryDataStore store = (PrimaryDataStore) snapshotOnPrimaryStore.getDataStore();
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    final RevertSnapshotContext<CommandResult> context = new RevertSnapshotContext<>(null, snapshot, future);
    final 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 (final InterruptedException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    } catch (final ExecutionException e) {
        s_logger.debug("revert snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

Example 8 with SnapshotResult

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

the class SnapshotServiceImpl method syncSnapshotCallBack.

protected Void syncSnapshotCallBack(final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> callback, final CopySnapshotContext<CommandResult> context) {
    final CopyCommandResult result = callback.getResult();
    final SnapshotInfo destSnapshot = context.destSnapshot;
    final SnapshotResult res = new SnapshotResult(destSnapshot, null);
    final 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 (final Exception e) {
        s_logger.debug("Failed to process sync snapshot callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with SnapshotResult

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

the class SnapshotServiceImpl method deleteSnapshotCallback.

protected Void deleteSnapshotCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, final DeleteSnapshotContext<CommandResult> context) {
    final CommandResult result = callback.getResult();
    final AsyncCallFuture<SnapshotResult> future = context.future;
    final SnapshotInfo snapshot = context.snapshot;
    SnapshotResult res = null;
    try {
        if (result.isFailed()) {
            s_logger.debug("delete snapshot failed" + result.getResult());
            snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
            res = new SnapshotResult(context.snapshot, null);
            res.setResult(result.getResult());
        } else {
            snapshot.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
            res = new SnapshotResult(context.snapshot, null);
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to in deleteSnapshotCallback", e);
        res.setResult(e.toString());
    }
    future.complete(res);
    return null;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 10 with SnapshotResult

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

the class SnapshotServiceImpl method deleteSnapshot.

@Override
public boolean deleteSnapshot(final SnapshotInfo snapInfo) {
    snapInfo.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    final DeleteSnapshotContext<CommandResult> context = new DeleteSnapshotContext<>(null, snapInfo, future);
    final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteSnapshotCallback(null, null)).setContext(context);
    final DataStore store = snapInfo.getDataStore();
    store.getDriver().deleteAsync(store, snapInfo, caller);
    SnapshotResult result = null;
    try {
        result = future.get();
        if (result.isFailed()) {
            throw new CloudRuntimeException(result.getResult());
        }
        return true;
    } catch (final InterruptedException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    } catch (final ExecutionException e) {
        s_logger.debug("delete snapshot is failed: " + e.toString());
    }
    return false;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)13 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 ExecutionException (java.util.concurrent.ExecutionException)10 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)9 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)9 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)8 CommandResult (com.cloud.storage.command.CommandResult)7 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)5 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)3 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)2 PrimaryDataStoreDriver (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)2 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)2 SnapshotVO (com.cloud.storage.SnapshotVO)2 DB (com.cloud.utils.db.DB)2 CreateSnapshotPayload (com.cloud.storage.CreateSnapshotPayload)1 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)1 SnapshotDataStoreVO (com.cloud.storage.datastore.db.SnapshotDataStoreVO)1 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)1