mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Bug 13326: Added is_elastic flag to IP address usage. Added new column in usage_ip_address, defaults to false. size column will contain is_elastic info in cloud_usage table
Status 13326: resolved fixed Reviewed-By: Nitin
This commit is contained in:
parent
b70f74088c
commit
a388ed792f
@ -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) {
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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() {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -41,15 +41,15 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase<UsageIPAddressVO, Long
|
||||
public static final Logger s_logger = Logger.getLogger(UsageIPAddressDaoImpl.class.getName());
|
||||
|
||||
protected static final String UPDATE_RELEASED = "UPDATE usage_ip_address SET released = ? WHERE account_id = ? AND public_ip_address = ? and released IS NULL";
|
||||
protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, assigned, released " +
|
||||
protected static final String GET_USAGE_RECORDS_BY_ACCOUNT = "SELECT id, account_id, domain_id, zone_id, public_ip_address, is_source_nat, is_elastic, assigned, released " +
|
||||
"FROM usage_ip_address " +
|
||||
"WHERE account_id = ? AND ((released IS NULL AND assigned <= ?) OR (assigned BETWEEN ? AND ?) OR " +
|
||||
" (released BETWEEN ? AND ?) OR ((assigned <= ?) AND (released >= ?)))";
|
||||
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<UsageIPAddressVO, Long
|
||||
Long dId = Long.valueOf(rs.getLong(3));
|
||||
Long zId = Long.valueOf(rs.getLong(4));
|
||||
String addr = rs.getString(5);
|
||||
Boolean isSourceNat = Boolean.valueOf(rs.getBoolean(6));
|
||||
Boolean isSourceNat = Boolean.valueOf(rs.getBoolean(6));
|
||||
Boolean isElastic = Boolean.valueOf(rs.getBoolean(7));
|
||||
Date assignedDate = null;
|
||||
Date releasedDate = null;
|
||||
String assignedTS = rs.getString(7);
|
||||
String releasedTS = rs.getString(8);
|
||||
String assignedTS = rs.getString(8);
|
||||
String releasedTS = rs.getString(9);
|
||||
|
||||
if (assignedTS != null) {
|
||||
assignedDate = DateUtil.parseDateString(s_gmtTimeZone, assignedTS);
|
||||
@ -131,7 +132,7 @@ public class UsageIPAddressDaoImpl extends GenericDaoBase<UsageIPAddressVO, Long
|
||||
releasedDate = DateUtil.parseDateString(s_gmtTimeZone, releasedTS);
|
||||
}
|
||||
|
||||
usageRecords.add(new UsageIPAddressVO(id, acctId, dId, zId, addr, isSourceNat, assignedDate, releasedDate));
|
||||
usageRecords.add(new UsageIPAddressVO(id, acctId, dId, zId, addr, isSourceNat, isElastic, assignedDate, releasedDate));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
txn.rollback();
|
||||
|
||||
@ -95,6 +95,7 @@ CREATE TABLE `cloud_usage`.`usage_ip_address` (
|
||||
`zone_id` bigint unsigned NOT NULL,
|
||||
`public_ip_address` varchar(15) NOT NULL,
|
||||
`is_source_nat` smallint(1) NOT NULL,
|
||||
`is_elastic` smallint(1) NOT NULL,
|
||||
`assigned` DATETIME NOT NULL,
|
||||
`released` DATETIME NULL,
|
||||
UNIQUE KEY (`id`, `assigned`)
|
||||
|
||||
@ -305,7 +305,7 @@ UPDATE `cloud_usage`.`usage_network` set agg_bytes_received = net_bytes_received
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__account_id`(`account_id`);
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__created`(`created`);
|
||||
ALTER TABLE `cloud_usage`.`usage_vpn_user` ADD INDEX `i_usage_vpn_user__deleted`(`deleted`);
|
||||
|
||||
ALTER TABLE `cloud_usage`.`usage_ip_address` ADD COLUMN `is_elastic` smallint(1) NOT NULL default '0';
|
||||
|
||||
DELETE FROM `cloud`.`configuration` WHERE name='host.capacity.checker.wait';
|
||||
DELETE FROM `cloud`.`configuration` WHERE name='host.capacity.checker.interval';
|
||||
|
||||
@ -1010,7 +1010,8 @@ public class UsageManagerImpl implements UsageManager, Runnable {
|
||||
long id = event.getResourceId();
|
||||
long sourceNat = event.getSize();
|
||||
boolean isSourceNat = (sourceNat == 1) ? true : false ;
|
||||
UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, event.getCreateDate(), null);
|
||||
boolean isElastic = (event.getTemplateId() == 1) ? true : false ;
|
||||
UsageIPAddressVO ipAddressVO = new UsageIPAddressVO(id, event.getAccountId(), acct.getDomainId(), zoneId, ipAddress, isSourceNat, isElastic, event.getCreateDate(), null);
|
||||
m_usageIPAddressDao.persist(ipAddressVO);
|
||||
} else if (EventTypes.EVENT_NET_IP_RELEASE.equals(event.getType())) {
|
||||
SearchCriteria<UsageIPAddressVO> sc = m_usageIPAddressDao.createSearchCriteria();
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user