mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Consider other conditions while listing templates with id (#4452)
This commit is contained in:
parent
e24a7b13dc
commit
2f5ed9eee4
@ -3443,11 +3443,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||||||
domain = _domainDao.findById(Domain.ROOT_DOMAIN);
|
domain = _domainDao.findById(Domain.ROOT_DOMAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// List<HypervisorType> hypers = null;
|
|
||||||
// if (!isIso) {
|
|
||||||
// hypers = _resourceMgr.listAvailHypervisorInZone(null, null);
|
|
||||||
// }
|
|
||||||
|
|
||||||
setIdsListToSearchCriteria(sc, ids);
|
setIdsListToSearchCriteria(sc, ids);
|
||||||
|
|
||||||
// add criteria for project or not
|
// add criteria for project or not
|
||||||
@ -3495,17 +3490,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isIso) {
|
|
||||||
// add hypervisor criteria for template case
|
|
||||||
if (hypers != null && !hypers.isEmpty()) {
|
|
||||||
String[] relatedHypers = new String[hypers.size()];
|
|
||||||
for (int i = 0; i < hypers.size(); i++) {
|
|
||||||
relatedHypers[i] = hypers.get(i).toString();
|
|
||||||
}
|
|
||||||
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, relatedHypers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// control different template filters
|
// control different template filters
|
||||||
if (templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community) {
|
if (templateFilter == TemplateFilter.featured || templateFilter == TemplateFilter.community) {
|
||||||
sc.addAnd("publicTemplate", SearchCriteria.Op.EQ, true);
|
sc.addAnd("publicTemplate", SearchCriteria.Op.EQ, true);
|
||||||
@ -3548,62 +3532,78 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||||||
}
|
}
|
||||||
sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc);
|
sc.addAnd("publicTemplate", SearchCriteria.Op.SC, scc);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add tags criteria
|
return templateChecks(isIso, hypers, tags, name, keyword, hyperType, onlyReady, bootable, zoneId, showDomr,
|
||||||
if (tags != null && !tags.isEmpty()) {
|
showRemovedTmpl, parentTemplateId, showUnique, searchFilter, sc);
|
||||||
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
|
|
||||||
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
}
|
||||||
SearchCriteria<TemplateJoinVO> scTag = _templateJoinDao.createSearchCriteria();
|
|
||||||
scTag.addAnd("tagKey", SearchCriteria.Op.EQ, entry.getKey());
|
private Pair<List<TemplateJoinVO>, Integer> templateChecks(boolean isIso, List<HypervisorType> hypers, Map<String, String> tags, String name, String keyword,
|
||||||
scTag.addAnd("tagValue", SearchCriteria.Op.EQ, entry.getValue());
|
HypervisorType hyperType, boolean onlyReady, Boolean bootable, Long zoneId, boolean showDomr,
|
||||||
if (isIso) {
|
boolean showRemovedTmpl, Long parentTemplateId, Boolean showUnique,
|
||||||
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.ISO);
|
Filter searchFilter, SearchCriteria<TemplateJoinVO> sc) {
|
||||||
} else {
|
if (!isIso) {
|
||||||
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.Template);
|
// add hypervisor criteria for template case
|
||||||
}
|
if (hypers != null && !hypers.isEmpty()) {
|
||||||
scc.addOr("tagKey", SearchCriteria.Op.SC, scTag);
|
String[] relatedHypers = new String[hypers.size()];
|
||||||
|
for (int i = 0; i < hypers.size(); i++) {
|
||||||
|
relatedHypers[i] = hypers.get(i).toString();
|
||||||
}
|
}
|
||||||
sc.addAnd("tagKey", SearchCriteria.Op.SC, scc);
|
sc.addAnd("hypervisorType", SearchCriteria.Op.IN, relatedHypers);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// other criteria
|
// add tags criteria
|
||||||
|
if (tags != null && !tags.isEmpty()) {
|
||||||
if (keyword != null) {
|
SearchCriteria<TemplateJoinVO> scc = _templateJoinDao.createSearchCriteria();
|
||||||
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
for (Map.Entry<String, String> entry : tags.entrySet()) {
|
||||||
} else if (name != null) {
|
SearchCriteria<TemplateJoinVO> scTag = _templateJoinDao.createSearchCriteria();
|
||||||
sc.addAnd("name", SearchCriteria.Op.EQ, name);
|
scTag.addAnd("tagKey", SearchCriteria.Op.EQ, entry.getKey());
|
||||||
|
scTag.addAnd("tagValue", SearchCriteria.Op.EQ, entry.getValue());
|
||||||
|
if (isIso) {
|
||||||
|
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.ISO);
|
||||||
|
} else {
|
||||||
|
scTag.addAnd("tagResourceType", SearchCriteria.Op.EQ, ResourceObjectType.Template);
|
||||||
|
}
|
||||||
|
scc.addOr("tagKey", SearchCriteria.Op.SC, scTag);
|
||||||
}
|
}
|
||||||
|
sc.addAnd("tagKey", SearchCriteria.Op.SC, scc);
|
||||||
|
}
|
||||||
|
|
||||||
if (isIso) {
|
// other criteria
|
||||||
sc.addAnd("format", SearchCriteria.Op.EQ, "ISO");
|
|
||||||
|
|
||||||
} else {
|
if (keyword != null) {
|
||||||
sc.addAnd("format", SearchCriteria.Op.NEQ, "ISO");
|
sc.addAnd("name", SearchCriteria.Op.LIKE, "%" + keyword + "%");
|
||||||
}
|
} else if (name != null) {
|
||||||
|
sc.addAnd("name", SearchCriteria.Op.EQ, name);
|
||||||
|
}
|
||||||
|
|
||||||
if (!hyperType.equals(HypervisorType.None)) {
|
SearchCriteria.Op op = isIso ? Op.EQ : Op.NEQ;
|
||||||
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hyperType);
|
sc.addAnd("format", op, "ISO");
|
||||||
}
|
|
||||||
|
|
||||||
if (bootable != null) {
|
if (!hyperType.equals(HypervisorType.None)) {
|
||||||
sc.addAnd("bootable", SearchCriteria.Op.EQ, bootable);
|
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hyperType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onlyReady) {
|
if (bootable != null) {
|
||||||
SearchCriteria<TemplateJoinVO> readySc = _templateJoinDao.createSearchCriteria();
|
sc.addAnd("bootable", SearchCriteria.Op.EQ, bootable);
|
||||||
readySc.addOr("state", SearchCriteria.Op.EQ, TemplateState.Ready);
|
}
|
||||||
readySc.addOr("format", SearchCriteria.Op.EQ, ImageFormat.BAREMETAL);
|
|
||||||
SearchCriteria<TemplateJoinVO> isoPerhostSc = _templateJoinDao.createSearchCriteria();
|
|
||||||
isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO);
|
|
||||||
isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST);
|
|
||||||
readySc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc);
|
|
||||||
sc.addAnd("state", SearchCriteria.Op.SC, readySc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!showDomr) {
|
if (onlyReady) {
|
||||||
// excluding system template
|
SearchCriteria<TemplateJoinVO> readySc = _templateJoinDao.createSearchCriteria();
|
||||||
sc.addAnd("templateType", SearchCriteria.Op.NEQ, Storage.TemplateType.SYSTEM);
|
readySc.addOr("state", SearchCriteria.Op.EQ, TemplateState.Ready);
|
||||||
}
|
readySc.addOr("format", SearchCriteria.Op.EQ, ImageFormat.BAREMETAL);
|
||||||
|
SearchCriteria<TemplateJoinVO> isoPerhostSc = _templateJoinDao.createSearchCriteria();
|
||||||
|
isoPerhostSc.addAnd("format", SearchCriteria.Op.EQ, ImageFormat.ISO);
|
||||||
|
isoPerhostSc.addAnd("templateType", SearchCriteria.Op.EQ, TemplateType.PERHOST);
|
||||||
|
readySc.addOr("templateType", SearchCriteria.Op.SC, isoPerhostSc);
|
||||||
|
sc.addAnd("state", SearchCriteria.Op.SC, readySc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!showDomr) {
|
||||||
|
// excluding system template
|
||||||
|
sc.addAnd("templateType", SearchCriteria.Op.NEQ, Storage.TemplateType.SYSTEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zoneId != null) {
|
if (zoneId != null) {
|
||||||
@ -3648,7 +3648,6 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q
|
|||||||
// VMTemplateDaoImpl.searchForTemplates and understand why we need to
|
// VMTemplateDaoImpl.searchForTemplates and understand why we need to
|
||||||
// specially handle ISO. The original logic is very twisted and no idea
|
// specially handle ISO. The original logic is very twisted and no idea
|
||||||
// about what the code was doing.
|
// about what the code was doing.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// findTemplatesByIdOrTempZonePair returns the templates with the given ids if showUnique is true, or else by the TempZonePair
|
// findTemplatesByIdOrTempZonePair returns the templates with the given ids if showUnique is true, or else by the TempZonePair
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user