Browse Source

AMBARI-11782. DataNode directories overrides values with "\n" symbol (onechiporenko)

Oleg Nechiporenko 10 years ago
parent
commit
82ff8884c1

+ 21 - 3
ambari-web/app/models/configs/objects/service_config_property.js

@@ -475,14 +475,14 @@ App.ServiceConfigProperty = Em.Object.extend({
   _validateOverrides: function () {
     var self = this;
     var isError = false;
-    var value = '' + this.get('value');
+    var value = this._getValueForCheck(this.get('value'));
     var isOriginalSCP = this.get('isOriginalSCP');
     var supportsFinal = this.get('supportsFinal');
     var isFinal = this.get('isFinal');
     var parentSCP = this.get('parentSCP');
     if (!isOriginalSCP) {
       if (!Em.isNone(parentSCP)) {
-        if (value === '' + parentSCP.get('value')) {
+        if (value === this._getValueForCheck(parentSCP.get('value'))) {
           if (supportsFinal) {
             if (isFinal === parentSCP.get('isFinal')) {
               this.set('errorMessage', Em.I18n.t('config.override.valueEqualToParentConfig'));
@@ -499,7 +499,7 @@ App.ServiceConfigProperty = Em.Object.extend({
           if (overrides) {
             overrides.forEach(function (override) {
               if (self == override) return;
-              if (value === '' + override.get('value')) {
+              if (value === self._getValueForCheck(override.get('value'))) {
                 if (supportsFinal) {
                   if (isFinal === parentSCP.get('isFinal')) {
                     self.set('errorMessage', Em.I18n.t('config.override.valueEqualToAnotherOverrideConfig'));
@@ -517,6 +517,24 @@ App.ServiceConfigProperty = Em.Object.extend({
       }
     }
     return isError;
+  },
+
+  /**
+   * Some values should be little bit changed before checking for overrides values
+   * `directories`-values should be "trimmed" for multiple mew-line symbols
+   * @param {string} value
+   * @returns {string}
+   * @private
+   */
+  _getValueForCheck: function (value) {
+    value = '' + value;
+    switch(this.get('displayType')) {
+      case 'directories':
+        return value.replace(/(\n\r?)+/g, '\n');
+        break;
+      default:
+        return value;
+    }
   }
 
 });

+ 39 - 0
ambari-web/test/models/configs/objects/service_config_property_test.js

@@ -568,6 +568,19 @@ describe('App.ServiceConfigProperty', function () {
             ]
           })
         }
+      },
+      {
+        m: '`directories`-config with almost equal value',
+        e: true,
+        c: {
+          value: "/hadoop/hdfs/data\n\n",
+          displayType: 'directories',
+          supportsFinal: false,
+          isOriginalSCP: false,
+          parentSCP: App.ServiceConfigProperty.create({
+            value: "/hadoop/hdfs/data\n"
+          })
+        }
       }
     ]).forEach(function (test) {
       it(test.m, function () {
@@ -613,4 +626,30 @@ describe('App.ServiceConfigProperty', function () {
 
   });
 
+  describe('#_getValueForCheck', function () {
+
+    beforeEach(function () {
+      serviceConfigProperty.setProperties({
+        value: "/hadoop/hdfs/data\n",
+        displayType: 'directories',
+        supportsFinal: false,
+        isOriginalSCP: true,
+        overrides: [
+          Em.Object.create({
+            value: "/hadoop/hdfs/data\n\n"
+          })
+        ]
+      });
+    });
+
+    it('should trim value', function () {
+      expect(serviceConfigProperty._getValueForCheck(serviceConfigProperty.get('value'))).to.equal('/hadoop/hdfs/data\n');
+    });
+
+    it('should trim value 2', function () {
+      expect(serviceConfigProperty._getValueForCheck(serviceConfigProperty.get('overrides.0.value'))).to.equal('/hadoop/hdfs/data\n');
+    });
+
+  });
+
 });

+ 1 - 0
ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js

@@ -27,6 +27,7 @@ describe('App.ListConfigWidgetView', function () {
       initPopover: Em.K,
       config: Em.Object.create({
         _validateOverrides: App.ServiceConfigProperty.prototype._validateOverrides,
+        _getValueForCheck: App.ServiceConfigProperty.prototype._getValueForCheck,
         validate: App.ServiceConfigProperty.prototype.validate,
         name: 'a.b.c',
         savedValue: '2,1',