Repository: ambari
Updated Branches:
  refs/heads/trunk 1be4506a4 -> 1cf2b9852


AMBARI-7601 Service pluggability: refactor UI code to externalize metrics graph 
definition to a single file (salvi via jaoki)


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

Branch: refs/heads/trunk
Commit: 1cf2b98520914f32ac33685951fc24cfadb55be6
Parents: 1be4506
Author: Jun Aoki <ja...@apache.org>
Authored: Thu Oct 16 14:55:36 2014 -0700
Committer: Jun Aoki <ja...@apache.org>
Committed: Thu Oct 16 14:55:36 2014 -0700

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js             |  2 +
 ambari-web/app/data/service_graph_config.js     | 93 +++++++++++++++++++
 .../app/views/main/service/info/summary.js      | 96 ++++++--------------
 .../views/main/service/info/summary_test.js     | 24 ++++-
 4 files changed, 146 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf2b985/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 1dff1b2..65082ab 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -167,6 +167,8 @@ var files = ['test/init_model_test',
   'test/views/main/charts/heatmap/heatmap_host_test',
   'test/views/main/service/item_test',
   'test/views/main/service/info/config_test',
+  'test/views/main/service/info/summary_test',
+  'test/views/main/mirroring/edit_dataset_view_test',
   'test/views/common/configs/services_config_test',
   'test/views/wizard/step3/hostLogPopupBody_view_test',
   'test/views/wizard/step3/hostWarningPopupBody_view_test',

http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf2b985/ambari-web/app/data/service_graph_config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/data/service_graph_config.js 
b/ambari-web/app/data/service_graph_config.js
new file mode 100644
index 0000000..51a9f9e
--- /dev/null
+++ b/ambari-web/app/data/service_graph_config.js
@@ -0,0 +1,93 @@
+/**
+ * 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');
+
+/**
+This determines the graphs to display on the service page under each service.
+
+This is based on the name of the object associated with it.
+
+The name of the object is of the format: 'App.ChartServiceMetrics<name>' where 
<name>
+is one of the items below.
+**/
+App.service_graph_config = {
+       'hdfs': [
+               'HDFS_SpaceUtilization',
+               'HDFS_FileOperations',
+               'HDFS_BlockStatus',
+               'HDFS_IO',
+               'HDFS_RPC',
+               'HDFS_GC',
+               'HDFS_JVMHeap',
+               'HDFS_JVMThreads'
+       ],
+
+       'yarn': [
+               'YARN_AllocatedMemory',
+               'YARN_QMR',
+               'YARN_AllocatedContainer',
+               'YARN_NMS',
+               'YARN_ApplicationCurrentStates',
+               'YARN_ApplicationFinishedStates',
+               'YARN_RPC',
+               'YARN_GC',
+               'YARN_JVMThreads',
+               'YARN_JVMHeap'
+       ],
+
+       'mapreduce': [
+               'MapReduce_JobsStatus',
+               'MapReduce_TasksRunningWaiting',
+               'MapReduce_MapSlots',
+               'MapReduce_ReduceSlots',
+               'MapReduce_GC',
+               'MapReduce_RPC',
+               'MapReduce_JVMHeap',
+               'MapReduce_JVMThreads'
+       ],
+
+       'hbase': [
+               'HBASE_ClusterRequests',
+               'HBASE_RegionServerReadWriteRequests',
+               'HBASE_RegionServerRegions',
+               'HBASE_RegionServerQueueSize',
+               'HBASE_HlogSplitTime',
+               'HBASE_HlogSplitSize'
+       ],
+
+       'flume': [
+               'Flume_ChannelSizeMMA',
+               'Flume_ChannelSizeSum',
+               'Flume_IncommingMMA',
+               'Flume_IncommingSum',
+               'Flume_OutgoingMMA',
+               'Flume_OutgoingSum',
+               'Flume_GarbageCollection',
+               'Flume_JVMHeapUsed',
+               'Flume_JVMThreadsRunnable',
+               'Flume_CPUUser'
+       ],
+
+       'storm': [
+               'STORM_SlotsNumber',
+               'STORM_Executors',
+               'STORM_Topologies',
+               'STORM_Tasks'
+       ]
+};
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf2b985/ambari-web/app/views/main/service/info/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service/info/summary.js 
b/ambari-web/app/views/main/service/info/summary.js
index d90f835..647ff3c 100644
--- a/ambari-web/app/views/main/service/info/summary.js
+++ b/ambari-web/app/views/main/service/info/summary.js
@@ -18,6 +18,7 @@
 var App = require('app');
 var batchUtils = require('utils/batch_scheduled_requests');
 require('views/main/service/service');
+require('data/service_graph_config');
 
 App.AlertItemView = Em.View.extend({
   tagName:"li",
@@ -314,81 +315,40 @@ App.MainServiceInfoSummaryView = Em.View.extend({
    * 'Restart Required bar' ended
    */
 
+   /*
+   * Find the graph class associated with the graph name, and split
+   * the array into sections of 4 for displaying on the page
+   * (will only display rows with 4 items)
+   */
+  constructGraphObjects: function(graphNames) {
+    var result = [], graphObjects = [], chunkSize = 4;
+
+    if (!graphNames) {
+      return [];
+    }
+
+    graphNames.forEach(function(graphName) {
+      graphObjects.push(App["ChartServiceMetrics" + graphName].extend());
+    });
+
+    while(graphObjects.length) {
+      result.push(graphObjects.splice(0, chunkSize));
+    }
+
+    return result;
+  },
+
   /**
    * Contains graphs for this particular service
    */
-  serviceMetricGraphs:function () {
+  serviceMetricGraphs:function() {
     var svcName = this.get('service.serviceName');
     var graphs = [];
+
     if (svcName) {
-      switch (svcName.toLowerCase()) {
-        case 'hdfs':
-          graphs = [ [App.ChartServiceMetricsHDFS_SpaceUtilization.extend(),
-            App.ChartServiceMetricsHDFS_FileOperations.extend(),
-            App.ChartServiceMetricsHDFS_BlockStatus.extend(),
-            App.ChartServiceMetricsHDFS_IO.extend()],
-            [App.ChartServiceMetricsHDFS_RPC.extend(),
-            App.ChartServiceMetricsHDFS_GC.extend(),
-            App.ChartServiceMetricsHDFS_JVMHeap.extend(),
-            App.ChartServiceMetricsHDFS_JVMThreads.extend()]];
-          break;
-        case 'yarn':
-          graphs = [[App.ChartServiceMetricsYARN_AllocatedMemory.extend(),
-              App.ChartServiceMetricsYARN_QMR.extend(),
-              App.ChartServiceMetricsYARN_AllocatedContainer.extend(),
-              App.ChartServiceMetricsYARN_NMS.extend()],
-            [App.ChartServiceMetricsYARN_ApplicationCurrentStates.extend(),
-             App.ChartServiceMetricsYARN_ApplicationFinishedStates.extend(),
-             App.ChartServiceMetricsYARN_RPC.extend(),
-            App.ChartServiceMetricsYARN_GC.extend()
-            ],
-            [App.ChartServiceMetricsYARN_JVMThreads.extend(),
-             App.ChartServiceMetricsYARN_JVMHeap.extend()]];
-          break;
-        case 'mapreduce':
-          graphs = [ [App.ChartServiceMetricsMapReduce_JobsStatus.extend(),
-            App.ChartServiceMetricsMapReduce_TasksRunningWaiting.extend(),
-            App.ChartServiceMetricsMapReduce_MapSlots.extend(),
-            App.ChartServiceMetricsMapReduce_ReduceSlots.extend()],
-            [App.ChartServiceMetricsMapReduce_GC.extend(),
-            App.ChartServiceMetricsMapReduce_RPC.extend(),
-            App.ChartServiceMetricsMapReduce_JVMHeap.extend(),
-            App.ChartServiceMetricsMapReduce_JVMThreads.extend()]];
-          break;
-        case 'hbase':
-          graphs = [  [App.ChartServiceMetricsHBASE_ClusterRequests.extend(),
-            
App.ChartServiceMetricsHBASE_RegionServerReadWriteRequests.extend(),
-            App.ChartServiceMetricsHBASE_RegionServerRegions.extend(),
-            App.ChartServiceMetricsHBASE_RegionServerQueueSize.extend()],
-            [App.ChartServiceMetricsHBASE_HlogSplitTime.extend(),
-            App.ChartServiceMetricsHBASE_HlogSplitSize.extend()]];
-          break;
-        case 'flume':
-          graphs = [[App.ChartServiceMetricsFlume_ChannelSizeMMA.extend(),
-             App.ChartServiceMetricsFlume_ChannelSizeSum.extend(),
-             App.ChartServiceMetricsFlume_IncommingMMA.extend(),
-             App.ChartServiceMetricsFlume_IncommingSum],
-             [App.ChartServiceMetricsFlume_OutgoingMMA,
-               App.ChartServiceMetricsFlume_OutgoingSum,
-             //App.ChartServiceMetricsFlume_GarbageCollection.extend(),
-              //App.ChartServiceMetricsFlume_JVMHeapUsed.extend(),
-              //App.ChartServiceMetricsFlume_JVMThreadsRunnable.extend(),
-              App.ChartServiceMetricsFlume_CPUUser.extend()]];
-          break;
-        case 'storm':
-          graphs = [
-            [
-              App.ChartServiceMetricsSTORM_SlotsNumber.extend(),
-              App.ChartServiceMetricsSTORM_Executors.extend(),
-              App.ChartServiceMetricsSTORM_Topologies.extend(),
-              App.ChartServiceMetricsSTORM_Tasks.extend()
-            ]
-          ];
-          break;
-        default:
-          break;
-      }
+      graphs = 
this.constructGraphObjects(App.service_graph_config[svcName.toLowerCase()]);
     }
+
     return graphs;
   }.property(''),
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/1cf2b985/ambari-web/test/views/main/service/info/summary_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/service/info/summary_test.js 
b/ambari-web/test/views/main/service/info/summary_test.js
index 8392ad0..7e30f29 100644
--- a/ambari-web/test/views/main/service/info/summary_test.js
+++ b/ambari-web/test/views/main/service/info/summary_test.js
@@ -102,4 +102,26 @@ describe('App.MainServiceInfoSummaryView', function() {
     });
 
   });
-});
+
+  describe("#constructGraphObjects", function() {
+    it("should return a single array with the items in the fom of 
'<name>.extend()' when the number of items is less than 4", function() {
+      var graphs = ['HDFS_SpaceUtilization'];
+
+      
expect(mainServiceInfoSummaryView.constructGraphObjects(graphs).length).to.equal(1);
+      
expect(mainServiceInfoSummaryView.constructGraphObjects(graphs)[0].length).to.equal(1);
+    });
+
+    it("should return an array with arrays that are grouped into sizes of 4 or 
less when number of items is greater than 4", function() {
+      var graphs = ['HDFS_SpaceUtilization', 'YARN_AllocatedMemory', 
'MapReduce_JobsStatus', 
+      'HBASE_ClusterRequests', 'Flume_ChannelSizeMMA'];
+
+      
expect(mainServiceInfoSummaryView.constructGraphObjects(graphs).length).to.equal(2);
+      
expect(mainServiceInfoSummaryView.constructGraphObjects(graphs)[0].length).to.equal(4);
+      
expect(mainServiceInfoSummaryView.constructGraphObjects(graphs)[1].length).to.equal(1);
+    });
+
+    it("should return an empty array if the graphs array provided is empty", 
function() {
+      expect(mainServiceInfoSummaryView.constructGraphObjects([])).to.be.empty;
+    });
+  });
+});
\ No newline at end of file

Reply via email to