Search in sources :

Example 21 with VolumeInfo

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

the class VolumeServiceImpl method migrateVolumeCallBack.

protected Void migrateVolumeCallBack(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final MigrateVolumeContext<VolumeApiResult> context) {
    final VolumeInfo srcVolume = context.srcVolume;
    final CopyCommandResult result = callback.getResult();
    final AsyncCallFuture<VolumeApiResult> future = context.future;
    final 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 (final Exception e) {
        s_logger.error("Failed to process migrate volume callback", 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 22 with VolumeInfo

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

the class VolumeServiceImpl method destroyVolume.

@Override
@DB
public boolean destroyVolume(final long volumeId) throws ConcurrentOperationException {
    // mark volume entry in volumes table as destroy state
    final VolumeInfo vol = volFactory.getVolume(volumeId);
    vol.stateTransit(Volume.Event.DestroyRequested);
    vol.stateTransit(Volume.Event.OperationSucceeded);
    return true;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) DB(com.cloud.utils.db.DB)

Example 23 with VolumeInfo

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

the class VolumeServiceImpl method copyVolume.

@Override
public AsyncCallFuture<VolumeApiResult> copyVolume(final VolumeInfo srcVolume, final DataStore destStore) {
    if (srcVolume.getState() == Volume.State.Uploaded) {
        return copyVolumeFromImageToPrimary(srcVolume, destStore);
    }
    if (destStore.getRole() == DataStoreRole.Image) {
        return copyVolumeFromPrimaryToImage(srcVolume, destStore);
    }
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final VolumeApiResult res = new VolumeApiResult(srcVolume);
    try {
        if (!snapshotMgr.canOperateOnVolume(srcVolume)) {
            s_logger.debug("There are snapshots creating on this volume, can not move this volume");
            res.setResult("There are snapshots creating on this volume, can not move this volume");
            future.complete(res);
            return future;
        }
        final VolumeVO destVol = duplicateVolumeOnAnotherStorage(srcVolume, (StoragePool) destStore);
        final VolumeInfo destVolume = volFactory.getVolume(destVol.getId(), destStore);
        destVolume.processEvent(Event.MigrationCopyRequested);
        srcVolume.processEvent(Event.MigrationRequested);
        final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyVolumeCallBack(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to copy volume" + e);
        res.setResult(e.toString());
        future.complete(res);
    }
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) VolumeVO(com.cloud.storage.VolumeVO) 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 24 with VolumeInfo

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

the class VolumeServiceImpl method resizeVolumeCallback.

protected Void resizeVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
    final CreateCmdResult result = callback.getResult();
    final AsyncCallFuture<VolumeApiResult> future = context.future;
    final VolumeInfo volume = (VolumeInfo) context.volume;
    if (result.isFailed()) {
        try {
            volume.processEvent(Event.OperationFailed);
        } catch (final Exception e) {
            s_logger.debug("Failed to change state", e);
        }
        final VolumeApiResult res = new VolumeApiResult(volume);
        res.setResult(result.getResult());
        future.complete(res);
        return null;
    }
    try {
        volume.processEvent(Event.OperationSuccessed);
    } catch (final Exception e) {
        s_logger.debug("Failed to change state", e);
        final VolumeApiResult res = new VolumeApiResult(volume);
        res.setResult(result.getResult());
        future.complete(res);
        return null;
    }
    final VolumeApiResult res = new VolumeApiResult(volume);
    future.complete(res);
    return null;
}
Also used : VolumeInfo(com.cloud.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 25 with VolumeInfo

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

the class VolumeServiceImpl method migrateVolume.

@Override
public AsyncCallFuture<VolumeApiResult> migrateVolume(final VolumeInfo srcVolume, final DataStore destStore) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final VolumeApiResult res = new VolumeApiResult(srcVolume);
    try {
        if (!snapshotMgr.canOperateOnVolume(srcVolume)) {
            s_logger.debug("Snapshots are being created on this volume. This volume cannot be migrated now.");
            res.setResult("Snapshots are being created on this volume. This volume cannot be migrated now.");
            future.complete(res);
            return future;
        }
        final VolumeInfo destVolume = volFactory.getVolume(srcVolume.getId(), destStore);
        srcVolume.processEvent(Event.MigrationRequested);
        final MigrateVolumeContext<VolumeApiResult> context = new MigrateVolumeContext<>(null, future, srcVolume, destVolume, destStore);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().migrateVolumeCallBack(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to copy volume", e);
        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)

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