瀏覽代碼

AMBARI-2914. HeatMaps Unit tests. (onechiporenko via yusaku)

Yusaku Sako 11 年之前
父節點
當前提交
4f4524474c
共有 18 個文件被更改,包括 889 次插入112 次删除
  1. 8 0
      ambari-web/app/assets/test/tests.js
  2. 3 1
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
  3. 3 27
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js
  4. 1 1
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_bytesread.js
  5. 1 1
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_byteswritten.js
  6. 4 27
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js
  7. 4 27
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js
  8. 5 27
      ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js
  9. 49 0
      ambari-web/app/utils/heatmap.js
  10. 1 1
      ambari-web/test/controllers/main/admin/security/add/step3_test.js
  11. 113 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_cpuWaitIO_test.js
  12. 45 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_bytesread_test.js
  13. 45 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_byteswritten_test.js
  14. 115 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_test.js
  15. 116 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_diskspaceused_test.js
  16. 125 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase_test.js
  17. 136 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_memoryused_test.js
  18. 115 0
      ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn_test.js

+ 8 - 0
ambari-web/app/assets/test/tests.js

@@ -26,6 +26,14 @@ require('test/controllers/main/admin/security/add/step3_test');
 require('test/controllers/main/admin/security/add/step4_test');
 require('test/controllers/main/charts/heatmap_test');
 require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_bytesread_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_byteswritten_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_cpuWaitIO_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_diskspaceused_test');
+require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_memoryused_test');
 require('test/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn_ResourceUsed_test');
 require('test/controllers/main/service/reassign_controller_test');
 require('test/controllers/main/dashboard_test');

+ 3 - 1
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js

@@ -18,6 +18,8 @@
 var App = require('app');
 var date = require('utils/date');
 
+var heatmap = require('utils/heatmap');
+
 /**
  * Base class for any heatmap metric.
  * 
@@ -30,7 +32,7 @@ var date = require('utils/date');
  * </ul>
  * 
  */
-App.MainChartHeatmapMetric = Em.Object.extend({
+App.MainChartHeatmapMetric = Em.Object.extend(heatmap.mappers, {
   /**
    * Name of this metric
    */

+ 3 - 27
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js

@@ -26,38 +26,14 @@ App.MainChartHeatmapDFSMetrics = App.MainChartHeatmapMetric.extend({
   /**
    * Custom mapper for DFS metrics
    */
-  metricMapper: function (json) {
-    var hostToValueMap = {};
-    var metricName = this.get('defaultMetric');
-    if (json.host_components) {
-      var props = metricName.split('.');
-      transformValueFunction = this.get('transformValue');
-      json.host_components.forEach(function (hc) {
-        var value = hc;
-        props.forEach(function (prop) {
-          if (value != null && prop in value) {
-            value = value[prop];
-          } else {
-            value = null;
-          }
-        });
-        if (value != null) {
-          if (transformValueFunction) {
-            value = transformValueFunction(value);
-          }
-          var hostName = hc.HostRoles.host_name;
-          hostToValueMap[hostName] = value;
-        }
-      });
-    }
-    return hostToValueMap;
+  metricMapper: function(json) {
+    return this.metricMapperWithTransform(json, this.get('defaultMetric'), this.get('transformValue'));
   },
-
   /**
    * Utility function which allows extending classes to transform the value
    * assigned to a host.
    * 
    * @type Function
    */
-  tranformValue: null
+  transformValue: null
 });

+ 1 - 1
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_bytesread.js

@@ -27,6 +27,6 @@ App.MainChartHeatmapDFSBytesReadMetric = App.MainChartHeatmapDFSMetrics.extend({
   units: 'MB',
   slotDefinitionLabelSuffix: 'MB',
   transformValue: function (value) {
-    return value / (1 << 6); // bytes divided by 1MB.
+    return value / (1024 * 1024); // bytes divided by 1MB.
   }
 });

+ 1 - 1
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_byteswritten.js

@@ -27,6 +27,6 @@ App.MainChartHeatmapDFSBytesWrittenMetric = App.MainChartHeatmapDFSMetrics.exten
   units: 'MB',
   slotDefinitionLabelSuffix: 'MB',
   transformValue: function (value) {
-    return value / (1 << 6); // bytes divided by 1MB.
+    return value / (1024 * 1024); // bytes divided by 1MB.
   }
 });

+ 4 - 27
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js

@@ -24,33 +24,10 @@ App.MainChartHeatmapHbaseMetrics = App.MainChartHeatmapMetric.extend({
   metricUrlTemplate: "/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=host_components/{metricName}",
 
   /**
-   * Custom mapper for DFS metrics
+   * Custom mapper for HBase metrics
    */
-  metricMapper: function (json) {
-    var hostToValueMap = {};
-    var metricName = this.get('defaultMetric');
-    if (json.host_components) {
-      var props = metricName.split('.');
-      transformValueFunction = this.get('transformValue');
-      json.host_components.forEach(function (hc) {
-        var value = hc;
-        props.forEach(function (prop) {
-          if (value != null && prop in value) {
-            value = value[prop];
-          } else {
-            value = null;
-          }
-        });
-        if (value != null) {
-          if (transformValueFunction) {
-            value = transformValueFunction(value);
-          }
-          var hostName = hc.HostRoles.host_name;
-          hostToValueMap[hostName] = value;
-        }
-      });
-    }
-    return hostToValueMap;
+  metricMapper: function(json) {
+    return this.metricMapperWithTransform(json, this.get('defaultMetric'), this.get('transformValue'));
   },
 
   /**
@@ -59,5 +36,5 @@ App.MainChartHeatmapHbaseMetrics = App.MainChartHeatmapMetric.extend({
    *
    * @type Function
    */
-  tranformValue: null
+  transformValue: null
 });

+ 4 - 27
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js

@@ -24,33 +24,10 @@ App.MainChartHeatmapMapreduceMetrics = App.MainChartHeatmapMetric.extend({
   metricUrlTemplate: "/clusters/{clusterName}/services/MAPREDUCE/components/TASKTRACKER?fields=host_components/{metricName}",
 
   /**
-   * Custom mapper for DFS metrics
+   * Custom mapper for MapReduce metrics
    */
-  metricMapper: function (json) {
-    var hostToValueMap = {};
-    var metricName = this.get('defaultMetric');
-    if (json.host_components) {
-      var props = metricName.split('.');
-      transformValueFunction = this.get('transformValue');
-      json.host_components.forEach(function (hc) {
-        var value = hc;
-        props.forEach(function (prop) {
-          if (value != null && prop in value) {
-            value = value[prop];
-          } else {
-            value = null;
-          }
-        });
-        if (value != null) {
-          if (transformValueFunction) {
-            value = transformValueFunction(value);
-          }
-          var hostName = hc.HostRoles.host_name;
-          hostToValueMap[hostName] = value;
-        }
-      });
-    }
-    return hostToValueMap;
+  metricMapper: function(json) {
+    return this.metricMapperWithTransform(json, this.get('defaultMetric'), this.get('transformValue'));
   },
 
   /**
@@ -59,5 +36,5 @@ App.MainChartHeatmapMapreduceMetrics = App.MainChartHeatmapMetric.extend({
    * 
    * @type Function
    */
-  tranformValue: null
+  transformValue: null
 });

+ 5 - 27
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js

@@ -24,33 +24,11 @@ App.MainChartHeatmapYarnMetrics = App.MainChartHeatmapMetric.extend({
   metricUrlTemplate: "/clusters/{clusterName}/services/YARN/components/NODEMANAGER?fields=host_components/{metricName}",
 
   /**
-   * Custom mapper for DFS metrics
+   * Custom mapper for YARN metrics
    */
-  metricMapper: function (json) {
-    var hostToValueMap = {};
-    var metricName = this.get('defaultMetric');
-    if (json.host_components) {
-      var props = metricName.split('.');
-      transformValueFunction = this.get('transformValue');
-      json.host_components.forEach(function (hc) {
-        var value = hc;
-        props.forEach(function (prop) {
-          if (value != null && prop in value) {
-            value = value[prop];
-          } else {
-            value = null;
-          }
-        });
-        if (value != null) {
-          if (transformValueFunction) {
-            value = transformValueFunction(value);
-          }
-          var hostName = hc.HostRoles.host_name;
-          hostToValueMap[hostName] = value;
-        }
-      });
-    }
-    return hostToValueMap;
+
+  metricMapper: function(json) {
+    return this.metricMapperWithTransform(json, this.get('defaultMetric'), this.get('transformValue'));
   },
 
   /**
@@ -59,5 +37,5 @@ App.MainChartHeatmapYarnMetrics = App.MainChartHeatmapMetric.extend({
    *
    * @type Function
    */
-  tranformValue: null
+  transformValue: null
 });

+ 49 - 0
ambari-web/app/utils/heatmap.js

@@ -0,0 +1,49 @@
+/**
+ * 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');
+module.exports = {
+  mappers: Em.Mixin.create({
+    metricMapperWithTransform: function (json, metricName, transformValueFunction) {
+      var hostToValueMap = {};
+      //var metricName = this.get('defaultMetric');
+      if (json.host_components) {
+        var props = metricName.split('.');
+        //var transformValueFunction = this.get('transformValue');
+        json.host_components.forEach(function (hc) {
+          var value = hc;
+          props.forEach(function (prop) {
+            if (value != null && prop in value) {
+              value = value[prop];
+            } else {
+              value = null;
+            }
+          });
+          if (value != null) {
+            if (transformValueFunction) {
+              value = transformValueFunction(value);
+            }
+            var hostName = hc.HostRoles.host_name;
+            hostToValueMap[hostName] = value;
+          }
+        });
+      }
+      return hostToValueMap;
+    }
+  })
+};

+ 1 - 1
ambari-web/test/controllers/main/admin/security/add/step3_test.js

@@ -31,7 +31,7 @@ describe('App.MainAdminSecurityAddStep3Controller', function () {
   describe('#getSecurityUsers', function() {
     it('no hosts, just check users (testMode = true)', function() {
       App.testMode = true;
-      expect(mainAdminSecurityAddStep3Controller.getSecurityUsers().length).to.equal(9);
+      expect(mainAdminSecurityAddStep3Controller.getSecurityUsers().length).to.equal(10);
     });
   });
 

+ 113 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_cpuWaitIO_test.js

@@ -0,0 +1,113 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_cpuWaitIO');
+
+describe('App.MainChartHeatmapCpuWaitIOMetric', function () {
+
+  var tests = [
+    {
+      json: {
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "cpu" : {
+                "cpu_wio" : 0.4
+              }
+            }
+          }
+        ]
+      },
+      m: 'One host',
+      e: {'dev01.hortonworks.com': '40.0'}
+    },
+    {
+      json: {
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "cpu" : {
+                "cpu_wio" : 0.4
+              }
+            }
+          },
+          {
+            "Hosts" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "cpu" : {
+                "cpu_wio" : 0.34566
+              }
+            }
+          }
+        ]
+      },
+      m: 'Two hosts',
+      e: {'dev01.hortonworks.com': '40.0', 'dev02.hortonworks.com': '34.6'}
+    },
+    {
+      json: {
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "cpu" : {
+                "cpu_wio" : 0.4
+              }
+            }
+          },
+          {
+            "Hosts" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "cpu" : {
+              }
+            }
+          }
+        ]
+      },
+      m: 'Two hosts, One without metric',
+      e: {'dev01.hortonworks.com': '40.0'}
+    }
+  ];
+
+  describe('#metricMapper()', function() {
+    var mainChartHeatmapCpuWaitIOMetric = App.MainChartHeatmapCpuWaitIOMetric.create();
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        var r = mainChartHeatmapCpuWaitIOMetric.metricMapper(test.json);
+        expect(r).to.eql(test.e);
+      });
+    });
+
+  });
+
+});

+ 45 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_bytesread_test.js

@@ -0,0 +1,45 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_dfs');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_bytesread');
+
+describe('App.MainChartHeatmapDFSBytesReadMetric', function () {
+
+  var tests = [
+    {i: 0, e: 0},
+    {i: 0.5 * 1024* 1024, e: 0.5},
+    {i: 1024* 1024, e: 1},
+    {i: 10.5 * 1024 * 1024,e: 10.5}
+  ];
+
+  describe('#transformValue()', function() {
+    var mainChartHeatmapDFSBytesReadMetric = App.MainChartHeatmapDFSBytesReadMetric.create();
+
+    tests.forEach(function(test) {
+      it(test.i + ' bytes to ' + test.e + ' MB', function() {
+        var r = mainChartHeatmapDFSBytesReadMetric.transformValue(test.i);
+        expect(r).to.eql(test.e);
+      });
+    });
+
+  });
+
+});

+ 45 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_byteswritten_test.js

@@ -0,0 +1,45 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_dfs');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_byteswritten');
+
+describe('App.MainChartHeatmapDFSBytesWrittenMetric', function () {
+
+  var tests = [
+    {i: 0, e: 0},
+    {i: 0.5 * 1024* 1024, e: 0.5},
+    {i: 1024* 1024, e: 1},
+    {i: 10.5 * 1024 * 1024,e: 10.5}
+  ];
+
+  describe('#transformValue()', function() {
+    var mainChartHeatmapDFSBytesWrittenMetric = App.MainChartHeatmapDFSBytesWrittenMetric.create();
+
+    tests.forEach(function(test) {
+      it(test.i + ' bytes to ' + test.e + ' MB', function() {
+        var r = mainChartHeatmapDFSBytesWrittenMetric.transformValue(test.i);
+        expect(r).to.eql(test.e);
+      });
+    });
+
+  });
+
+});

+ 115 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs_test.js

@@ -0,0 +1,115 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_dfs');
+
+describe('App.MainChartHeatmapDFSMetrics', function () {
+
+  var tests = [
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "gcTimeMillis" : 285
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 285},
+      m: 'One host_component'
+    },
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "gcTimeMillis" : 285
+              }
+            }
+          },
+          {
+            "HostRoles" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "gcTimeMillis" : 124
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 285, 'dev02.hortonworks.com': 124},
+      m: 'Two host_components'
+    },
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "gcTimeMillis" : 285
+              }
+            }
+          },
+          {
+            "HostRoles" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 285},
+      m: 'Two host_components, one without metric'
+    }
+  ];
+
+  describe('#metricMapper()', function() {
+    var mainChartHeatmapDFSMetrics = App.MainChartHeatmapDFSMetrics.create();
+    mainChartHeatmapDFSMetrics.set('defaultMetric', 'metrics.jvm.gcTimeMillis');
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        var r = mainChartHeatmapDFSMetrics.metricMapper(test.json);
+        expect(r).to.eql(test.result);
+      });
+    });
+
+  });
+
+});

+ 116 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_diskspaceused_test.js

@@ -0,0 +1,116 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_diskspaceused');
+
+describe('App.MainChartHeatmapDiskSpaceUsedMetric', function () {
+
+  var tests = [
+    {
+      json:{
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "disk" : {
+                "disk_free" : 89.973,
+                "disk_total" : 101.515
+              }
+            }
+          }
+        ]
+      },
+      m: 'One host',
+      e: {'dev01.hortonworks.com': '11.4'}
+    },
+    {
+      json:{
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "disk" : {
+                "disk_free" : 89.973,
+                "disk_total" : 101.515
+              }
+            }
+          },
+          {
+            "Hosts" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "disk" : {
+                "disk_free" : 89.973,
+                "disk_total" : 101.515
+              }
+            }
+          }
+        ]
+      },
+      m: 'Two hosts',
+      e: {'dev01.hortonworks.com': '11.4', 'dev02.hortonworks.com': '11.4'}
+    },
+    {
+      json:{
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "disk" : {
+                "disk_free" : 89.973,
+                "disk_total" : 101.515
+              }
+            }
+          },
+          {
+            "Hosts" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+
+            }
+          }
+        ]
+      },
+      m: 'Two hosts, One without metric',
+      e: {'dev01.hortonworks.com': '11.4'}
+    }
+  ];
+
+  describe('#metricMapper()', function() {
+    var mainChartHeatmapDiskSpaceUsedMetric = App.MainChartHeatmapDiskSpaceUsedMetric.create();
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        var r = mainChartHeatmapDiskSpaceUsedMetric.metricMapper(test.json);
+        expect(r).to.eql(test.e);
+      });
+    });
+
+  });
+
+});

+ 125 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase_test.js

@@ -0,0 +1,125 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_hbase');
+
+describe('App.MainChartHeatmapHbaseMetrics', function () {
+
+  var tests = [
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "hbase" : {
+                "regionserver" : {
+                  "readRequestsCount" : 0.0
+                }
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 0},
+      m: 'One host_component'
+    },
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "hbase" : {
+                "regionserver" : {
+                  "readRequestsCount" : 0.0
+                }
+              }
+            }
+          },
+          {
+            "HostRoles" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "hbase" : {
+                "regionserver" : {
+                  "readRequestsCount" : 1.0
+                }
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 0, 'dev02.hortonworks.com': 1},
+      m: 'Two host_components'
+    },
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "hbase" : {
+                "regionserver" : {
+                  "readRequestsCount" : 0.0
+                }
+              }
+            }
+          },
+          {
+            "HostRoles" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "hbase" : {
+                "regionserver" : {
+
+                }
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 0},
+      m: 'Two host_components, one without metric'
+    }
+  ];
+
+  describe('#metricMapper()', function() {
+    var mainChartHeatmapHbaseMetrics = App.MainChartHeatmapHbaseMetrics.create();
+    mainChartHeatmapHbaseMetrics.set('defaultMetric', 'metrics.hbase.regionserver.readRequestsCount');
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        var r = mainChartHeatmapHbaseMetrics.metricMapper(test.json);
+        expect(r).to.eql(test.result);
+      });
+    });
+
+  });
+
+});

+ 136 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_memoryused_test.js

@@ -0,0 +1,136 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_memoryused');
+
+describe('App.MainChartHeatmapMemoryUsedMetric', function () {
+
+  var tests = [
+    {
+      json:{
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "memory" : {
+                "mem_buffers" : 109888.0,
+                "mem_cached" : 1965624.0,
+                "mem_free" : 261632.0,
+                "mem_shared" : 0.0,
+                "mem_total" : 6123776.0,
+                "swap_free" : 4126820.0,
+                "swap_total" : 4128760.0
+              }
+            }
+          }
+        ]
+      },
+      m: 'One host',
+      e: {'dev01.hortonworks.com': '63.6'}
+    },
+    {
+      json:{
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "memory" : {
+                "mem_buffers" : 109888.0,
+                "mem_cached" : 1965624.0,
+                "mem_free" : 261632.0,
+                "mem_shared" : 0.0,
+                "mem_total" : 6123776.0,
+                "swap_free" : 4126820.0,
+                "swap_total" : 4128760.0
+              }
+            }
+          },
+          {
+            "Hosts" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "memory" : {
+                "mem_buffers" : 109888.0,
+                "mem_cached" : 1965624.0,
+                "mem_free" : 261632.0,
+                "mem_shared" : 0.0,
+                "mem_total" : 6123776.0,
+                "swap_free" : 4126820.0,
+                "swap_total" : 4128760.0
+              }
+            }
+          }
+        ]
+      },
+      m: 'Two hosts',
+      e: {'dev01.hortonworks.com': '63.6', 'dev02.hortonworks.com': '63.6'}
+    },
+    {
+      json:{
+        "items" : [
+          {
+            "Hosts" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "memory" : {
+                "mem_buffers" : 109888.0,
+                "mem_cached" : 1965624.0,
+                "mem_free" : 261632.0,
+                "mem_shared" : 0.0,
+                "mem_total" : 6123776.0,
+                "swap_free" : 4126820.0,
+                "swap_total" : 4128760.0
+              }
+            }
+          },
+          {
+            "Hosts" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+
+            }
+          }
+        ]
+      },
+      m: 'Two hosts, One without metric',
+      e: {'dev01.hortonworks.com': '63.6'}
+    }
+  ];
+
+  describe('#metricMapper()', function() {
+    var mainChartHeatmapMemoryUsedMetric = App.MainChartHeatmapMemoryUsedMetric.create();
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        var r = mainChartHeatmapMemoryUsedMetric.metricMapper(test.json);
+        expect(r).to.eql(test.e);
+      });
+    });
+
+  });
+
+});

+ 115 - 0
ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn_test.js

@@ -0,0 +1,115 @@
+/**
+ * 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('messages');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric');
+require('controllers/main/charts/heatmap_metrics/heatmap_metric_yarn');
+
+describe('App.MainChartHeatmapYarnMetrics', function () {
+
+  var tests = [
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "memHeapUsedM" : 10
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 10},
+      m: 'One host_component'
+    },
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "memHeapUsedM" : 10
+              }
+            }
+          },
+          {
+            "HostRoles" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "memHeapUsedM" : 20
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 10, 'dev02.hortonworks.com': 20},
+      m: 'Two host_components'
+    },
+    {
+      json: {
+        "host_components" : [
+          {
+            "HostRoles" : {
+              "host_name" : "dev01.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+                "memHeapUsedM" : 10
+              }
+            }
+          },
+          {
+            "HostRoles" : {
+              "host_name" : "dev02.hortonworks.com"
+            },
+            "metrics" : {
+              "jvm" : {
+
+              }
+            }
+          }
+        ]
+      },
+      result: {'dev01.hortonworks.com': 10},
+      m: 'Two host_components, one without metric'
+    }
+  ];
+
+  describe('#metricMapper()', function() {
+    var mainChartHeatmapYarnMetrics = App.MainChartHeatmapYarnMetrics.create();
+    mainChartHeatmapYarnMetrics.set('defaultMetric', 'metrics.jvm.memHeapUsedM');
+
+    tests.forEach(function(test) {
+      it(test.m, function() {
+        var r = mainChartHeatmapYarnMetrics.metricMapper(test.json);
+        expect(r).to.eql(test.result);
+      });
+    });
+
+  });
+
+});