bug 8866,4942: Added support for Direct Network Usage collection

status 8866,4942: resolved fixed
This commit is contained in:
kishan 2011-05-16 18:31:02 +05:30
parent 733a892aa4
commit b738408f7d
9 changed files with 30 additions and 20 deletions

View File

@ -93,13 +93,14 @@ public class UsageEventVO implements UsageEvent {
this.resourceName = resourceName;
}
public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, long size) {
public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, long size, String resourceType) {
this.type = usageType;
this.accountId = accountId;
this.zoneId = zoneId;
this.resourceId = resourceId;
this.resourceName = resourceName;
this.size = size;
this.resourceType = resourceType;
}
public UsageEventVO(String usageType, long accountId, long zoneId, long resourceId, String resourceName, Long offeringId, Long templateId, String resourceType) {

View File

@ -35,6 +35,6 @@ public interface UsageEventDao extends GenericDao<UsageEventVO, Long> {
List<UsageEventVO> getRecentEvents(Date endDate) throws UsageServerException;
List<UsageEventVO> listIpEvents(Date startDate, Date endDate);
List<UsageEventVO> listDirectIpEvents(Date startDate, Date endDate, long zoneId);
}

View File

@ -31,6 +31,7 @@ import org.apache.log4j.Logger;
import com.cloud.event.EventTypes;
import com.cloud.event.UsageEventVO;
import com.cloud.exception.UsageServerException;
import com.cloud.network.Network.GuestIpType;
import com.cloud.utils.DateUtil;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.Filter;
@ -61,6 +62,8 @@ public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implem
IpeventsSearch = createSearchBuilder();
IpeventsSearch.and("startdate", IpeventsSearch.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
IpeventsSearch.and("enddate", IpeventsSearch.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
IpeventsSearch.and("zoneid", IpeventsSearch.entity().getZoneId(), SearchCriteria.Op.EQ);
IpeventsSearch.and("networktype", IpeventsSearch.entity().getResourceType(), SearchCriteria.Op.EQ);
IpeventsSearch.and().op("assignEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
IpeventsSearch.or("releaseEvent", IpeventsSearch.entity().getType(), SearchCriteria.Op.EQ);
IpeventsSearch.closeParen();
@ -171,13 +174,15 @@ public class UsageEventDaoImpl extends GenericDaoBase<UsageEventVO, Long> implem
}
@Override
public List<UsageEventVO> listIpEvents(Date startDate, Date endDate) {
public List<UsageEventVO> listDirectIpEvents(Date startDate, Date endDate, long zoneId) {
Filter filter = new Filter(UsageEventVO.class, "createDate", Boolean.TRUE, null, null);
SearchCriteria<UsageEventVO> sc = IpeventsSearch.create();
sc.setParameters("startdate", startDate);
sc.setParameters("enddate", endDate);
sc.setParameters("assignEvent", EventTypes.EVENT_NET_IP_ASSIGN);
sc.setParameters("releaseEvent", EventTypes.EVENT_NET_IP_RELEASE);
sc.setParameters("zoneid", zoneId);
sc.setParameters("networktype", GuestIpType.Direct.toString());
return listBy(sc, filter);
}

View File

@ -210,7 +210,7 @@ public enum Config {
UsageStatsJobAggregationRange("Premium", ManagementServer.class, Integer.class, "usage.stats.job.aggregation.range", "1440", "The range of time for aggregating the user statistics specified in minutes (e.g. 1440 for daily, 60 for hourly.", null),
UsageStatsJobExecTime("Premium", ManagementServer.class, String.class, "usage.stats.job.exec.time", "00:15", "The time at which the usage statistics aggregation job will run as an HH24:MM time, e.g. 00:30 to run at 12:30am.", null),
EnableUsageServer("Premium", ManagementServer.class, Boolean.class, "enable.usage.server", "true", "Flag for enabling usage", null),
TrafficSentinelHostName("Premium", ManagementServer.class, String.class, "traffic.sentinel.hostname", null, "Hostname of the Traffic Sentinel in http://<hostname> format for querying direct network usage", null),
DirectNetworkStatsInterval("Premium", ManagementServer.class, Integer.class, "direct.network.stats.interval", "84600", "Interval (in seconds) to collect stats from Traffic Monitor", null),
// Hidden
UseSecondaryStorageVm("Hidden", ManagementServer.class, Boolean.class, "secondary.storage.vm", "false", "Deploys a VM per zone to manage secondary storage if true, otherwise secondary storage is mounted on management server", null),

View File

@ -307,7 +307,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
// Save usage event
if (owner.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), isSourceNat);
long networkId = addr.getSourceNetworkId();
NetworkVO network = _networksDao.findByIdIncludingRemoved(networkId);
String guestType = "";
if( (network != null) && (network.getGuestType() != null) ){
guestType = network.getGuestType().toString();
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_ASSIGN, owner.getId(), addr.getDataCenterId(), addr.getId(), addr.getAddress().toString(), isSourceNat, guestType);
_usageEventDao.persist(usageEvent);
// don't increment resource count for direct ip addresses
if (addr.getAssociatedWithNetworkId() != null) {
@ -2751,7 +2757,13 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
long isSourceNat = (ip.isSourceNat()) ? 1 : 0;
if (ip.getAccountId() != Account.ACCOUNT_ID_SYSTEM) {
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), isSourceNat);
NetworkVO network = _networksDao.findByIdIncludingRemoved(ip.getSourceNetworkId());
String guestType = "";
if( (network != null) && (network.getGuestType() != null)){
guestType = network.getGuestType().toString();
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_NET_IP_RELEASE, ip.getAccountId(), ip.getDataCenterId(), addrId, ip.getAddress().addr(), isSourceNat, guestType);
_usageEventDao.persist(usageEvent);
}

View File

@ -50,6 +50,4 @@ public interface IPAddressDao extends GenericDao<IPAddressVO, Long> {
IPAddressVO findByAccountAndIp(long accountId, String ipAddress);
List<IPAddressVO> listAllocatedIps();
}

View File

@ -52,7 +52,8 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
protected final GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCount;
protected final GenericSearchBuilder<IPAddressVO, Integer> AllIpCountForDashboard;
protected final GenericSearchBuilder<IPAddressVO, Integer> AllocatedIpCountForDashboard;
protected final SearchBuilder<IPAddressVO> AllocatedIpSearch;
// make it public for JUnit test
@ -98,9 +99,6 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
AllocatedIpCountForDashboard.and("allocated", AllocatedIpCountForDashboard.entity().getAllocatedTime(), Op.NNULL);
AllocatedIpCountForDashboard.done();
AllocatedIpSearch = createSearchBuilder();
AllocatedIpSearch.and("allocated", AllocatedIpSearch.entity().getAllocatedTime(), Op.NNULL);
AllocatedIpSearch.done();
}
@Override
@ -273,9 +271,4 @@ public class IPAddressDaoImpl extends GenericDaoBase<IPAddressVO, Long> implemen
return findOneBy(sc);
}
@Override
public List<IPAddressVO> listAllocatedIps() {
SearchCriteria<IPAddressVO> sc = AllocatedIpSearch.create();
return listBy(sc);
}
}

View File

@ -151,7 +151,8 @@ public class StatsCollector {
sc.addAnd("status", SearchCriteria.Op.EQ, Status.Up.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.Storage.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.ConsoleProxy.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorage.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.SecondaryStorage.toString());
sc.addAnd("type", SearchCriteria.Op.NEQ, Host.Type.TrafficMonitor.toString());
ConcurrentHashMap<Long, HostStats> hostStats = new ConcurrentHashMap<Long, HostStats>();
List<HostVO> hosts = _hostDao.search(sc, null);
for (HostVO host : hosts)

View File

@ -1896,9 +1896,9 @@ public class Upgrade218to22 implements DbUpgrade {
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, isSourceNatLong,"");
} 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, isSourceNatLong,"");
}
return usageEvent;
}