Fixup listing of serivce offering & storagepools with tags (#8937)

This commit is contained in:
Vishesh 2024-04-25 16:28:52 +05:30 committed by GitHub
parent 4c27574570
commit e409c6d870
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2977,7 +2977,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
ListResponse<StoragePoolResponse> response = new ListResponse<>();
List<StoragePoolResponse> poolResponses = ViewResponseHelper.createStoragePoolResponse(storagePools.first().toArray(new StoragePoolJoinVO[storagePools.first().size()]));
Map<String, Long> poolUuidToIdMap = storagePools.first().stream().collect(Collectors.toMap(StoragePoolJoinVO::getUuid, StoragePoolJoinVO::getId));
Map<String, Long> poolUuidToIdMap = storagePools.first().stream().collect(Collectors.toMap(StoragePoolJoinVO::getUuid, StoragePoolJoinVO::getId, (a, b) -> a));
for (StoragePoolResponse poolResponse : poolResponses) {
DataStore store = dataStoreManager.getPrimaryDataStore(poolResponse.getId());
if (store != null) {
@ -3790,9 +3790,8 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
List<String> storageTags = com.cloud.utils.StringUtils.csvTagsToList(diskOffering.getTags());
if (!storageTags.isEmpty() && VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.value()) {
for (String tag : storageTags) {
diskOfferingSearch.and(tag, diskOfferingSearch.entity().getTags(), Op.EQ);
diskOfferingSearch.and("storageTag" + tag, diskOfferingSearch.entity().getTags(), Op.FIND_IN_SET);
}
diskOfferingSearch.done();
}
}
@ -3904,18 +3903,24 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
srvOffrDomainDetailSearch.entity().getName(), serviceOfferingSearch.entity().setString(ApiConstants.DOMAIN_ID));
}
List<String> hostTags = new ArrayList<>();
if (currentVmOffering != null) {
List<String> hostTags = com.cloud.utils.StringUtils.csvTagsToList(currentVmOffering.getHostTag());
hostTags.addAll(com.cloud.utils.StringUtils.csvTagsToList(currentVmOffering.getHostTag()));
}
if (!hostTags.isEmpty()) {
serviceOfferingSearch.and().op("hostTag", serviceOfferingSearch.entity().getHostTag(), Op.NULL);
serviceOfferingSearch.or().op();
serviceOfferingSearch.or();
boolean flag = true;
for(String tag : hostTags) {
serviceOfferingSearch.and(tag, serviceOfferingSearch.entity().getHostTag(), Op.EQ);
if (flag) {
flag = false;
serviceOfferingSearch.op("hostTag" + tag, serviceOfferingSearch.entity().getHostTag(), Op.FIND_IN_SET);
} else {
serviceOfferingSearch.and("hostTag" + tag, serviceOfferingSearch.entity().getHostTag(), Op.FIND_IN_SET);
}
serviceOfferingSearch.cp().cp().done();
}
serviceOfferingSearch.cp().cp();
}
SearchCriteria<ServiceOfferingVO> sc = serviceOfferingSearch.create();
@ -4032,22 +4037,18 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
sc.setJoinParameters("domainDetailSearchNormalUser", "domainIdIN", domainIds.toArray());
}
if (currentVmOffering != null) {
if (diskOffering != null) {
List<String> storageTags = com.cloud.utils.StringUtils.csvTagsToList(diskOffering.getTags());
if (!storageTags.isEmpty() && VolumeApiServiceImpl.MatchStoragePoolTagsWithDiskOffering.value()) {
for (String tag : storageTags) {
sc.setJoinParameters("diskOfferingSearch", tag, tag);
sc.setJoinParameters("diskOfferingSearch", "storageTag" + tag, tag);
}
}
}
List<String> hostTags = com.cloud.utils.StringUtils.csvTagsToList(currentVmOffering.getHostTag());
if (!hostTags.isEmpty()) {
for(String tag : hostTags) {
sc.setParameters(tag, tag);
}
sc.setParameters("hostTag" + tag, tag);
}
}