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>
This commit is contained in:
Rohit Yadav 2015-01-18 17:06:39 +05:30
parent 2c515395d7
commit 065c556cf5
10 changed files with 38 additions and 1 deletions

View File

@ -1726,7 +1726,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
Long offeringId = event.getOfferingId();
Long zoneId = event.getZoneId();
Long accountId = event.getAccountId();
long size = event.getSize();
long size = event.getSize() == null ? 0L : event.getSize().longValue();
Date created = event.getCreateDate();
Account acct = _accountDao.findByIdIncludingRemoved(event.getAccountId());
Long domainId = acct.getDomainId();

View File

@ -101,6 +101,11 @@ public class IPAddressUsageParser {
IpAssignDate = startDate;
}
// ignore if assign date is after end date
if (IpAssignDate.after(endDate)) {
continue;
}
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)
updateIpUsageData(usageMap, key, usageIp.getId(), currentDuration);

View File

@ -98,6 +98,10 @@ public class LoadBalancerUsageParser {
lbCreateDate = startDate;
}
if (lbCreateDate.after(endDate)) {
continue;
}
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)
updateLBUsageData(usageMap, key, usageLB.getId(), currentDuration);

View File

@ -99,6 +99,10 @@ public class NetworkOfferingUsageParser {
noCreateDate = startDate;
}
if (noCreateDate.after(endDate)) {
continue;
}
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)
updateNOUsageData(usageMap, key, usageNO.getVmInstanceId(), currentDuration);

View File

@ -98,6 +98,10 @@ public class PortForwardingUsageParser {
pfCreateDate = startDate;
}
if (pfCreateDate.after(endDate)) {
continue;
}
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)
updatePFUsageData(usageMap, key, usagePF.getId(), currentDuration);

View File

@ -99,6 +99,10 @@ public class SecurityGroupUsageParser {
sgCreateDate = startDate;
}
if (sgCreateDate.after(endDate)) {
continue;
}
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)
updateSGUsageData(usageMap, key, usageSG.getVmInstanceId(), currentDuration);

View File

@ -107,6 +107,10 @@ public class StorageUsageParser {
storageCreateDate = startDate;
}
if (storageCreateDate.after(endDate)) {
continue;
}
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)
updateStorageUsageData(usageMap, key, usageStorage.getId(), currentDuration);

View File

@ -104,6 +104,10 @@ public class VMInstanceUsageParser {
vmStartDate = startDate;
}
if (vmStartDate.after(endDate)) {
continue;
}
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)
switch (usageType) {

View File

@ -94,6 +94,10 @@ public class VPNUserUsageParser {
vuCreateDate = startDate;
}
if (vuCreateDate.after(endDate)) {
continue;
}
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)
updateVUUsageData(usageMap, key, usageVU.getUserId(), currentDuration);

View File

@ -103,6 +103,10 @@ public class VolumeUsageParser {
volCreateDate = startDate;
}
if (volCreateDate.after(endDate)) {
continue;
}
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)
updateVolUsageData(usageMap, key, usageVol.getId(), currentDuration);