Skip to content

Commit a52bbfb

Browse files
committed
CLOUDSTACK-8166: add boundary checks in various usage parsers
- Add boundary condition to continue looping if creation data is after end date - Add null pointer fix for create snapshot bug Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> (cherry picked from commit 065c556) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent 7cb19f5 commit a52bbfb

10 files changed

Lines changed: 38 additions & 1 deletion

usage/src/com/cloud/usage/UsageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1729,7 +1729,7 @@ private void createVMSnapshotEvent(UsageEventVO event) {
17291729
Long offeringId = event.getOfferingId();
17301730
Long zoneId = event.getZoneId();
17311731
Long accountId = event.getAccountId();
1732-
long size = event.getSize();
1732+
long size = event.getSize() == null ? 0L : event.getSize().longValue();
17331733
Date created = event.getCreateDate();
17341734
Account acct = _accountDao.findByIdIncludingRemoved(event.getAccountId());
17351735
Long domainId = acct.getDomainId();

usage/src/com/cloud/usage/parser/IPAddressUsageParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
101101
IpAssignDate = startDate;
102102
}
103103

104+
// ignore if assign date is after end date
105+
if (IpAssignDate.after(endDate)) {
106+
continue;
107+
}
108+
104109
long currentDuration = (IpReleaseDeleteDate.getTime() - IpAssignDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
105110

106111
updateIpUsageData(usageMap, key, usageIp.getId(), currentDuration);

usage/src/com/cloud/usage/parser/LoadBalancerUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
9898
lbCreateDate = startDate;
9999
}
100100

101+
if (lbCreateDate.after(endDate)) {
102+
continue;
103+
}
104+
101105
long currentDuration = (lbDeleteDate.getTime() - lbCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
102106

103107
updateLBUsageData(usageMap, key, usageLB.getId(), currentDuration);

usage/src/com/cloud/usage/parser/NetworkOfferingUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
9999
noCreateDate = startDate;
100100
}
101101

102+
if (noCreateDate.after(endDate)) {
103+
continue;
104+
}
105+
102106
long currentDuration = (noDeleteDate.getTime() - noCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
103107

104108
updateNOUsageData(usageMap, key, usageNO.getVmInstanceId(), currentDuration);

usage/src/com/cloud/usage/parser/PortForwardingUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
9898
pfCreateDate = startDate;
9999
}
100100

101+
if (pfCreateDate.after(endDate)) {
102+
continue;
103+
}
104+
101105
long currentDuration = (pfDeleteDate.getTime() - pfCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
102106

103107
updatePFUsageData(usageMap, key, usagePF.getId(), currentDuration);

usage/src/com/cloud/usage/parser/SecurityGroupUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
9999
sgCreateDate = startDate;
100100
}
101101

102+
if (sgCreateDate.after(endDate)) {
103+
continue;
104+
}
105+
102106
long currentDuration = (sgDeleteDate.getTime() - sgCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
103107

104108
updateSGUsageData(usageMap, key, usageSG.getVmInstanceId(), currentDuration);

usage/src/com/cloud/usage/parser/StorageUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
107107
storageCreateDate = startDate;
108108
}
109109

110+
if (storageCreateDate.after(endDate)) {
111+
continue;
112+
}
113+
110114
long currentDuration = (storageDeleteDate.getTime() - storageCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
111115

112116
updateStorageUsageData(usageMap, key, usageStorage.getId(), currentDuration);

usage/src/com/cloud/usage/parser/VMInstanceUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
104104
vmStartDate = startDate;
105105
}
106106

107+
if (vmStartDate.after(endDate)) {
108+
continue;
109+
}
110+
107111
long currentDuration = (vmEndDate.getTime() - vmStartDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
108112

109113
switch (usageType) {

usage/src/com/cloud/usage/parser/VPNUserUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
9494
vuCreateDate = startDate;
9595
}
9696

97+
if (vuCreateDate.after(endDate)) {
98+
continue;
99+
}
100+
97101
long currentDuration = (vuDeleteDate.getTime() - vuCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
98102

99103
updateVUUsageData(usageMap, key, usageVU.getUserId(), currentDuration);

usage/src/com/cloud/usage/parser/VolumeUsageParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public static boolean parse(AccountVO account, Date startDate, Date endDate) {
103103
volCreateDate = startDate;
104104
}
105105

106+
if (volCreateDate.after(endDate)) {
107+
continue;
108+
}
109+
106110
long currentDuration = (volDeleteDate.getTime() - volCreateDate.getTime()) + 1; // make sure this is an inclusive check for milliseconds (i.e. use n - m + 1 to find total number of millis to charge)
107111

108112
updateVolUsageData(usageMap, key, usageVol.getId(), currentDuration);

0 commit comments

Comments
 (0)