Search in sources :

Example 11 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class DiskOfferingDaoImpl method remove.

@Override
public boolean remove(Long id) {
    DiskOfferingVO diskOffering = createForUpdate();
    diskOffering.setRemoved(new Date());
    return update(id, diskOffering);
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) Date(java.util.Date)

Example 12 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class ServiceOfferingDaoImpl method createSystemServiceOfferings.

@Override
public List<ServiceOfferingVO> createSystemServiceOfferings(String name, String uniqueName, int cpuCount, int ramSize, int cpuSpeed, Integer rateMbps, Integer multicastRateMbps, boolean offerHA, String displayText, ProvisioningType provisioningType, boolean recreatable, String tags, boolean systemUse, VirtualMachine.Type vmType, boolean defaultUse) {
    DiskOfferingVO diskOfferingVO = new DiskOfferingVO(name, displayText, provisioningType, false, tags, recreatable, false, true);
    diskOfferingVO.setUniqueName(uniqueName);
    diskOfferingVO = diskOfferingDao.persistDefaultDiskOffering(diskOfferingVO);
    List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
    ServiceOfferingVO offering = new ServiceOfferingVO(name, cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText, systemUse, vmType, defaultUse);
    offering.setUniqueName(uniqueName);
    offering.setDiskOfferingId(diskOfferingVO.getId());
    offering = persistSystemServiceOffering(offering);
    if (offering != null) {
        list.add(offering);
    }
    boolean useLocal = true;
    if (diskOfferingVO.isUseLocalStorage()) {
        // if 1st one is already local then 2nd needs to be shared
        useLocal = false;
    }
    diskOfferingVO = new DiskOfferingVO(name + (useLocal ? " - Local Storage" : ""), displayText, provisioningType, false, tags, recreatable, useLocal, true);
    diskOfferingVO.setUniqueName(uniqueName + (useLocal ? "-Local" : ""));
    diskOfferingVO = diskOfferingDao.persistDefaultDiskOffering(diskOfferingVO);
    offering = new ServiceOfferingVO(name + (useLocal ? " - Local Storage" : ""), cpuCount, ramSize, cpuSpeed, rateMbps, multicastRateMbps, offerHA, displayText, systemUse, vmType, defaultUse);
    offering.setUniqueName(uniqueName + (useLocal ? "-Local" : ""));
    offering.setDiskOfferingId(diskOfferingVO.getId());
    offering = persistSystemServiceOffering(offering);
    if (offering != null) {
        list.add(offering);
    }
    return list;
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 13 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class ServiceOfferingDaoImpl method persistSystemServiceOffering.

@Override
@DB
public ServiceOfferingVO persistSystemServiceOffering(ServiceOfferingVO offering) {
    assert offering.getUniqueName() != null : "how are you going to find this later if you don't set it?";
    ServiceOfferingVO vo = findByName(offering.getUniqueName());
    if (vo != null) {
        DiskOfferingVO diskOfferingVO = diskOfferingDao.findById(vo.getDiskOfferingId());
        // check invalid CPU speed in system service offering, set it to default value of 500 Mhz if 0 CPU speed is found
        if (vo.getSpeed() <= 0) {
            vo.setSpeed(500);
            update(vo.getId(), vo);
        }
        if (!vo.getUniqueName().endsWith("-Local")) {
            if (diskOfferingVO.isUseLocalStorage()) {
                vo.setUniqueName(vo.getUniqueName() + "-Local");
                vo.setName(vo.getName() + " - Local Storage");
                update(vo.getId(), vo);
            }
        }
        return vo;
    }
    try {
        return persist(offering);
    } catch (EntityExistsException e) {
        // Assume it's conflict on unique name
        return findByName(offering.getUniqueName());
    }
}
Also used : DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) EntityExistsException(javax.persistence.EntityExistsException) DB(com.cloud.utils.db.DB)

Example 14 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class StorageAllocatorTest method createDb.

protected void createDb() {
    DataCenterVO dc = new DataCenterVO(UUID.randomUUID().toString(), "test", "8.8.8.8", null, "10.0.0.1", null, "10.0.0.1/24", null, null, NetworkType.Basic, null, null, true, true, null, null);
    dc = dcDao.persist(dc);
    dcId = dc.getId();
    HostPodVO pod = new HostPodVO(UUID.randomUUID().toString(), dc.getId(), "255.255.255.255", "", 8, "test");
    pod = podDao.persist(pod);
    podId = pod.getId();
    ClusterVO cluster = new ClusterVO(dc.getId(), pod.getId(), "devcloud cluster");
    cluster.setHypervisorType(HypervisorType.XenServer.toString());
    cluster.setClusterType(ClusterType.CloudManaged);
    cluster.setManagedState(ManagedState.Managed);
    cluster = clusterDao.persist(cluster);
    clusterId = cluster.getId();
    DataStoreProvider provider = providerMgr.getDataStoreProvider(DataStoreProvider.DEFAULT_PRIMARY);
    storage = new StoragePoolVO();
    storage.setDataCenterId(dcId);
    storage.setPodId(podId);
    storage.setPoolType(StoragePoolType.NetworkFilesystem);
    storage.setClusterId(clusterId);
    storage.setStatus(StoragePoolStatus.Up);
    storage.setScope(ScopeType.CLUSTER);
    storage.setUsedBytes(1000);
    storage.setCapacityBytes(20000);
    storage.setHostAddress(UUID.randomUUID().toString());
    storage.setPath(UUID.randomUUID().toString());
    storage.setStorageProviderName(provider.getName());
    storage = storagePoolDao.persist(storage);
    storagePoolId = storage.getId();
    storageMgr.createCapacityEntry(storage.getId());
    diskOffering = new DiskOfferingVO();
    diskOffering.setDiskSize(500);
    diskOffering.setName("test-disk");
    diskOffering.setSystemUse(false);
    diskOffering.setUseLocalStorage(false);
    diskOffering.setCustomized(false);
    diskOffering.setRecreatable(false);
    diskOffering = diskOfferingDao.persist(diskOffering);
    diskOfferingId = diskOffering.getId();
    volume = new VolumeVO(Volume.Type.ROOT, "volume", dcId, 1, 1, diskOffering.getId(), Storage.ProvisioningType.THIN, diskOffering.getDiskSize(), diskOffering.getMinIops(), diskOffering.getMaxIops(), "");
    volume = volumeDao.persist(volume);
    volumeId = volume.getId();
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ClusterVO(com.cloud.dc.ClusterVO) VolumeVO(com.cloud.storage.VolumeVO) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) HostPodVO(com.cloud.dc.HostPodVO)

Example 15 with DiskOfferingVO

use of com.cloud.storage.DiskOfferingVO in project cloudstack by apache.

the class StorageAllocatorTest method testClusterAllocatorWithTags.

@Test
public void testClusterAllocatorWithTags() {
    try {
        createDb();
        StoragePoolDetailVO detailVO = new StoragePoolDetailVO(this.storagePoolId, "high", "true", true);
        poolDetailsDao.persist(detailVO);
        DiskOfferingVO diskOff = this.diskOfferingDao.findById(diskOffering.getId());
        List<String> tags = new ArrayList<String>();
        tags.add("high");
        diskOff.setTagsArray(tags);
        diskOfferingDao.update(diskOff.getId(), diskOff);
        DiskProfile profile = new DiskProfile(volume, diskOff, HypervisorType.XenServer);
        VirtualMachineProfile vmProfile = Mockito.mock(VirtualMachineProfile.class);
        Mockito.when(storageMgr.storagePoolHasEnoughSpace(Matchers.anyListOf(Volume.class), Matchers.any(StoragePool.class))).thenReturn(true);
        DeploymentPlan plan = new DataCenterDeployment(dcId, podId, clusterId, null, null, null);
        int foundAcct = 0;
        for (StoragePoolAllocator allocator : allocators) {
            List<StoragePool> pools = allocator.allocateToPool(profile, vmProfile, plan, new ExcludeList(), 1);
            if (!pools.isEmpty()) {
                Assert.assertEquals(pools.get(0).getId(), storage.getId());
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) ArrayList(java.util.ArrayList) StoragePoolDetailVO(org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

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