mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-16 10:32:34 +01:00
CLOUDSTACK-962:setAggBytesSent/setAggBytesReceived in NetworkUsageTask when not in case of dailyor hourly
Removed duplicate userstatsdao injection
This commit is contained in:
parent
8cb5c00c26
commit
fc3905fb57
@ -293,8 +293,6 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
UserVmDao _userVmDao;
|
||||
@Inject VMInstanceDao _vmDao;
|
||||
@Inject
|
||||
UserStatisticsDao _statsDao = null;
|
||||
@Inject
|
||||
NetworkOfferingDao _networkOfferingDao = null;
|
||||
@Inject
|
||||
GuestOSDao _guestOSDao = null;
|
||||
@ -364,7 +362,9 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
private String _usageTimeZone = "GMT";
|
||||
private final long mgmtSrvrId = MacAddress.getMacAddress().toLong();
|
||||
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 5; // 5 seconds
|
||||
|
||||
private static final int USAGE_AGGREGATION_RANGE_MIN = 10; // 10 minutes, same as com.cloud.usage.UsageManagerImpl.USAGE_AGGREGATION_RANGE_MIN
|
||||
private boolean _dailyOrHourly = false;
|
||||
|
||||
ScheduledExecutorService _executor;
|
||||
ScheduledExecutorService _checkExecutor;
|
||||
ScheduledExecutorService _networkStatsUpdateExecutor;
|
||||
@ -728,6 +728,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
cal.roll(Calendar.DAY_OF_YEAR, true);
|
||||
cal.add(Calendar.MILLISECOND, -1);
|
||||
endDate = cal.getTime().getTime();
|
||||
_dailyOrHourly = true;
|
||||
} else if (_usageAggregationRange == HOURLY_TIME) {
|
||||
cal.roll(Calendar.HOUR_OF_DAY, false);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
@ -736,8 +737,15 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
cal.roll(Calendar.HOUR_OF_DAY, true);
|
||||
cal.add(Calendar.MILLISECOND, -1);
|
||||
endDate = cal.getTime().getTime();
|
||||
_dailyOrHourly = true;
|
||||
} else {
|
||||
endDate = cal.getTime().getTime();
|
||||
_dailyOrHourly = false;
|
||||
}
|
||||
|
||||
if (_usageAggregationRange < USAGE_AGGREGATION_RANGE_MIN) {
|
||||
s_logger.warn("Usage stats job aggregation range is to small, using the minimum value of " + USAGE_AGGREGATION_RANGE_MIN);
|
||||
_usageAggregationRange = USAGE_AGGREGATION_RANGE_MIN;
|
||||
}
|
||||
|
||||
_networkStatsUpdateExecutor.scheduleAtFixedRate(new NetworkStatsUpdateTask(), (endDate - System.currentTimeMillis()),
|
||||
@ -854,7 +862,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
|
||||
forVpc, routerNic.getIp4Address());
|
||||
String routerType = router.getType().toString();
|
||||
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
|
||||
UserStatisticsVO previousStats = _userStatsDao.findBy(router.getAccountId(),
|
||||
router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
|
||||
NetworkUsageAnswer answer = null;
|
||||
try {
|
||||
@ -876,7 +884,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
continue;
|
||||
}
|
||||
txn.start();
|
||||
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
|
||||
UserStatisticsVO stats = _userStatsDao.lock(router.getAccountId(),
|
||||
router.getDataCenterId(), network.getId(), (forVpc ? routerNic.getIp4Address() : null), router.getId(), routerType);
|
||||
if (stats == null) {
|
||||
s_logger.warn("unable to find stats for account: " + router.getAccountId());
|
||||
@ -912,7 +920,12 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
|
||||
}
|
||||
stats.setCurrentBytesSent(answer.getBytesSent());
|
||||
_statsDao.update(stats.getId(), stats);
|
||||
if (! _dailyOrHourly) {
|
||||
//update agg bytes
|
||||
stats.setAggBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
|
||||
stats.setAggBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived());
|
||||
}
|
||||
_userStatsDao.update(stats.getId(), stats);
|
||||
txn.commit();
|
||||
} catch (Exception e) {
|
||||
txn.rollback();
|
||||
@ -954,7 +967,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
try {
|
||||
txn.start();
|
||||
//get all stats with delta > 0
|
||||
List<UserStatisticsVO> updatedStats = _statsDao.listUpdatedStats();
|
||||
List<UserStatisticsVO> updatedStats = _userStatsDao.listUpdatedStats();
|
||||
Date updatedTime = new Date();
|
||||
for(UserStatisticsVO stat : updatedStats){
|
||||
//update agg bytes
|
||||
@ -3598,7 +3611,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
boolean forVpc = router.getVpcId() != null;
|
||||
final NetworkUsageCommand usageCmd = new NetworkUsageCommand(privateIP, router.getHostName(),
|
||||
forVpc, routerNic.getIp4Address());
|
||||
UserStatisticsVO previousStats = _statsDao.findBy(router.getAccountId(),
|
||||
UserStatisticsVO previousStats = _userStatsDao.findBy(router.getAccountId(),
|
||||
router.getDataCenterId(), network.getId(), null, router.getId(), router.getType().toString());
|
||||
NetworkUsageAnswer answer = null;
|
||||
try {
|
||||
@ -3620,7 +3633,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
continue;
|
||||
}
|
||||
txn.start();
|
||||
UserStatisticsVO stats = _statsDao.lock(router.getAccountId(),
|
||||
UserStatisticsVO stats = _userStatsDao.lock(router.getAccountId(),
|
||||
router.getDataCenterId(), network.getId(), null, router.getId(), router.getType().toString());
|
||||
if (stats == null) {
|
||||
s_logger.warn("unable to find stats for account: " + router.getAccountId());
|
||||
@ -3656,7 +3669,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
|
||||
stats.setNetBytesSent(stats.getNetBytesSent() + stats.getCurrentBytesSent());
|
||||
}
|
||||
stats.setCurrentBytesSent(answer.getBytesSent());
|
||||
_statsDao.update(stats.getId(), stats);
|
||||
_userStatsDao.update(stats.getId(), stats);
|
||||
txn.commit();
|
||||
} catch (Exception e) {
|
||||
txn.rollback();
|
||||
|
||||
@ -44,17 +44,17 @@ public class UserStatisticsDaoImpl extends GenericDaoBase<UserStatisticsVO, Long
|
||||
"WHERE us.account_id = a.id AND (a.removed IS NULL OR a.removed >= ?) " +
|
||||
"ORDER BY us.id";
|
||||
private static final String UPDATED_STATS_SEARCH = "SELECT id, current_bytes_received, current_bytes_sent, net_bytes_received, net_bytes_sent, agg_bytes_received, agg_bytes_sent from user_statistics " +
|
||||
"where (agg_bytes_received < net_bytes_received + current_bytes_received) OR (agg_bytes_sent < net_bytes_sent + current_bytes_sent)";
|
||||
"where (agg_bytes_received < net_bytes_received + current_bytes_received) OR (agg_bytes_sent < net_bytes_sent + current_bytes_sent)";
|
||||
private final SearchBuilder<UserStatisticsVO> AllFieldsSearch;
|
||||
private final SearchBuilder<UserStatisticsVO> AccountSearch;
|
||||
|
||||
|
||||
public UserStatisticsDaoImpl() {
|
||||
AccountSearch = createSearchBuilder();
|
||||
AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
AccountSearch.done();
|
||||
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
|
||||
public UserStatisticsDaoImpl() {
|
||||
AccountSearch = createSearchBuilder();
|
||||
AccountSearch.and("account", AccountSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
AccountSearch.done();
|
||||
|
||||
AllFieldsSearch = createSearchBuilder();
|
||||
AllFieldsSearch.and("account", AllFieldsSearch.entity().getAccountId(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("dc", AllFieldsSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.and("network", AllFieldsSearch.entity().getNetworkId(), SearchCriteria.Op.EQ);
|
||||
@ -63,7 +63,7 @@ public class UserStatisticsDaoImpl extends GenericDaoBase<UserStatisticsVO, Long
|
||||
AllFieldsSearch.and("deviceType", AllFieldsSearch.entity().getDeviceType(), SearchCriteria.Op.EQ);
|
||||
AllFieldsSearch.done();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public UserStatisticsVO findBy(long accountId, long dcId, long networkId, String publicIp, Long deviceId, String deviceType) {
|
||||
SearchCriteria<UserStatisticsVO> sc = AllFieldsSearch.create();
|
||||
@ -133,5 +133,5 @@ public class UserStatisticsDaoImpl extends GenericDaoBase<UserStatisticsVO, Long
|
||||
}
|
||||
return userStats;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1430,7 +1430,7 @@ public class UsageManagerImpl extends ManagerBase implements UsageManager, Runna
|
||||
timeSinceJob = now - lastSuccess;
|
||||
}
|
||||
|
||||
if ((timeSinceJob > 0) && (timeSinceJob > aggregationDurationMillis)) {
|
||||
if ((timeSinceJob > 0) && (timeSinceJob > (aggregationDurationMillis - 100)) {
|
||||
if (timeToJob > (aggregationDurationMillis/2)) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("it's been " + timeSinceJob + " ms since last usage job and " + timeToJob + " ms until next job, scheduling an immediate job to catch up (aggregation duration is " + m_aggregationDuration + " minutes)");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user