From 70cdd14d74ae138867c378cc0cdfc1ea2003a933 Mon Sep 17 00:00:00 2001 From: nvazquez Date: Wed, 21 Aug 2024 10:37:39 -0300 Subject: [PATCH] Preferred storage pool setting as a cluster setting --- .../java/com/cloud/storage/StorageManager.java | 4 ++-- .../engine/orchestration/VolumeOrchestrator.java | 14 +++++++++----- .../deploy/DeploymentPlanningManagerImpl.java | 12 +++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java index c3909bc56b0d..346aed0de323 100644 --- a/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java +++ b/engine/components-api/src/main/java/com/cloud/storage/StorageManager.java @@ -174,8 +174,8 @@ public interface StorageManager extends StorageService { "If set to true, the disk is created only when there is a suitable storage pool that supports the disk provisioning type specified by the service/disk offering. " + "If set to false, the disk is created with a disk provisioning type supported by the pool. Default value is false, and this is currently supported for VMware only.", true, ConfigKey.Scope.Zone); - ConfigKey PreferredStoragePool = new ConfigKey(String.class, "preferred.storage.pool", "Advanced", "", - "The UUID of preferred storage pool for allocation.", true, ConfigKey.Scope.Account, null); + ConfigKey PreferredStoragePool = new ConfigKey<>(String.class, "preferred.storage.pool", "Advanced", "", + "The UUID of preferred storage pool for allocation.", true, ConfigKey.Scope.Cluster, null); ConfigKey MountDisabledStoragePool = new ConfigKey<>(Boolean.class, "mount.disabled.storage.pool", diff --git a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java index 36e281459492..60f8d6e79bc2 100644 --- a/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java +++ b/engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/VolumeOrchestrator.java @@ -349,16 +349,20 @@ private Optional getMatchingStoragePool(String preferredPoolId, Lis } private Optional getPreferredStoragePool(List poolList, VirtualMachine vm) { - String accountStoragePoolUuid = null; + String clusterPreferredStoragePoolUuid = null; + Long clusterId = null; if (vm != null) { - accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(vm.getAccountId()); + HostVO host = _hostDao.findById(vm.getHostId()); + if (host != null) { + clusterId = host.getClusterId(); + clusterPreferredStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(clusterId); + } } - Optional storagePool = getMatchingStoragePool(accountStoragePoolUuid, poolList); + Optional storagePool = getMatchingStoragePool(clusterPreferredStoragePoolUuid, poolList); if (storagePool.isPresent()) { String storagePoolToString = getReflectOnlySelectedFields(storagePool.get()); - logger.debug("The storage pool [{}] was specified for this account [{}] and will be used for allocation.", storagePoolToString, vm.getAccountId()); - + logger.debug("The storage pool [{}] was specified for this cluster [{}] and will be used for allocation.", storagePoolToString, clusterId); } else { String globalStoragePoolUuid = StorageManager.PreferredStoragePool.value(); storagePool = getMatchingStoragePool(globalStoragePoolUuid, poolList); diff --git a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java index dc302bacae7a..8c25bfcf8d30 100644 --- a/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java +++ b/server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java @@ -1903,11 +1903,17 @@ private Optional getMatchingStoragePool(String preferredPoolId, Lis } private Optional getPreferredStoragePool(List poolList, VirtualMachine vm) { - String accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(vm.getAccountId()); - Optional storagePool = getMatchingStoragePool(accountStoragePoolUuid, poolList); + Optional storagePool = Optional.empty(); + if (vm.getHostId() != null) { + HostVO host = _hostDao.findById(vm.getHostId()); + if (host != null) { + String accountStoragePoolUuid = StorageManager.PreferredStoragePool.valueIn(host.getClusterId()); + storagePool = getMatchingStoragePool(accountStoragePoolUuid, poolList); + } + } if (storagePool.isPresent()) { - logger.debug("A storage pool is specified for this account, so we will use this storage pool for allocation: " + logger.debug("A storage pool is specified for this cluster, so we will use this storage pool for allocation: " + storagePool.get().getUuid()); } else { String globalStoragePoolUuid = StorageManager.PreferredStoragePool.value();