Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 63C7010B85 for ; Fri, 9 Aug 2013 19:11:52 +0000 (UTC) Received: (qmail 58671 invoked by uid 500); 9 Aug 2013 19:11:51 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 58629 invoked by uid 500); 9 Aug 2013 19:11:50 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 58616 invoked by uid 99); 9 Aug 2013 19:11:49 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Aug 2013 19:11:49 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5ED178BB18D; Fri, 9 Aug 2013 19:11:49 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anthonyxu@apache.org To: commits@cloudstack.apache.org Message-Id: <94b7ccc4c1ab4589855a6489c0f513ae@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/master to 36d7b49 Date: Fri, 9 Aug 2013 19:11:49 +0000 (UTC) Updated Branches: refs/heads/master 5c36766ad -> 36d7b49d5 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/36d7b49d Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/36d7b49d Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/36d7b49d Branch: refs/heads/master Commit: 36d7b49d5faf3c1dc2d8936ab125a593b8910078 Parents: 5c36766 Author: Anthony Xu Authored: Fri Aug 9 12:02:17 2013 -0700 Committer: Anthony Xu Committed: Fri Aug 9 12:08:00 2013 -0700 ---------------------------------------------------------------------- .../template/HypervisorTemplateAdapter.java | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/36d7b49d/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 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;