You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2013/10/10 15:57:48 UTC

git commit: AMBARI-3494 UI optimization: control configurations loading. (atkach)

Updated Branches:
  refs/heads/trunk 8d72c0b9e -> 124e06d72


AMBARI-3494 UI optimization: control configurations loading. (atkach)


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

Branch: refs/heads/trunk
Commit: 124e06d72d793ce31e5d5f7805b0c54522ac4806
Parents: 8d72c0b
Author: atkach <an...@gmail.com>
Authored: Thu Oct 10 16:57:44 2013 +0300
Committer: atkach <an...@gmail.com>
Committed: Thu Oct 10 16:57:44 2013 +0300

----------------------------------------------------------------------
 ambari-web/app/controllers.js                   |  1 +
 .../global/configuration_controller.js          | 85 ++++++++++++++++++++
 .../main/admin/highAvailability_controller.js   | 26 +++---
 .../controllers/main/admin/misc_controller.js   |  2 +-
 .../app/controllers/main/admin/security.js      | 30 +++----
 .../controllers/main/service/info/configs.js    |  2 +-
 ambari-web/app/utils/ajax.js                    | 10 ---
 ambari-web/app/utils/db.js                      | 12 +++
 .../app/views/common/quick_view_link_view.js    | 48 ++++-------
 9 files changed, 137 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/controllers.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers.js b/ambari-web/app/controllers.js
index 18312e0..cd1ffb5 100644
--- a/ambari-web/app/controllers.js
+++ b/ambari-web/app/controllers.js
@@ -125,3 +125,4 @@ require('controllers/wizard/stack_upgrade/step2_controller');
 require('controllers/wizard/stack_upgrade/step3_controller');
 require('controllers/global/cluster_controller');
 require('controllers/global/update_controller');
+require('controllers/global/configuration_controller');

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/controllers/global/configuration_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/configuration_controller.js b/ambari-web/app/controllers/global/configuration_controller.js
new file mode 100644
index 0000000..401224d
--- /dev/null
+++ b/ambari-web/app/controllers/global/configuration_controller.js
@@ -0,0 +1,85 @@
+/**
+ * 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');
+
+App.ConfigurationController = Em.Controller.extend({
+  name: 'configurationController',
+
+  getConfigsByTags: function (tags) {
+    var storedTags = [];
+    App.db.getConfigs().forEach(function(site){
+      storedTags.push({
+        siteName: site.type,
+        tagName: site.tag
+      })
+    });
+    if (this.checkTagsChanges(tags, storedTags)) {
+      return this.loadFromServer(tags);
+    } else {
+      return this.loadFromDB(tags.mapProperty('siteName'));
+    }
+  },
+  /**
+   * check whether tag versions have been changed
+   * if they are different then return true
+   * otherwise false
+   * @param tags
+   * @param storedTags
+   * @return {Boolean}
+   */
+  checkTagsChanges: function (tags, storedTags) {
+    var isDifferent = false;
+    var i = 0;
+    while (i < tags.length && !isDifferent) {
+      var storedTag = storedTags.findProperty('siteName', tags[i].siteName);
+      isDifferent = (!storedTag || storedTag.tagName !== tags[i].tagName);
+      i++;
+    }
+    return isDifferent;
+  },
+  loadFromDB: function (siteNames) {
+    var configs = App.db.getConfigs();
+    return configs.filter(function (site) {
+      return (siteNames.contains(site.type));
+    })
+  },
+  /**
+   * load configs from server
+   * and update them in local DB
+   * @param tags
+   * @return {Array}
+   */
+  loadFromServer: function (tags) {
+    var loadedConfigs = App.config.loadConfigsByTags(tags);
+    var storedConfigs = App.db.getConfigs();
+    loadedConfigs.forEach(function (loadedSite) {
+      var storedSite = storedConfigs.findProperty('type', loadedSite.type);
+      if (storedSite) {
+        storedConfigs.tag = loadedSite.tag;
+        storedConfigs.properties = loadedSite.properties;
+      } else {
+        storedConfigs.push(loadedSite);
+      }
+    });
+    App.db.setConfigs(storedConfigs);
+    return loadedConfigs;
+  }
+
+
+});

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/controllers/main/admin/highAvailability_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/highAvailability_controller.js b/ambari-web/app/controllers/main/admin/highAvailability_controller.js
index 73c1ce5..b0e8b26 100644
--- a/ambari-web/app/controllers/main/admin/highAvailability_controller.js
+++ b/ambari-web/app/controllers/main/admin/highAvailability_controller.js
@@ -82,28 +82,20 @@ App.MainAdminHighAvailabilityController = Em.Controller.extend({
   },
 
   getServiceConfigsFromServer: function () {
-    App.ajax.send({
-      name: 'admin.service_config',
-      sender: this,
-      data: {
-        siteName: 'global',
+    var tags = [
+      {
+        siteName: "global",
         tagName: this.get('tag')
-      },
-      success: 'getServiceConfigsFromServerSuccessCallback',
-      error: 'errorCallback'
-    });
-  },
-
-  getServiceConfigsFromServerSuccessCallback: function (data) {
-    var configs = data.items.findProperty('tag', this.get('tag')).properties;
+      }
+    ];
+    var data = App.router.get('configurationController').getConfigsByTags(tags);
+    var configs = data.findProperty('tag', this.get('tag')).properties;
     if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
       this.set('securityEnabled', true);
-      this.set('dataIsLoaded', true);
-    }
-    else {
+    } else {
       this.set('securityEnabled', false);
-      this.set('dataIsLoaded', true);
     }
+    this.set('dataIsLoaded', true);
   },
 
   showErrorPopup: function (message) {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/controllers/main/admin/misc_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/misc_controller.js b/ambari-web/app/controllers/main/admin/misc_controller.js
index db594f6..4b64370 100644
--- a/ambari-web/app/controllers/main/admin/misc_controller.js
+++ b/ambari-web/app/controllers/main/admin/misc_controller.js
@@ -53,7 +53,7 @@ App.MainAdminMiscController = App.MainServiceInfoConfigsController.extend({
       }
     }
     this.setServiceConfigTags(loadedClusterSiteToTagMap);
-    var configGroups = App.config.loadConfigsByTags(this.get('serviceConfigTags'));
+    var configGroups = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
     var configSet = App.config.mergePreDefinedWithLoaded(configGroups, [], this.get('serviceConfigTags'), serviceName);
 
     var misc_configs = configSet.globalConfigs.filterProperty('serviceName', this.get('selectedService')).filterProperty('category', 'Users and Groups').filterProperty('isVisible', true);

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/controllers/main/admin/security.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/security.js b/ambari-web/app/controllers/main/admin/security.js
index e5f2e6d..092a8db 100644
--- a/ambari-web/app/controllers/main/admin/security.js
+++ b/ambari-web/app/controllers/main/admin/security.js
@@ -85,7 +85,7 @@ App.MainAdminSecurityController = Em.Controller.extend({
     services.forEach(function (_secureService) {
       this.setServiceTagNames(_secureService, this.get('desiredConfigs'));
     }, this);
-    var serverConfigs = App.config.loadConfigsByTags(this.get('serviceConfigTags'));
+    var serverConfigs = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
     this.setConfigValuesFromServer(this.get('stepConfigs'), serverConfigs);
 
     this.set('installedServices', App.Service.find().mapProperty('serviceName'));
@@ -280,29 +280,25 @@ App.MainAdminSecurityController = Em.Controller.extend({
   },
 
   getServiceConfigsFromServer: function () {
-    var urlParams = [];
-    urlParams.push('(type=global&tag=' + this.get('tag.global') + ')');
-    urlParams.push('(type=hdfs-site&tag=' + this.get('tag.hdfs-site') + ')');
-    App.ajax.send({
-      name: 'admin.security.all_configurations',
-      sender: this,
-      data: {
-        urlParams: urlParams.join('|')
+    var tags = [
+      {
+        siteName: "global",
+        tagName: this.get('tag.global')
       },
-      success: 'getServiceConfigsFromServerSuccessCallback',
-      error: 'errorCallback'
-    });
-  },
+      {
+        siteName: "hdfs-site",
+        tagName: this.get('tag.hdfs-site')
+      }
+    ];
 
-  getServiceConfigsFromServerSuccessCallback: function (data) {
-    console.log("TRACE: In success function for the GET getServiceConfigsFromServer call");
-    var configs = data.items.findProperty('tag', this.get('tag.global')).properties;
+    var data = App.router.get('configurationController').getConfigsByTags(tags);
+    var configs = data.findProperty('tag', this.get('tag.global')).properties;
     if (configs && (configs['security_enabled'] === 'true' || configs['security_enabled'] === true)) {
       this.set('securityEnabled', true);
     }
     else {
       this.set('securityEnabled', false);
-      var hdfsConfigs = data.items.findProperty('tag', this.get('tag.hdfs-site')).properties;
+      var hdfsConfigs = data.findProperty('tag', this.get('tag.hdfs-site')).properties;
       this.setNnHaStatus(hdfsConfigs);
     }
     this.loadUsers(configs);

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/controllers/main/service/info/configs.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service/info/configs.js b/ambari-web/app/controllers/main/service/info/configs.js
index adf3c98..e96635d 100644
--- a/ambari-web/app/controllers/main/service/info/configs.js
+++ b/ambari-web/app/controllers/main/service/info/configs.js
@@ -453,7 +453,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
     //STEP 3: Load advanced configs from server
     var advancedConfigs = App.config.loadAdvancedConfig(serviceName) || [];
     //STEP 4: Load on-site config by service from server
-    var configGroups = App.config.loadConfigsByTags(this.get('serviceConfigTags'));
+     var configGroups = App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags'));
     //STEP 5: Merge global and on-site configs with pre-defined
     var configSet = App.config.mergePreDefinedWithLoaded(configGroups, advancedConfigs, this.get('serviceConfigTags'), serviceName);
     configSet = App.config.syncOrderWithPredefined(configSet);

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/utils/ajax.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/ajax.js b/ambari-web/app/utils/ajax.js
index 8adbf7a..d8b8952 100644
--- a/ambari-web/app/utils/ajax.js
+++ b/ambari-web/app/utils/ajax.js
@@ -500,16 +500,6 @@ var urls = {
       };
     }
   },
-  'admin.service_config': {
-    'real': '/clusters/{clusterName}/configurations/?type={siteName}&tag={tagName}',
-    'mock': '',
-    'format': function (data, opt) {
-      return {
-        timeout: 10000,
-        async: false
-      };
-    }
-  },
   'admin.security_status': {
     'real': '/clusters/{clusterName}?fields=Clusters/desired_configs',
     'mock': '',

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/utils/db.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/db.js b/ambari-web/app/utils/db.js
index ebad01f..b915cb7 100644
--- a/ambari-web/app/utils/db.js
+++ b/ambari-web/app/utils/db.js
@@ -50,6 +50,7 @@ App.db.cleanUp = function () {
     'app': {
       'loginName': '',
       'authenticated': false,
+      'configs': [],
       'tables': {
         'filterConditions': {},
         'displayLength': {},
@@ -292,6 +293,12 @@ App.db.setStacks = function (stacks) {
   localStorage.setObject('ambari', App.db.data);
 };
 
+App.db.setConfigs = function (configs) {
+  App.db.data = localStorage.getObject('ambari');
+  App.db.data.app.configs = configs;
+  localStorage.setObject('ambari', App.db.data);
+};
+
 /**
  * Set current step value for specified Wizard Type
  * @param wizardType
@@ -692,6 +699,11 @@ App.db.getReassignMasterWizardComponentDir = function () {
   return App.db.data.ReassignMaster.componentDir;
 };
 
+App.db.getConfigs = function () {
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data.app.configs;
+};
+
 App.db.getReassignMasterWizardReassignHosts = function () {
   App.db.data = localStorage.getObject('ambari');
   return App.db.data.ReassignMaster.reassignHosts;

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/124e06d7/ambari-web/app/views/common/quick_view_link_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/quick_view_link_view.js b/ambari-web/app/views/common/quick_view_link_view.js
index 8ccc77e..42738cd 100644
--- a/ambari-web/app/views/common/quick_view_link_view.js
+++ b/ambari-web/app/views/common/quick_view_link_view.js
@@ -32,18 +32,15 @@ App.QuickViewLinks = Em.View.extend({
   },
 
   loadTagsSuccess: function(data) {
-    var tags = []
+    var tags = [];
     for( var prop in data.Clusters.desired_configs){
       tags.push(Em.Object.create({
         siteName: prop,
         tagName: data.Clusters.desired_configs[prop]['tag']
       }));
     }
-    var actual = this.get('actualTags');
-    if (JSON.stringify(actual) != JSON.stringify(tags)) {
-      this.set('actualTags',tags);
-      this.getSecurityPropertie();
-    }
+    this.set('actualTags', tags);
+    this.getSecurityProperties();
   },
 
   actualTags: [],
@@ -53,38 +50,23 @@ App.QuickViewLinks = Em.View.extend({
   /**
    * list of files that contains properties for enabling/disabling ssl
    */
-  siteNames: ['core-site'],
-
-  getSecurityPropertie: function() {
-    this.set('securityProperties',[]);
-    this.get('siteNames').forEach(function(name){
-      var tag = this.get('actualTags');
-      if (tag && tag.findProperty('siteName',name)) {
-        var tagName = tag.findProperty('siteName',name).tagName;
-        App.ajax.send({
-          name: 'admin.service_config',
-          sender: this,
-          data: {
-            tagName: tagName,
-            siteName: name
-          },
-          success: 'getSecurityPropertiesSuccess',
-          error: 'getSecurityPropertiesError'
-        });
-      }
-    }, this)
-  },
+  requiredSiteNames: ['core-site'],
 
-  getSecurityPropertiesSuccess: function(data) {
+  getSecurityProperties: function () {
+    this.set('securityProperties', []);
+    var requiredSiteNames = this.get('requiredSiteNames');
+    var tags = this.get('actualTags').filter(function(tag){
+      return requiredSiteNames.contains(tag.siteName);
+    });
+    var data = App.router.get('configurationController').getConfigsByTags(tags);
     var properties = this.get('securityProperties');
-    if(data.items[0]) {
-      properties.pushObject(data.items[0].properties);
+    var coreSiteProperties = data.findProperty('type', 'core-site');
+    if(coreSiteProperties) {
+      properties.pushObject(coreSiteProperties);
       this.set('securityProperties', properties);
     }
   },
-  getSecurityPropertiesError: function() {
-    console.warn('can\'t get properties')
-  },
+
   ambariProperties: function() {
     return App.router.get('clusterController.ambariProperties');
   },