瀏覽代碼

AMBARI-14399 Ranger error counter works wrong in some cases. (ababiichuk)

AndriyBabiychuk 9 年之前
父節點
當前提交
0061301ef4

+ 3 - 7
ambari-web/app/controllers/main/service/info/configs.js

@@ -122,13 +122,9 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A
    * Number of errors in the configs in the selected service (only for AdvancedTab if App supports Enhanced Configs)
    * Number of errors in the configs in the selected service (only for AdvancedTab if App supports Enhanced Configs)
    * @type {number}
    * @type {number}
    */
    */
-  errorsCount: function () {
-    return this.get('selectedService.configs').filter(function (config) {
-      return Em.isNone(config.get('widgetType'));
-    }).filter(function(config) {
-      return !config.get('isValid') || (config.get('overrides') || []).someProperty('isValid', false);
-    }).filterProperty('isVisible').length;
-  }.property('selectedService.configs.@each.isValid', 'selectedService.configs.@each.isVisible', 'selectedService.configs.@each.overrideErrorTrigger'),
+  errorsCount: function() {
+    return this.get('selectedService.configsWithErrors').rejectProperty('widgetType').length;
+  }.property('selectedService.configsWithErrors'),
 
 
   /**
   /**
    * Determines if Save-button should be disabled
    * Determines if Save-button should be disabled

+ 4 - 13
ambari-web/app/controllers/wizard/step7_controller.js

@@ -132,13 +132,9 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
    * Number of errors in the configs in the selected service
    * Number of errors in the configs in the selected service
    * @type {number}
    * @type {number}
    */
    */
-  errorsCount: function () {
-    return this.get('selectedService.configs').filter(function (config) {
-      return Em.isNone(config.get('widgetType'));
-    }).filter(function(config) {
-      return !config.get('isValid') || (config.get('overrides') || []).someProperty('isValid', false);
-    }).filterProperty('isVisible').length;
-  }.property('selectedService.configs.@each.isValid', 'selectedService.configs.@each.isVisible','selectedService.configs.@each.overrideErrorTrigger'),
+  errorsCount: function() {
+    return this.get('selectedService.configsWithErrors').rejectProperty('widgetType').length;
+  }.property('selectedService.configsWithErrors'),
 
 
   /**
   /**
    * Should Next-button be disabled
    * Should Next-button be disabled
@@ -665,12 +661,7 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
             } else if (configCondition.get('type') === 'config') {
             } else if (configCondition.get('type') === 'config') {
               //simulate section wrapper for condition type "config"
               //simulate section wrapper for condition type "config"
               themeResource = Em.Object.create({
               themeResource = Em.Object.create({
-                configProperties: [
-                  Em.Object.create({
-                    name: configCondition.get('configName'),
-                    fileName: configCondition.get('fileName')
-                  })
-                ]
+                configProperties: [App.config.configId(configCondition.get('configName'), configCondition.get('fileName'))]
               });
               });
             }
             }
             if (themeResource) {
             if (themeResource) {

+ 35 - 52
ambari-web/app/models/configs/objects/service_config.js

@@ -21,24 +21,47 @@ var App = require('app');
 App.ServiceConfig = Ember.Object.extend({
 App.ServiceConfig = Ember.Object.extend({
   serviceName: '',
   serviceName: '',
   configCategories: [],
   configCategories: [],
-  configs: null,
+  configCategoriesMap: function() {
+    var categoriesMap = {};
+    this.get('configCategories').forEach(function(c) {
+      if (!categoriesMap[c.get('name')]) categoriesMap[c.get('name')] = c;
+    });
+    return categoriesMap;
+  }.property('configCategories.[]'),
+  configs: [],
   restartRequired: false,
   restartRequired: false,
   restartRequiredMessage: '',
   restartRequiredMessage: '',
   restartRequiredHostsAndComponents: {},
   restartRequiredHostsAndComponents: {},
   configGroups: [],
   configGroups: [],
   dependentServiceNames: [],
   dependentServiceNames: [],
   initConfigsLength: 0, // configs length after initialization in order to watch changes
   initConfigsLength: 0, // configs length after initialization in order to watch changes
-  errorCount: function () {
-    var overrideErrors = 0,
-      masterErrors = 0,
-      slaveErrors = 0,
-      configs = this.get('configs'),
-      configCategories = this.get('configCategories'),
-      enhancedConfigsErrors = 0;
-    configCategories.forEach(function (_category) {
-      slaveErrors += _category.get('slaveErrorCount');
-      _category.set('nonSlaveErrorCount', 0);
+
+  errorCount: Em.computed.alias('configsWithErrors.length'),
+
+  visibleProperties: function() {
+    return this.get('configs').filter(function(c) {
+      return c.get('isVisible') && !c.get('hiddenBySection');
+    });
+  }.property('configs.@each.isVisible', 'configs.@each.hiddenBySection'),
+
+  configsWithErrors: function() {
+    return this.get('visibleProperties').filter(function(c) {
+      return !c.get('isValid') || !c.get('isValidOverride');
     });
     });
+  }.property('visibleProperties.@each.isValid', 'visibleProperties.@each.isValidOverride'),
+
+  observeErrors: function() {
+    this.get('configCategories').setEach('errorCount', 0);
+    this.get('configsWithErrors').forEach(function(c) {
+      if (this.get('configCategoriesMap')[c.get('category')]) {
+        this.get('configCategoriesMap')[c.get('category')].incrementProperty('errorCount');
+      }
+    }, this);
+  }.observes('configsWithErrors'),
+
+  observeForeignKeys: function() {
+    //TODO refactor or move this login to other place
+    var configs = this.get('configs');
     configs.forEach(function (item) {
     configs.forEach(function (item) {
       if (item.get('isVisible')) {
       if (item.get('isVisible')) {
         var options = item.get('options');
         var options = item.get('options');
@@ -55,29 +78,7 @@ App.ServiceConfig = Ember.Object.extend({
         }
         }
       }
       }
     });
     });
-    configs.forEach(function (item) {
-      var category = configCategories.findProperty('name', item.get('category'));
-      if (category && !item.get('isValid') && item.get('isVisible') && !item.get('widgetType')) {
-        category.incrementProperty('nonSlaveErrorCount');
-        masterErrors++;
-      }
-      if (!item.get('isValid') && item.get('widgetType') && item.get('isVisible') && !item.get('hiddenBySection')) {
-        enhancedConfigsErrors++;
-      }
-      if (item.get('overrides')) {
-        item.get('overrides').forEach(function (e) {
-          if (e.error) {
-            if (category && !Em.get(e, 'parentSCP.widget')) {
-              category.incrementProperty('nonSlaveErrorCount');
-            }
-            overrideErrors++;
-          }
-        });
-      }
-    });
-    return masterErrors + slaveErrors + overrideErrors + enhancedConfigsErrors;
-  }.property('configs.@each.isValid', 'configs.@each.isVisible', 'configCategories.@each.slaveErrorCount', 'configs.@each.overrideErrorTrigger'),
-
+  }.observes('configs.@each.isVisible'),
   /**
   /**
    * checks if for example for kdc_type, the value isn't just the pretty version of the saved value, for example mit-kdc
    * checks if for example for kdc_type, the value isn't just the pretty version of the saved value, for example mit-kdc
    * and Existing MIT KDC are the same value, but they are interpreted as being changed. This function fixes that
    * and Existing MIT KDC are the same value, but they are interpreted as being changed. This function fixes that
@@ -118,24 +119,6 @@ App.ServiceConfig = Ember.Object.extend({
   }
   }
 });
 });
 
 
-App.SlaveConfigs = Ember.Object.extend({
-  componentName: null,
-  displayName: null,
-  hosts: null,
-  groups: null
-});
-
-App.Group = Ember.Object.extend({
-  name: null,
-  hostNames: null,
-  properties: null,
-  errorCount: function () {
-    if (this.get('properties')) {
-      return this.get('properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
-    }
-  }.property('properties.@each.isValid', 'properties.@each.isVisible')
-});
-
 App.ConfigSiteTag = Ember.Object.extend({
 App.ConfigSiteTag = Ember.Object.extend({
   site: DS.attr('string'),
   site: DS.attr('string'),
   tag: DS.attr('string'),
   tag: DS.attr('string'),

+ 1 - 32
ambari-web/app/models/configs/objects/service_config_category.js

@@ -24,7 +24,6 @@ App.ServiceConfigCategory = Ember.Object.extend({
    *  We cant have spaces in the name as this is being used as HTML element id while rendering. Hence we introduced 'displayName' where we can have spaces like 'Secondary Name Node' etc.
    *  We cant have spaces in the name as this is being used as HTML element id while rendering. Hence we introduced 'displayName' where we can have spaces like 'Secondary Name Node' etc.
    */
    */
   displayName: null,
   displayName: null,
-  slaveConfigs: null,
   /**
   /**
    * check whether to show custom view in category instead of default
    * check whether to show custom view in category instead of default
    */
    */
@@ -40,38 +39,8 @@ App.ServiceConfigCategory = Ember.Object.extend({
    * Can this category add new properties. Used for custom configurations.
    * Can this category add new properties. Used for custom configurations.
    */
    */
   canAddProperty: false,
   canAddProperty: false,
-  nonSlaveErrorCount: 0,
-  primaryName: function () {
-    switch (this.get('name')) {
-      case 'DataNode':
-        return 'DATANODE';
-        break;
-      case 'TaskTracker':
-        return 'TASKTRACKER';
-        break;
-      case 'RegionServer':
-        return 'HBASE_REGIONSERVER';
-    }
-    return null;
-  }.property('name'),
 
 
-
-  isForMasterComponent: Em.computed.existsIn('name', ['NameNode', 'SNameNode', 'JobTracker', 'HBase Master', 'Oozie Master',
-    'Hive Metastore', 'WebHCat Server', 'ZooKeeper Server', 'Ganglia']),
-
-  isForSlaveComponent: Em.computed.existsIn('name', ['DataNode', 'TaskTracker', 'RegionServer']),
-
-  slaveErrorCount: function () {
-    var length = 0;
-    if (this.get('slaveConfigs.groups')) {
-      this.get('slaveConfigs.groups').forEach(function (_group) {
-        length += _group.get('errorCount');
-      }, this);
-    }
-    return length;
-  }.property('slaveConfigs.groups.@each.errorCount'),
-
-  errorCount: Em.computed.sumProperties('slaveErrorCount', 'nonSlaveErrorCount'),
+  errorCount: 0,
 
 
   isAdvanced : function(){
   isAdvanced : function(){
     var name = this.get('name');
     var name = this.get('name');

+ 7 - 6
ambari-web/app/models/configs/objects/service_config_property.js

@@ -169,9 +169,8 @@ App.ServiceConfigProperty = Em.Object.extend({
       }
       }
     });
     });
     return originalSCPIssued || overridesIssue;
     return originalSCPIssued || overridesIssue;
-  }.property('errorMessage', 'warnMessage', 'overrideErrorTrigger'),
+  }.property('errorMessage', 'warnMessage', 'overrides.@each.warnMessage', 'overrides.@each.errorMessage'),
 
 
-  overrideErrorTrigger: 0, //Trigger for overridable property error
   index: null, //sequence number in category
   index: null, //sequence number in category
   editDone: false, //Text field: on focusOut: true, on focusIn: false
   editDone: false, //Text field: on focusOut: true, on focusIn: false
   isNotSaved: false, // user property was added but not saved
   isNotSaved: false, // user property was added but not saved
@@ -202,11 +201,13 @@ App.ServiceConfigProperty = Em.Object.extend({
   additionalView: null,
   additionalView: null,
 
 
   /**
   /**
-   * On Overridable property error message, change overrideErrorTrigger value to recount number of errors service have
+   * Is property has active override with error
    */
    */
-  observeErrors: function () {
-    this.set("overrideErrorTrigger", this.get("overrideErrorTrigger") + 1);
-  }.observes("overrides.@each.errorMessage"),
+  isValidOverride: function () {
+    return this.get('overrides.length') ? !this.get('overrides').find(function(o) {
+     return o.get('isEditable') && o.get('errorMessage');
+    }) : true;
+  }.property("overrides.@each.errorMessage"),
   /**
   /**
    * No override capabilities for fields which are not edtiable
    * No override capabilities for fields which are not edtiable
    * and fields which represent master hosts.
    * and fields which represent master hosts.

+ 13 - 5
ambari-web/app/models/configs/theme/sub_section.js

@@ -94,17 +94,25 @@ App.SubSection = DS.Model.extend({
 
 
   showTabs: Em.computed.and('hasTabs', 'someSubSectionTabIsVisible'),
   showTabs: Em.computed.and('hasTabs', 'someSubSectionTabIsVisible'),
 
 
+  visibleProperties: function() {
+    return this.get('configs').filter(function(c) {
+      return c.get('isVisible') && !c.get('hiddenBySection');
+    });
+  }.property('configs.@each.isVisible', 'configs.@each.hiddenBySection'),
+
+  visibleTabs: Em.computed.filterBy('subSectionTabs', 'isVisible', true),
+
   /**
   /**
    * Number of the errors in all configs
    * Number of the errors in all configs
    * @type {number}
    * @type {number}
    */
    */
   errorsCount: function () {
   errorsCount: function () {
-    var visibleTabs = this.get('subSectionTabs').filterProperty('isVisible');
-    var subSectionTabsErrors = visibleTabs.length ? visibleTabs.mapProperty('errorsCount').reduce(Em.sum, 0) : 0;
-    return subSectionTabsErrors + this.get('configs').filter(function(config) {
-      return config.get('isVisible') && (!config.get('isValid') || (config.get('overrides') || []).someProperty('isValid', false));
+    var propertiesWithErrors = this.get('visibleProperties').filter(function(c) {
+      return !c.get('isValid') || !c.get('isValidOverride');
     }).length;
     }).length;
-  }.property('configs.@each.isValid', 'configs.@each.isVisible', 'configs.@each.overrideErrorTrigger', 'subSectionTabs.@each.isVisible', 'subSectionTabs.@each.errorsCount'),
+    var tabsWithErrors = this.get('visibleTabs').mapProperty('errorsCount').reduce(Em.sum, 0);
+    return propertiesWithErrors + tabsWithErrors;
+  }.property('visibleProperties.@each.isValid', 'visibleProperties.@each.isValidOverride', 'visibleTabs.@each.errorsCount'),
 
 
   /**
   /**
    * @type {boolean}
    * @type {boolean}

+ 11 - 10
ambari-web/app/models/configs/theme/sub_section_tab.js

@@ -55,15 +55,21 @@ App.SubSectionTab = DS.Model.extend({
    */
    */
   isActive: DS.attr('boolean', {defaultValue: false}),
   isActive: DS.attr('boolean', {defaultValue: false}),
 
 
+  visibleProperties: function() {
+    return this.get('configs').filter(function(c) {
+      return c.get('isVisible') && !c.get('hiddenBySection');
+    });
+  }.property('configs.@each.isVisible', 'configs.@each.hiddenBySection'),
+
   /**
   /**
    * Number of the errors in all configs
    * Number of the errors in all configs
    * @type {number}
    * @type {number}
    */
    */
   errorsCount: function () {
   errorsCount: function () {
-    return this.get('configs').filter(function(config) {
-      return config.get('isVisible') && (!config.get('isValid') || (config.get('overrides') || []).someProperty('isValid', false));
+    return this.get('visibleProperties').filter(function(config) {
+      return !config.get('isValid') || !config.get('isValidOverride');
     }).length;
     }).length;
-  }.property('configs.@each.isVisible', 'configs.@each.isValid', 'configs.@each.overrideErrorTrigger'),
+  }.property('visibleProperties.@each.isValid', 'visibleProperties.@each.isValidOverride'),
 
 
   /**
   /**
    * If the visibility of subsection is dependent on a value of some config
    * If the visibility of subsection is dependent on a value of some config
@@ -75,17 +81,12 @@ App.SubSectionTab = DS.Model.extend({
    * If there is no configs, subsection can't be hidden
    * If there is no configs, subsection can't be hidden
    * @type {boolean}
    * @type {boolean}
    */
    */
-  isHiddenByFilter: function () {
-    var configs = this.get('configs').filter(function(c) {
-      return !c.get('hiddenBySection') && c.get('isVisible');
-    });
-    return configs.length ? configs.everyProperty('isHiddenByFilter', true) : false;
-  }.property('configs.@each.isHiddenByFilter'),
+  isHiddenByFilter: Em.computed.everyBy('visibleProperties', 'isHiddenByFilter', true),
 
 
   /**
   /**
    * @type {boolean}
    * @type {boolean}
    */
    */
-  someConfigIsVisible: Em.computed.someBy('configs', 'isVisible', true),
+  someConfigIsVisible: Em.computed.gt('visibleProperties.length', 0),
 
 
   /**
   /**
    * Determines if subsection is visible
    * Determines if subsection is visible