Search in sources :

Example 1 with CreateCmdResult

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

the class TemplateServiceImpl method createTemplateCallback.

protected Void createTemplateCallback(final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> callback, final TemplateOpContext<TemplateApiResult> context) {
    final TemplateObject template = context.getTemplate();
    final AsyncCompletionCallback<TemplateApiResult> parentCallback = context.getParentCallback();
    final TemplateApiResult result = new TemplateApiResult(template);
    final CreateCmdResult callbackResult = callback.getResult();
    if (callbackResult.isFailed()) {
        template.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        result.setResult(callbackResult.getResult());
        if (parentCallback != null) {
            parentCallback.complete(result);
        }
        return null;
    }
    try {
        template.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
    } catch (final Exception e) {
        result.setResult(e.toString());
        if (parentCallback != null) {
            parentCallback.complete(result);
        }
        return null;
    }
    if (parentCallback != null) {
        parentCallback.complete(result);
    }
    return null;
}
Also used : CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TemplateObject(com.cloud.storage.image.store.TemplateObject)

Example 2 with CreateCmdResult

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

the class SnapshotServiceImpl method createSnapshotAsyncCallback.

protected Void createSnapshotAsyncCallback(final AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> callback, final CreateSnapshotContext<CreateCmdResult> context) {
    final CreateCmdResult result = callback.getResult();
    final SnapshotObject snapshot = (SnapshotObject) context.snapshot;
    final AsyncCallFuture<SnapshotResult> future = context.future;
    final SnapshotResult snapResult = new SnapshotResult(snapshot, result.getAnswer());
    if (result.isFailed()) {
        s_logger.debug("create snapshot " + context.snapshot.getName() + " failed: " + result.getResult());
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
            snapshot.processEvent(Event.OperationFailed);
        } catch (final Exception e) {
            s_logger.debug("Failed to update snapshot state due to " + e.getMessage());
        }
        snapResult.setResult(result.getResult());
        future.complete(snapResult);
        return null;
    }
    try {
        snapshot.processEvent(Event.OperationSuccessed, result.getAnswer());
        snapshot.processEvent(Snapshot.Event.OperationSucceeded);
    } catch (final Exception e) {
        s_logger.debug("Failed to create snapshot: ", e);
        snapResult.setResult(e.toString());
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e1.toString());
        }
    }
    future.complete(snapResult);
    return null;
}
Also used : SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with CreateCmdResult

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

the class SnapshotServiceImpl method takeSnapshot.

@Override
public SnapshotResult takeSnapshot(final SnapshotInfo snap) {
    final SnapshotObject snapshot = (SnapshotObject) snap;
    SnapshotObject snapshotOnPrimary = null;
    try {
        snapshotOnPrimary = (SnapshotObject) snap.getDataStore().create(snapshot);
    } catch (final Exception e) {
        s_logger.debug("Failed to create snapshot state on data store due to " + e.getMessage());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Snapshot.Event.CreateRequested);
    } catch (final NoTransitionException e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Event.CreateOnlyRequested);
    } catch (final Exception e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        try {
            snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e1.toString());
        }
        throw new CloudRuntimeException(e);
    }
    final AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<>();
    try {
        final CreateSnapshotContext<CommandResult> context = new CreateSnapshotContext<>(null, snap.getBaseVolume(), snapshotOnPrimary, future);
        final AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
        final PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver) snapshotOnPrimary.getDataStore().getDriver();
        primaryStore.takeSnapshot(snapshot, caller);
    } catch (final Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
            snapshot.processEvent(Event.OperationFailed);
        } catch (final NoTransitionException e1) {
            s_logger.debug("Failed to change state for event: OperationFailed", e);
        }
        throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId());
    }
    final SnapshotResult result;
    try {
        result = future.get();
        return result;
    } catch (final InterruptedException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    } catch (final ExecutionException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    }
}
Also used : SnapshotResult(com.cloud.engine.subsystem.api.storage.SnapshotResult) CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.cloud.storage.command.CommandResult) CopyCommandResult(com.cloud.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) PrimaryDataStoreDriver(com.cloud.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with CreateCmdResult

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

the class TemplateServiceImpl method copyTemplate.

@Override
public AsyncCallFuture<TemplateApiResult> copyTemplate(final TemplateInfo srcTemplate, final DataStore destStore) {
    // generate a URL from source template ssvm to download to destination data store
    final String url = generateCopyUrl(srcTemplate);
    if (url == null) {
        s_logger.warn("Unable to start/resume copy of template " + srcTemplate.getUniqueName() + " to " + destStore.getName() + ", no secondary storage vm in running state in source zone");
        throw new CloudRuntimeException("No secondary VM in running state in source template zone ");
    }
    final TemplateObject tmplForCopy = (TemplateObject) _templateFactory.getTemplate(srcTemplate, destStore);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting source template url to " + url);
    }
    tmplForCopy.setUrl(url);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Mark template_store_ref entry as Creating");
    }
    final AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    final DataObject templateOnStore = destStore.create(tmplForCopy);
    templateOnStore.processEvent(Event.CreateOnlyRequested);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Invoke datastore driver createAsync to create template on destination store");
    }
    try {
        final TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, (TemplateObject) templateOnStore, future);
        final AsyncCallbackDispatcher<TemplateServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().copyTemplateCrossZoneCallBack(null, null)).setContext(context);
        destStore.getDriver().createAsync(destStore, templateOnStore, caller);
    } catch (final CloudRuntimeException ex) {
        // clean up already persisted template_store_ref entry in case of createTemplateCallback is never called
        final TemplateDataStoreVO templateStoreVO = _vmTemplateStoreDao.findByStoreTemplate(destStore.getId(), srcTemplate.getId());
        if (templateStoreVO != null) {
            final TemplateInfo tmplObj = _templateFactory.getTemplate(srcTemplate, destStore);
            tmplObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
        }
        final TemplateApiResult res = new TemplateApiResult((TemplateObject) templateOnStore);
        res.setResult(ex.getMessage());
        future.complete(res);
    }
    return future;
}
Also used : CreateCmdResult(com.cloud.engine.subsystem.api.storage.CreateCmdResult) TemplateDataStoreVO(com.cloud.storage.datastore.db.TemplateDataStoreVO) TemplateObject(com.cloud.storage.image.store.TemplateObject) AsyncCallFuture(com.cloud.framework.async.AsyncCallFuture) TemplateInfo(com.cloud.engine.subsystem.api.storage.TemplateInfo) DataObject(com.cloud.engine.subsystem.api.storage.DataObject) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 5 with CreateCmdResult

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

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