You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2014/11/05 14:14:18 UTC

git commit: AMBARI-8155 Nagios showing hdfs config types. (atkach)

Repository: ambari
Updated Branches:
  refs/heads/branch-1.7.0 adabea0f1 -> ead69217f


AMBARI-8155 Nagios showing hdfs config types. (atkach)


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

Branch: refs/heads/branch-1.7.0
Commit: ead69217fa314af69a8349a8defc4bee14b0805e
Parents: adabea0
Author: Andrii Tkach <at...@hortonworks.com>
Authored: Wed Nov 5 15:13:58 2014 +0200
Committer: Andrii Tkach <at...@hortonworks.com>
Committed: Wed Nov 5 15:13:58 2014 +0200

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |  5 +-
 ambari-web/app/utils/lazy_loading.js            | 29 ++++--
 .../app/views/common/configs/services_config.js |  7 +-
 ambari-web/test/utils/lazy_loading_test.js      | 92 +++++++++++++++++++-
 .../widgets/uptime_text_widget_test.js          | 10 +--
 5 files changed, 124 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/ead69217/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index d811f60..7265466 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -127,7 +127,6 @@ var files = ['test/init_model_test',
   'test/utils/validator_test',
   'test/utils/config_test',
   'test/utils/string_utils_test',
-  'test/utils/lazy_loading_test',
   'test/utils/helper_test',
   'test/utils/object_utils_test',
   'test/utils/ui_effects_test',
@@ -205,7 +204,9 @@ var files = ['test/init_model_test',
   'test/models/stack_service_component_test',
   'test/models/service_test',
   'test/models/stack_service_test',
-  'test/models/user_test'
+  'test/models/user_test',
+  //contains test with fake timers that affect Date
+  'test/utils/lazy_loading_test'
 ];
 App.initialize();
 describe('Ambari Web Unit tests', function() {

http://git-wip-us.apache.org/repos/asf/ambari/blob/ead69217/ambari-web/app/utils/lazy_loading.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/lazy_loading.js b/ambari-web/app/utils/lazy_loading.js
index c0b8142..51e3aee 100644
--- a/ambari-web/app/utils/lazy_loading.js
+++ b/ambari-web/app/utils/lazy_loading.js
@@ -29,6 +29,7 @@ module.exports = {
    * options.source - source of items
    * options.context - the object that should know when data is completely loaded,
    * lazy loading will define "isLoaded" property for context object and update it
+   * @return {Object} - instance of lazy loading run
    */
   run: function (options) {
     var initSize = options.initSize || 25,
@@ -36,19 +37,24 @@ module.exports = {
       delay = options.delay || 300,
       destination = options.destination,
       source = options.source,
-      context = options.context,
+      self = this,
+      instance = {
+        context: options.context,
+        timeoutRef: null
+      },
       chunks;
     if (Array.isArray(destination) && Array.isArray(source)) {
       destination.pushObjects(source.slice(0, initSize));
       if(source.length > initSize) {
         chunks = this.divideIntoChunks(source.slice(initSize, source.length), chunkSize);
-        this.pushChunk(chunks, 0, delay, destination, context);
+        this.pushChunk(chunks, 0, delay, destination, instance);
       } else {
-        context.set('isLoaded', true);
+        instance.context.set('isLoaded', true);
       }
     } else {
       console.error('Lazy loading: source or destination has incorrect value');
     }
+    return instance;
   },
 
   /**
@@ -57,16 +63,16 @@ module.exports = {
    * @param index
    * @param delay
    * @param destination
-   * @param context
+   * @param instance
    */
-  pushChunk: function (chunks, index, delay, destination, context) {
+  pushChunk: function (chunks, index, delay, destination, instance) {
     var self = this;
-    setTimeout(function () {
+    instance.timeoutRef = setTimeout(function () {
       destination.pushObjects(chunks[index]);
       if (chunks.length === (++index)) {
-        context.set('isLoaded', true);
+        instance.context.set('isLoaded', true);
       } else {
-        self.pushChunk(chunks, index, delay, destination, context);
+        self.pushChunk(chunks, index, delay, destination, instance);
       }
     }, delay);
   },
@@ -94,5 +100,12 @@ module.exports = {
       chunks.push(chunk);
     }
     return chunks;
+  },
+  /**
+   * terminate lazy loading run
+   * @param instance - lazy loading instance
+   */
+  terminate: function (instance) {
+    clearTimeout(instance.timeoutRef);
   }
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/ead69217/ambari-web/app/views/common/configs/services_config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/configs/services_config.js b/ambari-web/app/views/common/configs/services_config.js
index 4b8d50d..5c5d733 100644
--- a/ambari-web/app/views/common/configs/services_config.js
+++ b/ambari-web/app/views/common/configs/services_config.js
@@ -775,6 +775,7 @@ App.ServiceConfigsByCategoryView = Ember.View.extend(App.UserPref, {
 
 App.ServiceConfigContainerView = Em.ContainerView.extend({
   view: null,
+  lazyLoading: null,
   pushView: function () {
     if (this.get('controller.selectedService')) {
       var self = this;
@@ -813,14 +814,14 @@ App.ServiceConfigContainerView = Em.ContainerView.extend({
           }));
         }
       });
-      lazyLoading.run({
+      this.set('lazyLoading', lazyLoading.run({
         destination: self.get('childViews.lastObject.serviceConfigsByCategoryView.childViews'),
         source: categoriesToPush,
         initSize: 3,
         chunkSize: 3,
         delay: 200,
         context: this
-      });
+      }));
     }
   },
   selectedServiceObserver: function () {
@@ -832,6 +833,8 @@ App.ServiceConfigContainerView = Em.ContainerView.extend({
       view.removeFromParent();
       this.set('view', view);
     }
+    //terminate lazy loading when switch service
+    if (this.get('lazyLoading')) lazyLoading.terminate(this.get('lazyLoading'));
     this.pushView();
   }.observes('controller.selectedService')
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/ead69217/ambari-web/test/utils/lazy_loading_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/lazy_loading_test.js b/ambari-web/test/utils/lazy_loading_test.js
index f5120ee..7d53d7b 100644
--- a/ambari-web/test/utils/lazy_loading_test.js
+++ b/ambari-web/test/utils/lazy_loading_test.js
@@ -20,7 +20,7 @@ var lazyLoading = require('utils/lazy_loading');
 
 describe('lazy_loading', function () {
 
-  describe('#run', function () {
+  describe('#run()', function () {
     var context = Em.Object.create({isLoaded: false});
     var options = {
       destination: [],
@@ -71,7 +71,7 @@ describe('lazy_loading', function () {
     });
   });
 
-  describe('#divideIntoChunks', function () {
+  describe('#divideIntoChunks()', function () {
     var testsInfo = [
       {
         title: 'load 11 item with chunkSize - 3',
@@ -106,5 +106,93 @@ describe('lazy_loading', function () {
     });
   });
 
+  describe("#pushChunk()", function() {
+    beforeEach(function () {
+      this.clock = sinon.useFakeTimers();
+      sinon.spy(lazyLoading, 'pushChunk');
+    });
+    afterEach(function () {
+      this.clock.restore();
+      lazyLoading.pushChunk.restore();
+    });
+    it("last chunk", function() {
+      this.clock = sinon.useFakeTimers();
+
+      var destination = [],
+          chunks = [[1]],
+          context = Em.Object.create(),
+          instance = {
+            context: context,
+            timeoutRef: null,
+            terminate: Em.K
+          };
+      lazyLoading.pushChunk(chunks, 0, 10, destination, instance);
+      this.clock.tick(10);
+      expect(destination[0]).to.equal(1);
+      expect(context.get('isLoaded')).to.be.true;
+      expect(lazyLoading.pushChunk.calledTwice).to.be.false;
+    });
+    it("two chunks", function() {
+      this.clock = sinon.useFakeTimers();
+      var destination = [],
+        chunks = [[1], [2]],
+        context = Em.Object.create(),
+        instance = {
+          context: context,
+          timeoutRef: null,
+          terminate: Em.K
+        };
+      lazyLoading.pushChunk(chunks, 0, 10, destination, instance);
+      this.clock.tick(20);
+      expect(destination.length).to.equal(2);
+      expect(context.get('isLoaded')).to.be.true;
+      expect(lazyLoading.pushChunk.calledTwice).to.be.true;
+    });
+    it("terminated chunks", function() {
+      this.clock = sinon.useFakeTimers();
+      var destination = [],
+        chunks = [[1]],
+        context = Em.Object.create({isLoaded: false}),
+        instance = {
+          context: context,
+          timeoutRef: null,
+          terminate: Em.K
+        };
+      lazyLoading.pushChunk(chunks, 0, 10, destination, instance);
+      clearTimeout(instance.timeoutRef);
+      this.clock.tick(10);
+      expect(destination.length).to.empty;
+      expect(context.get('isLoaded')).to.be.false;
+      expect(lazyLoading.pushChunk.calledTwice).to.be.false;
+    });
+  });
 
+  describe("#terminate()", function() {
+    before(function () {
+      sinon.spy(lazyLoading, 'pushChunk');
+      this.clock = sinon.useFakeTimers();
+    });
+    after(function () {
+      lazyLoading.pushChunk.restore();
+      this.clock.restore();
+    });
+    it("loading terminated", function() {
+      var context = Em.Object.create({isLoaded: false});
+      var options = {
+        destination: [],
+        source: [1, 2],
+        delay: 10,
+        chunkSize: 1,
+        initSize: 1,
+        context: context
+      };
+
+      var ll = lazyLoading.run(options);
+      lazyLoading.terminate(ll);
+      this.clock.tick(10);
+      expect(options.destination.length).to.equal(1);
+      expect(context.get('isLoaded')).to.be.false;
+      expect(lazyLoading.pushChunk.calledTwice).to.be.false;
+    });
+  });
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/ead69217/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js b/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
index d11c791..5179353 100644
--- a/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
+++ b/ambari-web/test/views/main/dashboard/widgets/uptime_text_widget_test.js
@@ -54,25 +54,25 @@ describe('App.UptimeTextDashboardWidgetView', function() {
   describe('#uptimeProcessing', function() {
     var timestamps = [
       {
-        t: (new Date()).getTime() - 10*1000,
+        diff: 10*1000,
         e: {
           timeUnit: 's'
         }
       },
       {
-        t: (new Date()).getTime() - 3600*1000,
+        diff: 3600*1000,
         e: {
           timeUnit: 'hr'
         }
       },
       {
-        t: (new Date()).getTime() - 24*3600*1000,
+        diff: 24*3600*1000,
         e: {
           timeUnit: 'd'
         }
       },
       {
-        t: (new Date()).getTime() - 1800*1000,
+        diff: 1800*1000,
         e: {
           timeUnit: 'min'
         }
@@ -81,7 +81,7 @@ describe('App.UptimeTextDashboardWidgetView', function() {
     timestamps.forEach(function(timestamp) {
       var uptimeTextDashboardWidgetView = App.UptimeTextDashboardWidgetView.create({thresh1:40, thresh2:70});
       it('timestamp ' + timestamp.t + '. timeUnit should be ' + '"' + timestamp.e.timeUnit + '"', function() {
-        var result = uptimeTextDashboardWidgetView.uptimeProcessing(timestamp.t);
+        var result = uptimeTextDashboardWidgetView.uptimeProcessing(((new Date()).getTime() - timestamp.diff));
         expect(uptimeTextDashboardWidgetView.get('timeUnit')).to.equal(timestamp.e.timeUnit);
       });
     });