|
105 | 105 | import com.cloud.storage.VolumeApiService; |
106 | 106 | import com.cloud.storage.VolumeVO; |
107 | 107 | import com.cloud.storage.dao.DiskOfferingDao; |
| 108 | +import com.cloud.storage.dao.StoragePoolTagsDao; |
108 | 109 | import com.cloud.storage.dao.GuestOSDao; |
109 | 110 | import com.cloud.storage.dao.GuestOSHypervisorDao; |
110 | 111 | import com.cloud.storage.dao.SnapshotDao; |
@@ -250,6 +251,8 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager { |
250 | 251 | @Inject |
251 | 252 | private DiskOfferingDao diskOfferingDao; |
252 | 253 | @Inject |
| 254 | + private StoragePoolTagsDao storagePoolTagsDao; |
| 255 | + @Inject |
253 | 256 | private ResourceManager resourceManager; |
254 | 257 | @Inject |
255 | 258 | private ResourceLimitService resourceLimitService; |
@@ -2201,16 +2204,43 @@ private List<StoragePoolVO> findInstanceConversionDestinationStoragePoolsInClust |
2201 | 2204 | Cluster destinationCluster, ServiceOfferingVO serviceOffering, |
2202 | 2205 | Map<String, Long> dataDiskOfferingMap, |
2203 | 2206 | DataStoreTO temporaryConvertLocation, boolean forceConvertToPool) { |
2204 | | - List<StoragePoolVO> poolsList; |
| 2207 | + List<StoragePoolVO> poolsList = new ArrayList<>(); |
2205 | 2208 | if (!forceConvertToPool) { |
2206 | | - Set<StoragePoolVO> pools = new HashSet<>(primaryDataStoreDao.findClusterWideStoragePoolsByHypervisorAndPoolType(destinationCluster.getId(), Hypervisor.HypervisorType.KVM, Storage.StoragePoolType.NetworkFilesystem)); |
2207 | | - pools.addAll(primaryDataStoreDao.findZoneWideStoragePoolsByHypervisorAndPoolType(destinationCluster.getDataCenterId(), Hypervisor.HypervisorType.KVM, Storage.StoragePoolType.NetworkFilesystem)); |
2208 | | - if (pools.isEmpty()) { |
2209 | | - String msg = String.format("Cannot find suitable storage pools in the cluster %s for the conversion", destinationCluster.getName()); |
2210 | | - logger.error(msg); |
2211 | | - throw new CloudRuntimeException(msg); |
| 2209 | + // Try to find pools based on disk offering tags |
| 2210 | + Set<Long> candidatePoolIds = new HashSet<>(); |
| 2211 | + if (serviceOffering.getDiskOfferingId() != null) { |
| 2212 | + DiskOfferingVO diskOffering = diskOfferingDao.findById(serviceOffering.getDiskOfferingId()); |
| 2213 | + if (diskOffering != null && StringUtils.isNotBlank(diskOffering.getTags())) { |
| 2214 | + String tag = diskOffering.getTags(); |
| 2215 | + List<Long> ids = storagePoolTagsDao.listPoolIdsByTag(tag); |
| 2216 | + if (ids != null) { |
| 2217 | + candidatePoolIds.addAll(ids); |
| 2218 | + } |
| 2219 | + } |
| 2220 | + } |
| 2221 | + |
| 2222 | + if (!candidatePoolIds.isEmpty()) { |
| 2223 | + for (Long poolid : candidatePoolIds) { |
| 2224 | + StoragePoolVO pool = primaryDataStoreDao.findById(poolid); |
| 2225 | + if (pool == null) { |
| 2226 | + continue; |
| 2227 | + } |
| 2228 | + poolsList.add(pool); |
| 2229 | + } |
| 2230 | + } |
| 2231 | + logger.info("find poolsList : " + poolsList); |
| 2232 | + |
| 2233 | + // Fallback to previous behavior if no tagged pools found |
| 2234 | + if (poolsList.isEmpty()) { |
| 2235 | + Set<StoragePoolVO> pools = new HashSet<>(primaryDataStoreDao.listPoolsByCluster(destinationCluster.getId())); |
| 2236 | + pools.addAll(primaryDataStoreDao.findZoneWideStoragePoolsByHypervisor(destinationCluster.getDataCenterId(), Hypervisor.HypervisorType.KVM)); |
| 2237 | + if (pools.isEmpty()) { |
| 2238 | + String msg = String.format("Cannot find suitable storage pools in the cluster %s for the conversion", destinationCluster.getName()); |
| 2239 | + logger.error(msg); |
| 2240 | + throw new CloudRuntimeException(msg); |
| 2241 | + } |
| 2242 | + poolsList.addAll(pools); |
2212 | 2243 | } |
2213 | | - poolsList = new ArrayList<>(pools); |
2214 | 2244 | } else { |
2215 | 2245 | DataStore dataStore = dataStoreManager.getDataStore(temporaryConvertLocation.getUuid(), temporaryConvertLocation.getRole()); |
2216 | 2246 | poolsList = Collections.singletonList(primaryDataStoreDao.findById(dataStore.getId())); |
|
0 commit comments