ソースを参照

AMBARI-6296 Components list on 'Host details page' contains only filtered elements when filter is used, second patch. (atkach)

atkach 11 年 前
コミット
f9082ee991

+ 86 - 5
ambari-web/app/controllers/global/update_controller.js

@@ -31,6 +31,11 @@ App.UpdateController = Em.Controller.extend({
     return App.router.get('location.lastSetURL');
   }.property('App.router.location.lastSetURL'),
 
+  /**
+   * keys which should be preloaded in order to filter hosts by host-components
+   */
+  hostsPreLoadKeys: ['host_components/HostRoles/component_name', 'host_components/HostRoles/stale_configs', 'host_components/HostRoles/maintenance_state'],
+
   getUrl: function (testUrl, url) {
     return (App.get('testMode')) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
   },
@@ -142,10 +147,12 @@ App.UpdateController = Em.Controller.extend({
 
   updateHost: function (callback, error) {
     var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
+    var self = this;
     var realUrl = '/hosts?<parameters>fields=Hosts/host_name,Hosts/maintenance_state,Hosts/public_host_name,Hosts/cpu_count,Hosts/ph_cpu_count,Hosts/total_mem,' +
       'Hosts/host_status,Hosts/last_heartbeat_time,Hosts/os_arch,Hosts/os_type,Hosts/ip,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,' +
       'host_components/HostRoles/stale_configs,host_components/HostRoles/service_name,metrics/disk,metrics/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,' +
       'metrics/memory/mem_total,metrics/memory/mem_free,alerts/summary&minimal_response=true';
+
     if (App.router.get('currentState.name') == 'index' && App.router.get('currentState.parentState.name') == 'hosts') {
       App.updater.updateInterval('updateHost', App.get('contentUpdateInterval'));
     } else if(App.router.get('currentState.name') == 'summary' && App.router.get('currentState.parentState.name') == 'hostDetails') {
@@ -159,11 +166,85 @@ App.UpdateController = Em.Controller.extend({
       }
     }
     this.get('queryParams').set('Hosts', App.router.get('mainHostController').getQueryParameters());
-    var hostsUrl = this.getComplexUrl(testUrl, realUrl, this.get('queryParams.Hosts'));
-    App.HttpClient.get(hostsUrl, App.hostsMapper, {
-      complete: callback,
-      error: error
-    });
+    var clientCallback = function (skipCall, queryParams) {
+      if (skipCall) {
+        App.hostsMapper.map({items: []});
+        callback();
+      } else {
+        var hostsUrl = self.getComplexUrl(testUrl, realUrl, queryParams);
+        App.HttpClient.get(hostsUrl, App.hostsMapper, {
+          complete: callback,
+          error: error
+        });
+      }
+    };
+
+    if (!this.preLoadHosts(clientCallback)) {
+      clientCallback(false, self.get('queryParams.Hosts'));
+    }
+  },
+
+  /**
+   * identify if any filter by host-component is active
+   * if so run @getHostByHostComponents
+   *
+   * @param callback
+   * @return {Boolean}
+   */
+  preLoadHosts: function (callback) {
+    var preLoadKeys = this.get('hostsPreLoadKeys');
+
+    if (this.get('queryParams.Hosts').length > 0 && this.get('queryParams.Hosts').filter(function (param) {
+      return (preLoadKeys.contains(param.key));
+    }, this).length > 0) {
+      this.getHostByHostComponents(callback);
+      return true;
+    }
+    return false;
+  },
+
+  /**
+   * get hosts' names which match filter by host-component
+   * @param callback
+   */
+  getHostByHostComponents: function (callback) {
+    var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
+    var realUrl = '/hosts?<parameters>minimal_response=true';
+
+    App.ajax.send({
+      name: 'hosts.host_components.pre_load',
+      sender: this,
+      data: {
+        url: this.getComplexUrl(testUrl, realUrl, this.get('queryParams.Hosts')),
+        callback: callback
+      },
+      success: 'getHostByHostComponentsSuccessCallback',
+      error: 'getHostByHostComponentsErrorCallback'
+    })
+  },
+  getHostByHostComponentsSuccessCallback: function (data, opt, params) {
+    var preLoadKeys = this.get('hostsPreLoadKeys');
+    var queryParams = this.get('queryParams.Hosts');
+    var hostNames = data.items.mapProperty('Hosts.host_name');
+    var skipCall = hostNames.length === 0;
+
+    if (skipCall) {
+      params.callback(skipCall);
+    } else {
+      queryParams = queryParams.filter(function (param) {
+        return !(preLoadKeys.contains(param.key));
+      });
+
+      queryParams.push({
+        key: 'Hosts/host_name',
+        value: hostNames,
+        type: 'MULTIPLE'
+      });
+      params.callback(skipCall, queryParams);
+    }
+  },
+  getHostByHostComponentsErrorCallback: function () {
+    console.warn('ERROR: filtering hosts by host-component failed');
   },
   graphs: [],
   graphsUpdate: function (callback) {

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

@@ -28,7 +28,6 @@ App.MainHostController = Em.ArrayController.extend({
   clearFilters: null,
 
   filteredCount: 0,
-  filteringComplete: true,
   /**
    * flag responsible for updating status counters of hosts
    */

+ 34 - 46
ambari-web/app/mappers/hosts_mapper.js

@@ -63,60 +63,48 @@ App.hostsMapper = App.QuickDataMapper.create({
     stale_configs: 'HostRoles.stale_configs',
     host_name: 'host_name'
   },
-  map: function (json, isAll) {
-    var self = this;
+  map: function (json) {
     console.time('App.hostsMapper execution time');
-    if (json.items.length) {
-      var hostNames = json.items.mapProperty('Hosts.host_name');
-      var realUrl = '/hosts?<parameters>fields=host_components/HostRoles/component_name,host_components/HostRoles/service_name,host_components/HostRoles/stale_configs,host_components/HostRoles/state,host_components/HostRoles/host_name,host_components/HostRoles/maintenance_state&minimal_response=true';
-      var hostsUrl = App.apiPrefix + '/clusters/' + App.get('clusterName') + realUrl.replace('<parameters>', 'Hosts/host_name.in(' + hostNames.join(',') + ')&');
+    if (json.items) {
+      var hostsWithFullInfo = [];
+      var hostIds = {};
+      var components = [];
+      json.items.forEach(function (item, index) {
+        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;
+          var component = this.parseIt(host_component, this.hostComponentConfig);
+          component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;
+          component.host_id = item.Hosts.host_name;
+          component.host_name = item.Hosts.host_name;
+          components.push(component);
+        }, this);
+        item.critical_alerts_count = (item.alerts) ? item.alerts.summary.CRITICAL + item.alerts.summary.WARNING : 0;
+        item.cluster_id = App.get('clusterName');
+        item.index = index;
 
-      $.getJSON(hostsUrl, function (jsonHostComponents) {
-        var hostsWithFullInfo = [];
-        var hostIds = {};
-        var components = [];
-        json.items.forEach(function (item, index) {
-          item.host_components = jsonHostComponents.items.findProperty('Hosts.host_name',item.Hosts.host_name).host_components || [];
-          item.host_components.forEach(function (host_component) {
-            host_component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;
-            var component = self.parseIt(host_component, self.hostComponentConfig);
-            component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;
-            component.host_id = item.Hosts.host_name;
-            component.host_name = item.Hosts.host_name;
-            components.push(component);
-          });
-          item.critical_alerts_count = (item.alerts) ? item.alerts.summary.CRITICAL + item.alerts.summary.WARNING : 0;
-          item.cluster_id = App.get('clusterName');
-          item.index = index;
 
-          var parsedItem = self.parseIt(item, self.config);
-          parsedItem.is_requested = !isAll;
+        var parsedItem = this.parseIt(item, this.config);
+        parsedItem.is_requested = true;
 
-          hostIds[item.Hosts.host_name] = parsedItem;
+        hostIds[item.Hosts.host_name] = parsedItem;
 
-          hostsWithFullInfo.push(parsedItem);
-        });
+        hostsWithFullInfo.push(parsedItem);
+      }, this);
 
-        hostsWithFullInfo = hostsWithFullInfo.sortProperty('public_host_name');
+      hostsWithFullInfo = hostsWithFullInfo.sortProperty('public_host_name');
 
-        App.Host.find().forEach(function (host) {
-          if (isAll && host.get('isRequested')) {
-            hostIds[host.get('hostName')].is_requested = true;
-          } else if (!hostIds[host.get('hostName')]) {
-            host.set('isRequested', false);
-          }
-        });
-        App.store.loadMany(App.HostComponent, components);
-        App.store.loadMany(App.Host, hostsWithFullInfo);
-        App.router.set('mainHostController.filteredCount', parseInt(json.itemTotal));
-        App.router.set('mainHostController.filteringComplete', true);
-      });
-    }else{
       App.Host.find().forEach(function (host) {
-        host.set('isRequested', false);
-      })
-      App.router.set('mainHostController.filteredCount', 0);
-      App.router.set('mainHostController.filteringComplete', true);
+        if (!hostIds[host.get('hostName')]) {
+          host.set('isRequested', false);
+        }
+      });
+      App.store.loadMany(App.HostComponent, components);
+      App.store.loadMany(App.Host, hostsWithFullInfo);
+      var itemTotal = parseInt(json.itemTotal);
+      if (itemTotal) {
+        App.router.set('mainHostController.filteredCount', itemTotal);
+      }
     }
     console.timeEnd('App.hostsMapper execution time');
   }

+ 0 - 1
ambari-web/app/mixins/common/tableServerProvider.js

@@ -52,7 +52,6 @@ App.TableServerProvider = Em.Mixin.create({
     if (!this.get('filteringComplete')) return false;
 
     this.set('filteringComplete', false);
-    this.set('controller.filteringComplete', false);
     var updaterMethodName = this.get('updater.tableUpdaterMap')[this.get('tableName')];
     this.get('updater')[updaterMethodName](function () {
       self.set('filteringComplete', true);

+ 1 - 1
ambari-web/app/templates/main/host.hbs

@@ -142,7 +142,7 @@
     </tbody>
   </table>
 
-  <div {{bindAttr class="controller.filteringComplete:hidden :hosts-overlay"}}>
+  <div {{bindAttr class="view.filteringComplete:hidden :hosts-overlay"}}>
     <div class="spinner"></div>
   </div>
 

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

@@ -2175,6 +2175,15 @@ var urls = {
         fields: data.fields.join(',')
       }
     }
+  },
+  'hosts.host_components.pre_load': {
+    real: '',
+    mock: '',
+    format: function(data) {
+      return {
+        url: data.url
+      }
+    }
   }
 };
 /**