You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2014/01/27 18:42:14 UTC
git commit: AMBARI-4431. Refactor helpers. (onechiporenko)
Updated Branches:
refs/heads/trunk a59e3d0b9 -> dce0e2041
AMBARI-4431. Refactor helpers. (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dce0e204
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dce0e204
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dce0e204
Branch: refs/heads/trunk
Commit: dce0e2041b943fc9eddc00bc5c7c48bb40571759
Parents: a59e3d0
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Mon Jan 27 19:09:54 2014 +0200
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Mon Jan 27 19:12:22 2014 +0200
----------------------------------------------------------------------
.../charts/heatmap_metrics/heatmap_metric.js | 73 ++--
.../heatmap_metrics/heatmap_metric_dfs.js | 10 +-
.../heatmap_metrics/heatmap_metric_hbase.js | 10 +-
.../heatmap_metrics/heatmap_metric_mapreduce.js | 10 +-
.../heatmap_metrics/heatmap_metric_yarn.js | 11 +-
ambari-web/app/utils/ajax.js | 150 ++++---
ambari-web/app/utils/helper.js | 388 ++++++-------------
ambari-web/app/utils/http_client.js | 11 +-
.../heatmap_metrics/heatmap_metric_test.js | 28 +-
9 files changed, 286 insertions(+), 405 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
index 18b0df5..a9ead0c 100644
--- a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
+++ b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric.js
@@ -121,16 +121,16 @@ App.MainChartHeatmapMetric = Em.Object.extend(heatmap.mappers, {
var labelSuffix = this.get('slotDefinitionLabelSuffix');
var delta = (max - min) / slotCount;
var defs = [];
- var fractions = max < 5;
var slotColors = this.get('slotColors');
var slotColorIndex = 0;
for ( var c = 0; c < slotCount - 1; c++) {
var from = this.formatLegendNumber(c * delta);
var to = this.formatLegendNumber((c + 1) * delta);
+ var label;
if ($.trim(labelSuffix) == 'ms') {
- var label = date.timingFormat(from, 'zeroValid') + " - " + date.timingFormat(to, 'zeroValid');
+ label = date.timingFormat(from, 'zeroValid') + " - " + date.timingFormat(to, 'zeroValid');
} else {
- var label = from + labelSuffix + " - " + to + labelSuffix;
+ label = from + labelSuffix + " - " + to + labelSuffix;
}
var slotColor = slotColors[slotColorIndex++];
defs.push(Em.Object.create({
@@ -144,9 +144,9 @@ App.MainChartHeatmapMetric = Em.Object.extend(heatmap.mappers, {
to = this.formatLegendNumber(max);
if ($.trim(labelSuffix) == 'ms') {
- var label = date.timingFormat(from, 'zeroValid') + " - " + date.timingFormat(to, 'zeroValid');
+ label = date.timingFormat(from, 'zeroValid') + " - " + date.timingFormat(to, 'zeroValid');
} else {
- var label = from + labelSuffix + " - " + to + labelSuffix;
+ label = from + labelSuffix + " - " + to + labelSuffix;
}
slotColor = slotColors[slotColorIndex++];
@@ -189,34 +189,27 @@ App.MainChartHeatmapMetric = Em.Object.extend(heatmap.mappers, {
*/
slotDefinitionLabelSuffix: '',
+ defaultMetric: '',
+
/**
- * URL template from which metrics will be gotten for all hosts. The
- * {metricName} param will be replaced by the 'defaultMetric' value.
+ * Name in the <code>App.ajax</code>
+ * @type {String}
*/
- metricUrlTemplate: "/clusters/{clusterName}/hosts?fields={metricName}",
+ ajaxIndex: 'hosts.metrics',
/**
- * URL from which data for this metric can be gotten from. This should be
- * extended by classes to provide correct value.
+ * Additional data for ajax-request
+ * May be redeclared in child-objects
+ * @type {Object}
*/
- metricUrl: function () {
- var clusterName = App.router.get('clusterController.clusterName');
- var fixedMetricName = this.get('defaultMetric');
- fixedMetricName = fixedMetricName.replace(/\./g, "/");
- return App.formatUrl(App.apiPrefix + this.get('metricUrlTemplate'), {
- clusterName: App.router.get('clusterController.clusterName'),
- metricName: fixedMetricName
- }, "/data/cluster_metrics/cpu_1hr.json");
- }.property('App.router.clusterController.clusterName', 'defaultMetric'),
-
- defaultMetric: '',
+ ajaxData: {},
/**
* Maps server JSON into an object where keys are hostnames and values are the
* true metric values. This function by default will map 'defaultMetric' into
* its corresponding value.
*
- * @type Function
+ * @Function
*/
metricMapper: function (json) {
var hostToValueMap = {};
@@ -249,7 +242,7 @@ App.MainChartHeatmapMetric = Em.Object.extend(heatmap.mappers, {
var allHosts = App.Host.find();
var hostToSlotMap = {};
if (hostToValueMap && allHosts) {
- allHosts.forEach(function(host, index, list){
+ allHosts.forEach(function(host){
var slot = -1;
var key = host.get('hostName');
if (key in hostToValueMap) {
@@ -286,20 +279,32 @@ App.MainChartHeatmapMetric = Em.Object.extend(heatmap.mappers, {
*/
refreshHostSlots: function () {
this.set('loading', true);
- jQuery.ajax({
- url: this.get('metricUrl'),
- dataType: 'json',
- error: jQuery.proxy(function () {
- this.set('loading', false);
- }, this),
- success: jQuery.proxy(function (data) {
- var hostToValueMap = this.metricMapper(data);
- this.set('hostToValueMap', hostToValueMap);
- this.set('loading', false);
- }, this)
+ var fixedMetricName = this.get('defaultMetric');
+ fixedMetricName = fixedMetricName.replace(/\./g, "/");
+ var ajaxData = {
+ metricName: fixedMetricName
+ };
+ jQuery.extend(ajaxData, this.get('ajaxData'));
+
+ App.ajax.send({
+ name: this.get('ajaxIndex'),
+ sender: this,
+ data: ajaxData,
+ success: 'refreshHostSlotsSuccessCallback',
+ error: 'refreshHostSlotsErrorCallback'
});
},
+ refreshHostSlotsSuccessCallback: function (data) {
+ var hostToValueMap = this.metricMapper(data);
+ this.set('hostToValueMap', hostToValueMap);
+ this.set('loading', false);
+ },
+
+ refreshHostSlotsErrorCallback: function () {
+ this.set('loading', false);
+ },
+
/**
* Turns numbers into displayable values. For example 24.345432425 into 24.3
* etc.
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js
index 336b081..100a65e 100644
--- a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js
+++ b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_dfs.js
@@ -21,7 +21,13 @@ var App = require('app');
* Base class for any HDFS metric.
*/
App.MainChartHeatmapDFSMetrics = App.MainChartHeatmapMetric.extend({
- metricUrlTemplate: "/clusters/{clusterName}/services/HDFS/components/DATANODE?fields=host_components/{metricName}",
+
+ ajaxIndex: 'hosts.metrics.host_component',
+
+ ajaxData: {
+ serviceName: 'HDFS',
+ componentName: 'DATANODE'
+ },
/**
* Custom mapper for DFS metrics
@@ -33,7 +39,7 @@ App.MainChartHeatmapDFSMetrics = App.MainChartHeatmapMetric.extend({
* Utility function which allows extending classes to transform the value
* assigned to a host.
*
- * @type Function
+ * @Function
*/
transformValue: null
});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js
index e0005bf..9b1fc4a 100644
--- a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js
+++ b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_hbase.js
@@ -21,7 +21,13 @@ var App = require('app');
* Base class for any HDFS metric.
*/
App.MainChartHeatmapHbaseMetrics = App.MainChartHeatmapMetric.extend({
- metricUrlTemplate: "/clusters/{clusterName}/services/HBASE/components/HBASE_REGIONSERVER?fields=host_components/{metricName}",
+
+ ajaxIndex: 'hosts.metrics.host_component',
+
+ ajaxData: {
+ serviceName: 'HBASE',
+ componentName: 'HBASE_REGIONSERVER'
+ },
/**
* Custom mapper for HBase metrics
@@ -34,7 +40,7 @@ App.MainChartHeatmapHbaseMetrics = App.MainChartHeatmapMetric.extend({
* Utility function which allows extending classes to transform the value
* assigned to a host.
*
- * @type Function
+ * @Function
*/
transformValue: null
});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js
index e26a33f..1f45b8a 100644
--- a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js
+++ b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_mapreduce.js
@@ -21,7 +21,13 @@ var App = require('app');
* Base class for any MapReduce metric.
*/
App.MainChartHeatmapMapreduceMetrics = App.MainChartHeatmapMetric.extend({
- metricUrlTemplate: "/clusters/{clusterName}/services/MAPREDUCE/components/TASKTRACKER?fields=host_components/{metricName}",
+
+ ajaxIndex: 'hosts.metrics.host_component',
+
+ ajaxData: {
+ serviceName: 'MAPREDUCE',
+ componentName: 'TASKTRACKER'
+ },
/**
* Custom mapper for MapReduce metrics
@@ -34,7 +40,7 @@ App.MainChartHeatmapMapreduceMetrics = App.MainChartHeatmapMetric.extend({
* Utility function which allows extending classes to transform the value
* assigned to a host.
*
- * @type Function
+ * @Function
*/
transformValue: null
});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js
index e266560..f60075d 100644
--- a/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js
+++ b/ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_yarn.js
@@ -21,12 +21,17 @@ var App = require('app');
* Base class for any YARN metric.
*/
App.MainChartHeatmapYarnMetrics = App.MainChartHeatmapMetric.extend({
- metricUrlTemplate: "/clusters/{clusterName}/services/YARN/components/NODEMANAGER?fields=host_components/{metricName}",
+
+ ajaxIndex: 'hosts.metrics.host_component',
+
+ ajaxData: {
+ serviceName: 'YARN',
+ componentName: 'NODEMANAGER'
+ },
/**
* Custom mapper for YARN metrics
*/
-
metricMapper: function(json) {
return this.metricMapperWithTransform(json, this.get('defaultMetric'), this.get('transformValue'));
},
@@ -35,7 +40,7 @@ App.MainChartHeatmapYarnMetrics = App.MainChartHeatmapMetric.extend({
* Utility function which allows extending classes to transform the value
* assigned to a host.
*
- * @type Function
+ * @Function
*/
transformValue: null
});
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index 49ce65b..5e59549 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -24,7 +24,7 @@ var App = require('app');
* mock - testMode url
* real - real url (without API prefix)
* type - request type (also may be defined in the format method)
- * format - function for processing ajax params after default formatRequest. Return ajax-params object
+ * format - function for processing ajax params after default formatRequest. May be called with one or two parameters (data, opt). Return ajax-params object
* testInProduction - can this request be executed on production tests (used only in tests)
*
* @type {Object}
@@ -66,7 +66,7 @@ var urls = {
'service.item.start_stop': {
'real': '/clusters/{clusterName}/services/{serviceName}',
'mock': '/data/wizard/deploy/poll_1.json',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
type: 'PUT',
data: JSON.stringify({
@@ -102,7 +102,7 @@ var urls = {
'real': '/clusters/{clusterName}/host_components?' +
'HostRoles/stale_configs=true&HostRoles/component_name.in({componentNames})',
'mock': '/data/wizard/deploy/poll_1.json',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
type: 'PUT',
data: JSON.stringify({
@@ -125,7 +125,7 @@ var urls = {
'reassign.stop_services': {
'real': '/clusters/{clusterName}/services',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
type: 'PUT',
data: JSON.stringify({
@@ -144,7 +144,7 @@ var urls = {
'reassign.start_services': {
'real': '/clusters/{clusterName}/services?params/run_smoke_test=true',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
type: 'PUT',
data: JSON.stringify({
@@ -211,7 +211,7 @@ var urls = {
'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}',
'mock': '',
'type': 'PUT',
- 'format': function (data, opt) {
+ 'format': function() {
return {
data: JSON.stringify({
RequestInfo: {
@@ -230,7 +230,7 @@ var urls = {
'config.advanced': {
'real': '{stack2VersionUrl}/stackServices/{serviceName}/configurations?fields=*',
'mock': '/data/wizard/stack/hdp/version{stackVersion}/{serviceName}.json',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -239,7 +239,7 @@ var urls = {
'config.advanced.global': {
'real': '{stack2VersionUrl}/stackServices?fields=configurations/StackConfigurations/type',
'mock': '/data/wizard/stack/hdp/version1.3.0/global.json',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -256,7 +256,7 @@ var urls = {
'config.tags.sync': {
'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
'mock': '/data/clusters/cluster.json',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -293,7 +293,7 @@ var urls = {
'config.on_site': {
'real': '/clusters/{clusterName}/configurations?{params}',
'mock': '/data/configurations/cluster_level_configs.json?{params}',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -302,7 +302,7 @@ var urls = {
'config.host_overrides': {
'real': '/clusters/{clusterName}/configurations?{params}',
'mock': '/data/configurations/host_level_overrides_configs.json?{params}',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -330,38 +330,22 @@ var urls = {
'host.host_component.slave_desired_admin_state': {
'real': '/clusters/{clusterName}/hosts/{hostName}/host_components/{componentName}/?fields=HostRoles/desired_admin_state',
'mock': '',
- 'type': 'GET',
- 'format': function (data, opt) {
- return {
- };
- }
+ 'type': 'GET'
},
'host.host_component.datanodes_decommission_status': {
'real': '/clusters/{clusterName}/services/HDFS/components/NAMENODE/?fields=ServiceComponentInfo',
'mock': '',
- 'type': 'GET',
- 'format': function (data, opt) {
- return {
- };
- }
+ 'type': 'GET'
},
'host.host_component.nodemanager_decommission_status': {
'real': '/clusters/{clusterName}/services/YARN/components/RESOURCEMANAGER/?fields=ServiceComponentInfo',
'mock': '',
- 'type': 'GET',
- 'format': function (data, opt) {
- return {
- };
- }
+ 'type': 'GET'
},
'host.host_component.tasktracker_decommission_status': {
'real': '/clusters/{clusterName}/services/MAPREDUCE/components/JOBTRACKER/?fields=ServiceComponentInfo',
'mock': '',
- 'type': 'GET',
- 'format': function (data, opt) {
- return {
- };
- }
+ 'type': 'GET'
},
'host.host_component.decommission_slave': {
'real' : '/clusters/{clusterName}/requests',
@@ -450,12 +434,20 @@ var urls = {
'real': '/clusters/{clusterName}/hosts/{hostName}',
'mock': '',
'type': 'DELETE',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
}
}
},
+ 'hosts.metrics': {
+ 'real': '/clusters/{clusterName}/hosts?fields={metricName}',
+ 'mock': '/data/cluster_metrics/cpu_1hr.json'
+ },
+ 'hosts.metrics.host_component': {
+ 'real': '/clusters/{clusterName}/services/{serviceName}/components/{componentName}?fields=host_components/{metricName}',
+ 'mock': '/data/cluster_metrics/cpu_1hr.json'
+ },
'service.metrics.flume.channel_fill_percent': {
'real': '/clusters/{clusterName}/services/FLUME/components/FLUME_SERVER?fields=host_components/metrics/flume/flume/CHANNEL/*/ChannelFillPercentage[{fromSeconds},{toSeconds},{stepSeconds}]',
'mock': '/data/services/metrics/flume/channelFillPct.json',
@@ -614,7 +606,7 @@ var urls = {
'service.start_stop': {
'real': '/clusters/{clusterName}/services?params/run_smoke_test=true',
'mock': '/data/mirroring/poll/poll_6.json',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
type: 'PUT',
async: false,
@@ -739,7 +731,7 @@ var urls = {
'host.service_config_hosts_overrides': {
'real': '/clusters/{clusterName}/configurations?{urlParams}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false,
timeout: 10000
@@ -749,7 +741,7 @@ var urls = {
'admin.security_status': {
'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
timeout: 10000
};
@@ -772,7 +764,7 @@ var urls = {
'cluster.load_cluster_name': {
'real': '/clusters',
'mock': '/data/clusters/info.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -782,7 +774,7 @@ var urls = {
'type': 'POST',
'real': '/persist/',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function(data) {
return {
async: false,
data: JSON.stringify(data.keyValuePair)
@@ -792,7 +784,7 @@ var urls = {
'cluster.update_upgrade_version': {
'real': '/stacks2/HDP/versions?fields=stackServices/StackServices,Versions',
'mock': '/data/wizard/stack/stacks.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -802,7 +794,7 @@ var urls = {
'real': '/stacks2/{stackName}/versions/{stackVersion}/operatingSystems?fields=repositories/*',
'mock': '',
'type': 'GET',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
data: data.data
};
@@ -811,7 +803,7 @@ var urls = {
'admin.high_availability.stop_all_services': {
'real': '/clusters/{clusterName}/services',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
type: 'PUT',
data: JSON.stringify({
@@ -830,7 +822,7 @@ var urls = {
'admin.high_availability.start_all_services': {
'real': '/clusters/{clusterName}/services',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
type: 'PUT',
data: JSON.stringify({
@@ -886,7 +878,7 @@ var urls = {
'real': '/clusters/{clusterName}/services?ServiceInfo/service_name=HDFS',
'mock': '',
'type': 'POST',
- 'format': function (data) {
+ 'format': function() {
return {
data: JSON.stringify({
"components": [
@@ -904,7 +896,7 @@ var urls = {
'real': '/clusters/{clusterName}/services?ServiceInfo/service_name=HDFS',
'mock': '',
'type': 'POST',
- 'format': function (data) {
+ 'format': function() {
return {
data: JSON.stringify({
"components": [
@@ -1026,7 +1018,7 @@ var urls = {
'admin.security.cluster_configs': {
'real': '/clusters/{clusterName}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
timeout: 10000
};
@@ -1040,7 +1032,7 @@ var urls = {
'admin.get.all_configurations': {
'real': '/clusters/{clusterName}/configurations?{urlParams}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
timeout: 10000
};
@@ -1049,7 +1041,7 @@ var urls = {
'admin.security.apply_configurations': {
'real': '/clusters/{clusterName}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
type: 'PUT',
timeout: 10000,
@@ -1060,7 +1052,7 @@ var urls = {
'admin.security.apply_configuration': {
'real': '/clusters/{clusterName}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function(data) {
return {
type: 'PUT',
async: false,
@@ -1072,7 +1064,7 @@ var urls = {
'admin.security.add.cluster_configs': {
'real': '/clusters/{clusterName}' + '?fields=Clusters/desired_configs',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
timeout: 10000
};
@@ -1081,7 +1073,7 @@ var urls = {
'admin.stack_upgrade.run_upgrade': {
'real': '/clusters/{clusterName}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function () {
return {
type: 'PUT',
async: false,
@@ -1092,7 +1084,7 @@ var urls = {
'admin.stack_upgrade.stop_services': {
'real': '/clusters/{clusterName}/services?ServiceInfo/state=STARTED',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function () {
return {
type: 'PUT',
async: false,
@@ -1118,7 +1110,7 @@ var urls = {
'wizard.install_services.add_host_controller.is_retry': {
'real': '/clusters/{cluster}/host_components',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
type: 'PUT',
async: false,
@@ -1129,7 +1121,7 @@ var urls = {
'wizard.install_services.add_host_controller.not_is_retry': {
'real': '/clusters/{cluster}/host_components',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function(data) {
return {
type: 'PUT',
async: false,
@@ -1141,7 +1133,7 @@ var urls = {
'real': '/clusters/{cluster}/host_components?HostRoles/state=INSTALLED',
'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
'type': 'PUT',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
async: false,
data: data.data
@@ -1152,7 +1144,7 @@ var urls = {
'real': '/clusters/{cluster}/services?ServiceInfo/state=INIT',
'mock': '/data/wizard/deploy/2_hosts/poll_1.json',
'type': 'PUT',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
async: false,
data: data.data
@@ -1162,7 +1154,7 @@ var urls = {
'wizard.install_services.add_service_controller.get_failed_host_components': {
'real': '/clusters/{clusterName}/host_components?fields=HostRoles/state,component/ServiceComponentInfo/service_name',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -1171,7 +1163,7 @@ var urls = {
'wizard.service_components': {
'real': '{stackUrl}/stackServices?fields=StackServices',
'mock': '/data/wizard/stack/hdp/version/{stackVersion}.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
timeout: 10000,
async: false
@@ -1181,22 +1173,22 @@ var urls = {
'wizard.step9.installer.launch_start_services': {
'real': '/clusters/{cluster}/services?ServiceInfo/state=INSTALLED¶ms/run_smoke_test=true¶ms/reconfigure_client=false',
'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
- 'format': function (data, opt) {
- var data = {
+ 'format': function (data) {
+ var d = {
type: 'PUT',
async: false,
data: data.data
};
if (App.testMode) {
- data.type = 'GET';
+ d.type = 'GET';
}
- return data;
+ return d;
}
},
'wizard.step9.add_host.launch_start_services': {
'real': '/clusters/{cluster}/host_components',
'mock': '/data/wizard/deploy/5_hosts/poll_6.json',
- 'format': function (data, opt) {
+ 'format': function (data) {
return {
type: 'PUT',
async: false,
@@ -1207,7 +1199,7 @@ var urls = {
'wizard.step8.delete_cluster': {
'real': '/clusters/{name}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
type: 'DELETE',
async: false
@@ -1217,7 +1209,7 @@ var urls = {
'wizard.step8.existing_cluster_names': {
'real': '/clusters',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -1226,7 +1218,7 @@ var urls = {
'wizard.step3.host_info': {
'real': '/hosts?fields=Hosts/total_mem,Hosts/cpu_count,Hosts/disk_info,Hosts/last_agent_env,Hosts/host_name,Hosts/os_type,Hosts/os_arch,Hosts/ip',
'mock': '/data/wizard/bootstrap/two_hosts_information.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
contentType: 'application/json'
};
@@ -1235,7 +1227,7 @@ var urls = {
'wizard.step3.rerun_checks': {
'real': '/hosts?fields=Hosts/last_agent_env',
'mock': '/data/wizard/bootstrap/two_hosts_information.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
contentType: 'application/json'
};
@@ -1252,7 +1244,7 @@ var urls = {
'wizard.stacks': {
'real': '/stacks2',
'mock': '/data/wizard/stack/stacks2.json',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -1261,7 +1253,7 @@ var urls = {
'wizard.stacks_versions': {
'real': '/stacks2/{stackName}/versions?fields=Versions,operatingSystems/repositories/Repositories',
'mock': '/data/wizard/stack/{stackName}_versions.json',
- 'format': function (data) {
+ 'format': function() {
return {
async: false
};
@@ -1282,7 +1274,7 @@ var urls = {
'router.login': {
'real': '/users/{loginName}',
'mock': '/data/users/user_{usr}.json',
- 'format': function (data, opt) {
+ 'format': function (data) {
var statusCode = jQuery.extend({}, require('data/statusCodes'));
statusCode['403'] = function () {
console.log("Error code 403: Forbidden.");
@@ -1303,7 +1295,7 @@ var urls = {
'router.set_ambari_stacks': {
'real': '/stacks',
'mock': '/data/wizard/stack/stacks.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -1312,7 +1304,7 @@ var urls = {
'router.authentication': {
'real': '/clusters',
'mock': '/data/clusters/info.json',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -1325,7 +1317,7 @@ var urls = {
'dashboard.get.user_pref': {
'real': '/persist/{key}',
'mock': '',
- 'format': function (data, opt) {
+ 'format': function() {
return {
async: false
};
@@ -1396,15 +1388,15 @@ var urls = {
'request_schedule.delete': {
'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
'mock': '',
- 'format' : function(data) {
+ 'format' : function() {
return {
- type : 'DELETE',
+ type : 'DELETE'
}
}
},
'request_schedule.get': {
'real': '/clusters/{clusterName}/request_schedules/{request_schedule_id}',
- 'mock': '',
+ 'mock': ''
},
'restart.service.hostComponents' : {
'real' : '/clusters/{clusterName}/requests',
@@ -1435,7 +1427,7 @@ var urls = {
'mirroring.get_dataset_definition': {
'real': 'falcon/entities/definition/feed/{dataset}',
'mock': '/data/mirroring/{dataset}_definition.xml',
- 'format': function (data) {
+ 'format': function () {
return {
dataType: 'xml'
}
@@ -1627,7 +1619,7 @@ var ajax = Em.Object.extend({
config.sender[config.beforeSend](opt, xhr, params);
}
};
- opt.success = function (data, textStatus, xhr) {
+ opt.success = function (data) {
console.log("TRACE: The url is: " + opt.url);
if (config.success) {
config.sender[config.success](data, opt, params);
@@ -1709,11 +1701,7 @@ if ($.mocho) {
* @returns {Array}
*/
fakeGetUrlNames: function() {
- var names = [];
- for (var name in urls) {
- names.push(name);
- }
- return names;
+ return Em.keys(urls);
},
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/utils/helper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/helper.js b/ambari-web/app/utils/helper.js
index 3c892cd..85996c5 100644
--- a/ambari-web/app/utils/helper.js
+++ b/ambari-web/app/utils/helper.js
@@ -23,85 +23,19 @@ String.prototype.trim = function () {
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
+
String.prototype.startsWith = function (prefix){
return this.indexOf(prefix) == 0;
};
+
String.prototype.contains = function(substring) {
return this.indexOf(substring) != -1;
};
-/**
- * convert ip address string to long int
- * @return {*}
- */
-String.prototype.ip2long = function () {
- // * example 1: ip2long('192.0.34.166');
- // * returns 1: 3221234342
- // * example 2: ip2long('0.0xABCDEF');
- // * returns 2: 11259375
- // * example 3: ip2long('255.255.255.256');
- // * returns 3: false
- // PHP allows decimal, octal, and hexadecimal IP components.
- // PHP allows between 1 (e.g. 127) to 4 (e.g 127.0.0.1) components.
- var IP = this.match(/^([1-9]\d*|0[0-7]*|0x[\da-f]+)(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?$/i); // Verify IP format.
- if (!IP) {
- return false; // Invalid format.
- }
- // Reuse IP variable for component counter.
- IP[0] = 0;
- for (var i = 1; i < 5; i += 1) {
- IP[0] += !!((IP[i] || '').length);
- IP[i] = parseInt(IP[i]) || 0;
- }
- // Continue to use IP for overflow values.
- // PHP does not allow any component to overflow.
- IP.push(256, 256, 256, 256);
- // Recalculate overflow of last component supplied to make up for missing components.
- IP[4 + IP[0]] *= Math.pow(256, 4 - IP[0]);
- if (IP[1] >= IP[5] || IP[2] >= IP[6] || IP[3] >= IP[7] || IP[4] >= IP[8]) {
- return false;
- }
- return IP[1] * (IP[0] === 1 || 16777216) + IP[2] * (IP[0] <= 2 || 65536) + IP[3] * (IP[0] <= 3 || 256) + IP[4] * 1;
-};
-
String.prototype.capitalize = function () {
return this.charAt(0).toUpperCase() + this.slice(1);
};
-Em.CoreObject.reopen({
- t:function (key, attrs) {
- return Em.I18n.t(key, attrs)
- }
-});
-
-Em.Handlebars.registerHelper('log', function (variable) {
- console.log(variable);
-});
-
-Em.Handlebars.registerHelper('warn', function (variable) {
- console.warn(variable);
-});
-
-Em.Handlebars.registerHelper('highlight', function (property, words, fn) {
- var context = (fn.contexts && fn.contexts[0]) || this;
- property = Em.Handlebars.getPath(context, property, fn);
-
- words = words.split(";");
-
-// if (highlightTemplate == undefined) {
- var highlightTemplate = "<b>{0}</b>";
-// }
-
- words.forEach(function (word) {
- var searchRegExp = new RegExp("\\b" + word + "\\b", "gi");
- property = property.replace(searchRegExp, function (found) {
- return highlightTemplate.format(found);
- });
- });
-
- return new Em.Handlebars.SafeString(property);
-});
-
/**
* Replace {i} with argument. where i is number of argument to replace with
* @return {String}
@@ -115,9 +49,7 @@ String.prototype.format = function () {
String.prototype.highlight = function (words, highlightTemplate) {
var self = this;
- if (highlightTemplate == undefined) {
- var highlightTemplate = "<b>{0}</b>";
- }
+ highlightTemplate = highlightTemplate ? highlightTemplate : "<b>{0}</b>";
words.forEach(function (word) {
var searchRegExp = new RegExp("\\b" + word + "\\b", "gi");
@@ -129,10 +61,6 @@ String.prototype.highlight = function (words, highlightTemplate) {
return self;
};
-Array.prototype.move = function(from, to) {
- this.splice(to, 0, this.splice(from, 1)[0]);
-};
-
Number.prototype.toDaysHoursMinutes = function () {
var formatted = {},
dateDiff = this,
@@ -151,67 +79,41 @@ Number.prototype.toDaysHoursMinutes = function () {
return formatted;
};
-Number.prototype.countPercentageRatio = function (maxValue) {
- var usedValue = this;
- return Math.round((usedValue / maxValue) * 100) + "%";
-};
+Em.CoreObject.reopen({
+ t:function (key, attrs) {
+ return Em.I18n.t(key, attrs)
+ }
+});
-Number.prototype.long2ip = function () {
- // http://kevin.vanzonneveld.net
- // + original by: Waldo Malqui Silva
- // * example 1: long2ip( 3221234342 );
- // * returns 1: '192.0.34.166'
- if (!isFinite(this))
- return false;
+Em.Handlebars.registerHelper('log', function (variable) {
+ console.log(variable);
+});
- return [this >>> 24, this >>> 16 & 0xFF, this >>> 8 & 0xFF, this & 0xFF].join('.');
-};
+Em.Handlebars.registerHelper('warn', function (variable) {
+ console.warn(variable);
+});
-/**
- * Formats the given URL template by replacing keys in 'substitutes'
- * with their values. If not in App.testMode, the testUrl is used.
- *
- * The substitution points in urlTemplate should be of format "...{key}..."
- * For example "http://apache.org/{projectName}".
- * The substitutes can then be{projectName: "Ambari"}.
- *
- * Keys which will be automatically taken care of are:
- * {
- * hostName: App.test_hostname,
- * fromSeconds: ..., // 1 hour back from now
- * toSeconds: ..., // now
- * stepSeconds: ..., // 15 seconds by default
- * }
- *
- * @param {String} urlTemplate URL template on which substitutions are to be made
- * @param substitutes Object containing keys to be replaced with respective values
- * @param {String} testUrl URL to be used if app is not in test mode (!App.testMode)
- * @return {String} Formatted URL
- */
-App = require('app');
+Em.Handlebars.registerHelper('highlight', function (property, words, fn) {
+ var context = (fn.contexts && fn.contexts[0]) || this;
+ property = Em.Handlebars.getPath(context, property, fn);
-App.formatUrl = function (urlTemplate, substitutes, testUrl) {
- var formatted = urlTemplate;
- if (urlTemplate) {
- if (!App.testMode) {
- var toSeconds = Math.round(new Date().getTime() / 1000);
- var allSubstitutes = {
- toSeconds:toSeconds,
- fromSeconds:toSeconds - 3600, // 1 hour back
- stepSeconds:15, // 15 seconds
- hostName:App.test_hostname
- };
- jQuery.extend(allSubstitutes, substitutes);
- for (var key in allSubstitutes) {
- var useKey = '{' + key + '}';
- formatted = formatted.replace(new RegExp(useKey, 'g'), allSubstitutes[key]);
- }
- } else {
- formatted = testUrl;
- }
- }
- return formatted;
-};
+ words = words.split(";");
+
+// if (highlightTemplate == undefined) {
+ var highlightTemplate = "<b>{0}</b>";
+// }
+
+ words.forEach(function (word) {
+ var searchRegExp = new RegExp("\\b" + word + "\\b", "gi");
+ property = property.replace(searchRegExp, function (found) {
+ return highlightTemplate.format(found);
+ });
+ });
+
+ return new Em.Handlebars.SafeString(property);
+});
+
+App = require('app');
/**
* Certain variables can have JSON in string
@@ -225,150 +127,85 @@ App.parseJSON = function (value) {
};
App.format = {
+
+ /**
+ * @type Object
+ */
+ components: {
+ 'APP_TIMELINE_SERVER': 'App Timeline Server',
+ 'DATANODE': 'DataNode',
+ 'DECOMMISSION_DATANODE': 'Update Exclude File',
+ 'DRPC_SERVER': 'DRPC Server',
+ 'FALCON': 'Falcon',
+ 'FALCON_SERVER': 'Falcon Server',
+ 'FALCON_SERVICE_CHECK': 'Falcon Service Check',
+ 'FLUME_SERVER': 'Flume Agent',
+ 'GANGLIA_MONITOR': 'Ganglia Monitor',
+ 'GANGLIA_SERVER': 'Ganglia Server',
+ 'GLUSTERFS_CLIENT': 'GLUSTERFS Client',
+ 'GLUSTERFS_SERVICE_CHECK': 'GLUSTERFS Service Check',
+ 'GMETAD_SERVICE_CHECK': 'Gmetad Service Check',
+ 'GMOND_SERVICE_CHECK': 'Gmond Service Check',
+ 'HADOOP_CLIENT': 'Hadoop Client',
+ 'HBASE_CLIENT': 'HBase Client',
+ 'HBASE_MASTER': 'HBase Master',
+ 'HBASE_REGIONSERVER': 'HBase RegionServer',
+ 'HBASE_SERVICE_CHECK': 'HBase Service Check',
+ 'HCAT': 'HCat',
+ 'HCAT_SERVICE_CHECK': 'HCat Service Check',
+ 'HDFS_CLIENT': 'HDFS Client',
+ 'HDFS_SERVICE_CHECK': 'HDFS Service Check',
+ 'HISTORYSERVER': 'History Server',
+ 'HIVE_CLIENT': 'Hive Client',
+ 'HIVE_METASTORE': 'Hive Metastore',
+ 'HIVE_SERVER': 'HiveServer2',
+ 'HIVE_SERVICE_CHECK': 'Hive Service Check',
+ 'HUE_SERVER': 'Hue Server',
+ 'JAVA_JCE': 'Java JCE',
+ 'JOBTRACKER': 'JobTracker',
+ 'JOBTRACKER_SERVICE_CHECK': 'JobTracker Service Check',
+ 'JOURNALNODE': 'JournalNode',
+ 'KERBEROS_ADMIN_CLIENT': 'Kerberos Admin Client',
+ 'KERBEROS_CLIENT': 'Kerberos Client',
+ 'KERBEROS_SERVER': 'Kerberos Server',
+ 'LOGVIEWER_SERVER': 'Logviewer Server',
+ 'MAPREDUCE2_CLIENT': 'MapReduce2 Client',
+ 'MAPREDUCE2_SERVICE_CHECK': 'MapReduce2 Service Check',
+ 'MAPREDUCE_CLIENT': 'MapReduce Client',
+ 'MAPREDUCE_SERVICE_CHECK': 'MapReduce Service Check',
+ 'MYSQL_SERVER': 'MySQL Server',
+ 'NAGIOS_SERVER': 'Nagios Server',
+ 'NAMENODE': 'NameNode',
+ 'NAMENODE_SERVICE_CHECK': 'NameNode Service Check',
+ 'NIMBUS': 'Nimbus',
+ 'NODEMANAGER': 'NodeManager',
+ 'OOZIE_CLIENT': 'Oozie Client',
+ 'OOZIE_SERVER': 'Oozie Server',
+ 'OOZIE_SERVICE_CHECK': 'Oozie Service Check',
+ 'PIG': 'Pig',
+ 'PIG_SERVICE_CHECK': 'Pig Service Check',
+ 'RESOURCEMANAGER': 'ResourceManager',
+ 'SECONDARY_NAMENODE': 'SNameNode',
+ 'SQOOP': 'Sqoop',
+ 'SQOOP_SERVICE_CHECK': 'Sqoop Service Check',
+ 'STORM_SERVICE_CHECK': 'Storm Service Check',
+ 'STORM_UI_SERVER': 'Storm UI Server',
+ 'SUPERVISOR': 'Supervisor',
+ 'TASKTRACKER': 'TaskTracker',
+ 'TEZ_CLIENT': 'Tez Client',
+ 'WEBHCAT_SERVER': 'WebHCat Server',
+ 'WEBHCAT_SERVICE_CHECK': 'WebHCat Service Check',
+ 'YARN_CLIENT': 'YARN Client',
+ 'YARN_SERVICE_CHECK': 'YARN Service Check',
+ 'ZKFC': 'ZKFailoverController',
+ 'ZOOKEEPER_CLIENT': 'ZooKeeper Client',
+ 'ZOOKEEPER_QUORUM_SERVICE_CHECK': 'ZK Quorum Service Check',
+ 'ZOOKEEPER_SERVER': 'ZooKeeper Server',
+ 'ZOOKEEPER_SERVICE_CHECK': 'ZooKeeper Service Check'
+ },
+
role:function (role) {
- switch (role) {
- case 'ZOOKEEPER_SERVER':
- return 'ZooKeeper Server';
- case 'ZOOKEEPER_CLIENT':
- return 'ZooKeeper Client';
- case 'NAMENODE':
- return 'NameNode';
- case 'NAMENODE_SERVICE_CHECK':
- return 'NameNode Service Check';
- case 'DATANODE':
- return 'DataNode';
- case 'JOURNALNODE':
- return 'JournalNode';
- case 'HDFS_SERVICE_CHECK':
- return 'HDFS Service Check';
- case 'SECONDARY_NAMENODE':
- return 'SNameNode';
- case 'HDFS_CLIENT':
- return 'HDFS Client';
- case 'HBASE_MASTER':
- return 'HBase Master';
- case 'HBASE_REGIONSERVER':
- return 'HBase RegionServer';
- case 'HBASE_CLIENT':
- return 'HBase Client';
- case 'JOBTRACKER':
- return 'JobTracker';
- case 'TASKTRACKER':
- return 'TaskTracker';
- case 'MAPREDUCE_CLIENT':
- return 'MapReduce Client';
- case 'HISTORYSERVER':
- return 'History Server';
- case 'NODEMANAGER':
- return 'NodeManager';
- case 'RESOURCEMANAGER':
- return 'ResourceManager';
- case 'TEZ_CLIENT':
- return 'Tez Client';
- case 'MAPREDUCE2_CLIENT':
- return 'MapReduce2 Client';
- case 'YARN_CLIENT':
- return 'YARN Client';
- case 'APP_TIMELINE_SERVER':
- return 'App Timeline Server';
- case 'JAVA_JCE':
- return 'Java JCE';
- case 'KERBEROS_SERVER':
- return 'Kerberos Server';
- case 'KERBEROS_CLIENT':
- return 'Kerberos Client';
- case 'KERBEROS_ADMIN_CLIENT':
- return 'Kerberos Admin Client';
- case 'HADOOP_CLIENT':
- return 'Hadoop Client';
- case 'JOBTRACKER_SERVICE_CHECK':
- return 'JobTracker Service Check';
- case 'MAPREDUCE_SERVICE_CHECK':
- return 'MapReduce Service Check';
- case 'ZOOKEEPER_SERVICE_CHECK':
- return 'ZooKeeper Service Check';
- case 'ZOOKEEPER_QUORUM_SERVICE_CHECK':
- return 'ZK Quorum Service Check';
- case 'HBASE_SERVICE_CHECK':
- return 'HBase Service Check';
- case 'MYSQL_SERVER':
- return 'MySQL Server';
- case 'HIVE_SERVER':
- return 'HiveServer2';
- case 'HIVE_METASTORE':
- return 'Hive Metastore';
- case 'HIVE_CLIENT':
- return 'Hive Client';
- case 'HIVE_SERVICE_CHECK':
- return 'Hive Service Check';
- case 'HCAT':
- return 'HCat';
- case 'HCAT_SERVICE_CHECK':
- return 'HCat Service Check';
- case 'OOZIE_CLIENT':
- return 'Oozie Client';
- case 'OOZIE_SERVER':
- return 'Oozie Server';
- case 'OOZIE_SERVICE_CHECK':
- return 'Oozie Service Check';
- case 'PIG':
- return 'Pig';
- case 'PIG_SERVICE_CHECK':
- return 'Pig Service Check';
- case 'MAPREDUCE2_SERVICE_CHECK':
- return 'MapReduce2 Service Check';
- case 'YARN_SERVICE_CHECK':
- return 'YARN Service Check';
- case 'SQOOP':
- return 'Sqoop';
- case 'SQOOP_SERVICE_CHECK':
- return 'Sqoop Service Check';
- case 'WEBHCAT_SERVER':
- return 'WebHCat Server';
- case 'WEBHCAT_SERVICE_CHECK':
- return 'WebHCat Service Check';
- case 'STORM_SERVICE_CHECK':
- return 'Storm Service Check';
- case 'FALCON_SERVICE_CHECK':
- return 'Falcon Service Check';
- case 'FALCON_SERVER':
- return 'Falcon Server';
- case 'FALCON':
- return 'Falcon';
- case 'NAGIOS_SERVER':
- return 'Nagios Server';
- case 'GANGLIA_SERVER':
- return 'Ganglia Server';
- case 'GANGLIA_MONITOR':
- return 'Ganglia Monitor';
- case 'GMOND_SERVICE_CHECK':
- return 'Gmond Service Check';
- case 'GMETAD_SERVICE_CHECK':
- return 'Gmetad Service Check';
- case 'DECOMMISSION_DATANODE':
- return 'Update Exclude File';
- case 'HUE_SERVER':
- return 'Hue Server';
- case 'GLUSTERFS_CLIENT':
- return 'GLUSTERFS Client';
- case 'GLUSTERFS_SERVICE_CHECK':
- return 'GLUSTERFS Service Check';
- case 'FLUME_SERVER':
- return 'Flume Agent';
- case 'ZKFC':
- return 'ZKFailoverController';
- case 'NIMBUS':
- return 'Nimbus';
- case 'SUPERVISOR':
- return 'Supervisor';
- case 'STORM_UI_SERVER':
- return 'Storm UI Server';
- case 'DRPC_SERVER':
- return 'DRPC Server';
- case 'LOGVIEWER_SERVER':
- return 'Logviewer Server';
- }
- return '';
+ return this.components[role] ? this.components[role] : '';
},
/**
@@ -450,6 +287,7 @@ App.registerBoundHelper('pluralize', Em.View.extend({
return singular;
}
}
+ return '';
},
/*
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/app/utils/http_client.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/http_client.js b/ambari-web/app/utils/http_client.js
index b11d27d..0000444 100644
--- a/ambari-web/app/utils/http_client.js
+++ b/ambari-web/app/utils/http_client.js
@@ -39,7 +39,9 @@ App.HttpClient = Em.Object.create({
if (json) {
Em.assert("HttpClient:", json);
} else {
- Em.assert("HttpClient:", errorThrown);
+ if (!$.mocho) { // don't use this assert on tests
+ Em.assert("HttpClient:", errorThrown);
+ }
}
},
@@ -50,7 +52,7 @@ App.HttpClient = Em.Object.create({
* @param {string} url
* @param {Object} ajaxOptions
* @param {App.ServerDataMapper} mapper - json processor
- * @param {function} errorHandler
+ * @param {callback} errorHandler
*/
request: function (url, ajaxOptions, mapper, errorHandler) {
@@ -103,11 +105,10 @@ App.HttpClient = Em.Object.create({
* @param {string} url
* @param {App.ServerDataMapper} mapper - json processor
* @param {Object} data - ajax data property
- * @param {function} errorHandler
+ * @param {callback} errorHandler
* @param {number} interval - frequency request
*/
get: function (url, mapper, data, errorHandler, interval) {
- var eHandler = data.complete;
if (!errorHandler && data.error) {
errorHandler = data.error;
}
@@ -132,7 +133,7 @@ App.HttpClient = Em.Object.create({
* @param {string} url
* @param {Object} data - ajax data property
* @param {App.ServerDataMapper} mapper - json processor
- * @param {function} errorHandler
+ * @param {callback} errorHandler
* @param {number} interval - frequecy request
*/
post: function (url, data, mapper, errorHandler, interval) {
http://git-wip-us.apache.org/repos/asf/ambari/blob/dce0e204/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js b/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
index 7d3a02b..a8bbe85 100644
--- a/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
+++ b/ambari-web/test/controllers/main/charts/heatmap_metrics/heatmap_metric_test.js
@@ -37,8 +37,34 @@ describe('MainChartHeatmapMetric', function () {
it('NaN to NaN' + ' ', function () {
expect(isNaN(mainChartHeatmapMetric.formatLegendNumber(NaN))).to.equal(true);
});
- })
+ });
+ describe('#refreshHostSlots', function() {
+ beforeEach(function() {
+ App.set('apiPrefix', '/api/v1');
+ App.set('clusterName', 'tdk');
+ App.testMode = false;
+ sinon.spy($, 'ajax');
+ });
+
+ afterEach(function() {
+ $.ajax.restore();
+ App.testMode = true;
+ });
+
+ mainChartHeatmapMetric = App.MainChartHeatmapMetric.create({});
+ mainChartHeatmapMetric.set('ajaxIndex', 'hosts.metrics.host_component');
+ mainChartHeatmapMetric.set('ajaxData', {
+ serviceName: 'SERVICE',
+ componentName: 'COMPONENT'
+ });
+ mainChartHeatmapMetric.set('defaultMetric', 'default.metric');
+
+ it('Should load proper URL', function() {
+ mainChartHeatmapMetric.refreshHostSlots();
+ expect($.ajax.args[0][0].url.endsWith('/api/v1/clusters/tdk/services/SERVICE/components/COMPONENT?fields=host_components/default/metric')).to.equal(true);
+ });
+ });
});