Search in sources :

Example 11 with StoragePoolAllocator

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

the class ManagementServerImpl method hasSuitablePoolsForVolume.

private boolean hasSuitablePoolsForVolume(final VolumeVO volume, final Host host, final VirtualMachineProfile vmProfile) {
    final DiskOfferingVO diskOffering = _diskOfferingDao.findById(volume.getDiskOfferingId());
    final DiskProfile diskProfile = new DiskProfile(volume, diskOffering, vmProfile.getHypervisorType());
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), host.getId(), null, null);
    final ExcludeList avoid = new ExcludeList();
    for (final StoragePoolAllocator allocator : _storagePoolAllocators) {
        final List<StoragePool> poolList = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, 1);
        if (poolList != null && !poolList.isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) StoragePool(com.cloud.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) DiskProfile(com.cloud.vm.DiskProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 12 with StoragePoolAllocator

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

the class VirtualMachineManagerImplTest method getCandidateStoragePoolsToMigrateLocalVolumeTestMoreThanOneAllocator.

@Test
public void getCandidateStoragePoolsToMigrateLocalVolumeTestMoreThanOneAllocator() {
    StoragePoolAllocator storagePoolAllocatorMock2 = Mockito.mock(StoragePoolAllocator.class);
    StoragePoolAllocator storagePoolAllocatorMock3 = Mockito.mock(StoragePoolAllocator.class);
    List<StoragePoolAllocator> storagePoolAllocatorsMock = new ArrayList<>();
    storagePoolAllocatorsMock.add(storagePoolAllocatorMock);
    storagePoolAllocatorsMock.add(storagePoolAllocatorMock2);
    storagePoolAllocatorsMock.add(storagePoolAllocatorMock3);
    virtualMachineManagerImpl.setStoragePoolAllocators(storagePoolAllocatorsMock);
    Mockito.doReturn(Mockito.mock(DiskOfferingVO.class)).when(diskOfferingDaoMock).findById(Mockito.anyLong());
    Mockito.doReturn(false).when(storagePoolVoMock).isLocal();
    List<StoragePool> poolListMock = new ArrayList<>();
    poolListMock.add(storagePoolVoMock);
    Mockito.doReturn(poolListMock).when(storagePoolAllocatorMock).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class), Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
    Mockito.doReturn(null).when(storagePoolAllocatorMock2).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class), Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
    Mockito.doReturn(new ArrayList<>()).when(storagePoolAllocatorMock3).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class), Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
    Mockito.doReturn(false).when(virtualMachineManagerImpl).isStorageCrossClusterMigration(hostMockId, storagePoolVoMock);
    List<StoragePool> poolList = virtualMachineManagerImpl.getCandidateStoragePoolsToMigrateLocalVolume(virtualMachineProfileMock, dataCenterDeploymentMock, volumeVoMock);
    Assert.assertTrue(poolList.isEmpty());
    Mockito.verify(storagePoolAllocatorMock).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class), Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
    Mockito.verify(storagePoolAllocatorMock2).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class), Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
    Mockito.verify(storagePoolAllocatorMock3).allocateToPool(Mockito.any(DiskProfile.class), Mockito.any(VirtualMachineProfile.class), Mockito.any(DeploymentPlan.class), Mockito.any(ExcludeList.class), Mockito.eq(StoragePoolAllocator.RETURN_UPTO_ALL));
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DiskOfferingVO(com.cloud.storage.DiskOfferingVO) ArrayList(java.util.ArrayList) DeploymentPlan(com.cloud.deploy.DeploymentPlan) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator) Test(org.junit.Test)

Example 13 with StoragePoolAllocator

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

the class VolumeOrchestrator method findChildDataStoreInDataStoreCluster.

@Override
public StoragePool findChildDataStoreInDataStoreCluster(DataCenter dc, Pod pod, Long clusterId, Long hostId, VirtualMachine vm, Long datastoreClusterId) {
    Long podId = null;
    if (pod != null) {
        podId = pod.getId();
    } else if (clusterId != null) {
        Cluster cluster = _entityMgr.findById(Cluster.class, clusterId);
        if (cluster != null) {
            podId = cluster.getPodId();
        }
    }
    List<StoragePoolVO> childDatastores = _storagePoolDao.listChildStoragePoolsInDatastoreCluster(datastoreClusterId);
    List<StoragePool> suitablePools = new ArrayList<StoragePool>();
    for (StoragePoolVO childDatastore : childDatastores) suitablePools.add((StoragePool) dataStoreMgr.getDataStore(childDatastore.getId(), DataStoreRole.Primary));
    VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
        final List<StoragePool> poolList = allocator.reorderPools(suitablePools, profile, plan, null);
        if (poolList != null && !poolList.isEmpty()) {
            return (StoragePool) dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
        }
    }
    return null;
}
Also used : StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) StoragePoolVO(org.apache.cloudstack.storage.datastore.db.StoragePoolVO) ArrayList(java.util.ArrayList) Cluster(com.cloud.org.Cluster) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 14 with StoragePoolAllocator

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

the class VolumeOrchestrator method findStoragePool.

@Override
public StoragePool findStoragePool(DiskProfile dskCh, DataCenter dc, Pod pod, Long clusterId, Long hostId, VirtualMachine vm, final Set<StoragePool> avoid) {
    Long podId = null;
    if (pod != null) {
        podId = pod.getId();
    } else if (clusterId != null) {
        Cluster cluster = _entityMgr.findById(Cluster.class, clusterId);
        if (cluster != null) {
            podId = cluster.getPodId();
        }
    }
    VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        ExcludeList avoidList = new ExcludeList();
        for (StoragePool pool : avoid) {
            avoidList.addPool(pool.getId());
        }
        DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
        final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, StoragePoolAllocator.RETURN_UPTO_ALL);
        if (poolList != null && !poolList.isEmpty()) {
            // Check if the preferred storage pool can be used. If yes, use it.
            Optional<StoragePool> storagePool = getPreferredStoragePool(poolList, vm);
            return (storagePool.isPresent()) ? (StoragePool) this.dataStoreMgr.getDataStore(storagePool.get().getId(), DataStoreRole.Primary) : (StoragePool) dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
        }
    }
    return null;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) Cluster(com.cloud.org.Cluster) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) StoragePoolAllocator(org.apache.cloudstack.engine.subsystem.api.storage.StoragePoolAllocator)

Example 15 with StoragePoolAllocator

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

the class VolumeOrchestrator method findStoragePoolsForVolumeWithNewDiskOffering.

public List<StoragePool> findStoragePoolsForVolumeWithNewDiskOffering(DiskProfile dskCh, DataCenter dc, Pod pod, Long clusterId, Long hostId, VirtualMachine vm, final Set<StoragePool> avoid) {
    Long podId = null;
    if (pod != null) {
        podId = pod.getId();
    } else if (clusterId != null) {
        Cluster cluster = _entityMgr.findById(Cluster.class, clusterId);
        if (cluster != null) {
            podId = cluster.getPodId();
        }
    }
    VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    List<StoragePool> suitablePools = new ArrayList<>();
    for (StoragePoolAllocator allocator : _storagePoolAllocators) {
        ExcludeList avoidList = new ExcludeList();
        for (StoragePool pool : avoid) {
            avoidList.addPool(pool.getId());
        }
        DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
        final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, StoragePoolAllocator.RETURN_UPTO_ALL);
        if (CollectionUtils.isEmpty(poolList)) {
            continue;
        }
        suitablePools.addAll(poolList);
    }
    return suitablePools;
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) StoragePool(com.cloud.storage.StoragePool) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) VirtualMachineProfileImpl(com.cloud.vm.VirtualMachineProfileImpl) ArrayList(java.util.ArrayList) Cluster(com.cloud.org.Cluster) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) 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