Search in sources :

Example 6 with DataObject

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

the class DataObjectManagerImpl method copyCallback.

protected Void copyCallback(final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> callback, final CopyContext<CreateCmdResult> context) {
    final CopyCommandResult result = callback.getResult();
    final DataObject destObj = context.destObj;
    if (result.isFailed()) {
        try {
            objectInDataStoreMgr.update(destObj, Event.OperationFailed);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to update copying state", e);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Failed to update copying state", e);
        }
        final CreateCmdResult res = new CreateCmdResult(null, null);
        res.setResult(result.getResult());
        context.getParentCallback().complete(res);
    }
    try {
        objectInDataStoreMgr.update(destObj, ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (final NoTransitionException | ConcurrentOperationException e) {
        s_logger.debug("Failed to update copying state: ", e);
        try {
            objectInDataStoreMgr.update(destObj, 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 update copying state: " + e.toString());
        context.getParentCallback().complete(res);
    }
    final CreateCmdResult res = new CreateCmdResult(result.getPath(), null);
    context.getParentCallback().complete(res);
    return null;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 7 with DataObject

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

the class VolumeServiceImpl method registerVolumeForPostUpload.

@Override
public Pair<EndPoint, DataObject> registerVolumeForPostUpload(final VolumeInfo volume, final DataStore store) {
    final EndPoint ep = _epSelector.select(store);
    if (ep == null) {
        final String errorMessage = "There is no secondary storage VM for image store " + store.getName();
        s_logger.warn(errorMessage);
        throw new CloudRuntimeException(errorMessage);
    }
    final DataObject volumeOnStore = store.create(volume);
    return new Pair<>(ep, volumeOnStore);
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) EndPoint(com.cloud.engine.subsystem.api.storage.EndPoint) RemoteHostEndPoint(com.cloud.storage.RemoteHostEndPoint) Pair(com.cloud.utils.Pair)

Example 8 with DataObject

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

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

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

the class VolumeServiceImpl method createVolumeFromBaseImageAsync.

@DB
protected void createVolumeFromBaseImageAsync(final VolumeInfo volume, final DataObject templateOnPrimaryStore, final PrimaryDataStore pd, final AsyncCallFuture<VolumeApiResult> future) {
    final DataObject volumeOnPrimaryStorage = pd.create(volume);
    volumeOnPrimaryStorage.processEvent(Event.CreateOnlyRequested);
    final CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volumeOnPrimaryStorage, pd, templateOnPrimaryStore, future, null);
    final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallBack(null, null));
    caller.setContext(context);
    motionSrv.copyAsync(context.templateOnStore, volumeOnPrimaryStorage, caller);
    return;
}
Also used : DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) DB(com.cloud.utils.db.DB)

Aggregations

DataObject (com.cloud.engine.subsystem.api.storage.DataObject)23 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 CopyCommandResult (com.cloud.engine.subsystem.api.storage.CopyCommandResult)9 CreateCmdResult (com.cloud.engine.subsystem.api.storage.CreateCmdResult)8 DataStore (com.cloud.engine.subsystem.api.storage.DataStore)8 EndPoint (com.cloud.engine.subsystem.api.storage.EndPoint)8 Answer (com.cloud.agent.api.Answer)6 AsyncCallFuture (com.cloud.framework.async.AsyncCallFuture)6 RemoteHostEndPoint (com.cloud.storage.RemoteHostEndPoint)6 CopyCommand (com.cloud.storage.command.CopyCommand)5 MigrateVolumeAnswer (com.cloud.agent.api.storage.MigrateVolumeAnswer)4 ZoneScope (com.cloud.engine.subsystem.api.storage.ZoneScope)4 VolumeDataStoreVO (com.cloud.storage.datastore.db.VolumeDataStoreVO)4 DB (com.cloud.utils.db.DB)4 ClusterScope (com.cloud.engine.subsystem.api.storage.ClusterScope)3 HostScope (com.cloud.engine.subsystem.api.storage.HostScope)3 Scope (com.cloud.engine.subsystem.api.storage.Scope)3 VolumeInfo (com.cloud.engine.subsystem.api.storage.VolumeInfo)3 Date (java.util.Date)3 DownloadAnswer (com.cloud.agent.api.storage.DownloadAnswer)2