Search in sources :

Example 6 with StoragePoolAllocator

use of org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator in project cloudstack by apache.

the class StorageAllocatorTest method testClusterAllocatorMultiplePools.

@Test
public void testClusterAllocatorMultiplePools() {
    Long newStorageId = null;
    try {
        createDb();
        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());
        StoragePoolVO newStorage = storagePoolDao.persist(storage);
        newStorageId = newStorage.getId();
        DiskProfile profile = new DiskProfile(volume, diskOffering, 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.size(), 1);
                foundAcct++;
            }
        }
        if (foundAcct > 1 || foundAcct == 0) {
            Assert.fail();
        }
    } catch (Exception e) {
        cleanDb();
        if (newStorageId != null) {
            storagePoolDao.remove(newStorageId);
        }
        Assert.fail();
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) DataStoreProvider(org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 7 with StoragePoolAllocator

use of org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator in project cloudstack by apache.

the class StorageAllocatorTest method testLocalStorageAllocator.

@Test
public void testLocalStorageAllocator() {
    try {
        createDb();
        StoragePoolVO pool = storagePoolDao.findById(storagePoolId);
        pool.setScope(ScopeType.HOST);
        storagePoolDao.update(pool.getId(), pool);
        DiskOfferingVO diskOff = diskOfferingDao.findById(diskOfferingId);
        diskOff.setUseLocalStorage(true);
        diskOfferingDao.update(diskOfferingId, 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) DiskProfile(com.cloud.vm.DiskProfile) Volume(com.cloud.storage.Volume) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 8 with StoragePoolAllocator

use of org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator in project cloudstack by apache.

the class GarbageCollectingStoragePoolAllocator method select.

@Override
public List<StoragePool> select(DiskProfile dskCh, VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo, boolean bypassStorageTypeCheck) {
    s_logger.debug("GarbageCollectingStoragePoolAllocator looking for storage pool");
    if (!_storagePoolCleanupEnabled) {
        s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped.");
        return null;
    }
    // Clean up all storage pools
    storageMgr.cleanupStorage(false);
    // Determine what allocator to use
    StoragePoolAllocator allocator;
    if (dskCh.useLocalStorage()) {
        allocator = _localStoragePoolAllocator;
    } else {
        allocator = _firstFitStoragePoolAllocator;
    }
    // Try to find a storage pool after cleanup
    ExcludeList myAvoids = new ExcludeList(avoid.getDataCentersToAvoid(), avoid.getPodsToAvoid(), avoid.getClustersToAvoid(), avoid.getHostsToAvoid(), avoid.getPoolsToAvoid());
    return allocator.allocateToPool(dskCh, vmProfile, plan, myAvoids, returnUpTo, bypassStorageTypeCheck);
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 9 with StoragePoolAllocator

use of org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator in project cloudstack by apache.

the class VirtualMachineManagerImpl method getCandidateStoragePoolsToMigrateLocalVolume.

/**
 * We use {@link StoragePoolAllocator} objects to find storage pools for given DataCenterDeployment where we would be able to allocate the given volume.
 */
protected List<StoragePool> getCandidateStoragePoolsToMigrateLocalVolume(VirtualMachineProfile profile, DataCenterDeployment plan, Volume volume) {
    List<StoragePool> poolList = new ArrayList<>();
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    DiskProfile diskProfile = new DiskProfile(volume, diskOffering, profile.getHypervisorType());
    ExcludeList avoid = new ExcludeList();
    StoragePoolVO volumeStoragePool = _storagePoolDao.findById(volume.getPoolId());
    if (volumeStoragePool.isLocal()) {
        diskProfile.setUseLocalStorage(true);
    }
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        List<StoragePool> poolListFromAllocator = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL);
        if (CollectionUtils.isEmpty(poolListFromAllocator)) {
            continue;
        }
        for (StoragePool pool : poolListFromAllocator) {
            if (pool.isLocal() || isStorageCrossClusterMigration(plan.getClusterId(), volumeStoragePool)) {
                poolList.add(pool);
            }
        }
    }
    return poolList;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 10 with StoragePoolAllocator

use of org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator in project cloudstack by apache.

the class ManagementServerImpl method findAllSuitableStoragePoolsForVm.

/**
 *  Looks for all suitable storage pools to allocate the given volume.
 *  We take into account the service offering of the VM and volume to find suitable storage pools. It is also excluded from the search the current storage pool used by the volume.
 *  We use {@link StoragePoolAllocator} to look for possible storage pools to allocate the given volume. We will look for possible local storage poosl even if the volume is using a shared storage disk offering.
 *
 *  Side note: the idea behind this method is to provide power for administrators of manually overriding deployments defined by CloudStack.
 */
private List<StoragePool> findAllSuitableStoragePoolsForVm(final VolumeVO volume, Long diskOfferingId, Long newSize, Long newMinIops, Long newMaxIops, VMInstanceVO vm, Host vmHost, ExcludeList avoid, Cluster srcCluster, HypervisorType hypervisorType) {
    List<StoragePool> suitablePools = new ArrayList<>();
    Long clusterId = null;
    Long podId = null;
    if (srcCluster != null) {
        clusterId = srcCluster.getId();
        podId = srcCluster.getPodId();
    }
    DataCenterDeployment plan = new DataCenterDeployment(volume.getDataCenterId(), podId, clusterId, null, null, null, null);
    VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    // OfflineVmwareMigration: vm might be null here; deal!
    DiskOfferingVO diskOffering = _diskOfferingDao.findById(diskOfferingId);
    DiskProfile diskProfile = new DiskProfile(volume, diskOffering, hypervisorType);
    if (!Objects.equals(volume.getDiskOfferingId(), diskOfferingId)) {
        diskProfile.setSize(newSize);
        diskProfile.setMinIops(newMinIops);
        diskProfile.setMaxIops(newMaxIops);
    }
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        List<StoragePool> pools = allocator.allocateToPool(diskProfile, profile, plan, avoid, StoragePoolAllocator.RETURN_UPTO_ALL, true);
        if (CollectionUtils.isEmpty(pools)) {
            continue;
        }
        for (StoragePool pool : pools) {
            boolean isLocalPoolSameHostAsVmHost = pool.isLocal() && (vmHost == null || StringUtils.equals(vmHost.getPrivateIpAddress(), pool.getHostAddress()));
            if (isLocalPoolSameHostAsVmHost || pool.isShared()) {
                suitablePools.add(pool);
            }
        }
    }
    return suitablePools;
}
Also used : StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Aggregations

StoragePoolAllocator (org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)19 ExcludeList (com.cloud.deploy.DeploymentPlanner.ExcludeList)17 StoragePool (com.cloud.storage.StoragePool)17 DataCenterDeployment (com.cloud.deploy.DataCenterDeployment)14 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)12 DiskProfile (com.cloud.vm.DiskProfile)11 Volume (com.cloud.storage.Volume)10 DeploymentPlan (com.cloud.deploy.DeploymentPlan)9 DiskOfferingVO (com.cloud.storage.DiskOfferingVO)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 StoragePoolVO (org.apache.cloudstack.storage.datastore.db.StoragePoolVO)8 VirtualMachineProfileImpl (com.cloud.vm.VirtualMachineProfileImpl)4 Cluster (com.cloud.org.Cluster)3 VolumeVO (com.cloud.storage.VolumeVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 HashMap (java.util.HashMap)2 StoragePoolDetailVO (org.apache.cloudstack.storage.datastore.db.StoragePoolDetailVO)2 DataCenterVO (com.cloud.dc.DataCenterVO)1 Account (com.cloud.user.Account)1