You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ab...@apache.org on 2016/09/13 11:26:49 UTC

ambari git commit: AMBARI-17497 Add validation check on UI based on minimum and maximum set for LLAP 'textbox' configs. (ababiichuk)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.5 dceba2f8a -> 5c4194253


AMBARI-17497 Add validation check on UI based on minimum and maximum set for LLAP 'textbox' configs. (ababiichuk)


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

Branch: refs/heads/branch-2.5
Commit: 5c4194253588a7f7337fe38cd6c493977d348877
Parents: dceba2f
Author: ababiichuk <ab...@hortonworks.com>
Authored: Tue Sep 13 14:26:37 2016 +0300
Committer: ababiichuk <ab...@hortonworks.com>
Committed: Tue Sep 13 14:26:37 2016 +0300

----------------------------------------------------------------------
 .../configs/objects/service_config_property.js  | 16 ++++++---
 ambari-web/app/utils/config.js                  | 35 ++++++++++++++++++--
 .../widgets/list_config_widget_view_test.js     |  1 +
 .../widgets/slider_config_widget_view_test.js   |  1 +
 4 files changed, 47 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/5c419425/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 2757804..265dd52 100644
--- a/ambari-web/app/models/configs/objects/service_config_property.js
+++ b/ambari-web/app/models/configs/objects/service_config_property.js
@@ -271,7 +271,8 @@ App.ServiceConfigProperty = Em.Object.extend({
   init: function () {
     this.setInitialValues();
     this.set('viewClass', App.config.getViewClass(this.get("displayType"), this.get('dependentConfigPattern'), this.get('unit')));
-    this.set('validator', App.config.getValidator(this.get("displayType")));
+    this.set('validateErrors', App.config.getErrorValidator(this.get("displayType")));
+    this.set('validateWarnings', App.config.getWarningValidator(this.get("displayType")));
     this.validate();
   },
 
@@ -350,16 +351,23 @@ App.ServiceConfigProperty = Em.Object.extend({
         this.set('warnMessage', Em.I18n.t('config.warnMessage.llap_queue_capacity.max'));
       } else {
         this.set('warnMessage', '');
-        this.set('errorMessage', this.validator(this.get('value'), this.get('name'), this.get('retypedPassword')));
+        this.set('errorMessage', this.validateErrors(this.get('value'), this.get('name'), this.get('retypedPassword')));
       }
     } else {
-      this.set('errorMessage', this.validator(this.get('value'), this.get('name'), this.get('retypedPassword')));
+      this.set('errorMessage', this.validateErrors(this.get('value'), this.get('name'), this.get('retypedPassword')));
+    }
+    if (!this.get('widgetType') || ('text-field' === this.get('widgetType'))) {
+      //temp conditions, since other warnings are calculated directly in widget view
+      this.set('warnMessage', this.validateWarnings(this.get('value'), this.get('name'), this.get('filename'),
+        this.get('stackConfigProperty'), this.get('unit')));
     }
   }.observes('value', 'retypedPassword', 'isEditable'),
 
   viewClass: App.ServiceConfigTextField,
 
-  validator: function() { return '' },
+  validateErrors: function() { return '' },
+
+  validateWarnings: function() { return '' },
 
   /**
    * Get override for selected group

http://git-wip-us.apache.org/repos/asf/ambari/blob/5c419425/ambari-web/app/utils/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js
index 3dd8926..0a4d546 100644
--- a/ambari-web/app/utils/config.js
+++ b/ambari-web/app/utils/config.js
@@ -565,12 +565,12 @@ App.config = Em.Object.create({
   },
 
   /**
-   * Returns validator function based on config type
+   * Returns error validator function based on config type
    *
    * @param displayType
    * @returns {Function}
    */
-  getValidator: function (displayType) {
+  getErrorValidator: function (displayType) {
     switch (displayType) {
       case 'checkbox':
       case 'custom':
@@ -632,6 +632,37 @@ App.config = Em.Object.create({
   },
 
   /**
+   * Returns warning validator function based on config type
+   *
+   * @param displayType
+   * @returns {Function}
+   */
+  getWarningValidator: function(displayType) {
+    switch (displayType) {
+      case 'int':
+      case 'float':
+        return function (value, name, filename, stackConfigProperty, unitLabel) {
+          stackConfigProperty = stackConfigProperty || App.configsCollection.getConfigByName(name, filename);
+          var maximum = Em.get(stackConfigProperty || {}, 'valueAttributes.maximum'),
+            minimum = Em.get(stackConfigProperty || {}, 'valueAttributes.minimum'),
+            min = validator.isValidFloat(minimum) ? parseFloat(minimum) : NaN,
+            max = validator.isValidFloat(maximum) ? parseFloat(maximum) : NaN,
+            val = validator.isValidFloat(value) ? parseFloat(value) : NaN;
+
+          if (!isNaN(val) && !isNaN(max) && val > max) {
+            return Em.I18n.t('config.warnMessage.outOfBoundaries.greater').format(max + unitLabel);
+          }
+          if (!isNaN(val) && !isNaN(min) && val < min) {
+            return Em.I18n.t('config.warnMessage.outOfBoundaries.less').format(min + unitLabel);
+          }
+          return '';
+        };
+      default:
+        return function () { return ''; }
+    }
+  },
+
+  /**
    * Defines if config support heterogeneous devices
    *
    * @param {string} name

http://git-wip-us.apache.org/repos/asf/ambari/blob/5c419425/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 66f9d09..84db9b1 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
@@ -34,6 +34,7 @@ describe('App.ListConfigWidgetView', function () {
         filename: 'f1',
         isFinal: false,
         supportsFinal: true,
+        widgetType: 'list-widget',
         stackConfigProperty: Em.Object.create({
           valueAttributes: {
             entries: [

http://git-wip-us.apache.org/repos/asf/ambari/blob/5c419425/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js b/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
index 86f9431..a6b25ce 100644
--- a/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
+++ b/ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js
@@ -645,6 +645,7 @@ describe('App.SliderConfigWidgetView', function () {
         viewInt.set('config.value', '100');
         viewInt.set('config.errorMessage', '');
         viewInt.set('config.warnMessage', '');
+        viewInt.set('config.widgetType', 'slider');
         assert.isTrue(viewInt.isValueCompatibleWithWidget(), 'value should be compatible with widget');
         assert.equal(viewInt.get('config.warnMessage'), Em.I18n.t('config.warnMessage.llap_queue_capacity.max'), 'warn message validation');
       });