Search in sources :

Example 16 with CopyCommandResult

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

the class VolumeServiceImpl method copyVolumeFromPrimaryToImage.

protected AsyncCallFuture<VolumeApiResult> copyVolumeFromPrimaryToImage(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);
        // this is just used for locking that src volume record in DB to avoid using lock
        srcVolume.processEvent(Event.MigrationRequested);
        destVolume.processEventOnly(Event.CreateOnlyRequested);
        final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyVolumeFromPrimaryToImageCallback(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
        return future;
    } catch (final Exception e) {
        s_logger.error("failed to copy volume to image store", e);
        if (destVolume != null) {
            destVolume.getDataStore().delete(destVolume);
        }
        // unlock source volume record
        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)

Example 17 with CopyCommandResult

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

the class VolumeServiceImpl method managedCopyBaseImageCallback.

protected Void managedCopyBaseImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final ManagedCreateBaseImageContext<VolumeApiResult> context) {
    final CopyCommandResult result = callback.getResult();
    final VolumeInfo volumeInfo = context.getVolumeInfo();
    final VolumeApiResult res = new VolumeApiResult(volumeInfo);
    if (result.isSuccess()) {
        // volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer());
        final VolumeVO volume = volDao.findById(volumeInfo.getId());
        final CopyCmdAnswer answer = (CopyCmdAnswer) result.getAnswer();
        final TemplateObjectTO templateObjectTo = (TemplateObjectTO) answer.getNewData();
        volume.setPath(templateObjectTo.getPath());
        if (templateObjectTo.getFormat() != null) {
            volume.setFormat(templateObjectTo.getFormat());
        }
        volDao.update(volume.getId(), volume);
    } else {
        volumeInfo.processEvent(Event.DestroyRequested);
        res.setResult(result.getResult());
    }
    final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(res);
    return null;
}
Also used : VolumeVO(com.cloud.storage.VolumeVO) VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) TemplateObjectTO(com.cloud.storage.to.TemplateObjectTO) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer)

Example 18 with CopyCommandResult

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

the class VolumeServiceImpl method copyVolumeFromPrimaryToImageCallback.

protected Void copyVolumeFromPrimaryToImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CopyVolumeContext<VolumeApiResult> context) {
    final VolumeInfo srcVolume = context.srcVolume;
    final 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()) {
            // back to Ready state in Volume table
            srcVolume.processEvent(Event.OperationFailed);
            destVolume.processEventOnly(Event.OperationFailed);
            res.setResult(result.getResult());
            future.complete(res);
        } else {
            // back to Ready state in Volume table
            srcVolume.processEvent(Event.OperationSuccessed);
            destVolume.processEventOnly(Event.OperationSuccessed, result.getAnswer());
            future.complete(res);
        }
    } catch (final Exception 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 19 with CopyCommandResult

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

the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.

@DB
protected Void createVolumeFromBaseImageCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
    final DataObject vo = context.vo;
    final DataObject tmplOnPrimary = context.templateOnStore;
    final CopyCommandResult result = callback.getResult();
    final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        vo.processEvent(Event.OperationFailed);
        volResult.setResult(result.getResult());
        // hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
        // template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
        final Answer ans = result.getAnswer();
        if (ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")) {
            if (tmplOnPrimary != null) {
                s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
                VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
                if (templatePoolRef != null) {
                    final long templatePoolRefId = templatePoolRef.getId();
                    templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
                    try {
                        if (templatePoolRef == null) {
                            s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
                        } else {
                            templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
                            templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
                            _tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
                        }
                    } finally {
                        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
                    }
                }
            }
        }
    }
    final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(volResult);
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) DB(com.cloud.utils.db.DB)

Example 20 with CopyCommandResult

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

the class VolumeServiceImpl method copyVolumeFromImageToPrimaryCallback.

protected Void copyVolumeFromImageToPrimaryCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CopyVolumeContext<VolumeApiResult> context) {
    final VolumeInfo srcVolume = context.srcVolume;
    final 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()) {
            destVolume.processEvent(Event.OperationFailed);
            srcVolume.processEvent(Event.OperationFailed);
            res.setResult(result.getResult());
            future.complete(res);
            return null;
        }
        srcVolume.processEvent(Event.OperationSuccessed);
        destVolume.processEvent(Event.OperationSuccessed, result.getAnswer());
        srcVolume.getDataStore().delete(srcVolume);
        future.complete(res);
    } catch (final Exception 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)

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