Search in sources :

Example 26 with CopyCommandResult

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

the class TemplateServiceImpl method syncTemplateCallBack.

protected Void syncTemplateCallBack(final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final TemplateInfo destTemplate = context.getTemplate();
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<TemplateApiResult> future = context.getFuture();
    final TemplateApiResult res = new TemplateApiResult(destTemplate);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
        // no change to existing template_store_ref, will try to re-sync later if other call triggers this sync operation, like copy template
        } else {
            // this will update install path properly, next time it will not sync anymore.
            destTemplate.processEvent(Event.OperationSuccessed, result.getAnswer());
        }
        future.complete(res);
    } catch (final Exception e) {
        s_logger.debug("Failed to process sync template callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 27 with CopyCommandResult

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

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

use of com.cloud.engine.subsystem.api.storage.CopyCommandResult 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)

Example 30 with CopyCommandResult

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

the class SnapshotServiceImpl method backupSnapshot.

@Override
public SnapshotInfo backupSnapshot(final SnapshotInfo snapshot) {
    final SnapshotObject snapObj = (SnapshotObject) snapshot;
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    final SnapshotResult result = new SnapshotResult(snapshot, null);
    try {
        snapObj.processEvent(Snapshot.Event.BackupToSecondary);
        final DataStore imageStore = findSnapshotImageStore(snapshot);
        if (imageStore == null) {
            throw new CloudRuntimeException("can not find an image stores");
        }
        final SnapshotInfo snapshotOnImageStore = (SnapshotInfo) imageStore.create(snapshot);
        snapshotOnImageStore.processEvent(Event.CreateOnlyRequested);
        final CopySnapshotContext<CommandResult> context = new CopySnapshotContext<>(null, snapshot, snapshotOnImageStore, future);
        final AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copySnapshotAsyncCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, snapshotOnImageStore, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to copy snapshot", e);
        result.setResult("Failed to copy snapshot:" + e.toString());
        try {
            snapObj.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change state: " + e1.toString());
        }
        future.complete(result);
    }
    try {
        final SnapshotResult res = future.get();
        if (res.isFailed()) {
            throw new CloudRuntimeException(res.getResult());
        }
        final SnapshotInfo destSnapshot = res.getSnashot();
        return destSnapshot;
    } catch (final InterruptedException e) {
        s_logger.debug("failed copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    } catch (final ExecutionException e) {
        s_logger.debug("Failed to copy snapshot", e);
        throw new CloudRuntimeException("Failed to copy snapshot", e);
    }
}
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) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)37 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)26 ExecutionException (java.util.concurrent.ExecutionException)17 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)14 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)12 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)12 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)9 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 CopyCmdAnswer (com.cloud.storage.command.CopyCmdAnswer)6 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)5 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)5 Answer (com.cloud.agent.api.Answer)4 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)4 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)4 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)4 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)4 CommandResult (com.cloud.storage.command.CommandResult)4 DB (com.cloud.utils.db.DB)4 CopyCommand (com.cloud.storage.command.CopyCommand)3