Search in sources :

Example 6 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateOnPrimary.

@Override
public AsyncCallFuture<TemplateApiResult> deleteTemplateOnPrimary(TemplateInfo template, StoragePool pool) {
    TemplateObject templateObject = (TemplateObject) _templateFactory.getTemplateOnPrimaryStorage(template.getId(), (DataStore) pool, template.getDeployAsIsConfiguration());
    templateObject.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    DataStore dataStore = _storeMgr.getPrimaryDataStore(pool.getId());
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<>();
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<>(null, templateObject, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context);
    dataStore.getDriver().deleteAsync(dataStore, templateObject, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 7 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateAsync.

@Override
public AsyncCallFuture<TemplateApiResult> deleteTemplateAsync(TemplateInfo template) {
    TemplateObject to = (TemplateObject) template;
    // update template_store_ref status
    to.processEvent(ObjectInDataStoreStateMachine.Event.DestroyRequested);
    AsyncCallFuture<TemplateApiResult> future = new AsyncCallFuture<TemplateApiResult>();
    TemplateOpContext<TemplateApiResult> context = new TemplateOpContext<TemplateApiResult>(null, to, future);
    AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().deleteTemplateCallback(null, null)).setContext(context);
    if (to.canBeDeletedFromDataStore()) {
        to.getDataStore().getDriver().deleteAsync(to.getDataStore(), to, caller);
    } else {
        CommandResult result = new CommandResult();
        caller.complete(result);
    }
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Example 8 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class TemplateServiceImpl method deleteTemplateCallback.

public Void deleteTemplateCallback(AsyncCallbackDispatcher<TemplateServiceImpl, CommandResult> callback, TemplateOpContext<TemplateApiResult> context) {
    CommandResult result = callback.getResult();
    TemplateObject vo = context.getTemplate();
    if (result.isSuccess()) {
        vo.processEvent(Event.OperationSuccessed);
    } else {
        vo.processEvent(Event.OperationFailed);
    }
    TemplateApiResult apiResult = new TemplateApiResult(vo);
    apiResult.setResult(result.getResult());
    apiResult.setSuccess(result.isSuccess());
    context.future.complete(apiResult);
    return null;
}
Also used : CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) TemplateObject(org.apache.cloudstack.storage.image.store.TemplateObject)

Example 9 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class SnapshotServiceImpl method takeSnapshot.

@Override
public SnapshotResult takeSnapshot(SnapshotInfo snap) {
    SnapshotObject snapshot = (SnapshotObject) snap;
    SnapshotObject snapshotOnPrimary = null;
    try {
        snapshotOnPrimary = (SnapshotObject) snap.getDataStore().create(snapshot);
    } catch (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 (NoTransitionException e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        throw new CloudRuntimeException(e);
    }
    try {
        snapshotOnPrimary.processEvent(Event.CreateOnlyRequested);
    } catch (Exception e) {
        s_logger.debug("Failed to change snapshot state: " + e.toString());
        try {
            snapshotOnPrimary.processEvent(Snapshot.Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change snapshot state: " + e1.toString());
        }
        throw new CloudRuntimeException(e);
    }
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    try {
        CreateSnapshotContext<CommandResult> context = new CreateSnapshotContext<CommandResult>(null, snap.getBaseVolume(), snapshotOnPrimary, future);
        AsyncCallbackDispatcher<SnapshotServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
        caller.setCallback(caller.getTarget().createSnapshotAsyncCallback(null, null)).setContext(context);
        PrimaryDataStoreDriver primaryStore = (PrimaryDataStoreDriver) snapshotOnPrimary.getDataStore().getDriver();
        primaryStore.takeSnapshot(snapshot, caller);
    } catch (Exception e) {
        s_logger.debug("Failed to take snapshot: " + snapshot.getId(), e);
        try {
            snapshot.processEvent(Snapshot.Event.OperationFailed);
            snapshot.processEvent(Event.OperationFailed);
        } catch (NoTransitionException e1) {
            s_logger.debug("Failed to change state for event: OperationFailed", e);
        }
        throw new CloudRuntimeException("Failed to take snapshot" + snapshot.getId());
    }
    SnapshotResult result;
    try {
        result = future.get();
        UsageEventUtils.publishUsageEvent(EventTypes.EVENT_SNAPSHOT_ON_PRIMARY, snap.getAccountId(), snap.getDataCenterId(), snap.getId(), snap.getName(), null, null, snapshotOnPrimary.getSize(), snapshotOnPrimary.getSize(), snap.getClass().getName(), snap.getUuid());
        return result;
    } catch (InterruptedException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    } catch (ExecutionException e) {
        s_logger.debug("Failed to create snapshot", e);
        throw new CloudRuntimeException("Failed to create snapshot", e);
    }
}
Also used : SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) PrimaryDataStoreDriver(org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 10 with CommandResult

use of org.apache.cloudstack.storage.command.CommandResult in project cloudstack by apache.

the class SnapshotServiceImpl method syncToRegionStoreAsync.

private AsyncCallFuture<SnapshotResult> syncToRegionStoreAsync(SnapshotInfo snapshot, DataStore store) {
    AsyncCallFuture<SnapshotResult> future = new AsyncCallFuture<SnapshotResult>();
    // no need to create entry on snapshot_store_ref here, since entries are already created when updateCloudToUseObjectStore is invoked.
    // But we need to set default install path so that sync can be done in the right s3 path
    SnapshotInfo snapshotOnStore = _snapshotFactory.getSnapshot(snapshot, store);
    String installPath = TemplateConstants.DEFAULT_SNAPSHOT_ROOT_DIR + "/" + snapshot.getAccountId() + "/" + snapshot.getVolumeId();
    ((SnapshotObject) snapshotOnStore).setPath(installPath);
    CopySnapshotContext<CommandResult> context = new CopySnapshotContext<CommandResult>(null, snapshot, snapshotOnStore, future);
    AsyncCallbackDispatcher<SnapshotServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
    caller.setCallback(caller.getTarget().syncSnapshotCallBack(null, null)).setContext(context);
    motionSrv.copyAsync(snapshot, snapshotOnStore, caller);
    return future;
}
Also used : AsyncCallFuture(org.apache.cloudstack.framework.async.AsyncCallFuture) SnapshotInfo(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo) SnapshotResult(org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult) CommandResult(org.apache.cloudstack.storage.command.CommandResult) CopyCommandResult(org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)

Aggregations

CommandResult (org.apache.cloudstack.storage.command.CommandResult)37 CopyCommandResult (org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult)35 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)17 VolumeInfo (org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo)15 DataStore (org.apache.cloudstack.engine.subsystem.api.storage.DataStore)12 ExecutionException (java.util.concurrent.ExecutionException)11 SnapshotInfo (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo)9 AsyncCallFuture (org.apache.cloudstack.framework.async.AsyncCallFuture)9 PrimaryDataStore (org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore)8 SnapshotResult (org.apache.cloudstack.engine.subsystem.api.storage.SnapshotResult)7 VolumeVO (com.cloud.storage.VolumeVO)6 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)6 HashMap (java.util.HashMap)6 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)5 Answer (com.cloud.agent.api.Answer)4 MigrateWithStorageAnswer (com.cloud.agent.api.MigrateWithStorageAnswer)4 MigrateWithStorageCommand (com.cloud.agent.api.MigrateWithStorageCommand)4 VirtualMachineTO (com.cloud.agent.api.to.VirtualMachineTO)4 Host (com.cloud.host.Host)4 VMInstanceVO (com.cloud.vm.VMInstanceVO)4