Repository: ambari Updated Branches: refs/heads/trunk 71a1f7e0e -> e3edcf574
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/e3edcf57 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e3edcf57 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e3edcf57 Branch: refs/heads/trunk Commit: e3edcf574c387aa8d4f16a07ae97d268a105247e Parents: 71a1f7e Author: Yusaku Sako <[email protected]> Authored: Thu Apr 7 14:15:19 2016 -0700 Committer: Yusaku Sako <[email protected]> Committed: Thu Apr 7 14:15:19 2016 -0700 ---------------------------------------------------------------------- .../app/mixins/common/widgets/widget_mixin.js | 34 +++++++++++----- .../test/mixins/common/widget_mixin_test.js | 41 ++++++++++++++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/e3edcf57/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 4d777e4..3de4cfb 100644 --- a/ambari-web/app/mixins/common/widgets/widget_mixin.js +++ b/ambari-web/app/mixins/common/widgets/widget_mixin.js @@ -287,6 +287,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; @@ -310,20 +312,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/e3edcf57/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 662f8b8..9612d7f 100644 --- a/ambari-web/test/mixins/common/widget_mixin_test.js +++ b/ambari-web/test/mixins/common/widget_mixin_test.js @@ -243,6 +243,47 @@ describe('App.WidgetMixin', function () { }); }); + describe("#disableGraph", function () { + var graph = Em.Object.create({ + _showMessage: Em.K + }); + + beforeEach(function() { + mixinObject.setProperties({ + 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 () { beforeEach(function () { sinon.stub(mixinObject, 'computeHostComponentCriteria').returns('criteria')
