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/11/05 14:15:53 UTC

git commit: AMBARI-3693 [perf] Hosts UI should not load host_components unless editing a host. (atkach)

Updated Branches:
  refs/heads/trunk ff720cd93 -> 747f5897e


AMBARI-3693 [perf] Hosts UI should not load host_components unless editing a host. (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/747f5897
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/747f5897
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/747f5897

Branch: refs/heads/trunk
Commit: 747f5897ecea6d8b05427c5835d72b9201c98107
Parents: ff720cd
Author: atkach <an...@gmail.com>
Authored: Tue Nov 5 15:15:47 2013 +0200
Committer: atkach <an...@gmail.com>
Committed: Tue Nov 5 15:15:47 2013 +0200

----------------------------------------------------------------------
 .../controllers/global/cluster_controller.js    |   9 +-
 .../app/controllers/global/update_controller.js |  21 +++-
 ambari-web/app/mappers/hosts_mapper.js          | 119 +++++++++----------
 ambari-web/app/mappers/server_data_mapper.js    |   5 +
 ambari-web/app/models/host.js                   |  20 +++-
 ambari-web/app/routes/add_host_routes.js        |   4 +-
 6 files changed, 105 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/747f5897/ambari-web/app/controllers/global/cluster_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/cluster_controller.js b/ambari-web/app/controllers/global/cluster_controller.js
index be350d8..dc9386e 100644
--- a/ambari-web/app/controllers/global/cluster_controller.js
+++ b/ambari-web/app/controllers/global/cluster_controller.js
@@ -268,13 +268,14 @@ App.ClusterController = Em.Controller.extend({
       return false;
     }
     var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/services.json':'/data/dashboard/services.json';
-    //desired_state property is eliminated since calculateState function is commented out, it become useless
-    var servicesUrl = this.getUrl(testUrl, '/services?fields=ServiceInfo,components/host_components/HostRoles/state');
+    var servicesUrl = '/services?fields=ServiceInfo,components/host_components/HostRoles/state';
     if (App.Service.find('HBASE')) {
       // HBase installed. We need the haStatus field as it has
       // moved to another field.
       servicesUrl += ',components/host_components/metrics/hbase/master/IsActiveMaster';
     }
+    //desired_state property is eliminated since calculateState function is commented out, it become useless
+    servicesUrl = this.getUrl(testUrl, servicesUrl);
 
     App.HttpClient.get(servicesUrl, App.statusMapper, {
       complete: callback
@@ -318,7 +319,9 @@ App.ClusterController = Em.Controller.extend({
       return;
     }
     var clusterUrl = this.getUrl('/data/clusters/cluster.json', '?fields=Clusters');
-    var hostsRealUrl = '/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/load/load_one';
+    var hostsRealUrl = '/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/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free';
     var usersUrl = App.testMode ? '/data/users/users.json' : App.apiPrefix + '/users/?fields=*';
     var racksUrl = "/data/racks/racks.json";
     var dataSetUrl = "/data/mirroring/all_datasets.json";

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/747f5897/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index a30307e..addc0c7 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -37,7 +37,7 @@ App.UpdateController = Em.Controller.extend({
    */
   updateAll:function(){
     if(this.get('isWorking')) {
-      App.updater.run(this, 'updateHost', 'isWorking');
+      App.updater.run(this, 'updateHostConditionally', 'isWorking');
       App.updater.run(this, 'updateServiceMetric', 'isWorking');
       App.updater.run(this, 'graphsUpdate', 'isWorking');
       if (App.supports.hostOverrides) {
@@ -45,13 +45,22 @@ App.UpdateController = Em.Controller.extend({
       }
     }
   }.observes('isWorking'),
+  updateHostConditionally: function (callback) {
+    var location = App.router.get('location.lastSetURL');
+    if (/\/main\/hosts.*/.test(location)) {
+      this.updateHost(callback);
+    } else {
+      callback();
+    }
+  },
 
   updateHost:function(callback) {
-    var testUrl =  App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json':'/data/hosts/hosts.json';
-      var hostsUrl = this.getUrl(testUrl, '/hosts?fields=Hosts/host_name,Hosts/host_status,Hosts/last_heartbeat_time,host_components,metrics/disk,metrics/load/load_one');
-      App.HttpClient.get(hostsUrl, App.hostsMapper, {
-        complete: callback
-      });
+    var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
+    var hostsUrl = this.getUrl(testUrl, '/hosts?fields=Hosts/host_name,Hosts/last_heartbeat_time,' +
+      'metrics/disk,metrics/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free');
+    App.HttpClient.get(hostsUrl, App.hostsMapper, {
+      complete: callback
+    });
   },
   graphs: [],
   graphsUpdate: function (callback) {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/747f5897/ambari-web/app/mappers/hosts_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/hosts_mapper.js b/ambari-web/app/mappers/hosts_mapper.js
index cd87744..32171d0 100644
--- a/ambari-web/app/mappers/hosts_mapper.js
+++ b/ambari-web/app/mappers/hosts_mapper.js
@@ -16,7 +16,6 @@
  */
 
 var App = require('app');
-var cacheData = {};
 
 App.hostsMapper = App.QuickDataMapper.create({
 
@@ -41,84 +40,82 @@ App.hostsMapper = App.QuickDataMapper.create({
     load_one: 'metrics.load.load_one',
     load_five: 'metrics.load.load_five',
     load_fifteen: 'metrics.load.load_fifteen',
-    cpu_usage: 'cpu_usage',
-    memory_usage: 'memory_usage',
+    cpu_system: 'metrics.cpu.cpu_system',
+    cpu_user: 'metrics.cpu.cpu_user',
+    mem_total: 'metrics.memory.mem_total',
+    mem_free: 'metrics.memory.mem_free',
     last_heart_beat_time: "Hosts.last_heartbeat_time",
     os_arch: 'Hosts.os_arch',
     os_type: 'Hosts.os_type',
-    ip: 'Hosts.ip',
-    disk_usage: 'disk_usage'
+    ip: 'Hosts.ip'
   },
   map: function (json) {
+    console.time('App.hostsMapper execution time');
     if (json.items) {
-      var result = this.parse(json.items);
+      var result = [];
+      var hostIds = {};
+      var cacheData = App.cache['Hosts'];
+
+      json.items.forEach(function (item) {
+        //receive host_components when added hosts
+        item.host_components = item.host_components || [];
+        item.host_components.forEach(function (host_component) {
+          host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
+        }, this);
+
+        hostIds[item.Hosts.host_name] = true;
+        result.push(this.parseIt(item, this.config));
+      }, this);
+      result = this.sortByPublicHostName(result);
+
       var clientHosts = App.Host.find();
-      if (clientHosts != null && clientHosts.get('length') < result.length) {
-        result.forEach(function (host) {
-          cacheData[host.id] = host;
-        });
-      } else if (clientHosts != null && clientHosts.get('length') > result.length) {
-        var hostsToDelete = [];
-        clientHosts.forEach(function (host) {
-          if (host !== null && result.filterProperty('host_name',host.get('hostName')).length === 0) {
-            // Delete old ones as new ones will be
-            // loaded by loadMany().
-            hostsToDelete.push(host);
-            delete cacheData[host.get('hostName')];
-          }
-        });
-        hostsToDelete.forEach(function (host) {
-          host.deleteRecord();
-          host.get('stateManager').transitionTo('loading');
-        });
+
+      if (clientHosts) {
+        // hosts were added
+        if (clientHosts.get('length') < result.length) {
+          result.forEach(function (host) {
+            cacheData[host.id] = {
+              ip: host.ip,
+              os_arch: host.os_arch,
+              os_type: host.os_type,
+              public_host_name: host.public_host_name,
+              memory: host.memory,
+              cpu: host.cpu,
+              host_components: host.host_components
+            };
+          });
+        }
+        // hosts were deleted
+        if (clientHosts.get('length') > result.length) {
+          clientHosts.forEach(function (host) {
+            if (host && !hostIds[host.get('hostName')]) {
+              // Delete old ones as new ones will be
+              // loaded by loadMany().
+              host.deleteRecord();
+              host.get('stateManager').transitionTo('loading');
+              delete cacheData[host.get('id')];
+            }
+          });
+        }
       }
       //restore properties from cache instead request them from server
       result.forEach(function (host) {
         var cacheHost = cacheData[host.id];
         if (cacheHost) {
-          host.ip ? cacheHost.ip = host.ip : host.ip = cacheHost.ip;
-          host.os_arch ? cacheHost.os_arch = host.os_arch : host.os_arch = cacheHost.os_arch;
-          host.os_type ?  cacheHost.os_type = host.os_type : host.os_type = cacheHost.os_type;
-          host.public_host_name ? cacheHost.public_host_name = host.public_host_name : host.public_host_name = cacheHost.public_host_name;
-          host.memory ? cacheHost.memory = host.memory : host.memory = cacheHost.memory;
-          host.cpu ? cacheHost.cpu = host.cpu : host.cpu = cacheHost.cpu;
+          host.ip = cacheHost.ip;
+          host.os_arch = cacheHost.os_arch;
+          host.os_type = cacheHost.os_type;
+          host.public_host_name = cacheHost.public_host_name;
+          host.memory = cacheHost.memory;
+          host.cpu = cacheHost.cpu;
+          host.host_components = cacheHost.host_components;
         }
       });
       App.store.loadMany(this.get('model'), result);
     }
+    console.timeEnd('App.hostsMapper execution time');
   },
 
-  parse: function(items) {
-    var result = [];
-    items.forEach(function (item) {
-
-      // Disk Usage
-      if (item.metrics && item.metrics.disk && item.metrics.disk.disk_total && item.metrics.disk.disk_free) {
-        var diskUsed = item.metrics.disk.disk_total - item.metrics.disk.disk_free;
-        var diskUsedPercent = (100 * diskUsed) / item.metrics.disk.disk_total;
-        item.disk_usage = diskUsedPercent.toFixed(1);
-      }
-      // CPU Usage
-      if (item.metrics && item.metrics.cpu && item.metrics.cpu.cpu_system && item.metrics.cpu.cpu_user) {
-        var cpuUsedPercent = item.metrics.cpu.cpu_system + item.metrics.cpu.cpu_user;
-        item.cpu_usage = cpuUsedPercent.toFixed(1);
-      }
-      // Memory Usage
-      if (item.metrics && item.metrics.memory && item.metrics.memory.mem_free && item.metrics.memory.mem_total) {
-        var memUsed = item.metrics.memory.mem_total - item.metrics.memory.mem_free;
-        var memUsedPercent = (100 * memUsed) / item.metrics.memory.mem_total;
-        item.memory_usage = memUsedPercent.toFixed(1);
-      }
-
-      item.host_components.forEach(function (host_component) {
-        host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
-      }, this);
-      result.push(this.parseIt(item, this.config));
-
-    }, this);
-    result = this.sortByPublicHostName(result);
-    return result;
-  },
   /**
    * Default data sorting by public_host_name field
    * @param data

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/747f5897/ambari-web/app/mappers/server_data_mapper.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mappers/server_data_mapper.js b/ambari-web/app/mappers/server_data_mapper.js
index 60be64f..e77a261 100644
--- a/ambari-web/app/mappers/server_data_mapper.js
+++ b/ambari-web/app/mappers/server_data_mapper.js
@@ -18,6 +18,11 @@
 
 var App = require('app');
 
+//initialize common cache container for mappers
+App.cache = {
+  'Hosts': {}
+};
+
 App.ServerDataMapper = Em.Object.extend({
   jsonKey: false,
   map: function (json) {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/747f5897/ambari-web/app/models/host.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/host.js b/ambari-web/app/models/host.js
index 457133b..287d21b 100644
--- a/ambari-web/app/models/host.js
+++ b/ambari-web/app/models/host.js
@@ -33,14 +33,30 @@ App.Host = DS.Model.extend({
   ip: DS.attr('string'),
   rack: DS.attr('string'),
   healthStatus: DS.attr('string'),
-  cpuUsage: DS.attr('number'),
-  memoryUsage: DS.attr('number'),
   lastHeartBeatTime: DS.attr('number'),
   osType: DS.attr("string"),
   diskInfo: DS.attr('object'),
   loadOne:DS.attr('number'),
   loadFive:DS.attr('number'),
   loadFifteen:DS.attr('number'),
+  memTotal:DS.attr('number'),
+  memFree:DS.attr('number'),
+  cpuSystem:DS.attr('number'),
+  cpuUser:DS.attr('number'),
+
+  cpuUsage: function () {
+    if (this.get('cpuSystem') && this.get('cpu_user')) {
+      return (this.get('cpuSystem') + this.get('cpu_user')).toFixed(1);
+    }
+  }.property('cpuSystem', 'cpuUser'),
+
+  memoryUsage: function () {
+    if (this.get('memFree') && this.get('memTotal')) {
+      var memUsed = this.get('memTotal') - this.get('memFree');
+      var memUsedPercent = (100 * memUsed) / this.get('memTotal');
+      return memUsedPercent.toFixed(1);
+    }
+  }.property('memTotal', 'memFree'),
 
   criticalAlertsCount: function () {
     return App.router.get('clusterController.alerts').filterProperty('hostName', this.get('hostName')).filterProperty('isOk', false).filterProperty('ignoredForHosts', false).length;

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/747f5897/ambari-web/app/routes/add_host_routes.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/add_host_routes.js b/ambari-web/app/routes/add_host_routes.js
index 8b0d53e..8f6e5d9 100644
--- a/ambari-web/app/routes/add_host_routes.js
+++ b/ambari-web/app/routes/add_host_routes.js
@@ -297,7 +297,9 @@ module.exports = Em.Route.extend({
     back: Em.Router.transitionTo('step5'),
     complete: function (router, context) {
       var addHostController = router.get('addHostController');
-      var hostsUrl = '/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/load/load_one';
+      var hostsUrl = '/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/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free';
       router.get('clusterController').requestHosts(hostsUrl, function () {
         console.log('Request for hosts, with immutable parameters')
       });