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();
}
}
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();
}
}
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);
}
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;
}
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;
}
Aggregations