You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ja...@apache.org on 2015/11/10 21:34:18 UTC

ambari git commit: Revert "AMBARI-12575 UI should allow to set same values for config and it's override without any errors. (ababiicuk)"

Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 1fee17d85 -> 7c837a1f4


Revert "AMBARI-12575 UI should allow to set same values for config and it's override without any errors. (ababiicuk)"

This reverts commit d3219265af0132edd6ec5109a56cf2ce7c319810.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7c837a1f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7c837a1f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7c837a1f

Branch: refs/heads/branch-2.1
Commit: 7c837a1f4d5d4875c85a705e58b92713b955b4d7
Parents: 1fee17d
Author: Jaimin Jetly <ja...@hortonworks.com>
Authored: Tue Nov 10 12:33:17 2015 -0800
Committer: Jaimin Jetly <ja...@hortonworks.com>
Committed: Tue Nov 10 12:33:57 2015 -0800

----------------------------------------------------------------------
 ambari-web/app/messages.js                      |   1 +
 .../configs/objects/service_config_property.js  |  70 ++++++++++
 .../objects/service_config_property_test.js     | 136 +++++++++++++++++++
 .../widgets/list_config_widget_view_test.js     |  17 +++
 4 files changed, 224 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7c837a1f/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 496a759..eba1551 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -432,6 +432,7 @@ Em.I18n.translations = {
   'users.userName.validationFail': 'Only lowercase letters and numbers are recommended; must start with a letter',
   'host.spacesValidation': 'Cannot contain whitespace',
   'host.trimspacesValidation': 'Cannot contain leading or trailing whitespace',
+  'config.override.valueEqualToParentConfig': 'Configuration overrides must have different value',
 
   'services.hdfs.rebalance.title' : 'HDFS Rebalance',
   'services.ganglia.description':'Ganglia Metrics Collection system',

http://git-wip-us.apache.org/repos/asf/ambari/blob/7c837a1f/ambari-web/app/models/configs/objects/service_config_property.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/configs/objects/service_config_property.js b/ambari-web/app/models/configs/objects/service_config_property.js
index bca0ed2..4b5bfd9 100644
--- a/ambari-web/app/models/configs/objects/service_config_property.js
+++ b/ambari-web/app/models/configs/objects/service_config_property.js
@@ -505,6 +505,10 @@ App.ServiceConfigProperty = Em.Object.extend({
       }
     }
 
+    if (!isError) {
+      isError = this._validateOverrides();
+    }
+
     if (!isWarn || isError) { // Errors get priority
       this.set('warnMessage', '');
       this.set('warn', false);
@@ -536,6 +540,72 @@ App.ServiceConfigProperty = Em.Object.extend({
   }.property('displayType', 'name', 'App.isHadoop22Stack'),
 
   /**
+   * Check config overrides and parent config overrides (if exist)
+   * @returns {boolean}
+   * @private
+   * @method _validateOverrides
+   */
+  _validateOverrides: function () {
+    var isError = false;
+    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');
+    var overrides = this.get('overrides');
+    if (isOriginalSCP) {
+      if (overrides) {
+        overrides.forEach(function (override) {
+          if (value === this._getValueForCheck(override.get('value'))) {
+            if (supportsFinal) {
+              if (isFinal === override.get('isFinal')) {
+                this.set('errorMessage', Em.I18n.t('config.override.valueEqualToParentConfig'));
+                isError = true;
+              }
+            }
+            else {
+              this.set('errorMessage', Em.I18n.t('config.override.valueEqualToParentConfig'));
+              isError = true;
+            }
+          }
+        }, this);
+      }
+    } else {
+      if (!Em.isNone(parentSCP) && value === this._getValueForCheck(parentSCP.get('value'))) {
+        if (supportsFinal) {
+          if (isFinal === parentSCP.get('isFinal')) {
+            this.set('errorMessage', Em.I18n.t('config.override.valueEqualToParentConfig'));
+            isError = true;
+          }
+        }
+        else {
+          this.set('errorMessage', Em.I18n.t('config.override.valueEqualToParentConfig'));
+          isError = true;
+        }
+      }
+    }
+    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').trim();
+        break;
+      default:
+        return value;
+    }
+  },
+
+  /**
    * Update description for `password`-config
    * Add extra-message about their comparison
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/7c837a1f/ambari-web/test/models/configs/objects/service_config_property_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/configs/objects/service_config_property_test.js b/ambari-web/test/models/configs/objects/service_config_property_test.js
index 58e7eaa..bda01a4 100644
--- a/ambari-web/test/models/configs/objects/service_config_property_test.js
+++ b/ambari-web/test/models/configs/objects/service_config_property_test.js
@@ -474,6 +474,116 @@ describe('App.ServiceConfigProperty', function () {
     });
   });
 
+  describe('#_validateOverrides', function () {
+
+    Em.A([
+      {
+        m: 'original config',
+        e: false,
+        c: {
+          value: 'on',
+          isOriginalSCP: true,
+          supportsFinal: false,
+          isFinal: false,
+          parentSCP: null
+        }
+      },
+      {
+        m: 'not original config, value equal to parent',
+        e: true,
+        c: {
+          value: 'on',
+          isOriginalSCP: false,
+          supportsFinal: false,
+          isFinal: false,
+          parentSCP: App.ServiceConfigProperty.create({
+            value: 'on'
+          })
+        }
+      },
+      {
+        m: 'not original config, isFinal equal to parent',
+        e: false,
+        c: {
+          value: 'on',
+          isOriginalSCP: false,
+          supportsFinal: true,
+          isFinal: false,
+          parentSCP: App.ServiceConfigProperty.create({
+            value: 'off',
+            isFinal: false
+          })
+        }
+      },
+      {
+        m: 'not original config, isFinal equal to parent, but final not supported',
+        e: false,
+        c: {
+          value: 'on',
+          isOriginalSCP: false,
+          supportsFinal: false,
+          isFinal: false,
+          parentSCP: App.ServiceConfigProperty.create({
+            value: 'off',
+            isFinal: false
+          })
+        }
+      },
+      {
+        m: 'not original config, parent override doesn\'t have same value',
+        e: false,
+        c: {
+          value: 'on',
+          isOriginalSCP: false,
+          supportsFinal: true,
+          isFinal: false,
+          parentSCP: App.ServiceConfigProperty.create({
+            value: 'off',
+            isFinal: true,
+            overrides: [
+              App.ServiceConfigProperty.create({
+                value: 'another',
+                isOriginalSCP: false
+              })
+            ]
+          })
+        }
+      },
+      {
+        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"
+          })
+        }
+      },
+      {
+        m: '`directories`-config with almost equal value (2)',
+        e: true,
+        c: {
+          value: "/hadoop/hdfs/data",
+          displayType: 'directories',
+          supportsFinal: false,
+          isOriginalSCP: false,
+          parentSCP: App.ServiceConfigProperty.create({
+            value: "/hadoop/hdfs/data\n"
+          })
+        }
+      }
+    ]).forEach(function (test) {
+      it(test.m, function () {
+        serviceConfigProperty.reopen(test.c);
+        expect(serviceConfigProperty._validateOverrides()).to.equal(test.e);
+      });
+    });
+
+  });
+
   describe('#undoAvailable', function () {
 
     Em.A([
@@ -509,6 +619,32 @@ 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');
+    });
+
+    it('should trim value 2', function () {
+      expect(serviceConfigProperty._getValueForCheck(serviceConfigProperty.get('overrides.0.value'))).to.equal('/hadoop/hdfs/data');
+    });
+
+  });
+
   describe('#overrideIsFinalValues', function () {
     it('should be defined as empty array', function () {
       expect(serviceConfigProperty.get('overrideIsFinalValues')).to.eql([]);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7c837a1f/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js b/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
index d72e38e..3db2dcb 100644
--- a/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
+++ b/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js
@@ -26,6 +26,8 @@ describe('App.ListConfigWidgetView', function () {
     view = App.ListConfigWidgetView.create({
       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',
@@ -192,6 +194,21 @@ describe('App.ListConfigWidgetView', function () {
       view.get('options').setEach('isSelected', true);
       expect(view.get('config.errorMessage')).to.equal('');
     });
+
+    it('check override', function () {
+
+      view.get('config').setProperties({
+        isOriginalSCP: false,
+        parentSCP: Em.Object.create({
+          value: '2,1',
+          isFinal: false
+        })
+      });
+      view.checkSelectedItemsCount();
+      expect(view.get('config.errorMessage')).to.equal(Em.I18n.t('config.override.valueEqualToParentConfig'));
+
+    });
+
   });
 
 });