From f8fd22c2d6206d3e0f73b7dd76c2c61cf88bb4ec Mon Sep 17 00:00:00 2001 From: Vishesh Date: Tue, 12 Mar 2024 13:38:41 +0530 Subject: [PATCH] Usage: Fixup entity exists exception (#8726) --- .../com/cloud/usage/UsageManagerImpl.java | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java index 21a81ad5c02c..dd838f2f3ff8 100644 --- a/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java +++ b/usage/src/main/java/com/cloud/usage/UsageManagerImpl.java @@ -32,6 +32,7 @@ import javax.inject.Inject; import javax.naming.ConfigurationException; +import javax.persistence.EntityExistsException; import org.apache.cloudstack.quota.QuotaAlertManager; import org.apache.cloudstack.quota.QuotaManager; @@ -983,34 +984,38 @@ private boolean parseHelperTables(AccountVO account, Date currentStartDate, Date private void createHelperRecord(UsageEventVO event) { String eventType = event.getType(); - if (isVMEvent(eventType)) { - createVMHelperEvent(event); - } else if (isIPEvent(eventType)) { - createIPHelperEvent(event); - } else if (isVolumeEvent(eventType)) { - createVolumeHelperEvent(event); - } else if (isTemplateEvent(eventType)) { - createTemplateHelperEvent(event); - } else if (isISOEvent(eventType)) { - createISOHelperEvent(event); - } else if (isSnapshotEvent(eventType)) { - createSnapshotHelperEvent(event); - } else if (isLoadBalancerEvent(eventType)) { - createLoadBalancerHelperEvent(event); - } else if (isPortForwardingEvent(eventType)) { - createPortForwardingHelperEvent(event); - } else if (isNetworkOfferingEvent(eventType)) { - createNetworkOfferingEvent(event); - } else if (isVPNUserEvent(eventType)) { - handleVpnUserEvent(event); - } else if (isSecurityGroupEvent(eventType)) { - createSecurityGroupEvent(event); - } else if (isVmSnapshotEvent(eventType)) { - handleVMSnapshotEvent(event); - } else if (isVmSnapshotOnPrimaryEvent(eventType)) { - createVmSnapshotOnPrimaryEvent(event); - } else if (isBackupEvent(eventType)) { - createBackupEvent(event); + try { + if (isVMEvent(eventType)) { + createVMHelperEvent(event); + } else if (isIPEvent(eventType)) { + createIPHelperEvent(event); + } else if (isVolumeEvent(eventType)) { + createVolumeHelperEvent(event); + } else if (isTemplateEvent(eventType)) { + createTemplateHelperEvent(event); + } else if (isISOEvent(eventType)) { + createISOHelperEvent(event); + } else if (isSnapshotEvent(eventType)) { + createSnapshotHelperEvent(event); + } else if (isLoadBalancerEvent(eventType)) { + createLoadBalancerHelperEvent(event); + } else if (isPortForwardingEvent(eventType)) { + createPortForwardingHelperEvent(event); + } else if (isNetworkOfferingEvent(eventType)) { + createNetworkOfferingEvent(event); + } else if (isVPNUserEvent(eventType)) { + handleVpnUserEvent(event); + } else if (isSecurityGroupEvent(eventType)) { + createSecurityGroupEvent(event); + } else if (isVmSnapshotEvent(eventType)) { + handleVMSnapshotEvent(event); + } else if (isVmSnapshotOnPrimaryEvent(eventType)) { + createVmSnapshotOnPrimaryEvent(event); + } else if (isBackupEvent(eventType)) { + createBackupEvent(event); + } + } catch (EntityExistsException e) { + s_logger.warn(String.format("Failed to create usage event id: %d type: %s due to %s", event.getId(), eventType, e.getMessage()), e); } }