Search in sources :

Example 11 with AsyncCallFuture

use of com.cloud.framework.async.AsyncCallFuture 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)

Example 12 with AsyncCallFuture

use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method registerVolume.

@Override
public AsyncCallFuture<VolumeApiResult> registerVolume(final VolumeInfo volume, final DataStore store) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final DataObject volumeOnStore = store.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().registerVolumeCallback(null, null));
        caller.setContext(context);
        store.getDriver().createAsync(store, 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(store.getId(), volume.getId());
        if (volStoreVO != null) {
            final VolumeInfo volObj = volFactory.getVolume(volume, store);
            volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final VolumeApiResult res = new VolumeApiResult((VolumeObject) volumeOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    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 13 with AsyncCallFuture

use of com.cloud.framework.async.AsyncCallFuture 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 14 with AsyncCallFuture

use of com.cloud.framework.async.AsyncCallFuture 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 15 with AsyncCallFuture

use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.

the class VolumeServiceImpl method expungeVolumeAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(final VolumeInfo volume) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    final VolumeApiResult result = new VolumeApiResult(volume);
    if (volume.getDataStore() == null) {
        s_logger.info("Expunge volume with no data store specified");
        if (canVolumeBeRemoved(volume.getId())) {
            s_logger.info("Volume " + volume.getId() + " is not referred anywhere, remove it from volumes table");
            volDao.remove(volume.getId());
        }
        future.complete(result);
        return future;
    }
    // Find out if the volume is at state of download_in_progress on secondary storage
    final VolumeDataStoreVO volumeStore = _volumeStoreDao.findByVolume(volume.getId());
    if (volumeStore != null) {
        if (volumeStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) {
            s_logger.debug("Volume: " + volume.getName() + " is currently being uploaded; cant' delete it.");
            future.complete(result);
            return future;
        }
    }
    final VolumeVO vol = volDao.findById(volume.getId());
    if (vol == null) {
        s_logger.debug("Volume " + volume.getId() + " is not found");
        future.complete(result);
        return future;
    }
    final String volumePath = vol.getPath();
    final Long poolId = vol.getPoolId();
    if (poolId == null || volumePath == null || volumePath.trim().isEmpty()) {
        // not created on primary store
        if (volumeStore == null) {
            // also not created on secondary store
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Marking volume that was never created as destroyed: " + vol);
            }
            volDao.remove(vol.getId());
            future.complete(result);
            return future;
        }
    }
    final VolumeObject vo = (VolumeObject) volume;
    if (volume.getDataStore().getRole() == DataStoreRole.Image) {
        // no need to change state in volumes table
        volume.processEventOnly(Event.DestroyRequested);
    } else if (volume.getDataStore().getRole() == DataStoreRole.Primary) {
        volume.processEvent(Event.ExpungeRequested);
    }
    final DeleteVolumeContext<VolumeApiResult> context = new DeleteVolumeContext<>(null, vo, future);
    final AsyncCallbackDispatcher<VolumeServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteVolumeCallback(null, null)).setContext(context);
    volume.getDataStore().getDriver().deleteAsync(volume.getDataStore(), volume, caller);
    return future;
}
Also used : CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) VolumeVO(com.cloud.storage.VolumeVO) VolumeDataStoreVO(com.cloud.storage.datastore.db.VolumeDataStoreVO) DB(com.cloud.utils.db.DB)

Aggregations

AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)21 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)17 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)15 ExecutionException (java.util.concurrent.ExecutionException)12 CommandResult (com.cloud.storage.command.CommandResult)8 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)7 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)6 PrimaryDataStore (com.cloud.engine.subsystem.api.storage.PrimaryDataStore)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)6 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)5 SnapshotResult (com.cloud.engine.subsystem.api.storage.SnapshotResult)5 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)4 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 SnapshotInfo (com.cloud.engine.subsystem.api.storage.SnapshotInfo)3 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)3 TemplateObject (com.cloud.storage.image.store.TemplateObject)3 PrimaryDataStoreDriver (com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver)2 VolumeVO (com.cloud.storage.VolumeVO)2 DB (com.cloud.utils.db.DB)2