use of com.cloud.storage.DiskOfferingVO 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);
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class UserVmManagerImplTest method prepareResizeVolumeCmdTestOfferingRootSizeZero.
@Test
public void prepareResizeVolumeCmdTestOfferingRootSizeZero() {
DiskOfferingVO rootSizeZero = prepareDiskOffering(0l, 3l, 100L, 200L);
prepareAndRunResizeVolumeTest(null, 100L, 200L, smallerDisdkOffering, rootSizeZero);
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class UserVmManagerImplTest method prepareResizeVolumeCmdTestRootVolumeNull.
@Test(expected = InvalidParameterValueException.class)
public void prepareResizeVolumeCmdTestRootVolumeNull() {
DiskOfferingVO newRootDiskOffering = Mockito.mock(DiskOfferingVO.class);
DiskOfferingVO currentRootDiskOffering = Mockito.mock(DiskOfferingVO.class);
userVmManagerImpl.prepareResizeVolumeCmd(null, currentRootDiskOffering, newRootDiskOffering);
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class UserVmManagerImplTest method prepareDiskOffering.
private DiskOfferingVO prepareDiskOffering(long rootSize, long diskOfferingId, long offeringMinIops, long offeringMaxIops) {
DiskOfferingVO newRootDiskOffering = Mockito.mock(DiskOfferingVO.class);
Mockito.when(newRootDiskOffering.getDiskSize()).thenReturn(rootSize);
Mockito.when(newRootDiskOffering.getId()).thenReturn(diskOfferingId);
Mockito.when(newRootDiskOffering.getMinIops()).thenReturn(offeringMinIops);
Mockito.when(newRootDiskOffering.getMaxIops()).thenReturn(offeringMaxIops);
Mockito.when(newRootDiskOffering.getName()).thenReturn("OfferingName");
return newRootDiskOffering;
}
use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.
the class VMwareGuru method createServiceOfferingForVMImporting.
/**
* Create and persist service offering
*/
private ServiceOfferingVO createServiceOfferingForVMImporting(Integer cpus, Integer memory, Integer maxCpuUsage) {
String name = "Imported-" + cpus + "-" + memory;
DiskOfferingVO diskOfferingVO = new DiskOfferingVO(name, name, Storage.ProvisioningType.THIN, false, null, false, false, true);
diskOfferingVO = diskOfferingDao.persistDefaultDiskOffering(diskOfferingVO);
ServiceOfferingVO vo = new ServiceOfferingVO(name, cpus, memory, maxCpuUsage, null, null, false, name, false, Type.User, false);
vo.setDiskOfferingId(diskOfferingVO.getId());
return serviceOfferingDao.persist(vo);
}
Aggregations