From 0d95cc81303c167388b8976c4350ea6ac80a8ada Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 2 May 2011 15:53:05 -0700 Subject: [PATCH] bug 9683: DB upgrade - generate usage_event for source nat ip addresses status 9683: resolved fixed --- .../com/cloud/upgrade/dao/Upgrade218to22.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index 62e816e3c02..dd786d3b695 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -1759,11 +1759,9 @@ public class Upgrade218to22 implements DbUpgrade { private UsageEventVO convertIPEvent(EventVO event, Connection conn) throws IOException, SQLException { Properties ipEventParams = new Properties(); - String ipAddress = null; - boolean isSourceNat = false; UsageEventVO usageEvent = null; ipEventParams.load(new StringReader(event.getParameters())); - ipAddress = ipEventParams.getProperty("address"); + String ipAddress = ipEventParams.getProperty("address"); if (ipAddress == null) { ipAddress = ipEventParams.getProperty("guestIPaddress"); if (ipAddress == null) { @@ -1785,20 +1783,14 @@ public class Upgrade218to22 implements DbUpgrade { rs.close(); pstmt.close(); - isSourceNat = Boolean.parseBoolean(ipEventParams.getProperty("sourceNat")); - if (isSourceNat) { - return null; // skip source nat IP addresses as we don't charge for them - } + boolean isSourceNat = Boolean.parseBoolean(ipEventParams.getProperty("sourceNat")); + long isSourceNatLong = isSourceNat ? 1 : 0; if (EventTypes.EVENT_NET_IP_ASSIGN.equals(event.getType())) { zoneId = Long.parseLong(ipEventParams.getProperty("dcId")); - usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, event.getAccountId(), zoneId, ipId, ipAddress, 0L); + usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNatLong); } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) { - if (!isSourceNat) { - // at this point it's not a sourceNat IP, so find the usage record with this IP and a null released date, update - // the released date - usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, event.getAccountId(), zoneId, ipId, ipAddress, 0L); - } + usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNatLong); } return usageEvent; }