From 6689e83d7f8c5af834e2d730d74654318e93b2a4 Mon Sep 17 00:00:00 2001 From: Min Chen Date: Sat, 20 Jul 2013 15:15:52 -0700 Subject: [PATCH] CLOUDSTACK-3513: ListIsos/ListTemplates does not return correct results when id and zoneid are passed. --- .../com/cloud/api/query/QueryManagerImpl.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java index cef5ddf01de..33327db9038 100644 --- a/server/src/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/com/cloud/api/query/QueryManagerImpl.java @@ -2876,17 +2876,6 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { sc.addAnd("state", SearchCriteria.Op.SC, readySc); } - if (zoneId != null) { - SearchCriteria zoneSc = _templateJoinDao.createSearchCriteria(); - zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId); - zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION); - // handle the case where xs-tools.iso and vmware-tools.iso do not have data_center information in template_view - SearchCriteria isoPerhostSc = _templateJoinDao.createSearchCriteria(); - isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO); - isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST); - zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc); - sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc); - } if (!showDomr) { // excluding system template @@ -2894,6 +2883,19 @@ public class QueryManagerImpl extends ManagerBase implements QueryService { } } + if (zoneId != null) { + SearchCriteria zoneSc = _templateJoinDao.createSearchCriteria(); + zoneSc.addOr("dataCenterId", SearchCriteria.Op.EQ, zoneId); + zoneSc.addOr("dataStoreScope", SearchCriteria.Op.EQ, ScopeType.REGION); + // handle the case where xs-tools.iso and vmware-tools.iso do not + // have data_center information in template_view + SearchCriteria isoPerhostSc = _templateJoinDao.createSearchCriteria(); + isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO); + isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST); + zoneSc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc); + sc.addAnd("dataCenterId", SearchCriteria.Op.SC, zoneSc); + } + // don't return removed template, this should not be needed since we // changed annotation for removed field in TemplateJoinVO. // sc.addAnd("removed", SearchCriteria.Op.NULL);