From 2102ede2e73c49e69a402c7b0f97a44b77e41e8f Mon Sep 17 00:00:00 2001 From: Min Chen Date: Tue, 14 May 2013 11:42:24 -0700 Subject: [PATCH] Fix CLOUDSTACK-2469: default template is not downloaded. --- .../storage/image/TemplateServiceImpl.java | 17 +++++++++++------ .../template/HypervisorTemplateAdapter.java | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java index 7419e9f5521..a9302b33d57 100644 --- a/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java +++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/TemplateServiceImpl.java @@ -340,11 +340,15 @@ public class TemplateServiceImpl implements TemplateService { } if (tmpltStore != null && tmpltStore.getDownloadState() != Status.DOWNLOADED) { s_logger.info("Template Sync did not find " + uniqueName + " ready on image store " + storeId + ", will request download to start/resume shortly"); + s_logger.info("Removing template " + uniqueName + " from template store table"); + // remove those leftover entries + _vmTemplateStoreDao.remove(tmpltStore.getId()); } else if (tmpltStore == null) { s_logger.info("Template Sync did not find " + uniqueName + " on the image store " + storeId + ", will request download shortly"); - TemplateDataStoreVO templtStore = new TemplateDataStoreVO(storeId, tmplt.getId(), new Date(), 0, Status.NOT_DOWNLOADED, null, null, null, null, tmplt.getUrl()); - _vmTemplateStoreDao.persist(templtStore); + // persist template_zone_ref table + // TODO: we may have some bugs in removing these entries in case of failure, maybe we should pass another callback below in invoking createTemplateAsync + // to just clear those entries. associateTemplateToZone(tmplt.getId(), zoneId); } @@ -370,20 +374,21 @@ public class TemplateServiceImpl implements TemplateService { continue; } // check if there is a record for this template in this store - TemplateDataStoreVO tmpltHost = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); + TemplateDataStoreVO tmpltStoreVO = _vmTemplateStoreDao.findByStoreTemplate(storeId, tmplt.getId()); // if this is private template, and there is no record for this // template in this store, skip + // TODO: don't understand this logic. What happens if we have a record for this template, still download? if (!tmplt.isPublicTemplate() && !tmplt.isFeatured()) { - if (tmpltHost == null) { + if (tmpltStoreVO == null) { continue; } } if (availHypers.contains(tmplt.getHypervisorType())) { - if (tmpltHost != null ) { + if (tmpltStoreVO != null && tmpltStoreVO.getDownloadState() == Status.DOWNLOADED) { continue; } - s_logger.debug("Template " + tmplt.getName() + " needs to be downloaded to " + store.getName()); + s_logger.info("Downloading template " + tmplt.getUniqueName() + " to image store " + store.getName()); TemplateInfo tmpl = _templateFactory.getTemplate(tmplt.getId(), DataStoreRole.Image); createTemplateAsync(tmpl, store, null); } diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java index b2a49a3b18c..74bae35ef75 100755 --- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java @@ -169,7 +169,7 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase { @Override public VMTemplateVO create(TemplateProfile profile) { - // persist entry in vm_template, vm_template_details and template_zone_ref tables + // persist entry in vm_template, vm_template_details and template_zone_ref tables, not that entry at template_store_ref is not created here, and created in createTemplateAsync. VMTemplateVO template = persistTemplate(profile); if (template == null) {