You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by al...@apache.org on 2014/08/28 00:50:06 UTC

git commit: AMBARI-7045. Slider View: When creating slider app, update Ganglia server host value (alexantonenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk 4c5ed4c0c -> 9dcb434ea


AMBARI-7045. Slider View: When creating slider app, update Ganglia server host value (alexantonenko)


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

Branch: refs/heads/trunk
Commit: 9dcb434eab370bafc3410e9fd80d8bef33008cb6
Parents: 4c5ed4c
Author: Alex Antonenko <hi...@gmail.com>
Authored: Wed Aug 27 21:34:22 2014 +0300
Committer: Alex Antonenko <hi...@gmail.com>
Committed: Thu Aug 28 01:49:20 2014 +0300

----------------------------------------------------------------------
 .../createAppWizard/step1_controller.js         | 30 ++++++++++++++++++++
 .../createAppWizard/step3_controller.js         |  9 ++++--
 .../src/main/resources/ui/app/helpers/ajax.js   | 27 ++++++++++++++++--
 .../src/main/resources/ui/app/initialize.js     |  2 ++
 .../ui/app/mappers/application_status.js        | 25 ++++++++++++++++
 5 files changed, 89 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9dcb434e/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js
index 9bfe68c..42c0080 100644
--- a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js
+++ b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js
@@ -81,11 +81,41 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend({
    * @method loadStep
    */
   loadStep: function () {
+    this.loadGangliaHost();
     this.initializeNewApp();
     this.loadAvailableTypes();
   },
 
   /**
+   * Load ganglia server host
+   * @method loadGangliaHost
+   */
+  loadGangliaHost: function () {
+    return App.ajax.send({
+      name: 'components_hosts',
+      sender: this,
+      data: {
+        componentName: "GANGLIA_SERVER",
+        urlPrefix: '/api/v1/'
+      },
+      success: 'loadGangliaHostSuccessCallback'
+    });
+
+  },
+
+  /**
+   * Success callback for hosts-request
+   * Save host name to gangliaHost
+   * @param {Object} data
+   * @method loadGangliaHostSuccessCallback
+   */
+  loadGangliaHostSuccessCallback: function (data) {
+    if(data.items[0]){
+      App.set('gangliaHost', Em.get(data.items[0], 'Hosts.host_name'));
+    }
+  },
+
+  /**
    * Initialize new App and set it to <code>newApp</code>
    * @method initializeNewApp
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/9dcb434e/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step3_controller.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step3_controller.js b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step3_controller.js
index b98afb4..12dd699 100644
--- a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step3_controller.js
+++ b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step3_controller.js
@@ -65,19 +65,24 @@ App.CreateAppWizardStep3Controller = Ember.ObjectController.extend({
    */
   loadStep: function () {
     this.clearStep();
-    this.initConfigs();
+    this.initConfigs(true);
   },
 
   /**
    * Format init value for <code>configs</code> property
+   * @param {bool} setDefaults
    * @method initConfigs
    */
-  initConfigs: function() {
+  initConfigs: function(setDefaults) {
+    setDefaults = setDefaults === true ? setDefaults : false;
     var configs = this.get('newAppConfigs') || {},
         c = Em.A();
 
     Object.keys(configs).forEach(function (key) {
       var label = (!!key.match('^site.'))?key.substr(5):key;
+      if(key === "site.global.ganglia_server_host" && setDefaults) {
+        configs[key] = App.get('gangliaHost') ? App.get('gangliaHost') : configs[key];
+      }
       c.push({name:key,value:configs[key],label:label})
     });
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/9dcb434e/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js
index 64c8385..255668f 100644
--- a/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js
+++ b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js
@@ -104,6 +104,22 @@ var urls = {
     }
   },
 
+  'components_hosts': {
+    real: 'clusters/{clusterName}/hosts?host_components/HostRoles/component_name={componentName}&minimal_response=true',
+    headers: {
+      Accept : "text/plain; charset=utf-8",
+      "Content-Type": "text/plain; charset=utf-8"
+    }
+  },
+
+  'cluster_name': {
+    real: 'clusters',
+    headers: {
+      Accept : "text/plain; charset=utf-8",
+      "Content-Type": "text/plain; charset=utf-8"
+    }
+  },
+
   'metrics': {
     real: 'apps/{id}/metrics/{metric}',
     mock: '/data/metrics/metric.json'
@@ -169,6 +185,9 @@ var formatRequest = function (data) {
   }
   else {
     var prefix = App.get('urlPrefix');
+    if(Em.get(data, 'urlPrefix')){
+      var prefix = Em.get(data, 'urlPrefix');
+    }
     opt.url = prefix + formatUrl(this.real, data);
   }
 
@@ -204,8 +223,12 @@ var ajax = Em.Object.extend({
     Ember.assert('Ajax sender should be defined!', config.sender);
     Ember.assert('Invalid config.name provided - ' + config.name, urls[config.name]);
 
-    var opt = {},
-      params = {};
+    var opt = {};
+
+    // default parameters
+    var params = {
+      clusterName: App.get('clusterName')
+    };
 
     if (config.data) {
       jQuery.extend(params, config.data);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9dcb434e/contrib/views/slider/src/main/resources/ui/app/initialize.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/initialize.js b/contrib/views/slider/src/main/resources/ui/app/initialize.js
index cc22ba2..e93550f 100755
--- a/contrib/views/slider/src/main/resources/ui/app/initialize.js
+++ b/contrib/views/slider/src/main/resources/ui/app/initialize.js
@@ -82,6 +82,8 @@ App.initializer({
       viewErrors: []
 
     });
+
+    application.ApplicationStatusMapper.getClusterName();
     application.ApplicationStatusMapper.loop('load');
     application.ApplicationTypeMapper.loop('load');
     application.SliderAppsMapper.loop('load');

http://git-wip-us.apache.org/repos/asf/ambari/blob/9dcb434e/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js b/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
index 40a6edf..93a3789 100644
--- a/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
+++ b/contrib/views/slider/src/main/resources/ui/app/mappers/application_status.js
@@ -68,6 +68,31 @@ App.ApplicationStatusMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
     Ember.keys(map).forEach(function(key) {
       App.set(key, Ember.getWithDefault(data, map[key], ''));
     });
+  },
+
+  /**
+   * Get cluster name from server
+   * @returns {$.ajax}
+   * @method getClusterName
+   */
+  getClusterName: function() {
+    return App.ajax.send({
+      name: 'cluster_name',
+      sender: this,
+      data: {
+        urlPrefix: '/api/v1/'
+      },
+      success: 'getClusterNameSuccessCallback'
+    });
+  },
+
+  /**
+   * Success callback for clusterName-request
+   * @param {object} data
+   * @method getClusterNameSuccessCallback
+   */
+  getClusterNameSuccessCallback: function(data) {
+    App.set('clusterName', Em.get(data.items[0], 'Clusters.cluster_name'));
   }
 
 });
\ No newline at end of file