ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akovale...@apache.org
Subject ambari git commit: AMBARI-12481. ambari-web should stop polling when user is on any view page (akovalenko)
Date Wed, 22 Jul 2015 10:36:03 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 4b05497f8 -> 469ca00e4


AMBARI-12481. ambari-web should stop polling when user is on any view page (akovalenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/469ca00e
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/469ca00e
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/469ca00e

Branch: refs/heads/trunk
Commit: 469ca00e4958421a1f9a8201fee3e1588d92ae44
Parents: 4b05497
Author: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Authored: Wed Jul 22 13:27:53 2015 +0300
Committer: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Committed: Wed Jul 22 13:28:09 2015 +0300

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js | 27 +++----------
 ambari-web/app/utils/updater.js                 | 18 ++++++---
 .../global/update_controller_test.js            | 41 --------------------
 ambari-web/test/utils/updater_test.js           | 14 +++++++
 4 files changed, 32 insertions(+), 68 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/469ca00e/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index f5c45fe..cc635d9 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -30,9 +30,6 @@ App.UpdateController = Em.Controller.extend({
   clusterName: function () {
     return App.router.get('clusterController.clusterName');
   }.property('App.router.clusterController.clusterName'),
-  location: function () {
-    return App.router.get('location.lastSetURL');
-  }.property('App.router.location.lastSetURL'),
 
   /**
    * keys which should be preloaded in order to filter hosts by host-components
@@ -145,33 +142,19 @@ App.UpdateController = Em.Controller.extend({
     if (this.get('isWorking')) {
       App.updater.run(this, 'updateServices', 'isWorking');
       App.updater.run(this, 'updateHost', 'isWorking');
-      App.updater.run(this, 'updateServiceMetricConditionally', 'isWorking', App.componentsUpdateInterval);
-      App.updater.run(this, 'updateComponentsState', 'isWorking', App.componentsUpdateInterval);
+      App.updater.run(this, 'updateServiceMetric', 'isWorking', App.componentsUpdateInterval,
'\/main\/(dashboard|services).*');
+      App.updater.run(this, 'updateComponentsState', 'isWorking', App.componentsUpdateInterval,
'\/main\/(dashboard|services|hosts).*');
       App.updater.run(this, 'graphsUpdate', 'isWorking');
       App.updater.run(this, 'updateComponentConfig', 'isWorking');
 
-      App.updater.run(this, 'updateAlertGroups', 'isWorking', App.alertGroupsUpdateInterval);
-      App.updater.run(this, 'updateAlertDefinitions', 'isWorking', App.alertDefinitionsUpdateInterval);
+      App.updater.run(this, 'updateAlertGroups', 'isWorking', App.alertGroupsUpdateInterval,
'\/main\/alerts.*');
+      App.updater.run(this, 'updateAlertDefinitions', 'isWorking', App.alertDefinitionsUpdateInterval,
'\/main\/alerts.*');
       App.updater.run(this, 'updateAlertDefinitionSummary', 'isWorking', App.alertDefinitionsUpdateInterval);
       if (!App.get('router.mainAlertInstancesController.isUpdating')) {
-        App.updater.run(this, 'updateUnhealthyAlertInstances', 'updateAlertInstances', App.alertInstancesUpdateInterval);
+        App.updater.run(this, 'updateUnhealthyAlertInstances', 'updateAlertInstances', App.alertInstancesUpdateInterval,
'\/main\/alerts.*');
       }
     }
   }.observes('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
-  /**
-   * Update service metrics depending on which page is open
-   * Make a call only on follow pages:
-   * /main/dashboard
-   * /main/services/*
-   * @param callback
-   */
-  updateServiceMetricConditionally: function (callback) {
-    if (/\/main\/(dashboard|services).*/.test(this.get('location'))) {
-      this.updateServiceMetric(callback);
-    } else {
-      callback();
-    }
-  },
 
   /**
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/469ca00e/ambari-web/app/utils/updater.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/updater.js b/ambari-web/app/utils/updater.js
index dcff44e..894a4f1 100644
--- a/ambari-web/app/utils/updater.js
+++ b/ambari-web/app/utils/updater.js
@@ -19,7 +19,7 @@ var App = require('app');
 
 var states = {};
 
-function update(obj, name, isWorking, interval){
+function update(obj, name, isWorking, interval, urlPattern){
   if(typeof isWorking == 'string' && !obj.get(isWorking)){
     return false;
   }
@@ -28,15 +28,21 @@ function update(obj, name, isWorking, interval){
 
   if(!state){
     var callback = function(){
-      update(obj, name, isWorking, interval);
+      update(obj, name, isWorking, interval, urlPattern);
     };
     states[name] = state = {
       timeout: null,
       func: function(){
+        var urlRegExp = new RegExp(urlPattern);
         if(typeof isWorking == 'string' && !obj.get(isWorking)){
           return false;
         }
-        obj[name](callback);
+
+        if (urlRegExp.test(App.router.get('location.lastSetURL'))) {
+          obj[name](callback);
+        } else {
+          callback();
+        }
         return true;
       },
       interval: interval,
@@ -104,12 +110,14 @@ App.updater = {
    * @param obj Object
    * @param name Method name
    * @param isWorking Property, which will be checked as a rule for working
+   * @param interval Interval between calls
+   * @param urlPattern Pattern to match allowed urls
    * @param [interval] Interval between calls
    * @return {*}
    */
-  run: function(obj, name, isWorking, interval){
+  run: function(obj, name, isWorking, interval, urlPattern){
     interval = interval || App.contentUpdateInterval;
-    return update(obj, name, isWorking, interval);
+    return update(obj, name, isWorking, interval, urlPattern);
   },
 
   /**

http://git-wip-us.apache.org/repos/asf/ambari/blob/469ca00e/ambari-web/test/controllers/global/update_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/update_controller_test.js b/ambari-web/test/controllers/global/update_controller_test.js
index 40b5c19..7237bf6 100644
--- a/ambari-web/test/controllers/global/update_controller_test.js
+++ b/ambari-web/test/controllers/global/update_controller_test.js
@@ -66,47 +66,6 @@ describe('App.UpdateController', function () {
     });
   });
 
-  describe('#updateServiceMetricConditionally()', function () {
-    var context = {
-      callback: function(){}
-    };
-
-    beforeEach(function () {
-      sinon.spy(controller, 'updateServiceMetric');
-      sinon.spy(context, 'callback');
-    });
-    afterEach(function () {
-      controller.updateServiceMetric.restore();
-      context.callback.restore();
-    });
-
-    it('location is empty', function () {
-      controller.set('location', '');
-      controller.updateServiceMetricConditionally(context.callback);
-      expect(controller.updateServiceMetric.called).to.equal(false);
-      expect(context.callback.called).to.equal(true);
-    });
-    it('location is "/main/hosts"', function () {
-      controller.set('location', '/main/hosts');
-      controller.updateServiceMetricConditionally(context.callback);
-      expect(controller.updateServiceMetric.called).to.equal(false);
-      expect(context.callback.called).to.equal(true);
-    });
-    it('location is "/main/dashboard"', function () {
-      controller.set('location', '/main/dashboard');
-      controller.updateServiceMetricConditionally(context.callback);
-      expect(controller.updateServiceMetric.called).to.equal(true);
-      expect(context.callback.called).to.equal(false);
-    });
-    it('location is "/main/services/HDFS"', function () {
-      controller.set('location', '/main/services/HDFS');
-      controller.updateServiceMetricConditionally(context.callback);
-      expect(controller.updateServiceMetric.called).to.equal(true);
-      expect(context.callback.called).to.equal(false);
-    });
-  });
-
-
   describe('#getConditionalFields()', function () {
 
     var testCases = [

http://git-wip-us.apache.org/repos/asf/ambari/blob/469ca00e/ambari-web/test/utils/updater_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/updater_test.js b/ambari-web/test/utils/updater_test.js
index 5ec7d10..1f0c90f 100644
--- a/ambari-web/test/utils/updater_test.js
+++ b/ambari-web/test/utils/updater_test.js
@@ -22,6 +22,7 @@ describe('utils/updater', function() {
   describe('#App.updater', function() {
     beforeEach(function() {
       this.clock = sinon.useFakeTimers();
+      sinon.stub(App.router, "get").returns('test');
     });
 
     var tests = {
@@ -51,6 +52,13 @@ describe('utils/updater', function() {
           isWorking: true
         }),
         m: 'method call should be ignored if `isWorking` set to false'
+      },
+      t5: {
+        obj: Em.Object.create({
+          method4: sinon.spy(),
+          isWorking: true
+        }),
+        m: 'method call should be ignored if urlPattern is not matching router location'
       }
     };
 
@@ -79,9 +87,15 @@ describe('utils/updater', function() {
       expect(tests.t4.obj.method3.called).to.be.false;
     });
 
+    it(tests.t5.m, function () {
+      App.updater.run(tests.t5.obj, 'method4', 'isWorking', 15000, 'pattern');
+      this.clock.tick(15000);
+      expect(tests.t5.obj.method4.called).to.be.false;
+    });
 
     afterEach(function() {
       this.clock.restore();
+      App.router.get.restore();
     });
   });
 });


Mime
View raw message