Search in sources :

Example 6 with AsyncCallFuture

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

the class VolumeServiceImpl method createVolumeFromTemplateAsync.

@DB
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(final VolumeInfo volume, final long dataStoreId, final TemplateInfo template) {
    final PrimaryDataStore pd = dataStoreMgr.getPrimaryDataStore(dataStoreId);
    final TemplateInfo templateOnPrimaryStore = pd.getTemplate(template.getId());
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    if (templateOnPrimaryStore == null) {
        createBaseImageAsync(volume, pd, template, future);
        return future;
    }
    createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, future);
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore) DB(com.cloud.utils.db.DB)

Example 7 with AsyncCallFuture

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

the class VolumeServiceImpl method createVolumeFromSnapshot.

@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(final VolumeInfo volume, final DataStore store, final SnapshotInfo snapshot) {
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    try {
        final DataObject volumeOnStore = store.create(volume);
        volumeOnStore.processEvent(Event.CreateOnlyRequested);
        snapshot.processEvent(Event.CopyingRequested);
        final CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volume, store, volumeOnStore, future, snapshot);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context);
        motionSrv.copyAsync(snapshot, volumeOnStore, caller);
    } catch (final Exception e) {
        s_logger.debug("create volume from snapshot failed", e);
        final VolumeApiResult result = new VolumeApiResult(volume);
        result.setResult(e.toString());
        future.complete(result);
    }
    return future;
}
Also used : AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) 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 8 with AsyncCallFuture

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

the class VolumeServiceImpl method copyVolumeFromImageToPrimary.

protected AsyncCallFuture<VolumeApiResult> copyVolumeFromImageToPrimary(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);
        destVolume.processEvent(Event.CopyingRequested);
        srcVolume.processEvent(Event.CopyingRequested);
        final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyVolumeFromImageToPrimaryCallback(null, null)).setContext(context);
        motionSrv.copyAsync(srcVolume, destVolume, caller);
        return future;
    } catch (final Exception e) {
        s_logger.error("failed to copy volume from image store", e);
        if (destVolume != null) {
            destVolume.processEvent(Event.OperationFailed);
        }
        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 9 with AsyncCallFuture

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

the class VolumeServiceImpl method createManagedStorageAndVolumeFromTemplateAsync.

@Override
public AsyncCallFuture<VolumeApiResult> createManagedStorageAndVolumeFromTemplateAsync(VolumeInfo volumeInfo, final long destDataStoreId, final TemplateInfo srcTemplateInfo, final long destHostId) {
    final PrimaryDataStore destPrimaryDataStore = dataStoreMgr.getPrimaryDataStore(destDataStoreId);
    final TemplateInfo destTemplateInfo = (TemplateInfo) destPrimaryDataStore.create(srcTemplateInfo);
    final Host destHost = _hostDao.findById(destHostId);
    if (destHost == null) {
        throw new CloudRuntimeException("Destinatin host should not be null.");
    }
    final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
    try {
        // must call driver to have a volume created
        final AsyncCallFuture<VolumeApiResult> createVolumeFuture = createVolumeAsync(volumeInfo, destPrimaryDataStore);
        final VolumeApiResult createVolumeResult = createVolumeFuture.get();
        if (createVolumeResult.isFailed()) {
            throw new CloudRuntimeException("Creation of a volume failed: " + createVolumeResult.getResult());
        }
        // refresh the volume from the DB
        volumeInfo = volFactory.getVolume(volumeInfo.getId(), destPrimaryDataStore);
        grantAccess(volumeInfo, destHost, destPrimaryDataStore);
        final ManagedCreateBaseImageContext<CreateCmdResult> context = new ManagedCreateBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, srcTemplateInfo, future);
        final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().managedCopyBaseImageCallback(null, null)).setContext(context);
        final Map<String, String> details = new HashMap<>();
        details.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString());
        details.put(PrimaryDataStore.STORAGE_HOST, destPrimaryDataStore.getHostAddress());
        details.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(destPrimaryDataStore.getPort()));
        // for managed storage, the storage repository (XenServer) or datastore (ESX) name is based off of the iScsiName property of a volume
        details.put(PrimaryDataStore.MANAGED_STORE_TARGET, volumeInfo.get_iScsiName());
        details.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, volumeInfo.getName());
        details.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
        final ChapInfo chapInfo = getChapInfo(volumeInfo, destPrimaryDataStore);
        if (chapInfo != null) {
            details.put(PrimaryDataStore.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
            details.put(PrimaryDataStore.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
            details.put(PrimaryDataStore.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
            details.put(PrimaryDataStore.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
        }
        destPrimaryDataStore.setDetails(details);
        motionSrv.copyAsync(srcTemplateInfo, destTemplateInfo, destHost, caller);
    } catch (InterruptedException | ExecutionException e) {
        String errMsg = e.getMessage();
        volumeInfo.processEvent(Event.DestroyRequested);
        revokeAccess(volumeInfo, destHost, destPrimaryDataStore);
        try {
            final AsyncCallFuture<VolumeApiResult> expungeVolumeFuture = expungeVolumeAsync(volumeInfo);
            final VolumeApiResult expungeVolumeResult = expungeVolumeFuture.get();
            if (expungeVolumeResult.isFailed()) {
                errMsg += " : Failed to expunge a volume that was created";
            }
        } catch (InterruptedException | ExecutionException innerException) {
            errMsg += " : " + innerException.getMessage();
        }
        final VolumeApiResult result = new VolumeApiResult(volumeInfo);
        result.setResult(errMsg);
        future.complete(result);
    }
    return future;
}
Also used : HashMap(java.util.HashMap) ChapInfo(com.cloud.engine.subsystem.api.storage.ChapInfo) Host(com.cloud.host.Host) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) PrimaryDataStore(com.cloud.engine.subsystem.api.storage.PrimaryDataStore)

Example 10 with AsyncCallFuture

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

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