use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method managedCopyBaseImageCallback.
protected Void managedCopyBaseImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final ManagedCreateBaseImageContext<VolumeApiResult> context) {
final CopyCommandResult result = callback.getResult();
final VolumeInfo volumeInfo = context.getVolumeInfo();
final VolumeApiResult res = new VolumeApiResult(volumeInfo);
if (result.isSuccess()) {
// volumeInfo.processEvent(Event.OperationSuccessed, result.getAnswer());
final VolumeVO volume = volDao.findById(volumeInfo.getId());
final CopyCmdAnswer answer = (CopyCmdAnswer) result.getAnswer();
final TemplateObjectTO templateObjectTo = (TemplateObjectTO) answer.getNewData();
volume.setPath(templateObjectTo.getPath());
if (templateObjectTo.getFormat() != null) {
volume.setFormat(templateObjectTo.getFormat());
}
volDao.update(volume.getId(), volume);
} else {
volumeInfo.processEvent(Event.DestroyRequested);
res.setResult(result.getResult());
}
final AsyncCallFuture<VolumeApiResult> future = context.getFuture();
future.complete(res);
return null;
}
use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolumeFromPrimaryToImageCallback.
protected Void copyVolumeFromPrimaryToImageCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CopyVolumeContext<VolumeApiResult> context) {
final VolumeInfo srcVolume = context.srcVolume;
final VolumeInfo destVolume = context.destVolume;
final CopyCommandResult result = callback.getResult();
final AsyncCallFuture<VolumeApiResult> future = context.future;
final VolumeApiResult res = new VolumeApiResult(destVolume);
try {
if (result.isFailed()) {
// back to Ready state in Volume table
srcVolume.processEvent(Event.OperationFailed);
destVolume.processEventOnly(Event.OperationFailed);
res.setResult(result.getResult());
future.complete(res);
} else {
// back to Ready state in Volume table
srcVolume.processEvent(Event.OperationSuccessed);
destVolume.processEventOnly(Event.OperationSuccessed, result.getAnswer());
future.complete(res);
}
} catch (final Exception e) {
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeAsync.
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeAsync(final VolumeInfo volume, final DataStore dataStore) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final DataObject volumeOnStore = dataStore.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().createVolumeCallback(null, null)).setContext(context);
dataStore.getDriver().createAsync(dataStore, 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(dataStore.getId(), volume.getId());
if (volStoreVO != null) {
final VolumeInfo volObj = volFactory.getVolume(volume, dataStore);
volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
final VolumeApiResult volResult = new VolumeApiResult((VolumeObject) volumeOnStore);
volResult.setResult(ex.getMessage());
future.complete(volResult);
}
return future;
}
use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolumeFromImageToPrimaryCallback.
protected Void copyVolumeFromImageToPrimaryCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CopyVolumeContext<VolumeApiResult> context) {
final VolumeInfo srcVolume = context.srcVolume;
final VolumeInfo destVolume = context.destVolume;
final CopyCommandResult result = callback.getResult();
final AsyncCallFuture<VolumeApiResult> future = context.future;
final VolumeApiResult res = new VolumeApiResult(destVolume);
try {
if (result.isFailed()) {
destVolume.processEvent(Event.OperationFailed);
srcVolume.processEvent(Event.OperationFailed);
res.setResult(result.getResult());
future.complete(res);
return null;
}
srcVolume.processEvent(Event.OperationSuccessed);
destVolume.processEvent(Event.OperationSuccessed, result.getAnswer());
srcVolume.getDataStore().delete(srcVolume);
future.complete(res);
} catch (final Exception e) {
res.setResult(e.toString());
future.complete(res);
}
return null;
}
use of com.cloud.engine.subsystem.api.storage.VolumeInfo in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromSnapshotCallback.
protected Void createVolumeFromSnapshotCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback, final CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
final CopyCommandResult result = callback.getResult();
final VolumeInfo volume = (VolumeInfo) context.templateOnStore;
final SnapshotInfo snapshot = context.snapshot;
final VolumeApiResult apiResult = new VolumeApiResult(volume);
Event event = null;
if (result.isFailed()) {
apiResult.setResult(result.getResult());
event = Event.OperationFailed;
} else {
event = Event.OperationSuccessed;
}
try {
if (result.isSuccess()) {
volume.processEvent(event, result.getAnswer());
} else {
volume.processEvent(event);
}
snapshot.processEvent(event);
} catch (final Exception e) {
s_logger.debug("create volume from snapshot failed", e);
apiResult.setResult(e.toString());
}
final AsyncCallFuture<VolumeApiResult> future = context.future;
future.complete(apiResult);
return null;
}
Aggregations