You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by GitBox <gi...@apache.org> on 2021/07/29 10:00:08 UTC

[GitHub] [cloudstack] DaanHoogland commented on a change in pull request #5249: Global setting to select preferred storage pool

DaanHoogland commented on a change in pull request #5249:
URL: https://github.com/apache/cloudstack/pull/5249#discussion_r679004476



##########
File path: server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java
##########
@@ -1674,7 +1675,12 @@ protected boolean hostCanAccessSPool(Host host, StoragePool pool) {
             for (StoragePoolAllocator allocator : _storagePoolAllocators) {
                 final List<StoragePool> suitablePools = allocator.allocateToPool(diskProfile, vmProfile, plan, avoid, returnUpTo);
                 if (suitablePools != null && !suitablePools.isEmpty()) {
-                    suitableVolumeStoragePools.put(toBeCreated, suitablePools);
+                    List<StoragePool> pools = new ArrayList<>();
+                    Optional<StoragePool> storagePool = getPreferredStoragePool(suitablePools, vmProfile.getVirtualMachine());
+                    storagePool.ifPresent(pools::add);
+
+                    pools.addAll(suitablePools);
+                    suitableVolumeStoragePools.put(toBeCreated, pools);

Review comment:
       can you extract this bit as to not enlarge an already too long method, please?

##########
File path: engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java
##########
@@ -321,9 +347,13 @@ public StoragePool findStoragePool(DiskProfile dskCh, DataCenter dc, Pod pod, Lo
             }
             DataCenterDeployment plan = new DataCenterDeployment(dc.getId(), podId, clusterId, hostId, null, null);
 
-            final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, 1);
+            final List<StoragePool> poolList = allocator.allocateToPool(dskCh, profile, plan, avoidList, StoragePoolAllocator.RETURN_UPTO_ALL);
             if (poolList != null && !poolList.isEmpty()) {
-                return (StoragePool)dataStoreMgr.getDataStore(poolList.get(0).getId(), DataStoreRole.Primary);
+                // 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);

Review comment:
       can you extract this into a `private StoragePool checkPreferredStorageForUse(..)` and than store the result in a `StoragePool poolToReturn = null;` so we have only one exit point. I.E. end the method with `return poolToReturn`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org