ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nc...@apache.org
Subject [40/50] [abbrv] ambari git commit: AMBARI-13699. Exported metrics have values in different units than widgets
Date Wed, 04 Nov 2015 13:37:07 GMT
AMBARI-13699. Exported metrics have values in different units than widgets


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

Branch: refs/heads/branch-dev-patch-upgrade
Commit: 3cb80cfc16365861596e3fd3b9a94d6774db9f50
Parents: 8aba9a4
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Tue Nov 3 17:43:36 2015 +0200
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Tue Nov 3 19:19:41 2015 +0200

----------------------------------------------------------------------
 .../common/widgets/export_metrics_mixin.js      | 26 +++++--
 .../app/views/common/chart/linear_time.js       | 25 +++++-
 .../views/common/widget/graph_widget_view.js    | 14 ++--
 .../views/main/dashboard/cluster_metrics/cpu.js |  2 +-
 .../main/dashboard/cluster_metrics/memory.js    |  2 +-
 .../main/dashboard/cluster_metrics/network.js   |  2 +-
 ambari-web/app/views/main/host/metrics/cpu.js   |  2 +-
 ambari-web/app/views/main/host/metrics/disk.js  |  2 +-
 .../app/views/main/host/metrics/memory.js       |  2 +-
 .../app/views/main/host/metrics/network.js      |  2 +-
 .../regionserver_block_cache_hit_percent.js     |  2 +-
 .../info/metrics/flume/channel_fill_pct.js      |  2 +-
 .../info/metrics/flume/channel_size_mma.js      |  3 +-
 .../service/info/metrics/flume/channel_sum.js   |  2 +-
 .../main/service/info/metrics/flume/cpu_user.js |  2 +-
 .../info/metrics/flume/flume_incoming_mma.js    |  3 +-
 .../info/metrics/flume/flume_outgoing_mma.js    |  3 +-
 .../views/main/service/info/metrics/flume/gc.js |  2 +-
 .../main/service/info/metrics/flume/jvm_heap.js |  2 +-
 .../common/widgets/export_metrics_mixin_test.js | 80 ++++++++++++++++++--
 .../test/views/common/chart/linear_time_test.js | 54 +++++++++++++
 .../common/widget/graph_widget_view_test.js     | 22 ++++++
 22 files changed, 217 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js b/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
index 84a2194..2ecb045 100644
--- a/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
+++ b/ambari-web/app/mixins/common/widgets/export_metrics_mixin.js
@@ -70,7 +70,7 @@ App.ExportMetricsMixin = Em.Mixin.create({
     } else {
       var fileType = params.isCSV ? 'csv' : 'json',
         fileName = 'data.' + fileType,
-        data = params.isCSV ? this.prepareCSV(seriesData) : JSON.stringify(seriesData, null,
4);
+        data = params.isCSV ? this.prepareCSV(seriesData) : JSON.stringify(seriesData, this.jsonReplacer(),
4);
       fileUtils.downloadTextFile(data, fileType, fileName);
     }
   },
@@ -80,16 +80,17 @@ App.ExportMetricsMixin = Em.Mixin.create({
   },
 
   prepareCSV: function (data) {
-    var titles,
+    var displayUnit = this.get('targetView.displayUnit'),
+      titles,
       ticksNumber,
       metricsNumber,
       metricsArray;
-    if (Em.isArray(data)) {
-      titles = data.mapProperty('name');
-      titles.unshift(Em.I18n.t('common.timestamp'));
-      ticksNumber = data[0].data.length;
-      metricsNumber = data.length;
-    }
+    titles = data.map(function (item) {
+      return displayUnit ? item.name + ' (' + displayUnit + ')' : item.name;
+    }, this);
+    titles.unshift(Em.I18n.t('common.timestamp'));
+    ticksNumber = data[0].data.length;
+    metricsNumber = data.length;
     metricsArray = [titles];
     for (var i = 0; i < ticksNumber; i++) {
       metricsArray.push([data[0].data[i][1]]);
@@ -98,6 +99,15 @@ App.ExportMetricsMixin = Em.Mixin.create({
       };
     }
     return stringUtils.arrayToCSV(metricsArray);
+  },
+
+  jsonReplacer: function () {
+    var displayUnit = this.get('targetView.displayUnit');
+    return function (key, value) {
+      if (['name', 'data'].contains(key) || (!isNaN(key))) {
+        return key == 'name' && displayUnit ? value + ' (' + displayUnit + ')' :
value;
+      }
+    }
   }
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/common/chart/linear_time.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/chart/linear_time.js b/ambari-web/app/views/common/chart/linear_time.js
index 24ca450..a6bd9a4 100644
--- a/ambari-web/app/views/common/chart/linear_time.js
+++ b/ambari-web/app/views/common/chart/linear_time.js
@@ -177,6 +177,7 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
 
   didInsertElement: function () {
     var self = this;
+    this.setYAxisFormatter();
     this.loadData();
     this.registerGraph();
     this.$().parent().on('mouseleave', function () {
@@ -469,7 +470,7 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
   /**
    * Provides the formatter to use in displaying Y axis.
    *
-   * Uses the App.ChartLinearTimeView.DefaultFormatter which shows 10K,
+   * By default, uses the App.ChartLinearTimeView.DefaultFormatter which shows 10K,
    * 300M etc.
    *
    * @type Function
@@ -479,6 +480,28 @@ App.ChartLinearTimeView = Ember.View.extend(App.ExportMetricsMixin, {
   },
 
   /**
+   * Sets the formatter to use in displaying Y axis depending on graph unit.
+   *
+   * @type Function
+   */
+  setYAxisFormatter: function () {
+    var method,
+      formatterMap = {
+        '%': 'PercentageFormatter',
+        '/s': 'CreateRateFormatter',
+        'B': 'BytesFormatter',
+        'ms': 'TimeElapsedFormatter'
+      },
+      methodName = formatterMap[this.get('displayUnit')];
+    if (methodName) {
+      method = (methodName == 'CreateRateFormatter') ?
+        App.ChartLinearTimeView.CreateRateFormatter('', App.ChartLinearTimeView.DefaultFormatter)
:
+        App.ChartLinearTimeView[methodName];
+      this.set('yAxisFormatter', method);
+    }
+  },
+
+  /**
    * Provides the color (in any HTML color format) to use for a particular
    * series.
    * May be redefined in child views

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/common/widget/graph_widget_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/widget/graph_widget_view.js b/ambari-web/app/views/common/widget/graph_widget_view.js
index 62bf4d5..7fc4e76 100644
--- a/ambari-web/app/views/common/widget/graph_widget_view.js
+++ b/ambari-web/app/views/common/widget/graph_widget_view.js
@@ -71,6 +71,10 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin,
{
    */
   data: [],
 
+  exportTargetView: function () {
+    return this.get('childViews.lastObject');
+  }.property(),
+
   drawWidget: function () {
     if (this.get('isLoaded')) {
       this.set('data', this.calculateValues());
@@ -228,10 +232,10 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin,
{
       return this.get('parentView.content.properties.display_unit');
     }.property('parentView.content.properties.display_unit'),
     setYAxisFormatter: function () {
-      var self = this;
-      if (this.get('displayUnit')) {
-        this.set('yAxisFormatter',  function (value) {
-          return App.ChartLinearTimeView.DisplayUnitFormatter(value, self.get('displayUnit'));
+      var displayUnit = this.get('displayUnit');
+      if (displayUnit) {
+        this.set('yAxisFormatter', function (value) {
+          return App.ChartLinearTimeView.DisplayUnitFormatter(value, displayUnit);
         });
       }
     }.observes('displayUnit'),
@@ -318,7 +322,7 @@ App.GraphWidgetView = Em.View.extend(App.WidgetMixin, App.ExportMetricsMixin,
{
         return Em.isArray(item.data);
       });
     if (hasData) {
-      data = isCSV ? this.prepareCSV(metrics) : JSON.stringify(metrics, ['name', 'data'],
4);
+      data = isCSV ? this.prepareCSV(metrics) : JSON.stringify(metrics, this.jsonReplacer(),
4);
       fileUtils.downloadTextFile(data, fileType, fileName);
     } else {
       App.showAlertPopup(Em.I18n.t('graphs.noData.title'), Em.I18n.t('graphs.noData.tooltip.title'));

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/dashboard/cluster_metrics/cpu.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/dashboard/cluster_metrics/cpu.js b/ambari-web/app/views/main/dashboard/cluster_metrics/cpu.js
index e959ca7..407487d 100644
--- a/ambari-web/app/views/main/dashboard/cluster_metrics/cpu.js
+++ b/ambari-web/app/views/main/dashboard/cluster_metrics/cpu.js
@@ -32,7 +32,7 @@ App.ChartClusterMetricsCPU = App.ChartLinearTimeView.extend({
   ajaxIndex: 'dashboard.cluster_metrics.cpu',
 
   title: Em.I18n.t('dashboard.clusterMetrics.cpu'),
-  yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
+  displayUnit: '%',
   isTimePagingDisable: false,
   seriesTemplate: {
     path: 'metrics.cpu'

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js b/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js
index 3bcdfb3..844f238 100644
--- a/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js
+++ b/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js
@@ -33,7 +33,7 @@ App.ChartClusterMetricsMemory = App.ChartLinearTimeView.extend({
 
   isTimePagingDisable: false,
   title: Em.I18n.t('dashboard.clusterMetrics.memory'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
   renderer: 'line',
   seriesTemplate: {
     path: 'metrics.memory',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/dashboard/cluster_metrics/network.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/dashboard/cluster_metrics/network.js b/ambari-web/app/views/main/dashboard/cluster_metrics/network.js
index 3323bf1..c844480 100644
--- a/ambari-web/app/views/main/dashboard/cluster_metrics/network.js
+++ b/ambari-web/app/views/main/dashboard/cluster_metrics/network.js
@@ -34,7 +34,7 @@ App.ChartClusterMetricsNetwork = App.ChartLinearTimeView.extend({
 
   isTimePagingDisable: false,
   title: Em.I18n.t('dashboard.clusterMetrics.network'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
   renderer: 'line',
   seriesTemplate: {
     path: 'metrics.network'

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/host/metrics/cpu.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/metrics/cpu.js b/ambari-web/app/views/main/host/metrics/cpu.js
index 8cbdb15..ba77b96 100644
--- a/ambari-web/app/views/main/host/metrics/cpu.js
+++ b/ambari-web/app/views/main/host/metrics/cpu.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartHostMetricsCPU = App.ChartLinearTimeView.extend({
   id: "host-metrics-cpu",
   title: Em.I18n.t('hosts.host.metrics.cpu'),
-  yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
+  displayUnit: '%',
 
   ajaxIndex: 'host.metrics.cpu',
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/host/metrics/disk.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/metrics/disk.js b/ambari-web/app/views/main/host/metrics/disk.js
index d05b65f..fce239d 100644
--- a/ambari-web/app/views/main/host/metrics/disk.js
+++ b/ambari-web/app/views/main/host/metrics/disk.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartHostMetricsDisk = App.ChartLinearTimeView.extend({
   id: "host-metrics-disk",
   title: Em.I18n.t('hosts.host.metrics.disk'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
   renderer: 'line',
 
   ajaxIndex: 'host.metrics.disk',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/host/metrics/memory.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/metrics/memory.js b/ambari-web/app/views/main/host/metrics/memory.js
index 93e6be9..36e51fb 100644
--- a/ambari-web/app/views/main/host/metrics/memory.js
+++ b/ambari-web/app/views/main/host/metrics/memory.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartHostMetricsMemory = App.ChartLinearTimeView.extend({
   id: "host-metrics-memory",
   title: Em.I18n.t('hosts.host.metrics.memory'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
   renderer: 'line',
 
   ajaxIndex: 'host.metrics.memory',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/host/metrics/network.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/metrics/network.js b/ambari-web/app/views/main/host/metrics/network.js
index 7b22481..50f04d8 100644
--- a/ambari-web/app/views/main/host/metrics/network.js
+++ b/ambari-web/app/views/main/host/metrics/network.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartHostMetricsNetwork = App.ChartLinearTimeView.extend({
   id: "host-metrics-network",
   title: Em.I18n.t('hosts.host.metrics.network'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
   renderer: 'line',
 
   ajaxIndex: 'host.metrics.network',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/ambari_metrics/regionserver_block_cache_hit_percent.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/ambari_metrics/regionserver_block_cache_hit_percent.js
b/ambari-web/app/views/main/service/info/metrics/ambari_metrics/regionserver_block_cache_hit_percent.js
index c9d42c1..16a8d70 100644
--- a/ambari-web/app/views/main/service/info/metrics/ambari_metrics/regionserver_block_cache_hit_percent.js
+++ b/ambari-web/app/views/main/service/info/metrics/ambari_metrics/regionserver_block_cache_hit_percent.js
@@ -30,7 +30,7 @@ App.ChartServiceMetricsAMS_RegionServerBlockCacheHitPercent = App.ChartServiceMe
   id: "service-metrics-ambari-metrics-region-server-block-cache-hit-percent",
   title: Em.I18n.t('services.service.info.metrics.ambariMetrics.regionServer.blockCacheHitPercent'),
   renderer: 'line',
-  yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
+  displayUnit: '%',
   ajaxIndex: 'service.metrics.ambari_metrics.region_server.block_cache_hit_percent',
 
   loadGroup: {

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/channel_fill_pct.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/channel_fill_pct.js b/ambari-web/app/views/main/service/info/metrics/flume/channel_fill_pct.js
index 524ec93..f646ddd 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/channel_fill_pct.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/channel_fill_pct.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartServiceMetricsFlume_ChannelFillPercent = App.ChartLinearTimeView.extend({
   id: "service-metrics-flume-channel-fill-percent",
   title: Em.I18n.t('services.service.info.metrics.flume.channelFillPercent'),
-  yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
+  displayUnit: '%',
 
   ajaxIndex: 'service.metrics.flume.channel_fill_percent',
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/channel_size_mma.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/channel_size_mma.js b/ambari-web/app/views/main/service/info/metrics/flume/channel_size_mma.js
index a5041bb..902d2f1 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/channel_size_mma.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/channel_size_mma.js
@@ -31,8 +31,7 @@ App.ChartServiceMetricsFlume_ChannelSizeMMA = App.ChartLinearTimeView.extend({
   title: Em.I18n.t('services.service.info.metrics.flume.channelSizeMMA'),
   renderer: 'line',
   ajaxIndex: 'service.metrics.flume.channel_size_for_all.mma',
-  yAxisFormatter: App.ChartLinearTimeView.CreateRateFormatter('',
-    App.ChartLinearTimeView.DefaultFormatter),
+  displayUnit: '/s',
 
   seriesTemplate: {
     path: 'metrics.flume.flume.CHANNEL.ChannelSize.rate',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/channel_sum.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/channel_sum.js b/ambari-web/app/views/main/service/info/metrics/flume/channel_sum.js
index c978132..89ff885 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/channel_sum.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/channel_sum.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartServiceMetricsFlume_ChannelSizeSum = App.ChartLinearTimeView.extend({
   id: "service-metrics-flume-channel-size-sum",
   title: Em.I18n.t('services.service.info.metrics.flume.channelSizeSum'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
 
   ajaxIndex: 'service.metrics.flume.channel_size_for_all.sum',
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/cpu_user.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/cpu_user.js b/ambari-web/app/views/main/service/info/metrics/flume/cpu_user.js
index c5c08d9..b5a86d7 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/cpu_user.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/cpu_user.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartServiceMetricsFlume_CPUUser = App.ChartLinearTimeView.extend({
   id: "service-metrics-flume-cpu-user",
   title: Em.I18n.t('services.service.info.metrics.flume.cpu.user'),
-  yAxisFormatter: App.ChartLinearTimeView.PercentageFormatter,
+  displayUnit: '%',
   renderer: 'line',
   
   ajaxIndex: 'service.metrics.flume.cpu_user',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/flume_incoming_mma.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/flume_incoming_mma.js b/ambari-web/app/views/main/service/info/metrics/flume/flume_incoming_mma.js
index 9d47a81..458dc46 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/flume_incoming_mma.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/flume_incoming_mma.js
@@ -31,8 +31,7 @@ App.ChartServiceMetricsFlume_IncommingMMA = App.ChartLinearTimeView.extend({
   title: Em.I18n.t('services.service.info.metrics.flume.incoming.mma'),
 
   ajaxIndex: 'service.metrics.flume.incoming_event_put_successCount.mma',
-  yAxisFormatter: App.ChartLinearTimeView.CreateRateFormatter('',
-      App.ChartLinearTimeView.DefaultFormatter),
+  displayUnit: '/s',
 
   seriesTemplate: {
     path: 'metrics.flume.flume.CHANNEL.EventPutSuccessCount.rate',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/flume_outgoing_mma.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/flume_outgoing_mma.js b/ambari-web/app/views/main/service/info/metrics/flume/flume_outgoing_mma.js
index 1b07536..b0b12be 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/flume_outgoing_mma.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/flume_outgoing_mma.js
@@ -31,8 +31,7 @@ App.ChartServiceMetricsFlume_OutgoingMMA = App.ChartLinearTimeView.extend({
   title: Em.I18n.t('services.service.info.metrics.flume.outgoing.mma'),
 
   ajaxIndex: 'service.metrics.flume.outgoing_event_take_success_count.mma',
-  yAxisFormatter: App.ChartLinearTimeView.CreateRateFormatter('',
-      App.ChartLinearTimeView.DefaultFormatter),
+  displayUnit: '/s',
 
   seriesTemplate: {
     path: 'metrics.flume.flume.CHANNEL.EventTakeSuccessCount.rate',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/gc.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/gc.js b/ambari-web/app/views/main/service/info/metrics/flume/gc.js
index ce2f035..5dae52f 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/gc.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/gc.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartServiceMetricsFlume_GarbageCollection = App.ChartLinearTimeView.extend({
   id: "service-metrics-flume-jvm-gc",
   title: Em.I18n.t('services.service.info.metrics.flume.gc'),
-  yAxisFormatter: App.ChartLinearTimeView.TimeElapsedFormatter,
+  displayUnit: 'ms',
 
   ajaxIndex: 'service.metrics.flume.gc',
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/app/views/main/service/info/metrics/flume/jvm_heap.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/metrics/flume/jvm_heap.js b/ambari-web/app/views/main/service/info/metrics/flume/jvm_heap.js
index 10acf19..12c2247 100644
--- a/ambari-web/app/views/main/service/info/metrics/flume/jvm_heap.js
+++ b/ambari-web/app/views/main/service/info/metrics/flume/jvm_heap.js
@@ -29,7 +29,7 @@ var App = require('app');
 App.ChartServiceMetricsFlume_JVMHeapUsed = App.ChartLinearTimeView.extend({
   id: "service-metrics-flume-jvm-heap-used",
   title: Em.I18n.t('services.service.info.metrics.flume.jvmHeapUsed'),
-  yAxisFormatter: App.ChartLinearTimeView.BytesFormatter,
+  displayUnit: 'B',
   renderer: 'line',
 
   ajaxIndex: 'service.metrics.flume.jvm_heap_used',

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js b/ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js
index ae27912..c08020c 100644
--- a/ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js
+++ b/ambari-web/test/mixins/common/widgets/export_metrics_mixin_test.js
@@ -237,7 +237,18 @@ describe('App.ExportMetricsMixin', function () {
 
   describe('#prepareCSV', function () {
 
-    var data = [
+    var cases = [
+        {
+          displayUnit: 'B',
+          result: 'Timestamp,n0 (B),n1 (B)\n1,0,4\n3,2,5\n',
+          title: 'display unit set'
+        },
+        {
+          result: 'Timestamp,n0,n1\n1,0,4\n3,2,5\n',
+          title: 'display unit not set'
+        }
+      ],
+      data = [
         {
           name: 'n0',
           data: [[0, 1], [2, 3]]
@@ -246,12 +257,17 @@ describe('App.ExportMetricsMixin', function () {
           name: 'n1',
           data: [[4, 1], [5, 3]]
         }
-      ],
-      result = 'Timestamp,n0,n1\n1,0,4\n3,2,5\n',
-      title = 'should do CSV export with formatting data as table';
+      ];
 
-    it(title, function () {
-      expect(obj.prepareCSV(data)).to.equal(result);
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        obj.reopen({
+          targetView: {
+            displayUnit: item.displayUnit
+          }
+        });
+        expect(obj.prepareCSV(data)).to.equal(item.result);
+      });
     });
 
   });
@@ -283,4 +299,56 @@ describe('App.ExportMetricsMixin', function () {
 
   });
 
+  describe('#jsonReplacer', function () {
+
+    var cases = [
+      {
+        json: [
+          {
+            name: 'n0',
+            data: [
+              [0, 1],
+              [1, 2]
+            ]
+          }
+        ],
+        result: '[{"name":"n0","data":[[0,1],[1,2]]}]',
+        title: 'valid object'
+      },
+      {
+        json: [
+          {
+            name: 'n1',
+            data: [
+              [0, 1],
+              [1, 2]
+            ],
+            p1: 'v1'
+          }
+        ],
+        result: '[{"name":"n1","data":[[0,1],[1,2]]}]',
+        title: 'object with redundant property'
+      },
+      {
+        json: [
+          {
+            name: 'n1',
+            data: {
+              p2: 'v2'
+            }
+          }
+        ],
+        result: '[{"name":"n1","data":{}}]',
+        title: 'object with malformed data'
+      }
+    ];
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        expect(JSON.stringify(item.json, obj.jsonReplacer())).to.equal(item.result);
+      });
+    });
+
+  });
+
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/test/views/common/chart/linear_time_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/chart/linear_time_test.js b/ambari-web/test/views/common/chart/linear_time_test.js
index b8475e8..60d02ee 100644
--- a/ambari-web/test/views/common/chart/linear_time_test.js
+++ b/ambari-web/test/views/common/chart/linear_time_test.js
@@ -291,6 +291,60 @@ describe('App.ChartLinearTimeView', function () {
     });
   });
 
+  describe('#setYAxisFormatter', function () {
+
+    var view,
+      cases = [
+        {
+          displayUnit: '%',
+          formatter: 'PercentageFormatter'
+        },
+        {
+          displayUnit: 'B',
+          formatter: 'BytesFormatter'
+        },
+        {
+          displayUnit: 'ms',
+          formatter: 'TimeElapsedFormatter'
+        },
+        {
+          displayUnit: 'kg',
+          formatter: 'DefaultFormatter',
+          title: 'other display unit'
+        },
+        {
+          formatter: 'DefaultFormatter',
+          title: 'no display unit'
+        }
+      ],
+      methodNames = ['PercentageFormatter', 'CreateRateFormatter', 'BytesFormatter', 'TimeElapsedFormatter',
'DefaultFormatter'];
+
+    beforeEach(function () {
+      view = App.ChartLinearTimeView.create();
+      methodNames.forEach(function (name) {
+        sinon.stub(App.ChartLinearTimeView, name, Em.K);
+      });
+    });
+
+    afterEach(function () {
+      methodNames.forEach(function (name) {
+        App.ChartLinearTimeView[name].restore();
+      });
+    });
+
+    cases.forEach(function (item) {
+      it(item.title || item.displayUnit, function () {
+        view.set('displayUnit', item.displayUnit);
+        view.setYAxisFormatter();
+        view.yAxisFormatter();
+        methodNames.forEach(function (name) {
+          expect(App.ChartLinearTimeView[name].callCount).to.equal(Number(name == item.formatter));
+        });
+      });
+    });
+
+  });
+
 });
 
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/3cb80cfc/ambari-web/test/views/common/widget/graph_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/widget/graph_widget_view_test.js b/ambari-web/test/views/common/widget/graph_widget_view_test.js
index 31cf5f0..3bb5028 100644
--- a/ambari-web/test/views/common/widget/graph_widget_view_test.js
+++ b/ambari-web/test/views/common/widget/graph_widget_view_test.js
@@ -225,4 +225,26 @@ describe('App.GraphWidgetView', function () {
 
   });
 
+  describe('#exportTargetView', function () {
+
+    var childViews = [
+        {
+          p0: 'v0'
+        },
+        {
+          p1: 'v1'
+        }
+      ],
+      title = 'should take last child view';
+
+    beforeEach(function () {
+      view.get('childViews').pushObjects(childViews);
+      view.propertyDidChange('exportTargetView');
+    });
+
+    it(title, function () {
+      expect(view.get('exportTargetView')).to.eql(childViews[1]);
+    });
+  });
+
 });
\ No newline at end of file


Mime
View raw message