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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations