From 3a6c226bc98243059b1bbcda2a487c0f098a1a40 Mon Sep 17 00:00:00 2001 From: kishan Date: Mon, 5 Sep 2011 16:16:02 +0530 Subject: [PATCH] bug 11345: Compare current and previous network stats before updating. Ignore stats if the current stats are not same as the prev stats. Set NetworkUsageAnswer log level to debug --- .../cloud/agent/api/NetworkUsageAnswer.java | 10 +++++++-- .../VirtualNetworkApplianceManagerImpl.java | 21 +++++++++++++------ .../src/com/cloud/vm/dao/DomainRouterDao.java | 5 ++--- .../com/cloud/vm/dao/DomainRouterDaoImpl.java | 11 ++++++++-- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/api/src/com/cloud/agent/api/NetworkUsageAnswer.java b/api/src/com/cloud/agent/api/NetworkUsageAnswer.java index 6138f7a1314..973bef08946 100644 --- a/api/src/com/cloud/agent/api/NetworkUsageAnswer.java +++ b/api/src/com/cloud/agent/api/NetworkUsageAnswer.java @@ -19,9 +19,10 @@ package com.cloud.agent.api; import com.cloud.agent.api.LogLevel.Log4jLevel; -@LogLevel(Log4jLevel.Trace) +@LogLevel(Log4jLevel.Debug) public class NetworkUsageAnswer extends Answer { - Long bytesSent; + String routerName; + Long bytesSent; Long bytesReceived; protected NetworkUsageAnswer() { @@ -31,6 +32,7 @@ public class NetworkUsageAnswer extends Answer { super(cmd, true, details); this.bytesReceived = bytesReceived; this.bytesSent = bytesSent; + routerName = cmd.getDomRName(); } @@ -49,4 +51,8 @@ public class NetworkUsageAnswer extends Answer { public Long getBytesSent() { return bytesSent; } + + public String getRouterName() { + return routerName; + } } diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java index 1d3bf250a92..e1726ef24bd 100755 --- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java +++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java @@ -176,6 +176,7 @@ import com.cloud.utils.concurrency.NamedThreadFactory; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.MacAddress; import com.cloud.utils.net.NetUtils; import com.cloud.vm.DomainRouterVO; import com.cloud.vm.NicProfile; @@ -311,11 +312,13 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian int _routerStatsInterval = 300; int _checkRouterInterval = 30; private ServiceOfferingVO _offering; - private String trafficSentinelHostname; private String _dnsBasicZoneUpdates = "all"; private boolean _disable_rp_filter = false; + + private long mgmtSrvrId = MacAddress.getMacAddress().toLong(); + ScheduledExecutorService _executor; ScheduledExecutorService _checkExecutor; @@ -617,8 +620,6 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian _systemAcct = _accountService.getSystemAccount(); - trafficSentinelHostname = configs.get("traffic.sentinel.hostname"); - s_logger.info("DomainRouterManager is configured."); return true; @@ -704,13 +705,14 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian @Override public void run() { - final List routers = _routerDao.listByStateAndNetworkType(State.Running, GuestIpType.Virtual); + final List routers = _routerDao.listByStateAndNetworkType(State.Running, GuestIpType.Virtual, mgmtSrvrId); s_logger.debug("Found " + routers.size() + " running routers. "); for (DomainRouterVO router : routers) { String privateIP = router.getPrivateIpAddress(); if (privateIP != null) { final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName()); + UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(), router.getDataCenterIdToDeployIn(), router.getNetworkId(), null, router.getId(), router.getType().toString()); final NetworkUsageAnswer answer = (NetworkUsageAnswer) _agentMgr.easySend(router.getHostId(), usageCmd); if (answer != null) { Transaction txn = Transaction.open(Transaction.CLOUD_DB); @@ -725,9 +727,16 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian s_logger.warn("unable to find stats for account: " + router.getAccountId()); continue; } + + if(previousStats != null + && ((previousStats.getCurrentBytesReceived() != stats.getCurrentBytesReceived()) || (previousStats.getCurrentBytesSent() != stats.getCurrentBytesSent()))){ + s_logger.debug("Router stats changed from the time NetworkUsageCommand was sent. Ignoring current answer. Router: "+answer.getRouterName()+" Rcvd: " + answer.getBytesReceived()+ "Sent: " +answer.getBytesSent()); + continue; + } + if (stats.getCurrentBytesReceived() > answer.getBytesReceived()) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Reported: " + answer.getBytesReceived() + s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesReceived() + " Stored: " + stats.getCurrentBytesReceived()); } stats.setNetBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived()); @@ -735,7 +744,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian stats.setCurrentBytesReceived(answer.getBytesReceived()); if (stats.getCurrentBytesSent() > answer.getBytesSent()) { if (s_logger.isDebugEnabled()) { - s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Reported: " + answer.getBytesSent() + s_logger.debug("Received # of bytes that's less than the last one. Assuming something went wrong and persisting it. Router: "+answer.getRouterName()+" Reported: " + answer.getBytesSent() + " Stored: " + stats.getCurrentBytesSent()); } stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent()); diff --git a/server/src/com/cloud/vm/dao/DomainRouterDao.java b/server/src/com/cloud/vm/dao/DomainRouterDao.java index 09e6dd6496b..694b3136a37 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDao.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDao.java @@ -94,10 +94,10 @@ public interface DomainRouterDao extends GenericDao { List listActive(long networkId); /** - * List domain routers by state and network type + * List domain routers by state and network type which reside on Host managed by the specified management server * @return */ - List listByStateAndNetworkType(State state, GuestIpType ipType); + List listByStateAndNetworkType(State state, GuestIpType ipType, long mgmtSrvrId); List findByNetworkOutsideThePod(long networkId, long podId, State state, Role role); @@ -105,5 +105,4 @@ public interface DomainRouterDao extends GenericDao { List listByNetworkAndRole(long networkId, Role role); - } diff --git a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java index bf2706bb353..1913d3f74cc 100755 --- a/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java +++ b/server/src/com/cloud/vm/dao/DomainRouterDaoImpl.java @@ -23,6 +23,8 @@ import javax.ejb.Local; import org.apache.log4j.Logger; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDaoImpl; import com.cloud.network.Network.GuestIpType; import com.cloud.network.NetworkVO; import com.cloud.network.dao.NetworkDaoImpl; @@ -48,7 +50,8 @@ public class DomainRouterDaoImpl extends GenericDaoBase im protected final SearchBuilder StateNetworkTypeSearch; protected final SearchBuilder OutsidePodSearch; NetworkDaoImpl _networksDao = ComponentLocator.inject(NetworkDaoImpl.class); - + HostDaoImpl _hostsDao = ComponentLocator.inject(HostDaoImpl.class); + protected DomainRouterDaoImpl() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterIdToDeployIn(), Op.EQ); @@ -81,6 +84,9 @@ public class DomainRouterDaoImpl extends GenericDaoBase im SearchBuilder joinStateNetwork = _networksDao.createSearchBuilder(); joinStateNetwork.and("guestType", joinStateNetwork.entity().getGuestType(), Op.EQ); StateNetworkTypeSearch.join("network", joinStateNetwork, joinStateNetwork.entity().getId(), StateNetworkTypeSearch.entity().getNetworkId(), JoinType.INNER); + SearchBuilder joinHost = _hostsDao.createSearchBuilder(); + joinHost.and("mgmtServerId", joinHost.entity().getManagementServerId(), Op.EQ); + StateNetworkTypeSearch.join("host", joinHost, joinHost.entity().getId(), StateNetworkTypeSearch.entity().getHostId(), JoinType.INNER); StateNetworkTypeSearch.done(); OutsidePodSearch = createSearchBuilder(); @@ -197,10 +203,11 @@ public class DomainRouterDaoImpl extends GenericDaoBase im } @Override - public List listByStateAndNetworkType(State state, GuestIpType ipType) { + public List listByStateAndNetworkType(State state, GuestIpType ipType, long mgmtSrvrId) { SearchCriteria sc = StateNetworkTypeSearch.create(); sc.setParameters("state", state); sc.setJoinParameters("network", "guestType", ipType); + sc.setJoinParameters("host", "mgmtServerId", mgmtSrvrId); return listBy(sc); }