incubator-cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kishan Kavala <Kishan.Kav...@citrix.com>
Subject RE: git commit: refs/heads/4.1 - CLOUDSTACK-962:setAggBytesSent/setAggBytesReceived in NetworkUsageTask when not in case of dailyor hourly Removed duplicate userstatsdao injection
Date Thu, 28 Feb 2013 07:04:22 GMT
Yes David. Fix can go into 4.0 branch also.

Wei Zhou,
 Would you be able to port these changes to 4.0 branch?

> -----Original Message-----
> From: David Nalley [mailto:david@gnsa.us]
> Sent: Tuesday, 26 February 2013 8:35 PM
> To: cloudstack-dev@incubator.apache.org
> Cc: cloudstack-commits@incubator.apache.org
> Subject: Re: git commit: refs/heads/4.1 - CLOUDSTACK-
> 962:setAggBytesSent/setAggBytesReceived in NetworkUsageTask when not
> in case of dailyor hourly Removed duplicate userstatsdao injection
>
> Kishan: Is there a reason this wasn't also added to 4.0 branch (it was filed
> against 4.0.0, but only applied to 4.1 and master)
>
> --David
>
> On Tue, Feb 26, 2013 at 5:57 AM,  <kishan@apache.org> wrote:
> > Updated Branches:
> >   refs/heads/4.1 c7935a9ab -> 03fdbfb29
> >
> >
> > CLOUDSTACK-962:setAggBytesSent/setAggBytesReceived in
> NetworkUsageTask
> > when not in case of dailyor hourly Removed duplicate userstatsdao
> > injection
> >
> >
> > Project:
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
> > Commit:
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/03f
> > dbfb2
> > Tree:
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/03fdb
> > fb2
> > Diff:
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/03fdb
> > fb2
> >
> > Branch: refs/heads/4.1
> > Commit: 03fdbfb29193885830de90edcbb6f71bd0baf487
> > Parents: c7935a9
> > Author: Wei Zhou <w.zhou@leaseweb.com>
> > Authored: Tue Feb 26 16:25:03 2013 +0530
> > Committer: Kishan Kavala <kishan@cloud.com>
> > Committed: Tue Feb 26 16:26:30 2013 +0530
> >
> > ----------------------------------------------------------------------
> >  .../router/VirtualNetworkApplianceManagerImpl.java |   33 ++++++++++--
> --
> >  .../com/cloud/user/dao/UserStatisticsDaoImpl.java  |   18 ++++----
> >  usage/src/com/cloud/usage/UsageManagerImpl.java    |    2 +-
> >  3 files changed, 33 insertions(+), 20 deletions(-)
> > ----------------------------------------------------------------------
> >
> >
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/03fdb
> >
> fb2/server/src/com/cloud/network/router/VirtualNetworkApplianceManag
> er
> > Impl.java
> > ----------------------------------------------------------------------
> > diff --git
> >
> a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerI
> m
> > pl.java
> >
> b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerI
> m
> > pl.java
> > index 980d482..abb4973 100755
> > ---
> >
> a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerI
> m
> > pl.java
> > +++
> b/server/src/com/cloud/network/router/VirtualNetworkApplianceManag
> > +++ erImpl.java
> > @@ -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();
> >
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/03fdb
> > fb2/server/src/com/cloud/user/dao/UserStatisticsDaoImpl.java
> > ----------------------------------------------------------------------
> > diff --git a/server/src/com/cloud/user/dao/UserStatisticsDaoImpl.java
> > b/server/src/com/cloud/user/dao/UserStatisticsDaoImpl.java
> > index 913ec07..4a1a51c 100644
> > --- a/server/src/com/cloud/user/dao/UserStatisticsDaoImpl.java
> > +++ b/server/src/com/cloud/user/dao/UserStatisticsDaoImpl.java
> > @@ -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();
> > +        AccountSearch = createSearchBuilder();
> > +        AccountSearch.and("account", AccountSearch.entity().getAccountId(),
> SearchCriteria.Op.EQ);
> > +        AccountSearch.done();
> >
> > -       AllFieldsSearch = createSearchBuilder();
> > +        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;
> >      }
> > -
> > +
> >  }
> >
> > http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/03fdb
> > fb2/usage/src/com/cloud/usage/UsageManagerImpl.java
> > ----------------------------------------------------------------------
> > diff --git a/usage/src/com/cloud/usage/UsageManagerImpl.java
> > b/usage/src/com/cloud/usage/UsageManagerImpl.java
> > index bfdca1d..66af7f4 100644
> > --- a/usage/src/com/cloud/usage/UsageManagerImpl.java
> > +++ b/usage/src/com/cloud/usage/UsageManagerImpl.java
> > @@ -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)");
> >

Mime
View raw message