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
This commit is contained in:
kishan 2011-11-11 13:42:06 +05:30
parent 4b074600eb
commit c15dbd561a
1 changed files with 10 additions and 0 deletions

View File

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