cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [03/22] git commit: updated refs/heads/4.5 to 78b9be0
Date Thu, 05 Feb 2015 11:51:39 GMT
Trigger user stats aggregation job at midnight in usage aggregation timezone

(cherry picked from commit 4ac96d637c9efe0db50dd707dd161426aeb54a13)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>

Conflicts:
	server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/6541354a
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/6541354a
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/6541354a

Branch: refs/heads/4.5
Commit: 6541354a590fe1583a68af826799f62f841d52bf
Parents: 782adc1
Author: Kishan Kavala <kishan@apache.org>
Authored: Thu Nov 20 17:08:17 2014 +0530
Committer: Rohit Yadav <rohit.yadav@shapeblue.com>
Committed: Thu Feb 5 14:33:27 2015 +0530

----------------------------------------------------------------------
 .../VirtualNetworkApplianceManagerImpl.java     | 23 ++++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/6541354a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
index 6c5ff9c..92f1af9 100755
--- a/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
+++ b/server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java
@@ -779,33 +779,35 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State,
VirtualMachine.
         }
 
         //Schedule Network stats update task
+        //Network stats aggregation should align with aggregation range
+        //For daily aggregation, update stats at the end of the day
+        //For hourly aggregation, update stats at the end of the hour
         final TimeZone usageTimezone = TimeZone.getTimeZone(_usageTimeZone);
         final Calendar cal = Calendar.getInstance(usageTimezone);
         cal.setTime(new Date());
-        long endDate = 0;
+        //aggDate is the time in millis when the aggregation should happen
+        long aggDate = 0;
         final int HOURLY_TIME = 60;
         final int DAILY_TIME = 60 * 24;
         if (_usageAggregationRange == DAILY_TIME) {
-            cal.roll(Calendar.DAY_OF_YEAR, false);
             cal.set(Calendar.HOUR_OF_DAY, 0);
             cal.set(Calendar.MINUTE, 0);
             cal.set(Calendar.SECOND, 0);
             cal.set(Calendar.MILLISECOND, 0);
             cal.roll(Calendar.DAY_OF_YEAR, true);
             cal.add(Calendar.MILLISECOND, -1);
-            endDate = cal.getTime().getTime();
+            aggDate = cal.getTime().getTime();
             _dailyOrHourly = true;
         } else if (_usageAggregationRange == HOURLY_TIME) {
-            cal.roll(Calendar.HOUR_OF_DAY, false);
             cal.set(Calendar.MINUTE, 0);
             cal.set(Calendar.SECOND, 0);
             cal.set(Calendar.MILLISECOND, 0);
             cal.roll(Calendar.HOUR_OF_DAY, true);
             cal.add(Calendar.MILLISECOND, -1);
-            endDate = cal.getTime().getTime();
+            aggDate = cal.getTime().getTime();
             _dailyOrHourly = true;
         } else {
-            endDate = cal.getTime().getTime();
+            aggDate = cal.getTime().getTime();
             _dailyOrHourly = false;
         }
 
@@ -814,7 +816,14 @@ VirtualMachineGuru, Listener, Configurable, StateListener<State, VirtualMachine.
             _usageAggregationRange = UsageUtils.USAGE_AGGREGATION_RANGE_MIN;
         }
 
-        _networkStatsUpdateExecutor.scheduleAtFixedRate(new NetworkStatsUpdateTask(), (endDate
- System.currentTimeMillis()), (_usageAggregationRange * 60 * 1000),
+        // We cannot schedule a job at specific time. Provide initial delay instead, from
current time, so that the job runs at desired time
+        long initialDelay = aggDate - System.currentTimeMillis();
+
+        if( initialDelay < 0){
+            s_logger.warn("Initial delay for network usage stats update task is incorrect.
Stats update task will run immediately");
+        }
+
+        _networkStatsUpdateExecutor.scheduleAtFixedRate(new NetworkStatsUpdateTask(), initialDelay,
(_usageAggregationRange * 60 * 1000),
                 TimeUnit.MILLISECONDS);
 
         if (_routerCheckInterval > 0) {


Mime
View raw message