You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2015/03/03 18:40:41 UTC

[2/2] ambari git commit: AMBARI-9898. Memory Usage widget shows wrong value (alexantonenko)

AMBARI-9898. Memory Usage widget shows wrong value (alexantonenko)


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

Branch: refs/heads/trunk
Commit: 52bcd9f06356febfe09a04df8a2717f3161a4026
Parents: 57251f4
Author: Alex Antonenko <hi...@gmail.com>
Authored: Tue Mar 3 19:41:24 2015 +0200
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Tue Mar 3 21:40:00 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |   1 +
 .../main/dashboard/cluster_metrics/memory.js    |  13 +-
 .../dashboard/cluster_metrics/memory_test.js    | 223 +++++++++++++++++++
 3 files changed, 236 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/52bcd9f0/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 ce137ea..78ea459 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -183,6 +183,7 @@ var files = ['test/init_model_test',
   'test/views/main/dashboard/config_history_view_test',
   'test/views/main/dashboard/widget_test',
   'test/views/main/dashboard/widgets_test',
+  'test/views/main/dashboard/cluster_metrics/memory_test',
   'test/views/main/dashboard/widgets/text_widget_test',
   'test/views/main/dashboard/widgets/uptime_text_widget_test',
   'test/views/main/dashboard/widgets/node_managers_live_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/52bcd9f0/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 fd96bc4..393f12f 100644
--- a/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js
+++ b/ambari-web/app/views/main/dashboard/cluster_metrics/memory.js
@@ -38,11 +38,22 @@ App.ChartClusterMetricsMemory = App.ChartLinearTimeView.extend({
   transformToSeries: function (jsonData) {
     var seriesArray = [];
     if (jsonData && jsonData.metrics && jsonData.metrics.memory) {
+      var isAmbariMetricsAvailable = App.StackService.find().someProperty('serviceName', 'AMBARI_METRICS');
+      var isAmbariMetricsInstalled = App.Service.find().someProperty('serviceName', 'AMBARI_METRICS');
+      var isGangliaInstalled = App.Service.find().someProperty('serviceName', 'GANGLIA');
+      var shouldConvertToBytes = isAmbariMetricsInstalled || isAmbariMetricsAvailable && !isGangliaInstalled;
+      var KB = Math.pow(2, 10);
       for ( var name in jsonData.metrics.memory) {
         var displayName = name;
         var seriesData = jsonData.metrics.memory[name];
         if (seriesData) {
-          seriesArray.push(this.transformData(seriesData, displayName));
+          var s = this.transformData(seriesData, displayName);
+          if (shouldConvertToBytes) {
+            for (var i = 0; i < s.data.length; i++) {
+              s.data[i].y *= KB;
+            }
+          }
+          seriesArray.push(s);
         }
       }
     }

http://git-wip-us.apache.org/repos/asf/ambari/blob/52bcd9f0/ambari-web/test/views/main/dashboard/cluster_metrics/memory_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/dashboard/cluster_metrics/memory_test.js b/ambari-web/test/views/main/dashboard/cluster_metrics/memory_test.js
new file mode 100644
index 0000000..2512166
--- /dev/null
+++ b/ambari-web/test/views/main/dashboard/cluster_metrics/memory_test.js
@@ -0,0 +1,223 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+require('views/main/dashboard/cluster_metrics/memory');
+
+describe('App.ChartClusterMetricsMemory', function () {
+
+  var view;
+
+  beforeEach(function () {
+    view = App.ChartClusterMetricsMemory.create();
+  });
+
+  describe('#transformToSeries', function () {
+
+    var cases = [
+        {
+          isAmbariMetricsInstalled: true,
+          seriesData: [
+            [
+              {
+                x: 1000000000,
+                y: 262144
+              },
+              {
+                x: 1000001000,
+                y: 524288
+              }
+            ],
+            [
+              {
+                x: 1100000000,
+                y: 1048576
+              },
+              {
+                x: 1100001000,
+                y: 2097152
+              }
+            ]
+          ],
+          title: 'Ambari Metrics is installed'
+        },
+        {
+          isAmbariMetricsInstalled: false,
+          isAmbariMetricsAvailable: true,
+          isGangliaInstalled: false,
+          seriesData: [
+            [
+              {
+                x: 1000000000,
+                y: 262144
+              },
+              {
+                x: 1000001000,
+                y: 524288
+              }
+            ],
+            [
+              {
+                x: 1100000000,
+                y: 1048576
+              },
+              {
+                x: 1100001000,
+                y: 2097152
+              }
+            ]
+          ],
+          title: 'Ganglia is not installed, Ambari Metrics is available'
+        },
+        {
+          isAmbariMetricsInstalled: false,
+          isAmbariMetricsAvailable: true,
+          isGangliaInstalled: true,
+          seriesData: [
+            [
+              {
+                x: 1000000000,
+                y: 256
+              },
+              {
+                x: 1000001000,
+                y: 512
+              }
+            ],
+            [
+              {
+                x: 1100000000,
+                y: 1024
+              },
+              {
+                x: 1100001000,
+                y: 2048
+              }
+            ]
+          ],
+          title: 'Ganglia is installed, Ambari Metrics is available'
+        },
+        {
+          isAmbariMetricsInstalled: false,
+          isAmbariMetricsAvailable: false,
+          isGangliaInstalled: true,
+          seriesData: [
+            [
+              {
+                x: 1000000000,
+                y: 256
+              },
+              {
+                x: 1000001000,
+                y: 512
+              }
+            ],
+            [
+              {
+                x: 1100000000,
+                y: 1024
+              },
+              {
+                x: 1100001000,
+                y: 2048
+              }
+            ]
+          ],
+          title: 'Ganglia is installed, Ambari Metrics is not available'
+        },
+        {
+          isAmbariMetricsInstalled: false,
+          isAmbariMetricsAvailable: false,
+          isGangliaInstalled: false,
+          seriesData: [
+            [
+              {
+                x: 1000000000,
+                y: 256
+              },
+              {
+                x: 1000001000,
+                y: 512
+              }
+            ],
+            [
+              {
+                x: 1100000000,
+                y: 1024
+              },
+              {
+                x: 1100001000,
+                y: 2048
+              }
+            ]
+          ],
+          title: 'Ganglia is not installed, Ambari Metrics is not available'
+        }
+      ],
+      jsonData = {
+        metrics: {
+          memory: {
+            Buffer: [
+              [256, 1000000000],
+              [512, 1000001000]
+            ],
+            Total: [
+              [1024, 1100000000],
+              [2048, 1100001000]
+            ]
+          }
+        }
+      },
+      names = ['Buffer', 'Total'];
+
+    afterEach(function () {
+      App.StackService.find.restore();
+      App.Service.find.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        var stackServices = [],
+          services = [];
+        if (item.isAmbariMetricsAvailable) {
+          stackServices.push({
+            serviceName: 'AMBARI_METRICS'
+          });
+        }
+        if (item.isAmbariMetricsInstalled) {
+          services.push({
+            serviceName: 'AMBARI_METRICS'
+          });
+        }
+        if (item.isGangliaInstalled) {
+          services.push({
+            serviceName: 'GANGLIA'
+          });
+        }
+        sinon.stub(App.StackService, 'find').returns(stackServices);
+        sinon.stub(App.Service, 'find').returns(services);
+        var series = view.transformToSeries(jsonData);
+        expect(series.mapProperty('name')).to.eql(names);
+        expect(series.mapProperty('data')).to.eql(item.seriesData);
+      });
+    });
+
+  });
+
+});