Search in sources :

Example 41 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo 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 42 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo 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 43 with VolumeInfo

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

the class VolumeServiceImpl method createVolumeAsync.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(final VolumeInfo volume, final DataStore dataStore) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final DataObject volumeOnStore = dataStore.create(volume);
    volumeOnStore.processEvent(Event.CreateOnlyRequested);
    try {
        final CreateVolumeContext<VolumeApiResult> context = new CreateVolumeContext<>(null, volumeOnStore, future);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeCallback(null, null)).setContext(context);
        dataStore.getDriver().createAsync(dataStore, volumeOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted volume_store_ref entry in case of createVolumeCallback is never called
        final VolumeDataStoreVO volStoreVO = _volumeStoreDao.findByStoreVolume(dataStore.getId(), volume.getId());
        if (volStoreVO != null) {
            final VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
        volResult.setResult(ex.getMessage());
        future.complete(volResult);
    }
    return future;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO)

Example 44 with VolumeInfo

use of com.cloud.engine.subsystem.api.storage.VolumeInfo 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)

Example 45 with VolumeInfo

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

the class VolumeServiceImpl method createVolumeFromSnapshotCallback.

protected Void createVolumeFromSnapshotCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
    final CopyCommandResult result = callback.getResult();
    final VolumeInfo volume = (VolumeInfo) context.templateOnStore;
    final SnapshotInfo snapshot = context.snapshot;
    final VolumeApiResult apiResult = new VolumeApiResult(volume);
    Event event = null;
    if (result.isFailed()) {
        apiResult.setResult(result.getResult());
        event = Event.OperationFailed;
    } else {
        event = Event.OperationSuccessed;
    }
    try {
        if (result.isSuccess()) {
            volume.processEvent(event, result.getAnswer());
        } else {
            volume.processEvent(event);
        }
        snapshot.processEvent(event);
    } catch (final Exception e) {
        s_logger.debug("create volume from snapshot failed", e);
        apiResult.setResult(e.toString());
    }
    final AsyncCallFuture<VolumeApiResult> future = context.future;
    future.complete(apiResult);
    return null;
}
Also used : SnapshotInfo(com.cloud.engine.subsystem.api.storage.SnapshotInfo) Event(com.cloud.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event) 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

VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)63 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)39 ExecutionException (java.util.concurrent.ExecutionException)26 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)21 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)19 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)19 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)17 VolumeVO (com.cloud.storage.VolumeVO)14 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)12 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)12 DB (com.cloud.utils.db.DB)12 StoragePoolVO (com.cloud.storage.datastore.db.StoragePoolVO)9 Account (com.cloud.user.Account)9 ArrayList (java.util.ArrayList)9 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)8 ActionEvent (com.cloud.event.ActionEvent)8 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)8 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)7 StoragePool (com.cloud.storage.StoragePool)7