incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jai...@apache.org
Subject git commit: AMBARI-2807: Security wizard: Apply configurations API calls should be batched to a single call. (jaimin)
Date Thu, 12 Sep 2013 21:31:42 GMT
Updated Branches:
  refs/heads/trunk 0b010afb0 -> aacb46fbd


AMBARI-2807: Security wizard: Apply configurations API calls should be batched to a single
call. (jaimin)


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

Branch: refs/heads/trunk
Commit: aacb46fbdd4de5fd30ddbbf55eeb5d03823e7ea3
Parents: 0b010af
Author: Jaimin Jetly <jaimin@hortonworks.com>
Authored: Thu Sep 12 14:30:55 2013 -0700
Committer: Jaimin Jetly <jaimin@hortonworks.com>
Committed: Thu Sep 12 14:31:03 2013 -0700

----------------------------------------------------------------------
 .../main/admin/security/add/step4.js            | 61 ++++++++++----------
 .../controllers/main/admin/security/disable.js  | 32 +++++-----
 ambari-web/app/utils/ajax.js                    | 24 +++++++-
 3 files changed, 69 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/aacb46fb/ambari-web/app/controllers/main/admin/security/add/step4.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security/add/step4.js b/ambari-web/app/controllers/main/admin/security/add/step4.js
index caccb82..af5ea30 100644
--- a/ambari-web/app/controllers/main/admin/security/add/step4.js
+++ b/ambari-web/app/controllers/main/admin/security/add/step4.js
@@ -20,15 +20,15 @@ var App = require('app');
 App.MainAdminSecurityAddStep4Controller = Em.Controller.extend({
 
   name: 'mainAdminSecurityAddStep4Controller',
-  secureMapping: function() {
-    if(App.get('isHadoop2Stack')) {
+  secureMapping: function () {
+    if (App.get('isHadoop2Stack')) {
       return require('data/HDP2/secure_mapping');
     } else {
       return require('data/secure_mapping');
     }
   }.property(App.isHadoop2Stack),
-  secureProperties: function() {
-    if(App.get('isHadoop2Stack')) {
+  secureProperties: function () {
+    if (App.get('isHadoop2Stack')) {
       return require('data/HDP2/secure_properties').configProperties;
     } else {
       return require('data/secure_properties').configProperties;
@@ -471,9 +471,6 @@ App.MainAdminSecurityAddStep4Controller = Em.Controller.extend({
 
 
   loadClusterConfigs: function () {
-    var self = this;
-    var url = App.apiPrefix + '/clusters/' + App.router.getClusterName();
-
     App.ajax.send({
       name: 'admin.security.add.cluster_configs',
       sender: this,
@@ -521,36 +518,38 @@ App.MainAdminSecurityAddStep4Controller = Em.Controller.extend({
   },
 
   applyConfigurationsToCluster: function () {
-    this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length);
+    var configData = [];
     this.get('serviceConfigTags').forEach(function (_serviceConfig) {
-      this.applyConfigurationToCluster({type: _serviceConfig.siteName, tag: _serviceConfig.newTagName,
properties: _serviceConfig.configs});
+      var Clusters = {
+        Clusters: {
+          desired_config: {
+            type: _serviceConfig.siteName,
+            tag: _serviceConfig.newTagName,
+            properties: _serviceConfig.configs
+          }
+        }
+      };
+      configData.pushObject(JSON.stringify(Clusters));
     }, this);
-  },
 
-  applyConfigurationToCluster: function (data) {
-    var clusterData = {
-      Clusters: {
-        desired_config: data
-      }
+    var data = {
+      configData: '[' + configData.toString() + ']'
     };
+
     App.ajax.send({
-      name: 'admin.security.apply_configuration',
+      name: 'admin.security.apply_configurations',
       sender: this,
-      data: {
-        clusterData: clusterData
-      },
+      data: data,
+      deferred: true,
       success: 'applyConfigurationToClusterSuccessCallback',
       error: 'applyConfigurationToClusterErrorCallback'
     });
   },
 
   applyConfigurationToClusterSuccessCallback: function (data) {
-    this.set('noOfWaitingAjaxCalls', this.get('noOfWaitingAjaxCalls') - 1);
-    if (this.get('noOfWaitingAjaxCalls') == 0) {
-      var currentStage = this.get('stages').findProperty('stage', 'stage3');
-      currentStage.set('isSuccess', true);
-      currentStage.set('isError', false);
-    }
+    var currentStage = this.get('stages').findProperty('stage', 'stage3');
+    currentStage.set('isSuccess', true);
+    currentStage.set('isError', false);
   },
 
   applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {
@@ -614,15 +613,15 @@ App.MainAdminSecurityAddStep4Controller = Em.Controller.extend({
   },
 
   /*
-    Iterate over keys of all configurations and escape xml characters in their values
+   Iterate over keys of all configurations and escape xml characters in their values
    */
-  escapeXMLCharacters: function(serviceConfigTags) {
+  escapeXMLCharacters: function (serviceConfigTags) {
     serviceConfigTags.forEach(function (_serviceConfigTags) {
       var configs = _serviceConfigTags.configs;
-        for (var key in configs) {
-          configs[key] =  App.config.escapeXMLCharacters(configs[key]);
-        }
-    },this);
+      for (var key in configs) {
+        configs[key] = App.config.escapeXMLCharacters(configs[key]);
+      }
+    }, this);
   },
 
   addSecureConfigs: function () {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/aacb46fb/ambari-web/app/controllers/main/admin/security/disable.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security/disable.js b/ambari-web/app/controllers/main/admin/security/disable.js
index 4ec152f..8fcae55 100644
--- a/ambari-web/app/controllers/main/admin/security/disable.js
+++ b/ambari-web/app/controllers/main/admin/security/disable.js
@@ -316,36 +316,38 @@ App.MainAdminSecurityDisableController = Em.Controller.extend({
   },
 
   applyConfigurationsToCluster: function () {
-    this.set('noOfWaitingAjaxCalls', this.get('serviceConfigTags').length);
+    var configData = [];
     this.get('serviceConfigTags').forEach(function (_serviceConfig) {
-      this.applyConfigurationToCluster({type: _serviceConfig.siteName, tag: _serviceConfig.newTagName,
properties: _serviceConfig.configs});
+      var Clusters = {
+        Clusters: {
+          desired_config: {
+            type: _serviceConfig.siteName,
+            tag: _serviceConfig.newTagName,
+            properties: _serviceConfig.configs
+          }
+        }
+      };
+      configData.pushObject(JSON.stringify(Clusters));
     }, this);
-  },
 
-  applyConfigurationToCluster: function (data) {
-    var clusterData = {
-      Clusters: {
-        desired_config: data
-      }
+    var data =  {
+      configData: '[' + configData.toString() + ']'
     };
+
     App.ajax.send({
-      name: 'admin.security.apply_configuration',
+      name: 'admin.security.apply_configurations',
       sender: this,
-      data: {
-        clusterData: clusterData
-      },
+      data: data,
+      deferred: true,
       success: 'applyConfigurationToClusterSuccessCallback',
       error: 'applyConfigurationToClusterErrorCallback'
     });
   },
 
   applyConfigurationToClusterSuccessCallback: function (data) {
-    this.set('noOfWaitingAjaxCalls', this.get('noOfWaitingAjaxCalls') - 1);
-    if (this.get('noOfWaitingAjaxCalls') == 0) {
       var currentStage = this.get('stages').findProperty('stage', 'stage3');
       currentStage.set('isSuccess', true);
       currentStage.set('isError', false);
-    }
   },
 
   applyConfigurationToClusterErrorCallback: function (request, ajaxOptions, error) {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/aacb46fb/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index 419a3ab..680437f 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -809,6 +809,16 @@ var urls = {
       };
     }
   },
+  'admin.security.apply_configurations': {
+    'real': '/clusters/{clusterName}',
+    'format': function (data, opt) {
+      return {
+        type: 'PUT',
+        timeout: 10000,
+        data:data.configData
+      };
+    }
+  },
   'admin.security.apply_configuration': {
     'real': '/clusters/{clusterName}',
     'format': function (data, opt) {
@@ -821,7 +831,7 @@ var urls = {
     }
   },
   'admin.security.add.cluster_configs': {
-    'real': '/clusters/{clusterName}',
+    'real': '/clusters/{clusterName}' + '?fields=Clusters/desired_configs',
     'format': function (data, opt) {
       return {
         timeout: 10000
@@ -1116,6 +1126,7 @@ App.ajax = {
    *  beforeSend - method-name for ajax beforeSend response callback
    *  success - method-name for ajax success response callback
    *  error - method-name for ajax error response callback
+   *  deferred - A flag that will call jquery.when for asynchronous call. This should be
used instead of setting async to false
    *  callback - callback from <code>App.updater.run</code> library
    */
   send: function (config) {
@@ -1169,7 +1180,16 @@ App.ajax = {
     if ($.mocho) {
       opt.url = 'http://' + $.hostName + opt.url;
     }
-    return $.ajax(opt);
+    if (config.deferred === true) {
+      var successCallback = opt.success;
+      var errorCallback = opt.error;
+      delete opt['success'];
+      delete opt['error'];
+      delete opt['async'];
+      $.when($.ajax(opt)).then(successCallback,errorCallback);
+    } else {
+      return $.ajax(opt);
+    }
   },
 
   // A single instance of App.ModalPopup view


Mime
View raw message