瀏覽代碼

AMBARI-6182 Restart indicators do not appear without manual refresh when reconfiguring client-only services. (atkach)

atkach 11 年之前
父節點
當前提交
b19d840f29

+ 9 - 8
ambari-web/app/controllers/global/cluster_controller.js

@@ -315,19 +315,20 @@ App.ClusterController = Em.Controller.extend({
         });
 
         updater.updateServiceMetric(function () {
+
+          if (App.supports.hostOverrides) {
+            updater.updateComponentConfig(function () {
+              self.updateLoadStatus('componentConfigs');
+            });
+          } else {
+            self.updateLoadStatus('componentConfigs');
+          }
+
           updater.updateComponentsState(function () {
             self.updateLoadStatus('componentsState');
           });
           self.updateLoadStatus('serviceMetrics');
         });
-
-        if (App.supports.hostOverrides) {
-          updater.updateComponentConfig(function () {
-            self.updateLoadStatus('componentConfigs');
-          });
-        } else {
-          self.updateLoadStatus('componentConfigs');
-        }
       });
     });
   },

+ 72 - 28
ambari-web/app/mappers/component_config_mapper.js

@@ -21,48 +21,92 @@ App.componentConfigMapper = App.QuickDataMapper.create({
   model: App.HostComponent,
   config: {
     id: 'id',
-    work_status: 'state',
-    passive_state: 'maintenance_state',
-    component_name: 'component_name',
-    host_name: 'host_name',
-    $ha_status: 'none',
+    work_status: 'HostRoles.state',
+    passive_state: 'HostRoles.maintenance_state',
+    component_name: 'HostRoles.component_name',
+    host_name: 'HostRoles.host_name',
+    $ha_status: '',
     $display_name_advanced: '',
-    stale_configs: 'stale_configs',
-    host_id: 'host_name',
-    service_id: 'service_name'
+    stale_configs: 'HostRoles.stale_configs',
+    host_id: 'HostRoles.host_name',
+    service_id: 'HostRoles.service_name'
   },
   map: function (json) {
     console.time('App.componentConfigMapper execution time');
     var hostComponents = [];
     var serviceToHostComponentIdMap = {};
-    var restartRequiredServices = [];
+    var cacheServices = App.cache['services'];
+    var componentsWithStaleConfigs = {};
+    var loadedServiceComponentsMap = this.buildServiceComponentMap(cacheServices);
+
     json.items.forEach(function (item) {
       item.host_components.forEach(function (host_component) {
-        host_component = host_component.HostRoles;
-        restartRequiredServices.push(host_component.service_name);
-        host_component.id = host_component.component_name + '_' + host_component.host_name;
+        var serviceName = host_component.HostRoles.service_name;
+        host_component.id = host_component.HostRoles.component_name + '_' + host_component.HostRoles.host_name;
         hostComponents.push(this.parseIt(host_component, this.get('config')));
-        if (!serviceToHostComponentIdMap[host_component.service_name]) {
-          serviceToHostComponentIdMap[host_component.service_name] = [];
+
+        componentsWithStaleConfigs[host_component.id] = true;
+
+        if (!serviceToHostComponentIdMap[serviceName]) {
+          serviceToHostComponentIdMap[serviceName] = [];
         }
-        serviceToHostComponentIdMap[host_component.service_name].push(host_component.id);
+        serviceToHostComponentIdMap[serviceName].push(host_component.id);
       }, this);
     }, this);
-    restartRequiredServices = restartRequiredServices.uniq();
-    var restartRequired = App.cache['restartRequiredServices'].concat(restartRequiredServices).uniq();
+
+    //reset(only for slave and client components) staleConfigs property to false before load to model
+    this.get('model').find().forEach(function (hostComponent) {
+      if (!componentsWithStaleConfigs[hostComponent.get('id')] && !hostComponent.get('isMaster')) {
+        hostComponent.set('staleConfigs', false);
+      }
+    });
     App.store.loadMany(this.get('model'), hostComponents);
-    restartRequired.forEach(function(serviceName) {
-      var service = App.cache['services'].findProperty('ServiceInfo.service_name', serviceName);
-      if (service) {
-        service.host_components = [];
-        for (var n in serviceToHostComponentIdMap[serviceName]) {
-          if (serviceToHostComponentIdMap[serviceName].hasOwnProperty(n)) {
-            service.host_components.pushObject(serviceToHostComponentIdMap[serviceName][n]);
+
+    this.addNewHostComponents(loadedServiceComponentsMap, serviceToHostComponentIdMap, cacheServices);
+    console.timeEnd('App.componentConfigMapper execution time');
+  },
+
+  /**
+   * build map that include loaded host-components to avoid duplicate loading
+   * @param cacheServices
+   * @return {Object}
+   */
+  buildServiceComponentMap: function (cacheServices) {
+    var loadedServiceComponentsMap = {};
+
+    cacheServices.forEach(function (cacheService) {
+      var componentsMap = {};
+
+      cacheService.host_components.forEach(function (componentId) {
+        componentsMap[componentId] = true;
+      });
+      loadedServiceComponentsMap[cacheService.ServiceInfo.service_name] = componentsMap;
+    });
+    return loadedServiceComponentsMap;
+  },
+
+  /**
+   * add only new host-components to every service
+   * to update service - host-component relations in model
+   * @param loadedServiceComponentsMap
+   * @param serviceToHostComponentIdMap
+   * @param cacheServices
+   * @return {boolean}
+   */
+  addNewHostComponents: function (loadedServiceComponentsMap, serviceToHostComponentIdMap, cacheServices) {
+    if (!loadedServiceComponentsMap || !serviceToHostComponentIdMap || !cacheServices) return false;
+
+    for (var serviceName in serviceToHostComponentIdMap) {
+      var loadedService = cacheServices.findProperty('ServiceInfo.service_name', serviceName);
+
+      if (serviceToHostComponentIdMap[serviceName] && loadedService) {
+        serviceToHostComponentIdMap[serviceName].forEach(function (componentId) {
+          if (!loadedServiceComponentsMap[serviceName][componentId]) {
+            loadedService.host_components.push(componentId)
           }
-        }
+        });
       }
-    }, this);
-    App.cache['restartRequiredServices'] = restartRequiredServices;
-    console.timeEnd('App.componentConfigMapper execution time');
+    }
+    return true;
   }
 });

+ 4 - 4
ambari-web/app/mappers/service_metrics_mapper.js

@@ -178,6 +178,7 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
       var services = App.cache['services'];
       var previousComponentStatuses = App.cache['previousComponentStatuses'];
       var previousComponentPassiveStates = App.cache['previousComponentPassiveStates'];
+      var result = [];
       /**
        * services contains constructed service-components structure from components array
        */
@@ -205,8 +206,6 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
       //load master components to model
       App.store.loadMany(this.get('model3'), hostComponents);
 
-      var result = [];
-
       //parse service metrics from components
       services.forEach(function (item) {
         var finalJson = [];
@@ -266,7 +265,8 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
       result = misc.sortByOrder(App.Service.servicesSortOrder, result);
 
       //load services to model
-      if (previousResponse.length !== result.length) {
+      App.store.loadMany(this.get('model'), result);
+      /*if (previousResponse.length !== result.length) {
         App.store.loadMany(this.get('model'), result);
       } else {
         result.forEach(function (serviceJson) {
@@ -283,7 +283,7 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
         }, this)
       }
 
-      previousResponse = result;
+      previousResponse = result;*/
     }
     console.timeEnd('App.serviceMetricsMapper execution time');
   },