Search in sources :

Example 11 with CommandResult

use of com.cloud.storage.command.CommandResult 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 12 with CommandResult

use of com.cloud.storage.command.CommandResult 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 13 with CommandResult

use of com.cloud.storage.command.CommandResult 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)

Example 14 with CommandResult

use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method revertSnapshotCallback.

protected Void revertSnapshotCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CommandResult> callback, final RevertSnapshotContext<CommandResult> context) {
    final CommandResult result = callback.getResult();
    final AsyncCallFuture<SnapshotResult> future = context.future;
    SnapshotResult res = null;
    try {
        if (result.isFailed()) {
            s_logger.debug("revert snapshot failed" + result.getResult());
            res = new SnapshotResult(context.snapshot, null);
            res.setResult(result.getResult());
        } else {
            res = new SnapshotResult(context.snapshot, null);
        }
    } catch (final Exception e) {
        s_logger.debug("Failed to in revertSnapshotCallback", e);
        res.setResult(e.toString());
    }
    future.complete(res);
    return null;
}
Also used : 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 15 with CommandResult

use of com.cloud.storage.command.CommandResult in project cosmic by MissionCriticalCloud.

the class SnapshotServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<SnapshotResult> syncToRegionStoreAsync(final SnapshotInfo snapshot, final DataStore store) {
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    // 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
    final SnapshotInfo snapshotOnStore = _snapshotFactory.getSnapshot(snapshot, store);
    final String installPath = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshot.getAccountId() + "/" + snapshot.getVolumeId();
    ((SnapshotObject) snapshotOnStore).setPath(installPath);
    final CopySnapshotContext<CommandResult> context = new CopySnapshotContext<>(null, snapshot, snapshotOnStore, future);
    final 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(com.cloud.framework.async.AsyncCallFuture) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CommandResult (com.cloud.storage.command.CommandResult)18 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)16 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 ExecutionException (java.util.concurrent.ExecutionException)11 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)8 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)7 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)6 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)6 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)5 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)4 Answer (com.cloud.agent.api.Answer)3 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)3 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)2 PrimaryDataStoreDriver (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)2 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)2