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