Repository: ambari Updated Branches: refs/heads/branch-2.2 61fa49bbf -> 38ad05bda
AMBARI-15768. Ambari Widget should display metrics for available metrics even if some of the metrics it expects are not returned by API. (atkach via yusaku) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/38ad05bd Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/38ad05bd Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/38ad05bd Branch: refs/heads/branch-2.2 Commit: 38ad05bda646c636dd0fc841ee0044a2411431b9 Parents: 61fa49b Author: Yusaku Sako <[email protected]> Authored: Thu Apr 7 14:16:07 2016 -0700 Committer: Yusaku Sako <[email protected]> Committed: Thu Apr 7 14:16:07 2016 -0700 ---------------------------------------------------------------------- .../app/mixins/common/widgets/widget_mixin.js | 34 ++++++++++----- .../test/mixins/common/widget_mixin_test.js | 44 +++++++++++++++++++- 2 files changed, 67 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/38ad05bd/ambari-web/app/mixins/common/widgets/widget_mixin.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/widgets/widget_mixin.js b/ambari-web/app/mixins/common/widgets/widget_mixin.js index 3612ad6..09615ad 100644 --- a/ambari-web/app/mixins/common/widgets/widget_mixin.js +++ b/ambari-web/app/mixins/common/widgets/widget_mixin.js @@ -289,6 +289,8 @@ App.WidgetMixin = Ember.Mixin.create({ */ getMetricsSuccessCallback: function (data) { var metrics = []; + var atLeastOneMetricPresent = false; + if (this.get('content.metrics')) { this.get('content.metrics').forEach(function (_metric) { var metric_path = _metric.metric_path; @@ -312,20 +314,32 @@ App.WidgetMixin = Ember.Mixin.create({ }, this); } if (!Em.isNone(metric_data)) { + atLeastOneMetricPresent = true; _metric.data = metric_data; this.get('metrics').pushObject(_metric); - } else if (this.get('graphView')) { - var graph = this.get('childViews') && this.get('childViews').findProperty('_showMessage'); - if (graph) { - graph.set('hasData', false); - this.set('isExportButtonHidden', true); - graph._showMessage('info', this.t('graphs.noData.title'), this.t('graphs.noDataAtTime.message')); - this.set('metrics', this.get('metrics').reject(function (item) { - return this.get('content.metrics').someProperty('name', item.name); - }, this)); - } } }, this); + + if (!atLeastOneMetricPresent) { + this.disableGraph(); + } + } + }, + + /** + * if no metrics were received from server then disable graph + */ + disableGraph: function() { + if (this.get('graphView')) { + var graph = this.get('childViews') && this.get('childViews').findProperty('_showMessage'); + if (graph) { + graph.set('hasData', false); + this.set('isExportButtonHidden', true); + graph._showMessage('info', this.t('graphs.noData.title'), this.t('graphs.noDataAtTime.message')); + this.set('metrics', this.get('metrics').reject(function (item) { + return this.get('content.metrics').someProperty('name', item.name); + }, this)); + } } }, http://git-wip-us.apache.org/repos/asf/ambari/blob/38ad05bd/ambari-web/test/mixins/common/widget_mixin_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/mixins/common/widget_mixin_test.js b/ambari-web/test/mixins/common/widget_mixin_test.js index 57bd212..882f70b 100644 --- a/ambari-web/test/mixins/common/widget_mixin_test.js +++ b/ambari-web/test/mixins/common/widget_mixin_test.js @@ -209,7 +209,7 @@ describe('App.WidgetMixin', function () { describe("#getMetricsSuccessCallback()", function () { var mixinObject = mixinClass.create(); - it("", function () { + it("should push metrics", function () { var data = { metrics: { "hbase": { @@ -231,6 +231,48 @@ describe('App.WidgetMixin', function () { }); }); + describe("#disableGraph", function () { + var mixinObject, + graph = Em.Object.create({ + _showMessage: Em.K + }); + + beforeEach(function() { + mixinObject = mixinClass.create({ + childViews: [ + graph + ], + graphView: {}, + metrics: [{name: 'm1'}, {name: 'm2'}], + content: { + metrics: [{name: 'm2'}] + } + }); + sinon.stub(graph, '_showMessage'); + mixinObject.disableGraph(); + }); + + afterEach(function() { + graph._showMessage.restore(); + }); + + it("hasData should be false", function() { + expect(graph.get('hasData')).to.be.false; + }); + + it("isExportButtonHidden should be true", function() { + expect(mixinObject.get('isExportButtonHidden')).to.be.true; + }); + + it("_showMessage should be called", function() { + expect(graph._showMessage.calledWith('info', mixinObject.t('graphs.noData.title'), mixinObject.t('graphs.noDataAtTime.message'))).to.be.true; + }); + + it("metrics should be filtered", function() { + expect(mixinObject.get('metrics').mapProperty('name')).to.be.eql(['m1']); + }); + }); + describe("#getHostComponentMetrics()", function () { var mixinObject = mixinClass.create(); before(function () {
