Skip to content

Commit 557dc5e

Browse files
authored
api: List details of template download state for stores corresponding to a zone (#5379)
* api: List details of template download state for stores corresponding to a zone * fix test
1 parent 8998479 commit 557dc5e

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/TemplateDataStoreDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface TemplateDataStoreDao extends GenericDao<TemplateDataStoreVO, Lo
6666

6767
List<TemplateDataStoreVO> listByTemplate(long templateId);
6868

69-
List<TemplateDataStoreVO> listByTemplateNotBypassed(long templateId);
69+
List<TemplateDataStoreVO> listByTemplateNotBypassed(long templateId, Long... storeIds);
7070

7171
TemplateDataStoreVO findByTemplateZoneReady(long templateId, Long zoneId);
7272

engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/TemplateDataStoreDaoImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
9999
templateSearch.and("template_id", templateSearch.entity().getTemplateId(), SearchCriteria.Op.EQ);
100100
templateSearch.and("download_state", templateSearch.entity().getDownloadState(), SearchCriteria.Op.NEQ);
101101
templateSearch.and("destroyed", templateSearch.entity().getDestroyed(), SearchCriteria.Op.EQ);
102+
templateSearch.and("storeids", templateSearch.entity().getDataStoreId(), Op.IN);
102103
templateSearch.done();
103104

104105
templateRoleSearch = createSearchBuilder();
@@ -421,11 +422,12 @@ public List<TemplateDataStoreVO> listByTemplate(long templateId) {
421422
}
422423

423424
@Override
424-
public List<TemplateDataStoreVO> listByTemplateNotBypassed(long templateId) {
425+
public List<TemplateDataStoreVO> listByTemplateNotBypassed(long templateId, Long... storeIds) {
425426
SearchCriteria<TemplateDataStoreVO> sc = templateSearch.create();
426427
sc.setParameters("template_id", templateId);
427428
sc.setParameters("download_state", Status.BYPASSED);
428429
sc.setParameters("destroyed", false);
430+
sc.setParameters("storeids", storeIds);
429431
return search(sc, null);
430432
}
431433

server/src/main/java/com/cloud/api/query/dao/TemplateJoinDaoImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ private String getTemplateStatus(TemplateJoinVO template) {
156156

157157
@Override
158158
public TemplateResponse newTemplateResponse(EnumSet<ApiConstants.DomainDetails> detailsView, ResponseView view, TemplateJoinVO template) {
159-
List<TemplateDataStoreVO> templatesInStore = _templateStoreDao.listByTemplateNotBypassed(template.getId());
159+
List<ImageStoreVO> storesInZone = dataStoreDao.listStoresByZoneId(template.getDataCenterId());
160+
Long[] storeIds = storesInZone.stream().map(ImageStoreVO::getId).toArray(Long[]::new);
161+
List<TemplateDataStoreVO> templatesInStore = _templateStoreDao.listByTemplateNotBypassed(template.getId(), storeIds);
160162
List<Map<String, String>> downloadProgressDetails = new ArrayList();
161163
HashMap<String, String> downloadDetailInImageStores = null;
162164
for (TemplateDataStoreVO templateInStore : templatesInStore) {

0 commit comments

Comments
 (0)