CLOUDSTACK-4210

delete templateVO entry when there is no image store having this template
This commit is contained in:
Anthony Xu 2013-08-09 12:02:17 -07:00
parent 822991a0e9
commit e547b9f4cc
1 changed files with 13 additions and 9 deletions

View File

@ -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;