Search in sources :

Example 1 with CopyCommandResult

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

the class TemplateServiceImpl method copyAsync.

private AsyncCallFuture<TemplateApiResult> copyAsync(final DataObject source, final TemplateInfo template, final DataStore store) {
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    final DataObject templateOnStore = store.create(template);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
    final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(source, templateOnStore, caller);
    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)

Example 2 with CopyCommandResult

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

the class TemplateServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<TemplateApiResult> syncToRegionStoreAsync(final TemplateInfo template, final DataStore store) {
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    // no need to create entry on template_store_ref here, since entries are already created when prepareSecondaryStorageForMigration is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    final TemplateInfo templateOnStore = _templateFactory.getTemplate(template, store);
    final String installPath = TemplateConstants.DEFAULT_TMPLT_ROOT_DIR + "/" + TemplateConstants.DEFAULT_TMPLT_FIRST_LEVEL_DIR + template.getAccountId() + "/" + template.getId() + "/" + template.getUniqueName();
    ((TemplateObject) templateOnStore).setInstallPath(installPath);
    final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
    final AsyncCallbackDispatcher<TemplateServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncTemplateCallBack(null, null)).setContext(context);
    _motionSrv.copyAsync(template, templateOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 3 with CopyCommandResult

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

the class StorageSystemDataMotionStrategy method handleCreateTemplateFromSnapshot.

private Void handleCreateTemplateFromSnapshot(final SnapshotInfo snapshotInfo, final TemplateInfo templateInfo, final AsyncCompletionCallback<CopyCommandResult> callback) {
    try {
        snapshotInfo.processEvent(Event.CopyingRequested);
    } catch (final Exception ex) {
        throw new CloudRuntimeException("This snapshot is not currently in a state where it can be used to create a template.");
    }
    final HostVO hostVO = getHost(snapshotInfo.getDataStore().getId());
    final DataStore srcDataStore = snapshotInfo.getDataStore();
    final String value = _configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
    final int primaryStorageDownloadWait = NumbersUtil.parseInt(value, Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
    final CopyCommand copyCommand = new CopyCommand(snapshotInfo.getTO(), templateInfo.getTO(), primaryStorageDownloadWait, VirtualMachineManager.ExecuteInSequence.value());
    String errMsg = null;
    CopyCmdAnswer copyCmdAnswer = null;
    try {
        _volumeService.grantAccess(snapshotInfo, hostVO, srcDataStore);
        final Map<String, String> srcDetails = getSnapshotDetails(_storagePoolDao.findById(srcDataStore.getId()), snapshotInfo);
        copyCommand.setOptions(srcDetails);
        copyCmdAnswer = (CopyCmdAnswer) _agentMgr.send(hostVO.getId(), copyCommand);
    } catch (final Exception ex) {
        throw new CloudRuntimeException(ex.getMessage());
    } finally {
        try {
            _volumeService.revokeAccess(snapshotInfo, hostVO, srcDataStore);
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
        if (copyCmdAnswer == null || !copyCmdAnswer.getResult()) {
            if (copyCmdAnswer != null && copyCmdAnswer.getDetails() != null && !copyCmdAnswer.getDetails().isEmpty()) {
                errMsg = copyCmdAnswer.getDetails();
            } else {
                errMsg = "Unable to perform host-side operation";
            }
        }
        try {
            if (errMsg == null) {
                snapshotInfo.processEvent(Event.OperationSuccessed);
            } else {
                snapshotInfo.processEvent(Event.OperationFailed);
            }
        } catch (final Exception ex) {
            s_logger.debug(ex.getMessage(), ex);
        }
    }
    final CopyCommandResult result = new CopyCommandResult(null, copyCmdAnswer);
    result.setResult(errMsg);
    callback.complete(result);
    return null;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CopyCommand(com.cloud.storage.command.CopyCommand) DataStore(com.cloud.engine.subsystem.api.storage.DataStore) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HostVO(com.cloud.host.HostVO) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 4 with CopyCommandResult

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

the class StorageSystemDataMotionStrategy method copyAsync.

@Override
public Void copyAsync(final Map<VolumeInfo, DataStore> volumeMap, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final AsyncCompletionCallback<CopyCommandResult> callback) {
    final CopyCommandResult result = new CopyCommandResult(null, null);
    result.setResult("Unsupported operation requested for copying data.");
    callback.complete(result);
    return null;
}
Also used : CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult)

Example 5 with CopyCommandResult

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

the class DataObjectManagerImpl method copyCallback.

protected Void copyCallback(final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> callback, final CopyContext<CreateCmdResult> context) {
    final CopyCommandResult result = callback.getResult();
    final DataObject destObj = context.destObj;
    if (result.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to update copying state", e);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Failed to update copying state", e);
        }
        final CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult(result.getResult());
        context.getParentCallback().complete(res);
    }
    try {
        objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (final NoTransitionException | ConcurrentOperationException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, 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 update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    }
    final CreateCmdResult res = new CreateCmdResult(result.getPath(), null);
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

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