You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ro...@apache.org on 2020/06/24 01:33:17 UTC
[cloudstack] branch 4.13 updated: server: fix for wrong affinity
group count (#4154)
This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch 4.13
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.13 by this push:
new 8010718 server: fix for wrong affinity group count (#4154)
8010718 is described below
commit 801071887810dbeb68a24e94e36f117e911883bc
Author: Abhishek Kumar <ab...@gmail.com>
AuthorDate: Wed Jun 24 07:02:56 2020 +0530
server: fix for wrong affinity group count (#4154)
Fixes wrong count in listAffinityGroup API.
API was returning the count of AffinityGroupJoinVO records.
Signed-off-by: Abhishek Kumar <ab...@gmail.com>
---
.../java/com/cloud/api/query/QueryManagerImpl.java | 23 +++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
index c41cd0e..bf30430 100644
--- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
@@ -3625,25 +3625,30 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
if (domainId != null) {
SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId,
affinityGroupName, affinityGroupType, keyword);
- affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
+ Pair<List<AffinityGroupJoinVO>, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId);
+ affinityGroups.addAll(groupsPair.first());
+ count += groupsPair.second();
} else {
for (Long permAcctId : permittedAccounts) {
Account permittedAcct = _accountDao.findById(permAcctId);
SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId,
affinityGroupName, affinityGroupType, keyword);
-
- affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId()));
+ Pair<List<AffinityGroupJoinVO>, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId());
+ affinityGroups.addAll(groupsPair.first());
+ count += groupsPair.second();
}
}
} else if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
// list all domain level affinity groups for the domain admin case
SearchCriteria<AffinityGroupJoinVO> scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList<Long>(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName,
affinityGroupType, keyword);
- affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId));
+ Pair<List<AffinityGroupJoinVO>, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId);
+ affinityGroups.addAll(groupsPair.first());
+ count += groupsPair.second();
}
- return new Pair<List<AffinityGroupJoinVO>, Integer>(affinityGroups, affinityGroups.size());
+ return new Pair<List<AffinityGroupJoinVO>, Integer>(affinityGroups, count);
}
@@ -3741,7 +3746,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
return new Pair<List<AffinityGroupJoinVO>, Integer>(ags, count);
}
- private List<AffinityGroupJoinVO> listDomainLevelAffinityGroups(SearchCriteria<AffinityGroupJoinVO> sc, Filter searchFilter, long domainId) {
+ private Pair<List<AffinityGroupJoinVO>, Integer> listDomainLevelAffinityGroups(SearchCriteria<AffinityGroupJoinVO> sc, Filter searchFilter, long domainId) {
List<Long> affinityGroupIds = new ArrayList<Long>();
Set<Long> allowedDomains = _domainMgr.getDomainParentIds(domainId);
List<AffinityGroupDomainMapVO> maps = _affinityGroupDomainMapDao.listByDomain(allowedDomains.toArray());
@@ -3765,7 +3770,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
Integer count = uniqueGroupsPair.second();
if (count.intValue() == 0) {
// empty result
- return new ArrayList<AffinityGroupJoinVO>();
+ return new Pair<>(new ArrayList<AffinityGroupJoinVO>(), 0);
}
List<AffinityGroupJoinVO> uniqueGroups = uniqueGroupsPair.first();
Long[] vrIds = new Long[uniqueGroups.size()];
@@ -3774,9 +3779,9 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
vrIds[i++] = v.getId();
}
List<AffinityGroupJoinVO> vrs = _affinityGroupJoinDao.searchByIds(vrIds);
- return vrs;
+ return new Pair<>(vrs, count);
} else {
- return new ArrayList<AffinityGroupJoinVO>();
+ return new Pair<>(new ArrayList<AffinityGroupJoinVO>(), 0);
}
}