Search in sources :

Example 16 with CommandResult

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

Example 17 with CommandResult

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

the class BaseImageStoreDriverImpl method deleteAsync.

@Override
public void deleteAsync(final DataStore dataStore, final DataObject data, final AsyncCompletionCallback<CommandResult> callback) {
    final CommandResult result = new CommandResult();
    try {
        final DeleteCommand cmd = new DeleteCommand(data.getTO());
        final EndPoint ep = _epSelector.select(data);
        Answer answer = null;
        if (ep == null) {
            final String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
            s_logger.error(errMsg);
            answer = new Answer(cmd, false, errMsg);
        } else {
            answer = ep.sendMessage(cmd);
        }
        if (answer != null && !answer.getResult()) {
            result.setResult(answer.getDetails());
        }
    } catch (final Exception ex) {
        s_logger.debug("Unable to destoy " + data.getType().toString() + ": " + data.getId(), ex);
        result.setResult(ex.toString());
    }
    callback.complete(result);
}
Also used : DeleteCommand(com.cloud.storage.command.DeleteCommand) DownloadAnswer(com.cloud.agent.api.storage.DownloadAnswer) Answer(com.cloud.agent.api.Answer) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 18 with CommandResult

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

the class TemplateServiceImpl method deleteTemplateCallback.

public Void deleteTemplateCallback(final AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final CommandResult result = callback.getResult();
    final TemplateObject vo = context.getTemplate();
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed);
    } else {
        vo.processEvent(Event.OperationFailed);
    }
    final TemplateApiResult apiResult = new TemplateApiResult(vo);
    apiResult.setResult(result.getResult());
    apiResult.setSuccess(result.isSuccess());
    context.future.complete(apiResult);
    return null;
}
Also used : CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(com.cloud.storage.image.store.TemplateObject)

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