Search in sources :

Example 6 with CreateCmdResult

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

the class DataObjectManagerImpl method copyAsync.

@Override
public void copyAsync(final DataObject srcData, final DataObject destData, final AsyncCompletionCallback<CreateCmdResult> callback) {
    try {
        objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
    } catch (final NoTransitionException | ConcurrentOperationException e) {
        s_logger.debug("failed to change state", e);
        try {
            objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.OperationFailed);
        } catch (final Exception e1) {
            s_logger.debug("failed to further change state to OperationFailed", e1);
        }
        final CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult("Failed to change state: " + e.toString());
        callback.complete(res);
    }
    final CopyContext<CreateCmdResult> anotherCall = new CopyContext<>(callback, srcData, destData);
    final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
    motionSrv.copyAsync(srcData, destData, caller);
}
Also used : NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 7 with CreateCmdResult

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

the class VolumeServiceImpl method createVolumeCallback.

protected Void createVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
    final CreateCmdResult result = callback.getResult();
    final DataObject vo = context.getVolume();
    String errMsg = null;
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed, result.getAnswer());
    } else {
        vo.processEvent(Event.OperationFailed);
        errMsg = result.getResult();
    }
    final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
    if (errMsg != null) {
        volResult.setResult(errMsg);
    }
    context.getFuture().complete(volResult);
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult)

Example 8 with CreateCmdResult

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

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

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

Aggregations

CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)20 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 DataObject (com.cloud.engine.subsystem.api.storage.DataObject)9 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)7 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)5 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)5 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)5 ExecutionException (java.util.concurrent.ExecutionException)5 TemplateInfo (com.cloud.engine.subsystem.api.storage.TemplateInfo)4 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)4 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)4 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)4 ResizeVolumeAnswer (com.cloud.agent.api.storage.ResizeVolumeAnswer)3 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)3 StorageUnavailableException (com.cloud.exception.StorageUnavailableException)3 TemplateDataStoreVO (com.cloud.storage.datastore.db.TemplateDataStoreVO)3 TemplateObject (com.cloud.storage.image.store.TemplateObject)3 Answer (com.cloud.agent.api.Answer)2 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)2