From f538db3949166bc11d9b7324e8028ca9e48bf489 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 18 Jun 2020 13:49:31 +0530 Subject: [PATCH 1/2] server: fix for wrong affinity group count Signed-off-by: Abhishek Kumar --- .../com/cloud/api/query/QueryManagerImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 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 127ac9037a1c..f8e4f77c1c41 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3624,25 +3624,30 @@ public Pair, Integer> searchForAffinityGroupsInternal( if (domainId != null) { SearchCriteria scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword); - affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId)); + List groups = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId); + affinityGroups.addAll(groups); + count += groups.size(); } else { for (Long permAcctId : permittedAccounts) { Account permittedAcct = _accountDao.findById(permAcctId); SearchCriteria scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword); - - affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId())); + List groups = listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId()); + affinityGroups.addAll(groups); + count += groups.size(); } } } else if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) { // list all domain level affinity groups for the domain admin case SearchCriteria scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword); - affinityGroups.addAll(listDomainLevelAffinityGroups(scDomain, searchFilter, domainId)); + List groups = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId); + affinityGroups.addAll(groups); + count += groups.size(); } - return new Pair, Integer>(affinityGroups, affinityGroups.size()); + return new Pair, Integer>(affinityGroups, count); } From d06e769277842a6a41f5f2663fb09a05ec4de063 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Mon, 22 Jun 2020 10:38:04 +0530 Subject: [PATCH 2/2] fix for correct unique domain level AG count Signed-off-by: Abhishek Kumar --- .../com/cloud/api/query/QueryManagerImpl.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 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 f8e4f77c1c41..33ca1bb258c0 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -3624,27 +3624,27 @@ public Pair, Integer> searchForAffinityGroupsInternal( if (domainId != null) { SearchCriteria scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword); - List groups = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId); - affinityGroups.addAll(groups); - count += groups.size(); + Pair, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId); + affinityGroups.addAll(groupsPair.first()); + count += groupsPair.second(); } else { for (Long permAcctId : permittedAccounts) { Account permittedAcct = _accountDao.findById(permAcctId); SearchCriteria scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword); - List groups = listDomainLevelAffinityGroups(scDomain, searchFilter, permittedAcct.getDomainId()); - affinityGroups.addAll(groups); - count += groups.size(); + Pair, 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 scDomain = buildAffinityGroupSearchCriteria(null, isRecursive, new ArrayList(), listProjectResourcesCriteria, affinityGroupId, affinityGroupName, affinityGroupType, keyword); - List groups = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId); - affinityGroups.addAll(groups); - count += groups.size(); + Pair, Integer> groupsPair = listDomainLevelAffinityGroups(scDomain, searchFilter, domainId); + affinityGroups.addAll(groupsPair.first()); + count += groupsPair.second(); } return new Pair, Integer>(affinityGroups, count); @@ -3745,7 +3745,7 @@ private Pair, Integer> listAffinityGroupsByVM(long vmI return new Pair, Integer>(ags, count); } - private List listDomainLevelAffinityGroups(SearchCriteria sc, Filter searchFilter, long domainId) { + private Pair, Integer> listDomainLevelAffinityGroups(SearchCriteria sc, Filter searchFilter, long domainId) { List affinityGroupIds = new ArrayList(); Set allowedDomains = _domainMgr.getDomainParentIds(domainId); List maps = _affinityGroupDomainMapDao.listByDomain(allowedDomains.toArray()); @@ -3769,7 +3769,7 @@ private List listDomainLevelAffinityGroups(SearchCriteria(); + return new Pair<>(new ArrayList(), 0); } List uniqueGroups = uniqueGroupsPair.first(); Long[] vrIds = new Long[uniqueGroups.size()]; @@ -3778,9 +3778,9 @@ private List listDomainLevelAffinityGroups(SearchCriteria vrs = _affinityGroupJoinDao.searchByIds(vrIds); - return vrs; + return new Pair<>(vrs, count); } else { - return new ArrayList(); + return new Pair<>(new ArrayList(), 0); } }