Skip to content

Commit 8c7dab4

Browse files
DaanHooglandclaude
andcommitted
storage: replace deprecated SearchCriteria.addAnd with SearchBuilders
Fixes #12316 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5a9c055 commit 8c7dab4

1 file changed

Lines changed: 34 additions & 27 deletions

File tree

‎server/src/main/java/com/cloud/storage/StorageManagerImpl.java‎

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
406406
protected GenericSearchBuilder<StoragePoolHostVO, Long> UpHostsInPoolSearch;
407407
protected SearchBuilder<VMInstanceVO> StoragePoolSearch;
408408
protected SearchBuilder<StoragePoolVO> LocalStorageSearch;
409+
protected SearchBuilder<CapacityVO> PoolCapacitySearch;
410+
protected SearchBuilder<StoragePoolVO> PoolUsedStatsSearch;
409411

410412
ScheduledExecutorService _executor = null;
411413
int _storagePoolAcquisitionWaitSeconds = 1800; // 30 minutes
@@ -600,6 +602,20 @@ public boolean configure(String name, Map<String, Object> params) {
600602
LocalStorageSearch.and("type", LocalStorageSearch.entity().getPoolType(), SearchCriteria.Op.IN);
601603
LocalStorageSearch.done();
602604

605+
PoolCapacitySearch = _capacityDao.createSearchBuilder();
606+
PoolCapacitySearch.and("hostOrPoolId", PoolCapacitySearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
607+
PoolCapacitySearch.and("dataCenterId", PoolCapacitySearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
608+
PoolCapacitySearch.and("capacityType", PoolCapacitySearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
609+
PoolCapacitySearch.done();
610+
611+
PoolUsedStatsSearch = _storagePoolDao.createSearchBuilder();
612+
PoolUsedStatsSearch.and("dataCenterId", PoolUsedStatsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
613+
PoolUsedStatsSearch.and("podId", PoolUsedStatsSearch.entity().getPodId(), SearchCriteria.Op.EQ);
614+
PoolUsedStatsSearch.and("clusterId", PoolUsedStatsSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
615+
PoolUsedStatsSearch.and("ids", PoolUsedStatsSearch.entity().getId(), SearchCriteria.Op.IN);
616+
PoolUsedStatsSearch.and("parent", PoolUsedStatsSearch.entity().getParent(), SearchCriteria.Op.EQ);
617+
PoolUsedStatsSearch.done();
618+
603619
Volume.State.getStateMachine().registerListener(new VolumeStateListener(_configDao, _vmInstanceDao));
604620

605621
return true;
@@ -1802,10 +1818,10 @@ public BigDecimal getStorageOverProvisioningFactor(Long poolId) {
18021818

18031819
@Override
18041820
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated) {
1805-
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
1806-
capacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, storagePool.getId());
1807-
capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, storagePool.getDataCenterId());
1808-
capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
1821+
SearchCriteria<CapacityVO> capacitySC = PoolCapacitySearch.create();
1822+
capacitySC.setParameters("hostOrPoolId", storagePool.getId());
1823+
capacitySC.setParameters("dataCenterId", storagePool.getDataCenterId());
1824+
capacitySC.setParameters("capacityType", capacityType);
18091825

18101826
List<CapacityVO> capacities = _capacityDao.search(capacitySC, null);
18111827

@@ -2952,11 +2968,6 @@ public void onManagementNodeIsolated() {
29522968

29532969
@Override
29542970
public CapacityVO getSecondaryStorageUsedStats(Long hostId, Long zoneId) {
2955-
SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
2956-
if (zoneId != null) {
2957-
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
2958-
}
2959-
29602971
List<Long> hosts = new ArrayList<>();
29612972
if (hostId != null) {
29622973
hosts.add(hostId);
@@ -2983,28 +2994,24 @@ public CapacityVO getSecondaryStorageUsedStats(Long hostId, Long zoneId) {
29832994
}
29842995

29852996
private CapacityVO getStoragePoolUsedStatsInternal(Long zoneId, Long podId, Long clusterId, List<Long> poolIds, Long poolId) {
2986-
SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
29872997
List<StoragePoolVO> pools = new ArrayList<>();
2988-
2989-
if (zoneId != null) {
2990-
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
2991-
}
2992-
if (podId != null) {
2993-
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
2994-
}
2995-
if (clusterId != null) {
2996-
sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId);
2997-
}
2998-
if (CollectionUtils.isNotEmpty(poolIds)) {
2999-
sc.addAnd("id", SearchCriteria.Op.IN, poolIds.toArray());
3000-
}
3001-
if (poolId != null) {
3002-
sc.addAnd("id", SearchCriteria.Op.EQ, poolId);
3003-
}
3004-
sc.addAnd("parent", SearchCriteria.Op.EQ, 0L);
30052998
if (poolId != null) {
30062999
pools.add(_storagePoolDao.findById(poolId));
30073000
} else {
3001+
SearchCriteria<StoragePoolVO> sc = PoolUsedStatsSearch.create();
3002+
if (zoneId != null) {
3003+
sc.setParameters("dataCenterId", zoneId);
3004+
}
3005+
if (podId != null) {
3006+
sc.setParameters("podId", podId);
3007+
}
3008+
if (clusterId != null) {
3009+
sc.setParameters("clusterId", clusterId);
3010+
}
3011+
if (CollectionUtils.isNotEmpty(poolIds)) {
3012+
sc.setParameters("ids", poolIds.toArray());
3013+
}
3014+
sc.setParameters("parent", 0L);
30083015
pools = _storagePoolDao.search(sc, null);
30093016
}
30103017

0 commit comments

Comments
 (0)