From d3c181efa75b33050a188beb253b261e921aca3c Mon Sep 17 00:00:00 2001 From: Min Chen Date: Thu, 20 Jun 2013 15:26:07 -0700 Subject: [PATCH] CLOUDSTACK-3080: listVirtualMachines tag search refinement no longer working. --- .../com/cloud/api/query/QueryManagerImpl.java | 73 ++++++------------- 1 file changed, 21 insertions(+), 52 deletions(-) diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index c2663e620b6..e05bc544913 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -702,14 +702,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("instanceGroupId", sb.entity().getInstanceGroupId(), SearchCriteria.Op.EQ); } - if (tags != null && !tags.isEmpty()) { - for (int count=0; count < tags.size(); count++) { - sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); - sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); - sb.cp(); - } - } - if (networkId != null) { sb.and("networkId", sb.entity().getNetworkId(), SearchCriteria.Op.EQ); } @@ -729,12 +721,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); if (tags != null && !tags.isEmpty()) { - int count = 0; + SearchCriteria tagSc = _userVmJoinDao.createSearchCriteria(); for (String key : tags.keySet()) { - sc.setParameters("key" + String.valueOf(count), key); - sc.setParameters("value" + String.valueOf(count), tags.get(key)); - count++; + SearchCriteria tsc = _userVmJoinDao.createSearchCriteria(); + tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key); + tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key)); + tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc); } + sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc); } if (groupId != null && (Long)groupId != -1) { @@ -878,13 +872,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("id", sb.entity().getId(), SearchCriteria.Op.EQ); sb.and("name", sb.entity().getName(), SearchCriteria.Op.EQ); - if (tags != null && !tags.isEmpty()) { - for (int count=0; count < tags.size(); count++) { - sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); - sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); - sb.cp(); - } - } SearchCriteria sc = sb.create(); _accountMgr.buildACLViewSearchCriteria(sc, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); @@ -894,14 +881,16 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } if (tags != null && !tags.isEmpty()) { - int count = 0; + SearchCriteria tagSc = _securityGroupJoinDao.createSearchCriteria(); for (String key : tags.keySet()) { - sc.setParameters("key" + String.valueOf(count), key); - sc.setParameters("value" + String.valueOf(count), tags.get(key)); - count++; + SearchCriteria tsc = _securityGroupJoinDao.createSearchCriteria(); + tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key); + tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key)); + tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc); } + sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc); } - + if (securityGroup != null) { sc.setParameters("name", securityGroup); } @@ -1159,13 +1148,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.and("accountId", sb.entity().getAccountId(), SearchCriteria.Op.EQ); } - if (tags != null && !tags.isEmpty()) { - for (int count = 0; count < tags.size(); count++) { - sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); - sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); - sb.cp(); - } - } + SearchCriteria sc = sb.create(); @@ -1204,14 +1187,7 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("domainPath", path); } - if (tags != null && !tags.isEmpty()) { - int count = 0; - for (String key : tags.keySet()) { - sc.setParameters("key" + String.valueOf(count), key); - sc.setParameters("value" + String.valueOf(count), tags.get(key)); - count++; - } - } + // search distinct projects to get count Pair, Integer> uniquePrjPair = _projectJoinDao.searchAndCount(sc, searchFilter); @@ -1529,15 +1505,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sb.or("nulltype", sb.entity().getVmType(), SearchCriteria.Op.NULL); sb.cp(); - if (tags != null && !tags.isEmpty()) { - for (int count=0; count < tags.size(); count++) { - sb.or().op("key" + String.valueOf(count), sb.entity().getTagKey(), SearchCriteria.Op.EQ); - sb.and("value" + String.valueOf(count), sb.entity().getTagValue(), SearchCriteria.Op.EQ); - sb.cp(); - } - } - - // now set the SC criteria... SearchCriteria sc = sb.create(); @@ -1558,12 +1525,14 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.setParameters("systemUse", 1); if (tags != null && !tags.isEmpty()) { - int count = 0; + SearchCriteria tagSc = _volumeJoinDao.createSearchCriteria(); for (String key : tags.keySet()) { - sc.setParameters("key" + String.valueOf(count), key); - sc.setParameters("value" + String.valueOf(count), tags.get(key)); - count++; + SearchCriteria tsc = _volumeJoinDao.createSearchCriteria(); + tsc.addAnd("tagKey", SearchCriteria.Op.EQ, key); + tsc.addAnd("tagValue", SearchCriteria.Op.EQ, tags.get(key)); + tagSc.addOr("tagKey", SearchCriteria.Op.SC, tsc); } + sc.addAnd("tagKey", SearchCriteria.Op.SC, tagSc); } if (id != null) {