From c15dbd561abf84e2410500abc428e75e0fb77d87 Mon Sep 17 00:00:00 2001 From: kishan Date: Fri, 11 Nov 2011 13:42:06 +0530 Subject: [PATCH] bug 11961: Before creating template usage_storage records, check if entry already exists. In multiple secondary storage case, duplicate usage events will be ignored. status 11961: resolved fixed reviewed-by: Nitin --- usage/src/com/cloud/usage/UsageManagerImpl.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java b/usage/src/com/cloud/usage/UsageManagerImpl.java index 037084a99bf..f372bd81c60 100644 --- a/usage/src/com/cloud/usage/UsageManagerImpl.java +++ b/usage/src/com/cloud/usage/UsageManagerImpl.java @@ -1054,6 +1054,11 @@ public class UsageManagerImpl implements UsageManager, Runnable { if (s_logger.isDebugEnabled()) { s_logger.debug("create template with id : " + templateId + " for account: " + event.getAccountId()); } + List storageVOs = m_usageStorageDao.listByIdAndZone(event.getAccountId(), templateId, StorageTypes.TEMPLATE, zoneId); + if (storageVOs.size() > 0) { + s_logger.warn("Usage entry for Template: " + templateId + " assigned to account: " + event.getAccountId() + "already exists in zone "+zoneId); + return; + } Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId()); UsageStorageVO storageVO = new UsageStorageVO(templateId, zoneId, event.getAccountId(), acct.getDomainId(), StorageTypes.TEMPLATE, event.getTemplateId(), templateSize, event.getCreateDate(), null); @@ -1091,6 +1096,11 @@ public class UsageManagerImpl implements UsageManager, Runnable { if (s_logger.isDebugEnabled()) { s_logger.debug("create iso with id : " + isoId + " for account: " + event.getAccountId()); } + List storageVOs = m_usageStorageDao.listByIdAndZone(event.getAccountId(), isoId, StorageTypes.ISO, zoneId); + if (storageVOs.size() > 0) { + s_logger.warn("Usage entry for ISO: " + isoId + " assigned to account: " + event.getAccountId() + "already exists in zone "+zoneId); + return; + } Account acct = m_accountDao.findByIdIncludingRemoved(event.getAccountId()); UsageStorageVO storageVO = new UsageStorageVO( isoId, zoneId, event.getAccountId(), acct.getDomainId(), StorageTypes.ISO, null, isoSize, event.getCreateDate(), null);