tweak logic to consider tags and rule tags at zone and cluster scope

This commit is contained in:
Pearl Dsilva 2026-01-16 15:11:01 -05:00
parent f48cc9cc8a
commit 89d66a1c61
1 changed files with 17 additions and 24 deletions

View File

@ -2009,60 +2009,53 @@ public class ManagementServerImpl extends ManagerBase implements ManagementServe
logger.debug("Finding suitable pools for detached volume {} with offering tags: {}, hypervisor: {}", logger.debug("Finding suitable pools for detached volume {} with offering tags: {}, hypervisor: {}",
volume.getUuid(), tags, hypervisorType); volume.getUuid(), tags, hypervisorType);
// Create a map for quick lookup and deduplication
Map<Long, StoragePool> allPoolsMap = allPools.stream()
.collect(Collectors.toMap(StoragePool::getId, pool -> pool));
Set<Long> matchingPoolIds = new HashSet<>(); Set<Long> matchingPoolIds = new HashSet<>();
List<StoragePoolVO> zonePoolsLiteral = _poolDao.findZoneWideStoragePoolsByTags(dcId, List<StoragePoolVO> zonePoolsStandard = _poolDao.findZoneWideStoragePoolsByTags(dcId,
tags.isEmpty() ? null : tags.toArray(new String[0]), true); tags.isEmpty() ? null : tags.toArray(new String[0]), true);
for (StoragePoolVO pool : zonePoolsLiteral) { for (StoragePoolVO pool : zonePoolsStandard) {
if (pool.getHypervisor() == null || pool.getHypervisor().equals(HypervisorType.Any) || if (pool.getHypervisor() == null || pool.getHypervisor().equals(HypervisorType.Any) ||
pool.getHypervisor().equals(hypervisorType)) { pool.getHypervisor().equals(hypervisorType)) {
matchingPoolIds.add(pool.getId()); matchingPoolIds.add(pool.getId());
logger.debug("Found zone-wide pool with literal tags: {} ({})", pool.getName(), pool.getId()); logger.debug("Found zone-wide pool with standard tags: {} ({})", pool.getName(), pool.getId());
} }
} }
List<StoragePoolVO> zonePoolsRules = _poolJoinDao.findStoragePoolByScopeAndRuleTags(dcId, null, null, List<StoragePoolVO> zonePoolsFlexible = _poolJoinDao.findStoragePoolByScopeAndRuleTags(dcId, null, null,
ScopeType.ZONE, tags); ScopeType.ZONE, tags);
for (StoragePoolVO pool : zonePoolsRules) { for (StoragePoolVO pool : zonePoolsFlexible) {
StoragePoolVO poolVO = _poolDao.findById(pool.getId()); StoragePoolVO poolVO = _poolDao.findById(pool.getId());
if (poolVO != null && (poolVO.getHypervisor() == null || poolVO.getHypervisor().equals(HypervisorType.Any) || if (poolVO != null && (poolVO.getHypervisor() == null || poolVO.getHypervisor().equals(HypervisorType.Any) ||
poolVO.getHypervisor().equals(hypervisorType))) { poolVO.getHypervisor().equals(hypervisorType))) {
matchingPoolIds.add(pool.getId()); matchingPoolIds.add(pool.getId());
logger.debug("Found zone-wide pool with rule-based tags: {} ({})", pool.getName(), pool.getId()); logger.debug("Found zone-wide pool with flexible tags: {} ({})", pool.getName(), pool.getId());
} }
} }
List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, hypervisorType.toString()); List<ClusterVO> clusters = _clusterDao.listByDcHyType(dcId, hypervisorType.toString());
for (ClusterVO cluster : clusters) { for (ClusterVO cluster : clusters) {
List<StoragePoolVO> clusterPoolsLiteral = _poolDao.findPoolsByTags(dcId, cluster.getPodId(), List<StoragePoolVO> clusterPoolsStandard = _poolDao.findPoolsByTags(dcId, cluster.getPodId(),
cluster.getId(), tags.isEmpty() ? null : tags.toArray(new String[0]), true, cluster.getId(), tags.isEmpty() ? null : tags.toArray(new String[0]), true,
VolumeApiServiceImpl.storageTagRuleExecutionTimeout.value()); VolumeApiServiceImpl.storageTagRuleExecutionTimeout.value());
for (StoragePoolVO pool : clusterPoolsLiteral) { for (StoragePoolVO pool : clusterPoolsStandard) {
matchingPoolIds.add(pool.getId()); matchingPoolIds.add(pool.getId());
logger.debug("Found cluster-scoped pool with literal tags: {} ({}) in cluster {}", logger.debug("Found cluster-scoped pool with standard tags: {} ({}) in cluster {}",
pool.getName(), pool.getId(), cluster.getName()); pool.getName(), pool.getId(), cluster.getName());
} }
List<StoragePoolVO> clusterPoolsRules = _poolJoinDao.findStoragePoolByScopeAndRuleTags(dcId,
List<StoragePoolVO> clusterPoolsFlexible = _poolJoinDao.findStoragePoolByScopeAndRuleTags(dcId,
cluster.getPodId(), cluster.getId(), ScopeType.CLUSTER, tags); cluster.getPodId(), cluster.getId(), ScopeType.CLUSTER, tags);
for (StoragePoolVO pool : clusterPoolsRules) { for (StoragePoolVO pool : clusterPoolsFlexible) {
matchingPoolIds.add(pool.getId()); matchingPoolIds.add(pool.getId());
logger.debug("Found cluster-scoped pool with rule-based tags: {} ({}) in cluster {}", logger.debug("Found cluster-scoped pool with flexible tags: {} ({}) in cluster {}",
pool.getName(), pool.getId(), cluster.getName()); pool.getName(), pool.getId(), cluster.getName());
} }
} }
for (Long poolId : matchingPoolIds) { for (StoragePool pool : allPools) {
if (allPoolsMap.containsKey(poolId)) { if (matchingPoolIds.contains(pool.getId()) && StoragePoolStatus.Up.equals(pool.getStatus())) {
StoragePool pool = allPoolsMap.get(poolId); suitablePools.add(pool);
if (StoragePoolStatus.Up.equals(pool.getStatus())) { logger.debug("Added pool {} to suitable pools", pool.getName());
suitablePools.add(pool);
logger.debug("Added pool {} to suitable pools", pool.getName());
} else {
logger.debug("Skipping pool {} - status is {}, not Up", pool.getName(), pool.getStatus());
}
} }
} }