Search in sources :

Example 41 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method createVolumeFromBaseImageAsync.

@DB
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, DataObject templateOnPrimaryStore, PrimaryDataStore pd, AsyncCallFuture<VolumeApiResult> future) {
    DataObject volumeOnPrimaryStorage = pd.create(volume);
    volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
    CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<VolumeApiResult>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null);
    AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
    caller.setContext(context);
    motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
    return;
}
Also used : DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Example 42 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method migrateVolumeCallBack.

protected Void migrateVolumeCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, MigrateVolumeContext<VolumeApiResult> context) {
    VolumeInfo srcVolume = context.srcVolume;
    CopyCommandResult result = callback.getResult();
    AsyncCallFuture<VolumeApiResult> future = context.future;
    VolumeApiResult res = new VolumeApiResult(srcVolume);
    try {
        if (result.isFailed()) {
            res.setResult(result.getResult());
            srcVolume.processEvent(Event.OperationFailed);
            future.complete(res);
        } else {
            srcVolume.processEvent(Event.OperationSuccessed);
            future.complete(res);
        }
    } catch (Exception e) {
        s_logger.error("Failed to process migrate volume callback", e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 43 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method createVolumeFromBaseImageCallBack.

@DB
protected Void createVolumeFromBaseImageCallBack(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
    DataObject vo = context.vo;
    DataObject tmplOnPrimary = context.templateOnStore;
    CopyCommandResult result = callback.getResult();
    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
        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) {
                    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.setTemplateSize(0);
                            templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
                            templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
                            _tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
                        }
                    } finally {
                        _tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
                    }
                }
            }
        }
    }
    AsyncCallFuture<VolumeApiResult> future = context.getFuture();
    future.complete(volResult);
    return null;
}
Also used : VMTemplateStoragePoolVO(com.cloud.storage.VMTemplateStoragePoolVO) Answer(com.cloud.agent.api.Answer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) ListVolumeAnswer(com.cloud.agent.api.storage.ListVolumeAnswer) DataObject(org.apache.cloudstack.engine.subsystem.api.storage.DataObject) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) DB(com.cloud.utils.db.DB)

Example 44 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method copyVolumeFromImageToPrimaryCallback.

protected Void copyVolumeFromImageToPrimaryCallback(AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, CopyVolumeContext<VolumeApiResult> context) {
    VolumeInfo srcVolume = context.srcVolume;
    VolumeInfo destVolume = context.destVolume;
    CopyCommandResult result = callback.getResult();
    AsyncCallFuture<VolumeApiResult> future = context.future;
    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 (Exception e) {
        res.setResult(e.toString());
        future.complete(res);
    }
    return null;
}
Also used : VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 45 with CopyCommandResult

use of org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult in project cloudstack by apache.

the class VolumeServiceImpl method migrateVmWithVolumesCallBack.

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

Aggregations

CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)16 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)15 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)15 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)13 DataObject (org.apache.cloudstack.engine.subsystem.api.storage.DataObject)11 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)9 HashMap (java.util.HashMap)8 ExecutionException (java.util.concurrent.ExecutionException)8 CopyCmdAnswer (org.apache.cloudstack.storage.command.CopyCmdAnswer)8 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)7 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 VMInstanceVO (com.cloud.vm.VMInstanceVO)7 CommandResult (org.apache.cloudstack.storage.command.CommandResult)7 Answer (com.cloud.agent.api.Answer)6 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)6 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)6 CreateCmdResult (org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)5 EndPoint (org.apache.cloudstack.engine.subsystem.api.storage.EndPoint)5