diff --git a/core/src/com/cloud/event/UsageEventVO.java b/core/src/com/cloud/event/UsageEventVO.java index cdc536d77b9..e7c33a38410 100644 --- a/core/src/com/cloud/event/UsageEventVO.java +++ b/core/src/com/cloud/event/UsageEventVO.java @@ -93,14 +93,16 @@ public class UsageEventVO implements UsageEvent { this.resourceName = resourceName; } - public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, long size, String resourceType) { + //IPAddress usage event + public UsageEventVO(String usageType, long accountId, long zoneId, long ipAddressId, String ipAddress, boolean isSourceNat, String guestType, boolean isElastic) { this.type = usageType; this.accountId = accountId; this.zoneId = zoneId; - this.resourceId = resourceId; - this.resourceName = resourceName; - this.size = size; - this.resourceType = resourceType; + this.resourceId = ipAddressId; + this.resourceName = ipAddress; + this.size = (isSourceNat ? 1L : 0L); + this.resourceType = guestType; + this.templateId = (isElastic ? 1L : 0L); } public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType) { diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java index 742c72f35b7..e10c9368649 100644 --- a/server/src/com/cloud/network/NetworkManagerImpl.java +++ b/server/src/com/cloud/network/NetworkManagerImpl.java @@ -439,7 +439,6 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag Transaction txn = Transaction.currentTxn(); Account owner = _accountMgr.getAccount(addr.getAllocatedToAccountId()); - long isSourceNat = (addr.isSourceNat()) ? 1 : 0; txn.start(); addr.setState(IpAddress.State.Allocated); @@ -450,8 +449,8 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag VlanVO vlan = _vlanDao.findById(addr.getVlanId()); String guestType = vlan.getVlanType().toString(); - - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), isSourceNat, guestType); + + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), addr.isSourceNat(), guestType, addr.getElastic()); _usageEventDao.persist(usageEvent); // don't increment resource count for direct ip addresses if (addr.getAssociatedWithNetworkId() != null) { @@ -3722,15 +3721,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag _resourceLimitMgr.decrementResourceCount(_ipAddressDao.findById(addrId).getAllocatedToAccountId(), ResourceType.public_ip); } - long isSourceNat = (ip.isSourceNat()) ? 1 : 0; - // Save usage event if (ip.getAllocatedToAccountId() != Account.ACCOUNT_ID_SYSTEM) { VlanVO vlan = _vlanDao.findById(ip.getVlanId()); String guestType = vlan.getVlanType().toString(); - UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), isSourceNat, guestType); + UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAllocatedToAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), ip.isSourceNat(), guestType, ip.getElastic()); _usageEventDao.persist(usageEvent); } diff --git a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java index 88c712d392a..c37f60b4d1b 100644 --- a/server/src/com/cloud/upgrade/dao/Upgrade218to22.java +++ b/server/src/com/cloud/upgrade/dao/Upgrade218to22.java @@ -1882,13 +1882,12 @@ public class Upgrade218to22 implements DbUpgrade { pstmt.close(); 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, isSourceNatLong,""); + usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNat,"", false); } else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) { - usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNatLong,""); + usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, event.getAccountId(), zoneId, ipId, ipAddress, isSourceNat,"", false); } return usageEvent; } diff --git a/server/src/com/cloud/usage/UsageIPAddressVO.java b/server/src/com/cloud/usage/UsageIPAddressVO.java index e0e6fbb8ff5..cc6375a3626 100644 --- a/server/src/com/cloud/usage/UsageIPAddressVO.java +++ b/server/src/com/cloud/usage/UsageIPAddressVO.java @@ -47,7 +47,10 @@ public class UsageIPAddressVO { @Column(name="is_source_nat") private boolean isSourceNat = false; - + + @Column(name="is_elastic") + private boolean isElastic = false; + @Column(name="assigned") @Temporal(value=TemporalType.TIMESTAMP) private Date assigned = null; @@ -59,13 +62,14 @@ public class UsageIPAddressVO { protected UsageIPAddressVO() { } - public UsageIPAddressVO(long id, long accountId, long domainId, long zoneId, String address, boolean isSourceNat, Date assigned, Date released) { + public UsageIPAddressVO(long id, long accountId, long domainId, long zoneId, String address, boolean isSourceNat, boolean isElastic, Date assigned, Date released) { this.id = id; this.accountId = accountId; this.domainId = domainId; this.zoneId = zoneId; this.address = address; - this.isSourceNat = isSourceNat; + this.isSourceNat = isSourceNat; + this.isElastic = isElastic; this.assigned = assigned; this.released = released; } @@ -99,6 +103,10 @@ public class UsageIPAddressVO { public boolean isSourceNat() { return isSourceNat; + } + + public boolean isElastic() { + return isElastic; } public Date getAssigned() { diff --git a/server/src/com/cloud/usage/UsageVO.java b/server/src/com/cloud/usage/UsageVO.java index 4bca01bfb72..8c35bdf5d94 100644 --- a/server/src/com/cloud/usage/UsageVO.java +++ b/server/src/com/cloud/usage/UsageVO.java @@ -150,7 +150,24 @@ public class UsageVO { this.startDate = startDate; this.endDate = endDate; } - + + //IPAddress Usage + public UsageVO(Long zoneId, Long accountId, Long domainId, String description, String usageDisplay, + int usageType, Double rawUsage, Long usageId, long size, String type, Date startDate, Date endDate) { + this.zoneId = zoneId; + this.accountId = accountId; + this.domainId = domainId; + this.description = description; + this.usageDisplay = usageDisplay; + this.usageType = usageType; + this.rawUsage = rawUsage; + this.usageId = usageId; + this.size = size; + this.type = type; + this.startDate = startDate; + this.endDate = endDate; + } + public Long getId() { return id; } diff --git a/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java b/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java index 334d4f9e24f..29145ec49a4 100644 --- a/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java +++ b/server/src/com/cloud/usage/dao/UsageIPAddressDaoImpl.java @@ -41,15 +41,15 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase= ?)))"; - protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, assigned, released " + + protected static final String GET_USAGE_RECORDS_BY_DOMAIN = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_elastic, assigned, released " + "FROM usage_ip_address " + "WHERE domain_id = ? AND ((released IS NULL AND assigned <= ?) OR (assigned BETWEEN ? AND ?) OR " + " (released BETWEEN ? AND ?) OR ((assigned <= ?) AND (released >= ?)))"; - protected static final String GET_ALL_USAGE_RECORDS = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, assigned, released " + + protected static final String GET_ALL_USAGE_RECORDS = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_elastic, assigned, released " + "FROM usage_ip_address " + "WHERE (released IS NULL AND assigned <= ?) OR (assigned BETWEEN ? AND ?) OR " + " (released BETWEEN ? AND ?) OR ((assigned <= ?) AND (released >= ?))"; @@ -118,11 +118,12 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase sc = m_usageIPAddressDao.createSearchCriteria(); diff --git a/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java b/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java index 02e39f3c621..0eb30676b5b 100644 --- a/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java +++ b/usage/src/com/cloud/usage/parser/IPAddressUsageParser.java @@ -78,7 +78,7 @@ public class IPAddressUsageParser { String key = ""+IpId; // store the info in the IP map - IPMap.put(key, new IpInfo(usageIp.getZoneId(), IpId, usageIp.getAddress(), usageIp.isSourceNat())); + IPMap.put(key, new IpInfo(usageIp.getZoneId(), IpId, usageIp.getAddress(), usageIp.isSourceNat(), usageIp.isElastic())); Date IpAssignDate = usageIp.getAssigned(); Date IpReleaseDeleteDate = usageIp.getReleased(); @@ -104,7 +104,7 @@ public class IPAddressUsageParser { // Only create a usage record if we have a runningTime of bigger than zero. if (useTime > 0L) { IpInfo info = IPMap.get(ipIdKey); - createUsageRecord(info.getZoneId(), useTime, startDate, endDate, account, info.getIpId(), info.getIPAddress(), info.isSourceNat()); + createUsageRecord(info.getZoneId(), useTime, startDate, endDate, account, info.getIpId(), info.getIPAddress(), info.isSourceNat(), info.isElastic); } } @@ -123,7 +123,7 @@ public class IPAddressUsageParser { usageDataMap.put(key, ipUsageInfo); } - private static void createUsageRecord(long zoneId, long runningTime, Date startDate, Date endDate, AccountVO account, long IpId, String IPAddress, boolean isSourceNat) { + private static void createUsageRecord(long zoneId, long runningTime, Date startDate, Date endDate, AccountVO account, long IpId, String IPAddress, boolean isSourceNat, boolean isElastic) { if (s_logger.isDebugEnabled()) { s_logger.debug("Total usage time " + runningTime + "ms"); } @@ -141,8 +141,8 @@ public class IPAddressUsageParser { // Create the usage record - UsageVO usageRecord = new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", - UsageTypes.IP_ADDRESS, new Double(usage), null, null, null, null, IpId, startDate, endDate, (isSourceNat?"SourceNat":"")); + UsageVO usageRecord = new UsageVO(zoneId, account.getAccountId(), account.getDomainId(), usageDesc, usageDisplay + " Hrs", UsageTypes.IP_ADDRESS, new Double(usage), IpId, + (isElastic?1:0), (isSourceNat?"SourceNat":""), startDate, endDate); m_usageDao.persist(usageRecord); } @@ -151,12 +151,14 @@ public class IPAddressUsageParser { private long IpId; private String IPAddress; private boolean isSourceNat; + private boolean isElastic; - public IpInfo(long zoneId,long IpId, String IPAddress, boolean isSourceNat) { + public IpInfo(long zoneId,long IpId, String IPAddress, boolean isSourceNat, boolean isElastic) { this.zoneId = zoneId; this.IpId = IpId; this.IPAddress = IPAddress; this.isSourceNat = isSourceNat; + this.isElastic = isElastic; } public long getZoneId() { @@ -174,6 +176,10 @@ public class IPAddressUsageParser { public boolean isSourceNat() { return isSourceNat; } + + public boolean isElastic() { + return isElastic; + } } }