use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromTemplateAsync.
@DB
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(final VolumeInfo volume, final long dataStoreId, final TemplateInfo template) {
final PrimaryDataStore pd = dataStoreMgr.getPrimaryDataStore(dataStoreId);
final TemplateInfo templateOnPrimaryStore = pd.getTemplate(template.getId());
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
if (templateOnPrimaryStore == null) {
createBaseImageAsync(volume, pd, template, future);
return future;
}
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, future);
return future;
}
use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method createVolumeFromSnapshot.
@Override
public AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(final VolumeInfo volume, final DataStore store, final SnapshotInfo snapshot) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
try {
final DataObject volumeOnStore = store.create(volume);
volumeOnStore.processEvent(Event.CreateOnlyRequested);
snapshot.processEvent(Event.CopyingRequested);
final CreateVolumeFromBaseImageContext<VolumeApiResult> context = new CreateVolumeFromBaseImageContext<>(null, volume, store, volumeOnStore, future, snapshot);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeFromSnapshotCallback(null, null)).setContext(context);
motionSrv.copyAsync(snapshot, volumeOnStore, caller);
} catch (final Exception e) {
s_logger.debug("create volume from snapshot failed", e);
final VolumeApiResult result = new VolumeApiResult(volume);
result.setResult(e.toString());
future.complete(result);
}
return future;
}
use of com.cloud.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolumeFromImageToPrimary.
protected AsyncCallFuture<VolumeApiResult> copyVolumeFromImageToPrimary(final VolumeInfo srcVolume, final DataStore destStore) {
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final VolumeApiResult res = new VolumeApiResult(srcVolume);
VolumeInfo destVolume = null;
try {
destVolume = (VolumeInfo) destStore.create(srcVolume);
destVolume.processEvent(Event.CopyingRequested);
srcVolume.processEvent(Event.CopyingRequested);
final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyVolumeFromImageToPrimaryCallback(null, null)).setContext(context);
motionSrv.copyAsync(srcVolume, destVolume, caller);
return future;
} catch (final Exception e) {
s_logger.error("failed to copy volume from image store", e);
if (destVolume != null) {
destVolume.processEvent(Event.OperationFailed);
}
srcVolume.processEvent(Event.OperationFailed);
res.setResult(e.toString());
future.complete(res);
return future;
}
}
use of com.cloud.framework.async.AsyncCallFuture 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.framework.async.AsyncCallFuture in project cosmic by MissionCriticalCloud.
the class VolumeServiceImpl method copyVolume.
@Override
public AsyncCallFuture<VolumeApiResult> copyVolume(final VolumeInfo srcVolume, final DataStore destStore) {
if (srcVolume.getState() == Volume.State.Uploaded) {
return copyVolumeFromImageToPrimary(srcVolume, destStore);
}
if (destStore.getRole() == DataStoreRole.Image) {
return copyVolumeFromPrimaryToImage(srcVolume, destStore);
}
final AsyncCallFuture<VolumeApiResult> future = new AsyncCallFuture<>();
final VolumeApiResult res = new VolumeApiResult(srcVolume);
try {
if (!snapshotMgr.canOperateOnVolume(srcVolume)) {
s_logger.debug("There are snapshots creating on this volume, can not move this volume");
res.setResult("There are snapshots creating on this volume, can not move this volume");
future.complete(res);
return future;
}
final VolumeVO destVol = duplicateVolumeOnAnotherStorage(srcVolume, (StoragePool) destStore);
final VolumeInfo destVolume = volFactory.getVolume(destVol.getId(), destStore);
destVolume.processEvent(Event.MigrationCopyRequested);
srcVolume.processEvent(Event.MigrationRequested);
final CopyVolumeContext<VolumeApiResult> context = new CopyVolumeContext<>(null, future, srcVolume, destVolume, destStore);
final AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyVolumeCallBack(null, null)).setContext(context);
motionSrv.copyAsync(srcVolume, destVolume, caller);
} catch (final Exception e) {
s_logger.debug("Failed to copy volume" + e);
res.setResult(e.toString());
future.complete(res);
}
return future;
}
Aggregations