Search in sources :

Example 66 with DiskOfferingVO

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);
}
Also used : CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) FileSystem(org.apache.cloudstack.storage.datastore.util.ElastistorUtil.FileSystem) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) CreateCmdResult(org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult)

Example 67 with DiskOfferingVO

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);
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 68 with DiskOfferingVO

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);
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 69 with DiskOfferingVO

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;
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO)

Example 70 with DiskOfferingVO

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);
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Aggregations

DiskOfferingVO (com.cloud.storage.DiskOfferingVO)86 ArrayList (java.util.ArrayList)34 ServiceOfferingVO (com.cloud.service.ServiceOfferingVO)32 VolumeVO (com.cloud.storage.VolumeVO)25 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)24 Account (com.cloud.user.Account)23 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)22 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)18 List (java.util.List)16 StoragePool (com.cloud.storage.StoragePool)15 HypervisorType (com.cloud.hypervisor.Hypervisor.HypervisorType)14 DiskProfile (com.cloud.vm.DiskProfile)14 VMInstanceVO (com.cloud.vm.VMInstanceVO)14 HostVO (com.cloud.host.HostVO)13 NetworkVO (com.cloud.network.dao.NetworkVO)13 Pair (com.cloud.utils.Pair)13 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)12 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)12 User (com.cloud.user.User)12 HashMap (java.util.HashMap)12