mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 7410 : listTemplates and ListIsos - Correcting the pagesize use. Putting all the filters in the DB query rather than after execution so that pagesize restriction happens at the end.
status 7410: resolved fixed
This commit is contained in:
parent
c2bec9fec4
commit
83145c38fd
@ -19,6 +19,7 @@ package com.cloud.api;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.api.commands.QueryAsyncJobResultCmd;
|
||||
import com.cloud.api.response.AccountResponse;
|
||||
@ -92,6 +93,7 @@ import com.cloud.user.Account;
|
||||
import com.cloud.user.User;
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
@ -168,7 +170,7 @@ public interface ResponseGenerator {
|
||||
|
||||
RemoteAccessVpnResponse createRemoteAccessVpnResponse(RemoteAccessVpn vpn);
|
||||
|
||||
void createTemplateResponse(List<TemplateResponse> responses, VirtualMachineTemplate template, Long zoneId, boolean isAdmin,
|
||||
void createTemplateResponse(List<TemplateResponse> responses, Pair<Long, Long> templateZonePair, boolean isAdmin,
|
||||
Account account);
|
||||
|
||||
ListResponse<TemplateResponse> createTemplateResponse2(VirtualMachineTemplate template, Long zoneId);
|
||||
@ -195,8 +197,7 @@ public interface ResponseGenerator {
|
||||
|
||||
EventResponse createEventResponse(Event event);
|
||||
|
||||
ListResponse<TemplateResponse> createIsoResponse(List<? extends VirtualMachineTemplate> isos, Long zoneId, boolean onlyReady, boolean isAdmin,
|
||||
Account account);
|
||||
ListResponse<TemplateResponse> createIsoResponse(Set<Pair<Long,Long>> isoZonePairSet, boolean onlyReady, Account account);
|
||||
|
||||
TemplateResponse createIsoResponse(VirtualMachineTemplate result);
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -33,6 +34,7 @@ import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@Implementation(description="Lists all available ISO files.", responseObject=TemplateResponse.class)
|
||||
public class ListIsosCmd extends BaseListCmd {
|
||||
@ -137,7 +139,7 @@ public class ListIsosCmd extends BaseListCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
List<? extends VirtualMachineTemplate> isos = _mgr.listIsos(this);
|
||||
Set<Pair<Long, Long>> isoZonePairSet = _mgr.listIsos(this);
|
||||
TemplateFilter isoFilterObj = null;
|
||||
|
||||
try {
|
||||
@ -152,23 +154,12 @@ public class ListIsosCmd extends BaseListCmd {
|
||||
}
|
||||
|
||||
boolean isAdmin = false;
|
||||
boolean isAccountSpecific = true;
|
||||
Account account = UserContext.current().getAccount();
|
||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||
isAdmin = true;
|
||||
if ((accountName == null) || (domainId == null)) {
|
||||
isAccountSpecific = false;
|
||||
}
|
||||
isAdmin = true;
|
||||
}
|
||||
|
||||
boolean onlyReady = (isoFilterObj == TemplateFilter.featured) ||
|
||||
(isoFilterObj == TemplateFilter.selfexecutable) ||
|
||||
(isoFilterObj == TemplateFilter.sharedexecutable) ||
|
||||
(isoFilterObj == TemplateFilter.executable && isAccountSpecific) ||
|
||||
(isoFilterObj == TemplateFilter.community);
|
||||
|
||||
|
||||
ListResponse<TemplateResponse> response = _responseGenerator.createIsoResponse(isos, zoneId, onlyReady, isAdmin, account);
|
||||
ListResponse<TemplateResponse> response = _responseGenerator.createIsoResponse(isoZonePairSet, isAdmin, account);
|
||||
response.setResponseName(getName());
|
||||
this.setResponseObject(response);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ package com.cloud.api.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -35,6 +36,7 @@ import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
@Implementation(description="List all public, private, and privileged templates.", responseObject=TemplateResponse.class)
|
||||
public class ListTemplatesCmd extends BaseListCmd {
|
||||
@ -118,35 +120,19 @@ public class ListTemplatesCmd extends BaseListCmd {
|
||||
|
||||
@Override
|
||||
public void execute(){
|
||||
List<? extends VirtualMachineTemplate> templates = _mgr.listTemplates(this);
|
||||
TemplateFilter templateFilterObj;
|
||||
try {
|
||||
templateFilterObj = TemplateFilter.valueOf(templateFilter);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// how did we get this far? The request should've been rejected already before the response stage...
|
||||
templateFilterObj = TemplateFilter.selfexecutable;
|
||||
}
|
||||
|
||||
Set<Pair<Long, Long>> templateZonePairSet = _mgr.listTemplates(this);
|
||||
|
||||
boolean isAdmin = false;
|
||||
boolean isAccountSpecific = true;
|
||||
Account account = UserContext.current().getAccount();
|
||||
if ((account == null) || (account.getType() == Account.ACCOUNT_TYPE_ADMIN) || (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN)) {
|
||||
isAdmin = true;
|
||||
if ((accountName == null) || (domainId == null)) {
|
||||
isAccountSpecific = false;
|
||||
}
|
||||
}
|
||||
|
||||
boolean showDomr = (templateFilterObj != TemplateFilter.selfexecutable);
|
||||
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
List<TemplateResponse> templateResponses = new ArrayList<TemplateResponse>();
|
||||
|
||||
for (VirtualMachineTemplate template : templates) {
|
||||
if (!showDomr && template.getTemplateType() == Storage.TemplateType.SYSTEM) {
|
||||
continue;
|
||||
}
|
||||
_responseGenerator.createTemplateResponse(templateResponses, template, zoneId, isAdmin, account);
|
||||
for (Pair<Long, Long> template : templateZonePairSet) {
|
||||
_responseGenerator.createTemplateResponse(templateResponses, template, isAdmin, account);
|
||||
}
|
||||
|
||||
response.setResponses(templateResponses);
|
||||
|
||||
@ -21,6 +21,7 @@ import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.alert.Alert;
|
||||
import com.cloud.api.ServerApiException;
|
||||
@ -101,6 +102,7 @@ import com.cloud.template.VirtualMachineTemplate;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
@ -309,14 +311,14 @@ public interface ManagementService {
|
||||
* @param cmd The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account, and zoneId parameters.
|
||||
* @return list of ISOs
|
||||
*/
|
||||
List<? extends VirtualMachineTemplate> listIsos(ListIsosCmd cmd);
|
||||
Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd);
|
||||
|
||||
/**
|
||||
* List templates that match the specified criteria.
|
||||
* @param cmd The command that wraps the (optional) templateId, name, keyword, templateFilter, bootable, account, and zoneId parameters.
|
||||
* @return list of ISOs
|
||||
*/
|
||||
List<? extends VirtualMachineTemplate> listTemplates(ListTemplatesCmd cmd);
|
||||
Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd);
|
||||
|
||||
/**
|
||||
* Search for disk offerings based on search criteria
|
||||
|
||||
@ -139,6 +139,7 @@ import com.cloud.user.UserContext;
|
||||
import com.cloud.user.UserStatisticsVO;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.InstanceGroupVO;
|
||||
@ -1492,9 +1493,10 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTemplateResponse(List<TemplateResponse> responses, VirtualMachineTemplate template, Long zoneId, boolean isAdmin, Account account) {
|
||||
List<VMTemplateHostVO> templateHostRefsForTemplate = ApiDBUtils.listTemplateHostBy(template.getId(), zoneId);
|
||||
|
||||
public void createTemplateResponse(List<TemplateResponse> responses, Pair<Long,Long> templateZonePair, boolean isAdmin, Account account) {
|
||||
List<VMTemplateHostVO> templateHostRefsForTemplate = ApiDBUtils.listTemplateHostBy(templateZonePair.first(), templateZonePair.second());
|
||||
VMTemplateVO template = ApiDBUtils.findTemplateById(templateZonePair.first());
|
||||
|
||||
for (VMTemplateHostVO templateHostRef : templateHostRefsForTemplate) {
|
||||
|
||||
TemplateResponse templateResponse = new TemplateResponse();
|
||||
@ -2009,11 +2011,13 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListResponse<TemplateResponse> createIsoResponse(List<? extends VirtualMachineTemplate> isos, Long zoneId, boolean onlyReady, boolean isAdmin, Account account) {
|
||||
public ListResponse<TemplateResponse> createIsoResponse(Set<Pair<Long,Long>> isoZonePairSet, boolean isAdmin, Account account) {
|
||||
|
||||
ListResponse<TemplateResponse> response = new ListResponse<TemplateResponse>();
|
||||
List<TemplateResponse> isoResponses = new ArrayList<TemplateResponse>();
|
||||
for (VirtualMachineTemplate iso : isos) {
|
||||
|
||||
for (Pair<Long,Long> isoZonePair : isoZonePairSet) {
|
||||
VMTemplateVO iso = ApiDBUtils.findTemplateById(isoZonePair.first());
|
||||
if ( iso.getTemplateType() == TemplateType.PERHOST ) {
|
||||
TemplateResponse isoResponse = new TemplateResponse();
|
||||
isoResponse.setId(iso.getId());
|
||||
@ -2031,12 +2035,8 @@ public class ApiResponseHelper implements ResponseGenerator {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<VMTemplateHostVO> isoHosts = ApiDBUtils.listTemplateHostBy(iso.getId(), zoneId);
|
||||
for (VMTemplateHostVO isoHost : isoHosts) {
|
||||
if (onlyReady && isoHost.getDownloadState() != Status.DOWNLOADED) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<VMTemplateHostVO> isoHosts = ApiDBUtils.listTemplateHostBy(iso.getId(), isoZonePair.second());
|
||||
for (VMTemplateHostVO isoHost : isoHosts) {
|
||||
TemplateResponse isoResponse = new TemplateResponse();
|
||||
isoResponse.setId(iso.getId());
|
||||
isoResponse.setName(iso.getName());
|
||||
|
||||
@ -41,9 +41,11 @@ import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -1562,7 +1564,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> listIsos(ListIsosCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||
public Set<Pair<Long, Long>> listIsos(ListIsosCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||
TemplateFilter isoFilter = TemplateFilter.valueOf(cmd.getIsoFilter());
|
||||
Long accountId = null;
|
||||
Account account = UserContext.current().getAccount();
|
||||
@ -1598,7 +1600,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> listTemplates(ListTemplatesCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||
public Set<Pair<Long, Long>> listTemplates(ListTemplatesCmd cmd) throws IllegalArgumentException, InvalidParameterValueException {
|
||||
TemplateFilter templateFilter = TemplateFilter.valueOf(cmd.getTemplateFilter());
|
||||
Long accountId = null;
|
||||
Account account = UserContext.current().getAccount();
|
||||
@ -1634,7 +1636,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
return listTemplates(cmd.getId(), cmd.getTemplateName(), cmd.getKeyword(), templateFilter, false, null, accountId, cmd.getPageSizeVal(), cmd.getStartIndex(), cmd.getZoneId(), hypervisorType, isAccountSpecific, showDomr);
|
||||
}
|
||||
|
||||
private List<VMTemplateVO> listTemplates(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Long accountId, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean isAccountSpecific, boolean showDomr) throws InvalidParameterValueException {
|
||||
private Set<Pair<Long, Long>> listTemplates(Long templateId, String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Long accountId, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean isAccountSpecific, boolean showDomr) throws InvalidParameterValueException {
|
||||
VMTemplateVO template = null;
|
||||
if (templateId != null) {
|
||||
template = _templateDao.findById(templateId);
|
||||
@ -1667,16 +1669,15 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
domain = _domainDao.findById(DomainVO.ROOT_DOMAIN);
|
||||
}
|
||||
|
||||
List<VMTemplateVO> templates = new ArrayList<VMTemplateVO>();
|
||||
Set<Pair<Long, Long>> templateZonePairSet = new HashSet<Pair<Long,Long>>();
|
||||
|
||||
if (template == null) {
|
||||
templates = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, bootable, account, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr);
|
||||
} else {
|
||||
templates = new ArrayList<VMTemplateVO>();
|
||||
templates.add(template);
|
||||
templateZonePairSet = _templateDao.searchTemplates(name, keyword, templateFilter, isIso, bootable, account, domain, pageSize, startIndex, zoneId, hyperType, onlyReady, showDomr);
|
||||
} else {
|
||||
templateZonePairSet.add(new Pair<Long,Long>(template.getId(), zoneId));
|
||||
}
|
||||
|
||||
return templates;
|
||||
return templateZonePairSet;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -19,12 +19,14 @@
|
||||
package com.cloud.storage.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.cloud.domain.DomainVO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
/*
|
||||
@ -56,7 +58,7 @@ public interface VMTemplateDao extends GenericDao<VMTemplateVO, Long> {
|
||||
public List<VMTemplateVO> findIsosByIdAndPath(Long domainId, Long accountId, String path);
|
||||
public List<VMTemplateVO> listReadyTemplates();
|
||||
public List<VMTemplateVO> listByAccountId(long accountId);
|
||||
public List<VMTemplateVO> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable,
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable,
|
||||
Account account, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady, boolean showDomr);
|
||||
|
||||
public long addTemplateToZone(VMTemplateVO tmplt, long zoneId);
|
||||
|
||||
@ -23,8 +23,11 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
@ -41,6 +44,7 @@ import com.cloud.storage.Storage.TemplateType;
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
@ -61,6 +65,12 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
|
||||
private final String SELECT_ALL = "SELECT t.id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
|
||||
"t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
|
||||
private final String SELECT_TEMPLATE_HOST_REF = "SELECT t.id, h.data_center_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
|
||||
"t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t";
|
||||
|
||||
private final String SELECT_TEMPLATE_ZONE_REF = "SELECT t.id, tzr.zone_id, t.unique_name, t.name, t.public, t.featured, t.type, t.hvm, t.bits, t.url, t.format, t.created, t.account_id, " +
|
||||
"t.checksum, t.display_text, t.enable_password, t.guest_os_id, t.bootable, t.prepopulate, t.cross_zones, t.hypervisor_type FROM vm_template t INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
|
||||
|
||||
protected SearchBuilder<VMTemplateVO> TemplateNameSearch;
|
||||
protected SearchBuilder<VMTemplateVO> UniqueNameSearch;
|
||||
@ -113,6 +123,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
SearchCriteria<VMTemplateVO> sc = PublicIsoSearch.create();
|
||||
sc.setParameters("public", 1);
|
||||
sc.setParameters("format", "ISO");
|
||||
sc.setParameters("type", TemplateType.PERHOST.toString());
|
||||
return listBy(sc);
|
||||
}
|
||||
|
||||
@ -200,6 +211,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
PublicIsoSearch = createSearchBuilder();
|
||||
PublicIsoSearch.and("public", PublicIsoSearch.entity().isPublicTemplate(), SearchCriteria.Op.EQ);
|
||||
PublicIsoSearch.and("format", PublicIsoSearch.entity().getFormat(), SearchCriteria.Op.EQ);
|
||||
PublicIsoSearch.and("type", PublicIsoSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
|
||||
|
||||
tmpltTypeHyperSearch = createSearchBuilder();
|
||||
tmpltTypeHyperSearch.and("templateType", tmpltTypeHyperSearch.entity().getTemplateType(), SearchCriteria.Op.EQ);
|
||||
@ -234,12 +246,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VMTemplateVO> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Account account, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady,boolean showDomr) {
|
||||
public Set<Pair<Long, Long>> searchTemplates(String name, String keyword, TemplateFilter templateFilter, boolean isIso, Boolean bootable, Account account, DomainVO domain, Long pageSize, Long startIndex, Long zoneId, HypervisorType hyperType, boolean onlyReady,boolean showDomr) {
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
List<VMTemplateVO> templates = new ArrayList<VMTemplateVO>();
|
||||
|
||||
Set<Pair<Long, Long>> templateZonePairList = new HashSet<Pair<Long, Long>>();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
ResultSet rs = null;
|
||||
String sql = SELECT_TEMPLATE_ZONE_REF;
|
||||
try {
|
||||
short accountType;
|
||||
String accountId = null;
|
||||
@ -252,20 +266,16 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
|
||||
String guestOSJoin = "";
|
||||
StringBuilder templateHostRefJoin = new StringBuilder();
|
||||
String templateZoneRef = "";
|
||||
|
||||
if (isIso && !hyperType.equals(HypervisorType.None)) {
|
||||
guestOSJoin = " INNER JOIN guest_os guestOS on (guestOS.id = t.guest_os_id) INNER JOIN guest_os_hypervisor goh on ( goh.guest_os_id = guestOS.id) ";
|
||||
}
|
||||
if (onlyReady){
|
||||
templateHostRefJoin.append(" INNER JOIN template_host_ref thr on (t.id = thr.template_id) ");
|
||||
if(zoneId != null){
|
||||
templateHostRefJoin.append("INNER JOIN host h on (thr.host_id = h.id)");
|
||||
}
|
||||
}else if (zoneId != null){
|
||||
templateZoneRef = " INNER JOIN template_zone_ref tzr on (t.id = tzr.template_id) ";
|
||||
templateHostRefJoin.append(" INNER JOIN template_host_ref thr on (t.id = thr.template_id) INNER JOIN host h on (thr.host_id = h.id)");
|
||||
sql = SELECT_TEMPLATE_HOST_REF;
|
||||
}
|
||||
|
||||
String sql = SELECT_ALL + guestOSJoin + templateHostRefJoin + templateZoneRef;
|
||||
sql += guestOSJoin + templateHostRefJoin;
|
||||
String whereClause = "";
|
||||
|
||||
if (templateFilter == TemplateFilter.featured) {
|
||||
@ -291,7 +301,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
} else if (templateFilter == TemplateFilter.all && accountType == Account.ACCOUNT_TYPE_ADMIN) {
|
||||
whereClause += " WHERE ";
|
||||
} else if (accountType != Account.ACCOUNT_TYPE_ADMIN) {
|
||||
return templates;
|
||||
return templateZonePairList;
|
||||
}
|
||||
|
||||
if (whereClause.equals("")) {
|
||||
@ -300,25 +310,20 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
whereClause += " AND ";
|
||||
}
|
||||
|
||||
sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, onlyReady, showDomr) + getOrderByLimit(pageSize, startIndex);
|
||||
sql += whereClause + getExtrasWhere(templateFilter, name, keyword, isIso, bootable, hyperType, zoneId, onlyReady, showDomr, accountType) + getOrderByLimit(pageSize, startIndex);
|
||||
|
||||
pstmt = txn.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
VMTemplateVO tmplt = toEntityBean(rs, false);
|
||||
if (zoneId != null) {
|
||||
VMTemplateZoneVO vtzvo = _templateZoneDao.findByZoneTemplate(zoneId, tmplt.getId());
|
||||
if (vtzvo != null){
|
||||
templates.add(tmplt);
|
||||
}
|
||||
} else {
|
||||
templates.add(tmplt);
|
||||
}
|
||||
Pair<Long, Long> templateZonePair = new Pair<Long, Long>(rs.getLong(1), rs.getLong(2));
|
||||
templateZonePairList.add(templateZonePair);
|
||||
}
|
||||
|
||||
if(isIso && (account.getType() == Account.ACCOUNT_TYPE_NORMAL)){
|
||||
List<VMTemplateVO> publicIsos = publicIsoSearch();
|
||||
templates.addAll(publicIsos);
|
||||
if(isIso && templateZonePairList.size() < pageSize && templateFilter != TemplateFilter.community){
|
||||
List<VMTemplateVO> publicIsos = publicIsoSearch();
|
||||
for( int i=0; i < publicIsos.size(); i++){
|
||||
templateZonePairList.add(new Pair<Long,Long>(publicIsos.get(i).getId(), null));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Error listing templates", e);
|
||||
@ -336,10 +341,10 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
}
|
||||
|
||||
return templates;
|
||||
return templateZonePairList;
|
||||
}
|
||||
|
||||
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr) {
|
||||
private String getExtrasWhere(TemplateFilter templateFilter, String name, String keyword, boolean isIso, Boolean bootable, HypervisorType hyperType, Long zoneId, boolean onlyReady, boolean showDomr, short accountType) {
|
||||
String sql = "";
|
||||
if (keyword != null) {
|
||||
sql += " t.name LIKE \"%" + keyword + "%\" AND";
|
||||
@ -348,7 +353,10 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
}
|
||||
|
||||
if (isIso) {
|
||||
sql += " t.format = 'ISO'";
|
||||
sql += " t.format = 'ISO'";
|
||||
if (accountType == Account.ACCOUNT_TYPE_NORMAL){
|
||||
sql += " AND t.public = 1 ";
|
||||
}
|
||||
if (!hyperType.equals(HypervisorType.None)) {
|
||||
sql += " AND goh.hypervisor_type = '" + hyperType.toString() + "'";
|
||||
}
|
||||
@ -372,7 +380,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
|
||||
sql += " AND tzr.zone_id = " +zoneId;
|
||||
}
|
||||
if (!showDomr){
|
||||
sql += " AND t.type = '" +Storage.TemplateType.SYSTEM.toString() + "'";
|
||||
sql += " AND t.type != '" +Storage.TemplateType.SYSTEM.toString() + "'";
|
||||
}
|
||||
|
||||
sql += " AND t.removed IS NULL";
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user