|
97 | 97 | import java.util.concurrent.ScheduledExecutorService; |
98 | 98 | import java.util.concurrent.TimeUnit; |
99 | 99 |
|
| 100 | +import javax.inject.Inject; |
| 101 | +import javax.naming.ConfigurationException; |
| 102 | +import javax.persistence.EntityExistsException; |
| 103 | + |
| 104 | +import org.apache.cloudstack.quota.QuotaAlertManager; |
| 105 | +import org.apache.cloudstack.quota.QuotaManager; |
| 106 | +import org.apache.cloudstack.quota.QuotaStatement; |
| 107 | +import org.apache.cloudstack.utils.usage.UsageUtils; |
| 108 | +import org.apache.commons.collections.CollectionUtils; |
| 109 | +import org.apache.log4j.Logger; |
| 110 | +import org.springframework.stereotype.Component; |
| 111 | +import org.apache.cloudstack.framework.config.dao.ConfigurationDao; |
| 112 | +import org.apache.cloudstack.managed.context.ManagedContextRunnable; |
| 113 | +import org.apache.cloudstack.usage.UsageTypes; |
| 114 | + |
| 115 | +import com.cloud.alert.AlertManager; |
| 116 | +import com.cloud.event.EventTypes; |
| 117 | +import com.cloud.event.UsageEventDetailsVO; |
| 118 | +import com.cloud.event.UsageEventVO; |
| 119 | +import com.cloud.event.dao.UsageEventDao; |
| 120 | +import com.cloud.event.dao.UsageEventDetailsDao; |
| 121 | +import com.cloud.usage.dao.UsageDao; |
| 122 | +import com.cloud.usage.dao.UsageIPAddressDao; |
| 123 | +import com.cloud.usage.dao.UsageJobDao; |
| 124 | +import com.cloud.usage.dao.UsageLoadBalancerPolicyDao; |
| 125 | +import com.cloud.usage.dao.UsageNetworkDao; |
| 126 | +import com.cloud.usage.dao.UsageNetworkOfferingDao; |
| 127 | +import com.cloud.usage.dao.UsagePortForwardingRuleDao; |
| 128 | +import com.cloud.usage.dao.UsageSecurityGroupDao; |
| 129 | +import com.cloud.usage.dao.UsageBackupDao; |
| 130 | +import com.cloud.usage.dao.UsageVMSnapshotOnPrimaryDao; |
| 131 | +import com.cloud.usage.dao.UsageStorageDao; |
| 132 | +import com.cloud.usage.dao.UsageVMInstanceDao; |
| 133 | +import com.cloud.usage.dao.UsageVMSnapshotDao; |
| 134 | +import com.cloud.usage.dao.UsageVPNUserDao; |
| 135 | +import com.cloud.usage.dao.UsageVmDiskDao; |
| 136 | +import com.cloud.usage.dao.UsageVolumeDao; |
| 137 | +import com.cloud.usage.parser.IPAddressUsageParser; |
| 138 | +import com.cloud.usage.parser.LoadBalancerUsageParser; |
| 139 | +import com.cloud.usage.parser.NetworkOfferingUsageParser; |
| 140 | +import com.cloud.usage.parser.NetworkUsageParser; |
| 141 | +import com.cloud.usage.parser.PortForwardingUsageParser; |
| 142 | +import com.cloud.usage.parser.SecurityGroupUsageParser; |
| 143 | +import com.cloud.usage.parser.StorageUsageParser; |
| 144 | +import com.cloud.usage.parser.BackupUsageParser; |
| 145 | +import com.cloud.usage.parser.VMInstanceUsageParser; |
| 146 | +import com.cloud.usage.parser.VMSnapshotOnPrimaryParser; |
| 147 | +import com.cloud.usage.parser.VMSnapshotUsageParser; |
| 148 | +import com.cloud.usage.parser.VPNUserUsageParser; |
| 149 | +import com.cloud.usage.parser.VmDiskUsageParser; |
| 150 | +import com.cloud.usage.parser.VolumeUsageParser; |
| 151 | +import com.cloud.user.Account; |
| 152 | +import com.cloud.user.AccountVO; |
| 153 | +import com.cloud.user.UserStatisticsVO; |
| 154 | +import com.cloud.user.VmDiskStatisticsVO; |
| 155 | +import com.cloud.user.dao.AccountDao; |
| 156 | +import com.cloud.user.dao.UserStatisticsDao; |
| 157 | +import com.cloud.user.dao.VmDiskStatisticsDao; |
| 158 | +import com.cloud.utils.component.ManagerBase; |
| 159 | +import com.cloud.utils.concurrency.NamedThreadFactory; |
| 160 | +import com.cloud.utils.db.DB; |
| 161 | +import com.cloud.utils.db.Filter; |
| 162 | +import com.cloud.utils.db.GlobalLock; |
| 163 | +import com.cloud.utils.db.QueryBuilder; |
| 164 | +import com.cloud.utils.db.SearchCriteria; |
| 165 | +import com.cloud.utils.db.TransactionLegacy; |
| 166 | +import com.cloud.utils.exception.CloudRuntimeException; |
| 167 | + |
100 | 168 | import static com.cloud.utils.NumbersUtil.toHumanReadableSize; |
101 | 169 |
|
102 | 170 | @Component |
@@ -1036,34 +1104,38 @@ private boolean parseHelperTables(AccountVO account, Date currentStartDate, Date |
1036 | 1104 |
|
1037 | 1105 | private void createHelperRecord(UsageEventVO event) { |
1038 | 1106 | String eventType = event.getType(); |
1039 | | - if (isVMEvent(eventType)) { |
1040 | | - createVMHelperEvent(event); |
1041 | | - } else if (isIPEvent(eventType)) { |
1042 | | - createIPHelperEvent(event); |
1043 | | - } else if (isVolumeEvent(eventType)) { |
1044 | | - createVolumeHelperEvent(event); |
1045 | | - } else if (isTemplateEvent(eventType)) { |
1046 | | - createTemplateHelperEvent(event); |
1047 | | - } else if (isISOEvent(eventType)) { |
1048 | | - createISOHelperEvent(event); |
1049 | | - } else if (isSnapshotEvent(eventType)) { |
1050 | | - createSnapshotHelperEvent(event); |
1051 | | - } else if (isLoadBalancerEvent(eventType)) { |
1052 | | - createLoadBalancerHelperEvent(event); |
1053 | | - } else if (isPortForwardingEvent(eventType)) { |
1054 | | - createPortForwardingHelperEvent(event); |
1055 | | - } else if (isNetworkOfferingEvent(eventType)) { |
1056 | | - createNetworkOfferingEvent(event); |
1057 | | - } else if (isVPNUserEvent(eventType)) { |
1058 | | - handleVpnUserEvent(event); |
1059 | | - } else if (isSecurityGroupEvent(eventType)) { |
1060 | | - createSecurityGroupEvent(event); |
1061 | | - } else if (isVmSnapshotEvent(eventType)) { |
1062 | | - handleVMSnapshotEvent(event); |
1063 | | - } else if (isVmSnapshotOnPrimaryEvent(eventType)) { |
1064 | | - createVmSnapshotOnPrimaryEvent(event); |
1065 | | - } else if (isBackupEvent(eventType)) { |
1066 | | - createBackupEvent(event); |
| 1107 | + try { |
| 1108 | + if (isVMEvent(eventType)) { |
| 1109 | + createVMHelperEvent(event); |
| 1110 | + } else if (isIPEvent(eventType)) { |
| 1111 | + createIPHelperEvent(event); |
| 1112 | + } else if (isVolumeEvent(eventType)) { |
| 1113 | + createVolumeHelperEvent(event); |
| 1114 | + } else if (isTemplateEvent(eventType)) { |
| 1115 | + createTemplateHelperEvent(event); |
| 1116 | + } else if (isISOEvent(eventType)) { |
| 1117 | + createISOHelperEvent(event); |
| 1118 | + } else if (isSnapshotEvent(eventType)) { |
| 1119 | + createSnapshotHelperEvent(event); |
| 1120 | + } else if (isLoadBalancerEvent(eventType)) { |
| 1121 | + createLoadBalancerHelperEvent(event); |
| 1122 | + } else if (isPortForwardingEvent(eventType)) { |
| 1123 | + createPortForwardingHelperEvent(event); |
| 1124 | + } else if (isNetworkOfferingEvent(eventType)) { |
| 1125 | + createNetworkOfferingEvent(event); |
| 1126 | + } else if (isVPNUserEvent(eventType)) { |
| 1127 | + handleVpnUserEvent(event); |
| 1128 | + } else if (isSecurityGroupEvent(eventType)) { |
| 1129 | + createSecurityGroupEvent(event); |
| 1130 | + } else if (isVmSnapshotEvent(eventType)) { |
| 1131 | + handleVMSnapshotEvent(event); |
| 1132 | + } else if (isVmSnapshotOnPrimaryEvent(eventType)) { |
| 1133 | + createVmSnapshotOnPrimaryEvent(event); |
| 1134 | + } else if (isBackupEvent(eventType)) { |
| 1135 | + createBackupEvent(event); |
| 1136 | + } |
| 1137 | + } catch (EntityExistsException e) { |
| 1138 | + s_logger.warn(String.format("Failed to create usage event id: %d type: %s due to %s", event.getId(), eventType, e.getMessage()), e); |
1067 | 1139 | } |
1068 | 1140 | } |
1069 | 1141 |
|
|
0 commit comments