Search in sources :

Example 6 with CopyCommandResult

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

the class DataObjectManagerImpl method copyAsync.

@Override
public void copyAsync(final DataObject srcData, final DataObject destData, final AsyncCompletionCallback<CreateCmdResult> callback) {
    try {
        objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
    } catch (final NoTransitionException | ConcurrentOperationException e) {
        s_logger.debug("failed to change state", e);
        try {
            objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (final Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        final CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to change state: " + e.toString());
        callback.complete(res);
    }
    final CopyContext<CreateCmdResult> anotherCall = new CopyContext<>(callback, srcData, destData);
    final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
    motionSrv.copyAsync(srcData, destData, caller);
}
Also used : NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 7 with CopyCommandResult

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

the class VolumeServiceImpl method createVolumeFromSnapshot.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(final VolumeInfo volume, final DataStore store, final SnapshotInfo snapshot) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    try {
        final DataObject volumeOnStore = store.create(volume);
        volumeOnStore.processEvent(Event.CreateOnlyRequested);
        snapshot.processEvent(Event.CopyingRequested);
        final CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volume, store, volumeOnStore, future, snapshot);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, volumeOnStore, caller);
    } catch (final Exception e) {
        s_logger.debug("create volume from snapshot failed", e);
        final VolumeApiResult result = new VolumeApiResult(volume);
        result.setResult(e.toString());
        future.complete(result);
    }
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with CopyCommandResult

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

the class VolumeServiceImpl method copyVolumeCallBack.

protected Void copyVolumeCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CopyVolumeContext<VolumeApiResult> context) {
    VolumeInfo srcVolume = context.srcVolume;
    VolumeInfo destVolume = context.destVolume;
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<VolumeApiResult> future = context.future;
    final VolumeApiResult res = new VolumeApiResult(destVolume);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            destVolume.processEvent(Event.MigrationCopyFailed);
            srcVolume.processEvent(Event.OperationFailed);
            destroyVolume(destVolume.getId());
            destVolume = volFactory.getVolume(destVolume.getId());
            final AsyncCallFuture<VolumeApiResult> destroyFuture = expungeVolumeAsync(destVolume);
            destroyFuture.get();
            future.complete(res);
            return null;
        }
        srcVolume.processEvent(Event.OperationSuccessed);
        destVolume.processEvent(Event.MigrationCopySucceeded, result.getAnswer());
        volDao.updateUuid(srcVolume.getId(), destVolume.getId());
        try {
            destroyVolume(srcVolume.getId());
            srcVolume = volFactory.getVolume(srcVolume.getId());
            AsyncCallFuture<VolumeApiResult> destroyFuture = expungeVolumeAsync(srcVolume);
            // If volume destroy fails, this could be because of vdi is still in use state, so wait and retry.
            if (destroyFuture.get().isFailed()) {
                Thread.sleep(5 * 1000);
                destroyFuture = expungeVolumeAsync(srcVolume);
                destroyFuture.get();
            }
            future.complete(res);
        } catch (final Exception e) {
            s_logger.debug("failed to clean up volume on storage", e);
        }
        return null;
    } catch (final Exception e) {
        s_logger.debug("Failed to process copy volume callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with CopyCommandResult

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

the class VolumeServiceImpl method migrateVmWithVolumesCallBack.

protected Void migrateVmWithVolumesCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final MigrateVmWithVolumesContext<CommandResult> context) {
    final Map<VolumeInfo, DataStore> volumeToPool = context.volumeToPool;
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<CommandResult> future = context.future;
    final CommandResult res = new CommandResult();
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                final VolumeInfo volume = entry.getKey();
                volume.processEvent(Event.OperationFailed);
            }
            future.complete(res);
        } else {
            for (final Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
                final VolumeInfo volume = entry.getKey();
                volume.processEvent(Event.OperationSuccessed);
            }
            future.complete(res);
        }
    } catch (final Exception e) {
        s_logger.error("Failed to process copy volume callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : DataStore(com.cloud.engine.subsystem.api.storage.DataStore) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) Map(java.util.Map) HashMap(java.util.HashMap) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) 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 CopyCommandResult

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

the class VolumeServiceImpl method copyVolumeFromImageToPrimary.

protected AsyncCallFuture<VolumeApiResult> copyVolumeFromImageToPrimary(final VolumeInfo srcVolume, final DataStore destStore) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final VolumeApiResult res = new VolumeApiResult(srcVolume);
    VolumeInfo destVolume = null;
    try {
        destVolume = (VolumeInfo) destStore.create(srcVolume);
        destVolume.processEvent(Event.CopyingRequested);
        srcVolume.processEvent(Event.CopyingRequested);
        final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyVolumeFromImageToPrimaryCallback(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
        return future;
    } catch (final Exception e) {
        s_logger.error("failed to copy volume from image store", e);
        if (destVolume != null) {
            destVolume.processEvent(Event.OperationFailed);
        }
        srcVolume.processEvent(Event.OperationFailed);
        res.setResult(e.toString());
        future.complete(res);
        return future;
    }
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

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