use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class SamplePrimaryDataStoreDriverImpl method createAsync.
/*
* private class CreateVolumeFromBaseImageContext<T> extends
* AsyncRpcContext<T> { private final VolumeObject volume;
*
* public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T>
* callback, VolumeObject volume) { super(callback); this.volume = volume; }
*
* public VolumeObject getVolume() { return this.volume; }
*
* }
*
* @Override public void createVolumeFromBaseImageAsync(VolumeObject volume,
* TemplateInfo template, AsyncCompletionCallback<CommandResult> callback) {
* VolumeTO vol = this.dataStore.getVolumeTO(volume); List<EndPoint>
* endPoints = this.dataStore.getEndPoints(); EndPoint ep =
* endPoints.get(0); String templateUri =
* template.getDataStore().grantAccess(template, ep);
* CreateVolumeFromBaseImageCommand cmd = new
* CreateVolumeFromBaseImageCommand(vol, templateUri);
*
* CreateVolumeFromBaseImageContext<CommandResult> context = new
* CreateVolumeFromBaseImageContext<CommandResult>(callback, volume);
* AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl, Answer> caller
* = AsyncCallbackDispatcher.create(this); caller.setContext(context)
* .setCallback
* (caller.getTarget().createVolumeFromBaseImageAsyncCallback(null, null));
*
* ep.sendMessageAsync(cmd, caller); }
*/
/*
* public Object
* createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher
* <DefaultPrimaryDataStoreDriverImpl, Answer> callback,
* CreateVolumeFromBaseImageContext<CommandResult> context) {
* CreateVolumeAnswer answer = (CreateVolumeAnswer)callback.getResult();
* CommandResult result = new CommandResult(); if (answer == null ||
* answer.getDetails() != null) { result.setSuccess(false); if (answer !=
* null) { result.setResult(answer.getDetails()); } } else {
* result.setSuccess(true); VolumeObject volume = context.getVolume();
* volume.setPath(answer.getVolumeUuid()); }
* AsyncCompletionCallback<CommandResult> parentCall =
* context.getParentCallback(); parentCall.complete(result); return null; }
*/
@Override
public void createAsync(DataStore dataStore, DataObject vol, AsyncCompletionCallback<CreateCmdResult> callback) {
EndPoint ep = selector.select(vol);
if (ep == null) {
String errMsg = "No remote endpoint to send command, check if host or ssvm is down?";
s_logger.error(errMsg);
throw new CloudRuntimeException(errMsg);
}
CreateObjectCommand createCmd = new CreateObjectCommand(null);
CreateVolumeContext<CreateCmdResult> context = new CreateVolumeContext<CreateCmdResult>(callback, vol);
AsyncCallbackDispatcher<SamplePrimaryDataStoreDriverImpl, Answer> caller = AsyncCallbackDispatcher.create(this);
caller.setContext(context).setCallback(caller.getTarget().createAsyncCallback(null, null));
ep.sendMessageAsync(createCmd, caller);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class CloudStackPrimaryDataStoreDriverImpl method createAsync.
@Override
public void createAsync(DataStore dataStore, DataObject data, AsyncCompletionCallback<CreateCmdResult> callback) {
String errMsg = null;
Answer answer = null;
CreateCmdResult result = new CreateCmdResult(null, null);
if (data.getType() == DataObjectType.VOLUME) {
try {
answer = createVolume((VolumeInfo) data);
if ((answer == null) || (!answer.getResult())) {
result.setSuccess(false);
if (answer != null) {
result.setResult(answer.getDetails());
}
} else {
result.setAnswer(answer);
}
} catch (StorageUnavailableException e) {
s_logger.debug("failed to create volume", e);
errMsg = e.toString();
} catch (Exception e) {
s_logger.debug("failed to create volume", e);
errMsg = e.toString();
}
}
if (errMsg != null) {
result.setResult(errMsg);
}
callback.complete(result);
}
use of org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult in project cloudstack by apache.
the class ElastistorPrimaryDataStoreDriver method createAsync.
@Override
public void createAsync(DataStore dataStore, DataObject dataObject, AsyncCompletionCallback<CreateCmdResult> callback) {
String iqn = null;
String errMsg = null;
CreateCmdResult result = new CreateCmdResult(iqn, new Answer(null, errMsg == null, errMsg));
if (dataObject.getType() == DataObjectType.VOLUME) {
VolumeInfo volumeInfo = (VolumeInfo) dataObject;
long storagePoolId = dataStore.getId();
String volumeName = volumeInfo.getName();
Long Iops = volumeInfo.getMaxIops();
// quota size of the cloudbyte volume will be increased with the given HypervisorSnapshotReserve
Long quotaSize = getDataObjectSizeIncludingHypervisorSnapshotReserve(volumeInfo, _storagePoolDao.findById(storagePoolId));
StoragePoolVO storagePool = _storagePoolDao.findById(dataStore.getId());
VolumeVO volume = _volumeDao.findById(volumeInfo.getId());
// calling super(default) that creates a vdi(disk) only.
if (!(storagePool.isManaged())) {
super.createAsync(dataStore, dataObject, callback);
// update the volume property
volume.setPoolType(storagePool.getPoolType());
_volumeDao.update(volume.getId(), volume);
return;
}
DiskOfferingVO diskOffering = _diskOfferingDao.findById(volumeInfo.getDiskOfferingId());
long capacityIops = storagePool.getCapacityIops();
capacityIops = capacityIops - Iops;
if (capacityIops < 0) {
throw new CloudRuntimeException("IOPS not available. [pool:" + storagePool.getName() + "] [availiops:" + capacityIops + "] [requirediops:" + Iops + "]");
}
String protocoltype = null;
StoragePoolVO dataStoreVO = _storagePoolDao.findById(storagePoolId);
String desc = diskOffering.getDisplayText();
if (desc.toLowerCase().contains("iscsi")) {
protocoltype = "iscsi";
} else if (dataStoreVO.getPoolType().equals(StoragePoolType.NetworkFilesystem) || dataStoreVO.getPoolType().equals(StoragePoolType.Filesystem)) {
protocoltype = "nfs";
} else {
protocoltype = "iscsi";
}
FileSystem esvolume = null;
try {
esvolume = ElastistorUtil.createElastistorVolume(volumeName, dataStoreVO.getUuid(), quotaSize, Iops, protocoltype, volumeName);
} catch (Throwable e) {
s_logger.error(e.toString(), e);
result.setResult(e.toString());
callback.complete(result);
throw new CloudRuntimeException(e.getMessage());
}
if (esvolume.getNfsenabled().equalsIgnoreCase("true")) {
volume.set_iScsiName(esvolume.getPath());
volume.setPoolType(StoragePoolType.NetworkFilesystem);
} else {
iqn = esvolume.getIqn();
String modifiediqn = "/" + iqn + "/0";
volume.set_iScsiName(modifiediqn);
volume.setPoolType(StoragePoolType.IscsiLUN);
}
volume.setFolder(String.valueOf(esvolume.getUuid()));
volume.setPoolId(storagePoolId);
volume.setUuid(esvolume.getUuid());
volume.setPath(null);
_volumeDao.update(volume.getId(), volume);
// create new volume details for the volume
//updateVolumeDetails(volume, esvolume);
long capacityBytes = storagePool.getCapacityBytes();
long usedBytes = storagePool.getUsedBytes();
Long inbytes = volume.getSize();
usedBytes += inbytes;
storagePool.setCapacityIops(capacityIops);
storagePool.setUsedBytes(usedBytes > capacityBytes ? capacityBytes : usedBytes);
_storagePoolDao.update(storagePoolId, storagePool);
s_logger.info("Elastistor volume creation complete.");
} else {
errMsg = "Invalid DataObjectType (" + dataObject.getType() + ") passed to createAsync";
s_logger.error(errMsg);
}
result.setResult(errMsg);
callback.complete(result);
}
Aggregations