Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 34 additions & 27 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@
protected GenericSearchBuilder<StoragePoolHostVO, Long> UpHostsInPoolSearch;
protected SearchBuilder<VMInstanceVO> StoragePoolSearch;
protected SearchBuilder<StoragePoolVO> LocalStorageSearch;
protected SearchBuilder<CapacityVO> PoolCapacitySearch;

Check warning on line 409 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "PoolCapacitySearch" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxphDZYtd_M9S3tMXK&open=AaGxphDZYtd_M9S3tMXK&pullRequest=14564
protected SearchBuilder<StoragePoolVO> PoolUsedStatsSearch;

Check warning on line 410 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Rename this field "PoolUsedStatsSearch" to match the regular expression '^[a-z][a-zA-Z0-9]*$'.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxphDZYtd_M9S3tMXL&open=AaGxphDZYtd_M9S3tMXL&pullRequest=14564

ScheduledExecutorService _executor = null;
int _storagePoolAcquisitionWaitSeconds = 1800; // 30 minutes
Expand Down Expand Up @@ -600,6 +602,20 @@
LocalStorageSearch.and("type", LocalStorageSearch.entity().getPoolType(), SearchCriteria.Op.IN);
LocalStorageSearch.done();

PoolCapacitySearch = _capacityDao.createSearchBuilder();
PoolCapacitySearch.and("hostOrPoolId", PoolCapacitySearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
PoolCapacitySearch.and("dataCenterId", PoolCapacitySearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);

Check failure on line 607 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "dataCenterId" 4 times.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxphDZYtd_M9S3tMXI&open=AaGxphDZYtd_M9S3tMXI&pullRequest=14564
PoolCapacitySearch.and("capacityType", PoolCapacitySearch.entity().getCapacityType(), SearchCriteria.Op.EQ);
PoolCapacitySearch.done();

PoolUsedStatsSearch = _storagePoolDao.createSearchBuilder();
PoolUsedStatsSearch.and("dataCenterId", PoolUsedStatsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
PoolUsedStatsSearch.and("podId", PoolUsedStatsSearch.entity().getPodId(), SearchCriteria.Op.EQ);

Check failure on line 613 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "podId" 4 times.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxphDZYtd_M9S3tMXH&open=AaGxphDZYtd_M9S3tMXH&pullRequest=14564
PoolUsedStatsSearch.and("clusterId", PoolUsedStatsSearch.entity().getClusterId(), SearchCriteria.Op.EQ);

Check failure on line 614 in server/src/main/java/com/cloud/storage/StorageManagerImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Define a constant instead of duplicating this literal "clusterId" 4 times.

See more on https://sonarcloud.io/project/issues?id=apache_cloudstack&issues=AaGxphDZYtd_M9S3tMXJ&open=AaGxphDZYtd_M9S3tMXJ&pullRequest=14564
PoolUsedStatsSearch.and("ids", PoolUsedStatsSearch.entity().getId(), SearchCriteria.Op.IN);
PoolUsedStatsSearch.and("parent", PoolUsedStatsSearch.entity().getParent(), SearchCriteria.Op.EQ);
PoolUsedStatsSearch.done();

Volume.State.getStateMachine().registerListener(new VolumeStateListener(_configDao, _vmInstanceDao));

return true;
Expand Down Expand Up @@ -1802,10 +1818,10 @@

@Override
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated) {
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
capacitySC.addAnd("hostOrPoolId", SearchCriteria.Op.EQ, storagePool.getId());
capacitySC.addAnd("dataCenterId", SearchCriteria.Op.EQ, storagePool.getDataCenterId());
capacitySC.addAnd("capacityType", SearchCriteria.Op.EQ, capacityType);
SearchCriteria<CapacityVO> capacitySC = PoolCapacitySearch.create();
capacitySC.setParameters("hostOrPoolId", storagePool.getId());
capacitySC.setParameters("dataCenterId", storagePool.getDataCenterId());
capacitySC.setParameters("capacityType", capacityType);

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

Expand Down Expand Up @@ -2952,11 +2968,6 @@

@Override
public CapacityVO getSecondaryStorageUsedStats(Long hostId, Long zoneId) {
SearchCriteria<HostVO> sc = _hostDao.createSearchCriteria();
if (zoneId != null) {
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
}

List<Long> hosts = new ArrayList<>();
if (hostId != null) {
hosts.add(hostId);
Expand All @@ -2983,28 +2994,24 @@
}

private CapacityVO getStoragePoolUsedStatsInternal(Long zoneId, Long podId, Long clusterId, List<Long> poolIds, Long poolId) {
SearchCriteria<StoragePoolVO> sc = _storagePoolDao.createSearchCriteria();
List<StoragePoolVO> pools = new ArrayList<>();

if (zoneId != null) {
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
}
if (podId != null) {
sc.addAnd("podId", SearchCriteria.Op.EQ, podId);
}
if (clusterId != null) {
sc.addAnd("clusterId", SearchCriteria.Op.EQ, clusterId);
}
if (CollectionUtils.isNotEmpty(poolIds)) {
sc.addAnd("id", SearchCriteria.Op.IN, poolIds.toArray());
}
if (poolId != null) {
sc.addAnd("id", SearchCriteria.Op.EQ, poolId);
}
sc.addAnd("parent", SearchCriteria.Op.EQ, 0L);
if (poolId != null) {
pools.add(_storagePoolDao.findById(poolId));
} else {
SearchCriteria<StoragePoolVO> sc = PoolUsedStatsSearch.create();
if (zoneId != null) {
sc.setParameters("dataCenterId", zoneId);
}
if (podId != null) {
sc.setParameters("podId", podId);
}
if (clusterId != null) {
sc.setParameters("clusterId", clusterId);
}
if (CollectionUtils.isNotEmpty(poolIds)) {
sc.setParameters("ids", poolIds.toArray());
}
sc.setParameters("parent", 0L);
pools = _storagePoolDao.search(sc, null);
}

Expand Down
Loading