Updated Branches: refs/heads/4.2 822991a0e -> e547b9f4c
CLOUDSTACK-4210 delete templateVO entry when there is no image store having this template Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/e547b9f4 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/e547b9f4 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/e547b9f4 Branch: refs/heads/4.2 Commit: e547b9f4cc6552e4ce50f04041e987a8e680420a Parents: 822991a Author: Anthony Xu <anthony...@citrix.com> Authored: Fri Aug 9 12:02:17 2013 -0700 Committer: Anthony Xu <anthony...@citrix.com> Committed: Fri Aug 9 12:02:17 2013 -0700 ---------------------------------------------------------------------- .../template/HypervisorTemplateAdapter.java | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e547b9f4/server/src/com/cloud/template/HypervisorTemplateAdapter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java index de0ed7e..7ec7114 100755 --- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java @@ -329,15 +329,19 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase { } } if (success) { - s_logger.info("Delete template from template table"); - // remove template from vm_templates table - if (_tmpltDao.remove(template.getId())) { - // Decrement the number of templates and total secondary storage - // space used by the account - Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId()); - _resourceLimitMgr.decrementResourceCount(template.getAccountId(), ResourceType.template); - _resourceLimitMgr.recalculateResourceCount(template.getAccountId(), account.getDomainId(), - ResourceType.secondary_storage.getOrdinal()); + + // find all eligible image stores for this template + List<DataStore> iStores = this.templateMgr.getImageStoreByTemplate(template.getId(), null); + if (iStores == null || iStores.size() == 0) { + // remove template from vm_templates table + if (_tmpltDao.remove(template.getId())) { + // Decrement the number of templates and total secondary storage + // space used by the account + Account account = _accountDao.findByIdIncludingRemoved(template.getAccountId()); + _resourceLimitMgr.decrementResourceCount(template.getAccountId(), ResourceType.template); + _resourceLimitMgr.recalculateResourceCount(template.getAccountId(), account.getDomainId(), + ResourceType.secondary_storage.getOrdinal()); + } } } return success;