@Override public void updateUserStats(List<UserStatisticsVO> userStats) { TransactionLegacy txn = TransactionLegacy.currentTxn(); try { txn.start(); String sql = UPDATE_USER_STATS; PreparedStatement pstmt = null; pstmt = txn.prepareAutoCloseStatement(sql); // in reality I just want CLOUD_USAGE dataSource connection for (UserStatisticsVO userStat : userStats) { pstmt.setLong(1, userStat.getNetBytesReceived()); pstmt.setLong(2, userStat.getNetBytesSent()); pstmt.setLong(3, userStat.getCurrentBytesReceived()); pstmt.setLong(4, userStat.getCurrentBytesSent()); pstmt.setLong(5, userStat.getAggBytesReceived()); pstmt.setLong(6, userStat.getAggBytesSent()); pstmt.setLong(7, userStat.getId()); pstmt.addBatch(); } pstmt.executeBatch(); txn.commit(); } catch (Exception ex) { txn.rollback(); s_logger.error("error updating user stats to cloud_usage db", ex); throw new CloudRuntimeException(ex.getMessage()); } }
pstmt.setLong(1, userStat.getId()); pstmt.setLong(2, userStat.getDataCenterId()); pstmt.setLong(3, userStat.getAccountId());
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { // get all stats with delta > 0 final List<UserStatisticsVO> updatedStats = _userStatsDao.listUpdatedStats(); final Date updatedTime = new Date(); for (final UserStatisticsVO stat : updatedStats) { // update agg bytes stat.setAggBytesReceived(stat.getCurrentBytesReceived() + stat.getNetBytesReceived()); stat.setAggBytesSent(stat.getCurrentBytesSent() + stat.getNetBytesSent()); _userStatsDao.update(stat.getId(), stat); // insert into op_user_stats_log final UserStatsLogVO statsLog = new UserStatsLogVO(stat.getId(), stat.getNetBytesReceived(), stat.getNetBytesSent(), stat .getCurrentBytesReceived(), stat.getCurrentBytesSent(), stat.getAggBytesReceived(), stat.getAggBytesSent(), updatedTime); _userStatsLogDao.persist(statsLog); } s_logger.debug("Successfully updated aggregate network stats"); } });
private boolean updateBytes(UserStatisticsVO userStats, long newCurrentBytesSent, long newCurrentBytesReceived) { long oldNetBytesSent = userStats.getNetBytesSent(); long oldNetBytesReceived = userStats.getNetBytesReceived(); long oldCurrentBytesSent = userStats.getCurrentBytesSent(); long oldCurrentBytesReceived = userStats.getCurrentBytesReceived(); String warning = "Received an external network stats byte count that was less than the stored value. Zone ID: " + userStats.getDataCenterId() + ", account ID: " + userStats.getAccountId() + "."; userStats.setCurrentBytesSent(newCurrentBytesSent); if (oldCurrentBytesSent > newCurrentBytesSent) { s_logger.warn(warning + "Stored bytes sent: " + oldCurrentBytesSent + ", new bytes sent: " + newCurrentBytesSent + "."); userStats.setNetBytesSent(oldNetBytesSent + oldCurrentBytesSent); } userStats.setCurrentBytesReceived(newCurrentBytesReceived); if (oldCurrentBytesReceived > newCurrentBytesReceived) { s_logger.warn(warning + "Stored bytes received: " + oldCurrentBytesReceived + ", new bytes received: " + newCurrentBytesReceived + "."); userStats.setNetBytesReceived(oldNetBytesReceived + oldCurrentBytesReceived); } return _userStatsDao.update(userStats.getId(), userStats); }
if (_userStatsDao.update(userStats.getId(), userStats)) { s_logger.debug("Successfully updated stats for " + statsEntryIdentifier); } else {
@Override public void doInTransactionWithoutResult(final TransactionStatus status) { // FIXME!!! - UserStats command should grab bytesSent/Received // for all guest interfaces of the VR final List<Long> routerGuestNtwkIds = _routerDao.getRouterNetworks(router.getId()); for (final Long guestNtwkId : routerGuestNtwkIds) { final UserStatisticsVO userStats = _userStatsDao.lock(router.getAccountId(), router.getDataCenterId(), guestNtwkId, null, router.getId(), router.getType() .toString()); if (userStats != null) { final long currentBytesRcvd = userStats.getCurrentBytesReceived(); userStats.setCurrentBytesReceived(0); userStats.setNetBytesReceived(userStats.getNetBytesReceived() + currentBytesRcvd); final long currentBytesSent = userStats.getCurrentBytesSent(); userStats.setCurrentBytesSent(0); userStats.setNetBytesSent(userStats.getNetBytesSent() + currentBytesSent); _userStatsDao.update(userStats.getId(), userStats); s_logger.debug("Successfully updated user statistics as a part of domR " + router + " reboot/stop"); } else { s_logger.warn("User stats were not created for account " + router.getAccountId() + " and dc " + router.getDataCenterId()); } } } });
stats.setAggBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived()); _userStatsDao.update(stats.getId(), stats);
stats.setAggBytesReceived(stats.getNetBytesReceived() + stats.getCurrentBytesReceived()); _userStatsDao.update(stats.getId(), stats);
@Override public void doInTransactionWithoutResult(TransactionStatus status) { for (UserStatisticsVO stat : collectedStats) { UserStatisticsVO stats = _statsDao.lock(stat.getAccountId(), stat.getDataCenterId(), 0L, null, host.getId(), "DirectNetwork"); if (stats == null) { stats = new UserStatisticsVO(stat.getAccountId(), zoneId, null, host.getId(), "DirectNetwork", 0L); stats.setCurrentBytesSent(stat.getCurrentBytesSent()); stats.setCurrentBytesReceived(stat.getCurrentBytesReceived()); _statsDao.persist(stats); } else { stats.setCurrentBytesSent(stats.getCurrentBytesSent() + stat.getCurrentBytesSent()); stats.setCurrentBytesReceived(stats.getCurrentBytesReceived() + stat.getCurrentBytesReceived()); _statsDao.update(stats.getId(), stats); } } lastCollectDetail.setValue("" + now.getTime()); _detailsDao.update(lastCollectDetail.getId(), lastCollectDetail); } });
_userStatsDao.update(vmNetworkStat_lock.getId(), vmNetworkStat_lock);
_userStatsDao.update(vmNetworkStat_lock.getId(), vmNetworkStat_lock);