Return-Path: X-Original-To: apmail-ambari-commits-archive@www.apache.org Delivered-To: apmail-ambari-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4AEB310040 for ; Tue, 3 Mar 2015 17:41:43 +0000 (UTC) Received: (qmail 45674 invoked by uid 500); 3 Mar 2015 17:41:37 -0000 Delivered-To: apmail-ambari-commits-archive@ambari.apache.org Received: (qmail 45645 invoked by uid 500); 3 Mar 2015 17:41:36 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 45636 invoked by uid 99); 3 Mar 2015 17:41:36 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Mar 2015 17:41:36 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D0087E07F3; Tue, 3 Mar 2015 17:41:36 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: alexantonenko@apache.org To: commits@ambari.apache.org Message-Id: <4e7cdf561fec44f7b03d01c0bc0f303c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ambari git commit: AMBARI-9898. Memory Usage widget shows wrong value (alexantonenko) Date: Tue, 3 Mar 2015 17:41:36 +0000 (UTC) Repository: ambari Updated Branches: refs/heads/branch-2.0.0 0191f6c58 -> cb8672ef9 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/cb8672ef Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/cb8672ef Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/cb8672ef Branch: refs/heads/branch-2.0.0 Commit: cb8672ef99955461d90292c93ca02750e780127d Parents: 0191f6c Author: Alex Antonenko Authored: Tue Mar 3 19:41:24 2015 +0200 Committer: Alex Antonenko Committed: Tue Mar 3 21:41:32 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/cb8672ef/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 f0cbfb5..2ab9432 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/cb8672ef/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/cb8672ef/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); + }); + }); + + }); + +});