use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class DataObjectManagerImpl method copyAsync.
@Override
public void copyAsync(final DataObject srcData, final DataObject destData, final AsyncCompletionCallback<CreateCmdResult> callback) {
try {
objectInDataStoreMgr.update(destData, ObjectInDataStoreStateMachine.Event.CopyingRequested);
} catch (final NoTransitionException | ConcurrentOperationException e) {
s_logger.debug("failed to change state", e);
try {
objectInDataStoreMgr.update(destData, 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 change state: " + e.toString());
callback.complete(res);
}
final CopyContext<CreateCmdResult> anotherCall = new CopyContext<>(callback, srcData, destData);
final AsyncCallbackDispatcher<DataObjectManagerImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyCallback(null, null)).setContext(anotherCall);
motionSrv.copyAsync(srcData, destData, caller);
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult 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;
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createManagedStorageAndVolumeFromTemplateAsync.
@Override
public AsyncCallFuture<VolumeApiResult> createManagedStorageAndVolumeFromTemplateAsync(VolumeInfo volumeInfo, final long destDataStoreId, final TemplateInfo srcTemplateInfo, final long destHostId) {
final PrimaryDataStore destPrimaryDataStore = dataStoreMgr.getPrimaryDataStore(destDataStoreId);
final TemplateInfo destTemplateInfo = (TemplateInfo) destPrimaryDataStore.create(srcTemplateInfo);
final Host destHost = _hostDao.findById(destHostId);
if (destHost == null) {
throw new CloudRuntimeException("Destinatin host should not be null.");
}
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
try {
// must call driver to have a volume created
final AsyncCallFuture<VolumeApiResult> createVolumeFuture = createVolumeAsync(volumeInfo, destPrimaryDataStore);
final VolumeApiResult createVolumeResult = createVolumeFuture.get();
if (createVolumeResult.isFailed()) {
throw new CloudRuntimeException("Creation of a volume failed: " + createVolumeResult.getResult());
}
// refresh the volume from the DB
volumeInfo = volFactory.getVolume(volumeInfo.getId(), destPrimaryDataStore);
grantAccess(volumeInfo, destHost, destPrimaryDataStore);
final ManagedCreateBaseImageContext<CreateCmdResult> context = new ManagedCreateBaseImageContext<>(null, volumeInfo, destPrimaryDataStore, srcTemplateInfo, future);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().managedCopyBaseImageCallback(null, null)).setContext(context);
final Map<String, String> details = new HashMap<>();
details.put(PrimaryDataStore.MANAGED, Boolean.TRUE.toString());
details.put(PrimaryDataStore.STORAGE_HOST, destPrimaryDataStore.getHostAddress());
details.put(PrimaryDataStore.STORAGE_PORT, String.valueOf(destPrimaryDataStore.getPort()));
// for managed storage, the storage repository (XenServer) or datastore (ESX) name is based off of the iScsiName property of a volume
details.put(PrimaryDataStore.MANAGED_STORE_TARGET, volumeInfo.get_iScsiName());
details.put(PrimaryDataStore.MANAGED_STORE_TARGET_ROOT_VOLUME, volumeInfo.getName());
details.put(PrimaryDataStore.VOLUME_SIZE, String.valueOf(volumeInfo.getSize()));
final ChapInfo chapInfo = getChapInfo(volumeInfo, destPrimaryDataStore);
if (chapInfo != null) {
details.put(PrimaryDataStore.CHAP_INITIATOR_USERNAME, chapInfo.getInitiatorUsername());
details.put(PrimaryDataStore.CHAP_INITIATOR_SECRET, chapInfo.getInitiatorSecret());
details.put(PrimaryDataStore.CHAP_TARGET_USERNAME, chapInfo.getTargetUsername());
details.put(PrimaryDataStore.CHAP_TARGET_SECRET, chapInfo.getTargetSecret());
}
destPrimaryDataStore.setDetails(details);
motionSrv.copyAsync(srcTemplateInfo, destTemplateInfo, destHost, caller);
} catch (InterruptedException | ExecutionException e) {
String errMsg = e.getMessage();
volumeInfo.processEvent(Event.DestroyRequested);
revokeAccess(volumeInfo, destHost, destPrimaryDataStore);
try {
final AsyncCallFuture<VolumeApiResult> expungeVolumeFuture = expungeVolumeAsync(volumeInfo);
final VolumeApiResult expungeVolumeResult = expungeVolumeFuture.get();
if (expungeVolumeResult.isFailed()) {
errMsg += " : Failed to expunge a volume that was created";
}
} catch (InterruptedException | ExecutionException innerException) {
errMsg += " : " + innerException.getMessage();
}
final VolumeApiResult result = new VolumeApiResult(volumeInfo);
result.setResult(errMsg);
future.complete(result);
}
return future;
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method resizeVolumeCallback.
protected Void resizeVolumeCallback(final AsyncCallbackDispatcher<VolumeServiceImpl, CreateCmdResult> callback, final CreateVolumeContext<VolumeApiResult> context) {
final CreateCmdResult result = callback.getResult();
final AsyncCallFuture<VolumeApiResult> future = context.future;
final VolumeInfo volume = (VolumeInfo) context.volume;
if (result.isFailed()) {
try {
volume.processEvent(Event.OperationFailed);
} catch (final Exception e) {
s_logger.debug("Failed to change state", e);
}
final VolumeApiResult res = new VolumeApiResult(volume);
res.setResult(result.getResult());
future.complete(res);
return null;
}
try {
volume.processEvent(Event.OperationSuccessed);
} catch (final Exception e) {
s_logger.debug("Failed to change state", e);
final VolumeApiResult res = new VolumeApiResult(volume);
res.setResult(result.getResult());
future.complete(res);
return null;
}
final VolumeApiResult res = new VolumeApiResult(volume);
future.complete(res);
return null;
}
use of com.cloud.engine.subsystem.api.storage.CreateCmdResult in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method registerVolume.
@Override
public AsyncCallFuture<VolumeApiResult> registerVolume(final VolumeInfo volume, final DataStore store) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final DataObject volumeOnStore = store.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().registerVolumeCallback(null, null));
caller.setContext(context);
store.getDriver().createAsync(store, 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(store.getId(), volume.getId());
if (volStoreVO != null) {
final VolumeInfo volObj = volFactory.getVolume(volume, store);
volObj.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
}
final VolumeApiResult res = new VolumeApiResult((VolumeObject) volumeOnStore);
res.setResult(ex.getMessage());
future.complete(res);
}
return future;
}
Aggregations