Prechádzať zdrojové kódy

AMBARI-6050. Error in loading stale_configs. (akovalenko)

Aleksandr Kovalenko 11 rokov pred
rodič
commit
296c2508b8

+ 1 - 1
ambari-web/app/controllers/global/update_controller.js

@@ -280,7 +280,7 @@ App.UpdateController = Em.Controller.extend({
   },
   updateComponentConfig: function (callback) {
     var testUrl = '/data/services/host_component_stale_configs.json';
-    var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/host_name&HostRoles/stale_configs=true&minimal_response=true');
+    var componentConfigUrl = this.getUrl(testUrl, '/components?ServiceComponentInfo/category.in(SLAVE,CLIENT)&host_components/HostRoles/stale_configs=true&fields=host_components/HostRoles/service_name,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,host_components/HostRoles/host_name,host_components/HostRoles/stale_configs&minimal_response=true');
     App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
       complete: callback
     });

+ 29 - 33
ambari-web/app/mappers/component_config_mapper.js

@@ -17,44 +17,40 @@
 
 var App = require('app');
 
-/**
- * The usage of previousResponse is due to detect
- * which exactly components has stale_configs changed in comparison to previous response
- */
-var previousResponse = {};
-
 App.componentConfigMapper = App.QuickDataMapper.create({
+  model: App.HostComponent,
+  config: {
+    id: 'id',
+    work_status: 'state',
+    passive_state: 'maintenance_state',
+    component_name: 'component_name',
+    $ha_status: 'none',
+    $display_name_advanced: 'none',
+    stale_configs: 'stale_configs',
+    host_id: 'host_name',
+    service_id: 'service_name'
+  },
   map: function (json) {
     console.time('App.componentConfigMapper execution time');
-    if (json.items) {
-      var hostComponentRecordsMap = App.cache['hostComponentRecordsMap'];
-      var staleConfigsTrue = [];
-      var currentResponse = {};
-      json.items.forEach(function (component) {
-        var id = component.HostRoles.component_name + "_" + component.HostRoles.host_name;
-        if (previousResponse[id]) {
-          delete previousResponse[id];
-        } else {
-          staleConfigsTrue.push(id);
+    var hostComponents = [];
+    var serviceToHostComponentIdMap = {};
+    json.items.forEach(function (item) {
+      item.host_components.forEach(function (host_component) {
+        host_component = host_component.HostRoles;
+        host_component.id = host_component.component_name + '_' + host_component.host_name;
+        hostComponents.push(this.parseIt(host_component, this.get('config')));
+        if (!serviceToHostComponentIdMap[host_component.service_name]) {
+          serviceToHostComponentIdMap[host_component.service_name] = [];
         }
-        currentResponse[id] = true;
-      });
-
-      /**
-       * if stale_configs of components became
-       * true:
-       *  then they will be in "staleConfigsTrue" object
-       * false:
-       *  then they will be in "previousResponse" object
-       * if stale_configs haven't changed then both objects will be empty and components stay the same
-       */
-      staleConfigsTrue.forEach(function (id) {
-        hostComponentRecordsMap[id].set('staleConfigs', true);
-      });
-      for (var id in previousResponse) {
-        hostComponentRecordsMap[id].set('staleConfigs', false)
+        serviceToHostComponentIdMap[host_component.service_name].push(host_component.id);
+      }, this);
+    }, this);
+    App.store.loadMany(this.get('model'), hostComponents);
+    for (var serviceName in serviceToHostComponentIdMap) {
+      var service = App.cache['services'].findProperty('ServiceInfo.service_name', serviceName);
+      if (service) {
+        service.host_components.pushObjects(serviceToHostComponentIdMap[serviceName]);
       }
-      previousResponse = currentResponse;
     }
     console.timeEnd('App.componentConfigMapper execution time');
   }

+ 1 - 2
ambari-web/app/mappers/server_data_mapper.js

@@ -28,8 +28,7 @@ App.cache = {
   'previousComponentStatuses': {},
   'previousComponentPassiveStates': {},
   'hostComponentsOnService': {},
-  'services': [],
-  'hostComponentRecordsMap': {}
+  'services': []
 };
 
 App.ServerDataMapper = Em.Object.extend({

+ 5 - 1
ambari-web/app/mappers/service_metrics_mapper.js

@@ -213,7 +213,11 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
       services.forEach(function (item) {
         var finalJson = [];
 
-        item.host_components = hostComponents.filterProperty('service_id', item.ServiceInfo.service_name).mapProperty('id');
+        hostComponents.filterProperty('service_id', item.ServiceInfo.service_name).mapProperty('id').forEach(function (hostComponent) {
+          if (!item.host_components.contains(hostComponent)) {
+            item.host_components.push(hostComponent);
+          }
+        }, this);
         item.host_components.sort();
 
         if (item && item.ServiceInfo && item.ServiceInfo.service_name == "HDFS") {