Forráskód Böngészése

AMBARI-1467. UI should block on cluster metric api call before making subsequent one. (yusaku)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1448925 13f79535-47bb-0310-9956-ffa450edef68
Yusaku Sako 12 éve
szülő
commit
17d0b2622f

+ 3 - 0
CHANGES.txt

@@ -348,6 +348,9 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1467. UI should block on cluster metric api call before making
+ subsequent one. (yusaku)
+
  AMBARI-1462. PB (petabytes) is shown as "undefined". (yusaku)
 
  AMBARI-1455. Setting App.testMode=true, alwaysGoToInstaller=true does not

+ 58 - 23
ambari-web/app/controllers/global/update_controller.js

@@ -32,34 +32,65 @@ App.UpdateController = Em.Controller.extend({
     return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
   },
 
+  /**
+   * Wrapper for all updates
+   */
   updateAll:function(){
-    var timeIntervalId = this.get('timeIntervalId');
-    var self = this;
-    if(this.get('isWorking')){
-      if(timeIntervalId) return;
-      this.set('timeIntervalId', setInterval(function(){
-        self.updateAllWrapper();
-      }, App.contentUpdateInterval));
-    } else {
-      clearInterval(timeIntervalId);
-      this.set('timeIntervalId', null);
+    if(this.get('isWorking')) {
+      this.update('updateHost');
+      this.update('updateServiceMetric');
+      this.update('graphsUpdate');
     }
   }.observes('isWorking'),
 
-  updateAllWrapper: function() {
-    this.updateHost();
-    this.updateServiceMetric();
-    this.graphsUpdate();
+  /**
+   * States for each update method (each field - method name)
+   */
+  states: {
+    'updateHost': null,
+    'updateServiceMetric': null,
+    'graphsUpdate': null
+  },
+
+  /**
+   * Callback for each update method
+   * @param {String} name - state name
+   * @return {Function}
+   */
+  updateCallback: function(name) {
+    var self = this;
+    return function() {
+      self.update(name);
+    }
+  },
+
+  /**
+   * Common method that executes provided by name update method (name from states object)
+   * @param {String} name - key in the states object
+   * @return {Boolean}
+   */
+  update: function(name) {
+    if(!this.get('isWorking')) {
+      return false;
+    }
+    clearTimeout(this.states[name]);
+    var self = this;
+    this.states[name] = setTimeout(function() {
+      self[name](self.updateCallback(name));
+    }, App.contentUpdateInterval);
   },
 
-  updateHost:function(){
+  updateHost:function(callback) {
+    var self = this;
       var hostsUrl = this.getUrl('/data/hosts/hosts.json', '/hosts?fields=Hosts/host_name,Hosts/public_host_name,Hosts/cpu_count,Hosts/total_mem,Hosts/host_status,Hosts/last_heartbeat_time,Hosts/os_arch,Hosts/os_type,Hosts/ip,host_components,metrics/disk,metrics/cpu,metrics/load,metrics/memory');
       App.HttpClient.get(hostsUrl, App.hostsMapper, {
-        complete:function (jqXHR, textStatus) {}
+        complete:function (jqXHR, textStatus) {
+          callback();
+        }
       });
   },
   graphs: [],
-  graphsUpdate: function () {
+  graphsUpdate: function (callback) {
       var existedGraphs = [];
       this.get('graphs').forEach(function (_graph) {
         var view = Em.View.views[_graph.id];
@@ -73,12 +104,14 @@ App.UpdateController = Em.Controller.extend({
           }
         }
       });
-      this.set('graphs', existedGraphs);
+    callback();
+    this.set('graphs', existedGraphs);
   },
-  
+
   /**
    * Updates the services information. 
-   * 
+   *
+   * @param callback
    * @param isInitialLoad  If true, only basic information is loaded.
    */
   updateServiceMetric: function (callback, isInitialLoad) {
@@ -90,9 +123,11 @@ App.UpdateController = Em.Controller.extend({
     var callback = callback || function (jqXHR, textStatus) {
       self.set('isUpdated', true);
     };
-    App.HttpClient.get(servicesUrl, App.servicesMapper, {
-      complete: callback
-    });
+      App.HttpClient.get(servicesUrl, App.servicesMapper, {
+        complete: function() {
+          callback();
+        }
+      });
   }
 
 

+ 1 - 1
ambari-web/app/routes/add_host_routes.js

@@ -291,7 +291,7 @@ module.exports = Em.Route.extend({
     complete: function (router, context) {
       if (true) {   // this function will be moved to installerController where it will validate
         var addHostController = router.get('addHostController');
-        App.router.get('updateController').updateAllWrapper();
+        App.router.get('updateController').updateAll();
         addHostController.finish();
         $(context.currentTarget).parents("#modal").find(".close").trigger('click');
 

+ 1 - 1
ambari-web/app/utils/http_client.js

@@ -74,7 +74,7 @@ App.HttpClient = Em.Object.create({
    * @param {App.ServerDataMapper} mapper - json processor
    * @param {Object} data - ajax data property
    * @param {function} errorHandler
-   * @param {number} interval - frequecy request
+   * @param {number} interval - frequency request
    */
   get: function (url, mapper, data, errorHandler, interval) {
     var eHandler = data.complete