Browse Source

AMBARI-6252 Service Configs page loads too slow on 2k node cluster (Buzhor Denys via ababiichuk)

aBabiichuk 11 years ago
parent
commit
43ed20c0bb

+ 19 - 0
ambari-web/app/controllers/global/cluster_controller.js

@@ -232,6 +232,24 @@ App.ClusterController = Em.Controller.extend({
     return !!App.Service.find().findProperty('serviceName', 'GANGLIA');
   }.property('App.router.updateController.isUpdated', 'dataLoadList.serviceMetrics'),
 
+  /**
+   * Get all host names. We have many places where we need it.
+   **/
+  loadAllHostNames: function () {
+    App.ajax.send({
+      sender: this,
+      name: 'cluster.fields',
+      data: {
+        fields: ['hosts'],
+        clusterName: App.get('clusterName')
+      },
+      success: 'loadAllHostNamesSuccess'
+    });
+  },
+
+  loadAllHostNamesSuccess: function(response) {
+    App.cache['HostsList'] = response.hosts.mapProperty('Hosts.host_name');
+  },
   /**
    *
    *  load all data and update load status
@@ -240,6 +258,7 @@ App.ClusterController = Em.Controller.extend({
     var self = this;
     this.loadAmbariProperties();
     this.loadAmbariViews();
+    this.loadAllHostNames();
     if (!this.get('clusterName')) {
       return;
     }

+ 66 - 71
ambari-web/app/controllers/main/service/info/configs.js

@@ -199,13 +199,27 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
       sender: this,
       data: {
         serviceName: this.get('content.serviceName'),
-        serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName'))
+        serviceConfigsDef: this.get('serviceConfigs').findProperty('serviceName', this.get('content.serviceName')),
+        urlParams: "&config_groups/ConfigGroup/tag=" + this.get('content.serviceName')
       },
-      success: 'loadServiceTagsSuccess'
+      success: 'loadServiceConfigsSuccess'
     });
   },
 
-  loadServiceTagsSuccess: function (data, opt, params) {
+  loadServiceConfigsSuccess: function(data, opt, params) {
+    if (data) {
+      this.setConfigGroups.apply(this, Array.prototype.slice.call(arguments, 0));
+    } else {
+      App.ajax.send({
+        name: 'config.tags',
+        sender: this,
+        data: App.permit(params, ['clusterName', 'serviceConfigsDef', 'serviceName']),
+        success: 'setConfigGroups'
+      });
+    }
+  },
+
+  setConfigGroups: function (data, opt, params) {
     var serviceConfigsDef = params.serviceConfigsDef;
     var serviceName = this.get('content.serviceName');
     console.debug("loadServiceConfigs(): data=", data);
@@ -224,7 +238,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
     //parse loaded config groups
     if (App.supports.hostOverrides) {
       var configGroups = [];
-      if (data.config_groups.length) {
+      if (data.config_groups && data.config_groups.length) {
         data.config_groups.forEach(function (item) {
           item = item.ConfigGroup;
           if (item.tag === this.get('content.serviceName')) {
@@ -414,25 +428,37 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   getInfoForDefaults: function() {
 
     App.ajax.send({
-      name: 'host_components.all',
+      name: 'hosts.config_groups',
       sender: this,
       data: {
         clusterName: App.get('clusterName')
       },
-      success: 'slavesSuccessCallback'
+      success: 'configGroupsHostsSuccessCallback'
     });
+  },
 
+  configGroupsHostsSuccessCallback: function(response) {
+    this.set('defaultsInfo', {
+      masterComponentHosts: this.getMasterComponents(response),
+      slaveComponentHosts: this.getSlaveComponents(response),
+      hosts: this.getHostsInfo(response)
+    });
   },
 
-  slavesSuccessCallback: function (response) {
-    var slaveComponentHosts = [];
-    var slaves = response.items.mapProperty('HostRoles').filter(function (c) {
-      return App.StackServiceComponent.find().findProperty('componentName', c.component_name).get('isSlave');
-    }).map(function(item) {
-      return Em.Object.create({
-        host: item.host_name,
-        componentName: item.component_name
+  getSlaveComponents: function (response) {
+    var slaveComponentHosts = [],
+        slaves = [];
+    response.items.forEach(function(item) {
+      var hostName = item.Hosts.host_name;
+      var _slaves = item.host_components.mapProperty('HostRoles.component_name').filter(function(componentName) {
+        return App.StackServiceComponent.find().findProperty('componentName', componentName).get('isSlave');
+      }).map(function(componentName) {
+        return Em.Object.create({
+          host: hostName,
+          componentName: componentName
+        });
       });
+      slaves = slaves.concat(_slaves);
     });
     slaves.forEach(function(slave) {
       var s = slaveComponentHosts.findProperty('componentName', slave.componentName);
@@ -446,45 +472,30 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
         });
       }
     });
-
-    App.ajax.send({
-      name: 'host_components.with_services_names',
-      sender: this,
-      data: {
-        clusterName: App.get('clusterName'),
-        slaveComponentHosts: slaveComponentHosts
-      },
-      success: 'mastersSuccessCallback'
-    });
-
-  },
-
-  mastersSuccessCallback: function (response, request, data) {
-
-    var masterComponentHosts = response.items.filter(function (c) {
-      return App.StackServiceComponent.find().findProperty('componentName', c.HostRoles.component_name).get('isMaster');
-    }).map(function(item) {
-      return {
-        component: item.HostRoles.component_name,
-        serviceId: item.component[0].ServiceComponentInfo.service_name,
-        host: item.HostRoles.host_name
-      }
-    });
-
-    App.ajax.send({
-      name: 'hosts.confirmed',
-      sender: this,
-      data: {
-        clusterName: App.get('clusterName'),
-        masterComponentHosts: masterComponentHosts,
-        slaveComponentHosts: data.slaveComponentHosts
-      },
-      success: 'hostsSuccessCallback'
+    return slaveComponentHosts;
+  },
+
+  getMasterComponents: function (response) {
+    var serviceMasterComponents = this.get('content.hostComponents').filterProperty('isMaster', true).mapProperty('componentName').uniq(),
+        masterComponentHosts = [],
+        _this = this;
+    response.items.forEach(function(item) {
+      var hostName = item.Hosts.host_name;
+      item.host_components.mapProperty('HostRoles.component_name').forEach(function(componentName) {
+        if (serviceMasterComponents.contains(componentName)) {
+          masterComponentHosts.push({
+            component: componentName,
+            serviceId: _this.get('content.serviceName'),
+            host: hostName
+          });
+        }
+      });
     });
 
+    return masterComponentHosts;
   },
 
-  hostsSuccessCallback: function (response, request, data) {
+  getHostsInfo: function (response) {
     var hosts = {};
     response.items.mapProperty('Hosts').map(function(host) {
       hosts[host.host_name] = {
@@ -494,28 +505,8 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
         disk_info: host.disk_info
       };
     });
-    var obj =  {
-      masterComponentHosts: [],
-      slaveComponentHosts: [],
-      hosts: hosts
-    };
-    lazyLoading.run({
-      initSize: 20,
-      chunkSize: 50,
-      delay: 50,
-      destination: obj.masterComponentHosts,
-      source: data.masterComponentHosts,
-      context: Em.Object.create()
-    });
-    lazyLoading.run({
-      initSize: 20,
-      chunkSize: 50,
-      delay: 50,
-      destination: obj.slaveComponentHosts,
-      source: obj.slaveComponentHosts,
-      context: Em.Object.create()
-    });
-    this.set('defaultsInfo', obj);
+
+    return hosts;
   },
 
   /**
@@ -584,6 +575,10 @@ App.MainServiceInfoConfigsController = Em.Controller.extend({
   setRecommendedDefaults: function (advancedConfigs) {
     var s = this.get('serviceConfigsData').findProperty('serviceName', this.get('content.serviceName'));
     var dfd = $.Deferred();
+    if (!s.defaultsProviders) {
+      dfd.resolve();
+      return dfd.promise();
+    }
     this.getInfoForDefaults();
     this.addObserver('defaultsInfo.hosts.length', this, function() {
       var localDB = this.get('defaultsInfo');

+ 1 - 0
ambari-web/app/controllers/main/service/manage_config_groups_controller.js

@@ -103,6 +103,7 @@ App.ManageConfigGroupsController = Em.Controller.extend({
           memory: host.Hosts.total_mem,
           diskTotal: host.metrics.disk.disk_total,
           diskFree: host.metrics.disk.disk_free,
+          disksMounted: host.Hosts.disk_info.length,
           hostComponents: hostComponents
         }
       ));

+ 0 - 2
ambari-web/app/mappers/hosts_mapper.js

@@ -69,9 +69,7 @@ App.hostsMapper = App.QuickDataMapper.create({
       var hostsWithFullInfo = [];
       var hostIds = {};
       var components = [];
-      App.cache['HostsList'] = [];
       json.items.forEach(function (item, index) {
-        App.cache['HostsList'].push(item.Hosts.host_name);
         item.host_components = item.host_components || [];
         item.host_components.forEach(function (host_component) {
           host_component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;

+ 10 - 0
ambari-web/app/utils/ajax/ajax.js

@@ -2171,6 +2171,16 @@ var urls = {
   'hosts.config_groups': {
     'real': '/clusters/{clusterName}/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem,Hosts/ip,Hosts/os_type,Hosts/os_arch,Hosts/public_host_name,metrics/disk,host_components&minimal_response=true',
     'mock': ''
+  },
+  'cluster.fields': {
+    real: '/clusters/{clusterName}?fields={fields}',
+    mock: '',
+    format: function(data) {
+      return {
+        async: true,
+        fields: data.fields.join(',')
+      }
+    }
   }
 };
 /**