template list fix

Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com>
This commit is contained in:
Abhishek Kumar 2024-09-16 14:28:51 +05:30
parent 99115b9f09
commit 33321f00ce
3 changed files with 9 additions and 12 deletions

View File

@ -175,7 +175,7 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
List<Long> listAllIds();
List<HypervisorType> findDistinctHypervisorTypesForZone(final long zoneId);
List<HypervisorType> listDistinctHypervisorTypes(final Long zoneId);
List<Long> listAllHostIdsInCluster(final long clusterId);
}

View File

@ -1562,14 +1562,16 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
}
@Override
public List<HypervisorType> findDistinctHypervisorTypesForZone(long zoneId) {
public List<HypervisorType> listDistinctHypervisorTypes(final Long zoneId) {
GenericSearchBuilder<HostVO, HypervisorType> sb = createSearchBuilder(HypervisorType.class);
sb.and("zoneId", sb.entity().getDataCenterId(), SearchCriteria.Op.EQ);
sb.and("type", sb.entity().getType(), SearchCriteria.Op.EQ);
sb.select(null, Func.DISTINCT, sb.entity().getHypervisorType());
sb.done();
SearchCriteria<HypervisorType> sc = sb.create();
sc.setParameters("zoneId", zoneId);
if (zoneId != null) {
sc.setParameters("zoneId", zoneId);
}
sc.setParameters("type", Type.Routing);
return customSearch(sc, null);
}

View File

@ -546,19 +546,14 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem
@Override
public List<VMTemplateVO> listAllReadySystemVMTemplates(Long zoneId) {
List<HypervisorType> availableHypervisors = null;
if (zoneId != null) {
availableHypervisors = _hostDao.findDistinctHypervisorTypesForZone(zoneId);
if (CollectionUtils.isEmpty(availableHypervisors)) {
return Collections.emptyList();
}
List<HypervisorType> availableHypervisors = _hostDao.listDistinctHypervisorTypes(zoneId);
if (CollectionUtils.isEmpty(availableHypervisors)) {
return Collections.emptyList();
}
SearchCriteria<VMTemplateVO> sc = readySystemTemplateSearch.create();
sc.setParameters("templateType", Storage.TemplateType.SYSTEM);
sc.setParameters("state", VirtualMachineTemplate.State.Active);
if (CollectionUtils.isNotEmpty(availableHypervisors)) {
sc.setParameters("hypervisorType", availableHypervisors.toArray());
}
sc.setParameters("hypervisorType", availableHypervisors.toArray());
sc.setJoinParameters("vmTemplateJoinTemplateStoreRef", "downloadState",
List.of(VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
VMTemplateStorageResourceAssoc.Status.BYPASSED).toArray());