Преглед изворни кода

AMBARI-10499 Installer configs showing error even when values present. (ababiichuk)

aBabiichuk пре 10 година
родитељ
комит
ba25a16a32

+ 15 - 11
ambari-web/app/mixins/common/configs/enhanced_configs.js

@@ -177,8 +177,7 @@ App.EnhancedConfigsMixin = Em.Mixin.create({
   getRecommendationsForDependencies: function(changedConfigs, initial, onComplete) {
   getRecommendationsForDependencies: function(changedConfigs, initial, onComplete) {
     if (Em.isArray(changedConfigs) && changedConfigs.length > 0 || initial) {
     if (Em.isArray(changedConfigs) && changedConfigs.length > 0 || initial) {
       var recommendations = this.get('hostGroups');
       var recommendations = this.get('hostGroups');
-      var configs = this._getConfigsByGroup(this.get('stepConfigs'));
-      recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(this.get('services'), configs);
+      recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(this.get('services'), this.get('stepConfigs'));
 
 
       var dataToSend = {
       var dataToSend = {
         recommend: 'configurations',
         recommend: 'configurations',
@@ -298,7 +297,7 @@ App.EnhancedConfigsMixin = Em.Mixin.create({
         var dependentConfig = dependentConfigs.filterProperty('propertyName', cp.get('name')).findProperty('fileName', App.config.getConfigTagFromFileName(cp.get('filename')));
         var dependentConfig = dependentConfigs.filterProperty('propertyName', cp.get('name')).findProperty('fileName', App.config.getConfigTagFromFileName(cp.get('filename')));
         if (dependentConfig) {
         if (dependentConfig) {
           var valueToSave = dependentConfig.saveRecommended ? dependentConfig.recommendedValue : dependentConfig.value;
           var valueToSave = dependentConfig.saveRecommended ? dependentConfig.recommendedValue : dependentConfig.value;
-          if (selectedGroup.get('isDefault')) {
+          if (!selectedGroup || selectedGroup.get('isDefault')) {
             cp.set('value', valueToSave);
             cp.set('value', valueToSave);
           } else {
           } else {
             if (serviceConfigs.get('serviceName') !== self.get('content.serviceName')) {
             if (serviceConfigs.get('serviceName') !== self.get('content.serviceName')) {
@@ -327,16 +326,21 @@ App.EnhancedConfigsMixin = Em.Mixin.create({
   /**
   /**
    * get config group object for current service
    * get config group object for current service
    * @param serviceName
    * @param serviceName
-   * @returns {*}
+   * @returns {App.ConfigGroup|null}
    */
    */
   getGroupForService: function(serviceName) {
   getGroupForService: function(serviceName) {
-    if (this.get('content.serviceName') === serviceName) {
-      return this.get('selectedConfigGroup')
+    if (this.get('stepConfigs.length') === 0) return null;
+    if (this.get('name') === 'wizardStep7Controller') {
+      return this.get('stepConfigs').findProperty('serviceName', serviceName).get('selectedConfigGroup');
     } else {
     } else {
-      if (this.get('selectedConfigGroup.isDefault')) {
-        return this.get('dependentConfigGroups').filterProperty('service.serviceName', serviceName).findProperty('isDefault');
+      if (this.get('content.serviceName') === serviceName) {
+        return this.get('selectedConfigGroup')
       } else {
       } else {
-        return this.get('dependentConfigGroups').findProperty('name', this.get('groupsToSave')[serviceName]);
+        if (this.get('selectedConfigGroup.isDefault')) {
+          return this.get('dependentConfigGroups').filterProperty('service.serviceName', serviceName).findProperty('isDefault');
+        } else {
+          return this.get('dependentConfigGroups').findProperty('name', this.get('groupsToSave')[serviceName]);
+        }
       }
       }
     }
     }
   },
   },
@@ -442,10 +446,10 @@ App.EnhancedConfigsMixin = Em.Mixin.create({
 
 
           var stackProperty = App.StackConfigProperty.find(propertyName + '_' + key);
           var stackProperty = App.StackConfigProperty.find(propertyName + '_' + key);
           if (stackProperty && stackProperty.get('valueAttributes')) {
           if (stackProperty && stackProperty.get('valueAttributes')) {
-            if (configs[key].property_attributes[propertyName].min) {
+            if (configs[key].property_attributes[propertyName].minimum) {
               stackProperty.set('valueAttributes.minimum', configs[key].property_attributes[propertyName].minimum);
               stackProperty.set('valueAttributes.minimum', configs[key].property_attributes[propertyName].minimum);
             }
             }
-            if (configs[key].property_attributes[propertyName].max) {
+            if (configs[key].property_attributes[propertyName].maximum) {
               stackProperty.set('valueAttributes.maximum', configs[key].property_attributes[propertyName].maximum);
               stackProperty.set('valueAttributes.maximum', configs[key].property_attributes[propertyName].maximum);
             }
             }
             if (configs[key].property_attributes[propertyName].increment_step) {
             if (configs[key].property_attributes[propertyName].increment_step) {

+ 1 - 1
ambari-web/app/mixins/unit_convert/base_unit_convert_mixin.js

@@ -203,7 +203,7 @@ App.BaseUnitConvertMixin = Em.Mixin.create({
     else {
     else {
       value *= factor;
       value *= factor;
     }
     }
-    return isInt(value) ? value : parseFloat(value.toFixed(2));
+    return isInt(value) ? value : parseFloat(value.toFixed(3));
   }
   }
 
 
 });
 });

+ 2 - 1
ambari-web/app/mixins/unit_convert/convert_unit_widget_view_mixin.js

@@ -41,7 +41,8 @@ App.ConvertUnitWidgetViewMixin = Em.Mixin.create(App.BaseUnitConvertMixin, {
    * @method configValueByWidget
    * @method configValueByWidget
    */
    */
   configValueByWidget: function(value) {
   configValueByWidget: function(value) {
-    return '' + this.convertValue(value, this._converterGetWidgetUnits(), this._converterGetPropertyAttributes());
+    var cfgValue = this.convertValue(value, this._converterGetWidgetUnits(), this._converterGetPropertyAttributes());
+    return '' + this.get('config.stackConfigProperty.valueAttributes.type') === 'int' ? Math.round(cfgValue) : cfgValue;
   },
   },
 
 
   /**
   /**

+ 88 - 55
ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js

@@ -56,6 +56,62 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
 
 
   undoAllowed: false,
   undoAllowed: false,
 
 
+  /**
+   * max allowed value transformed form config unit to widget unit
+   * @type {Number}
+   */
+  maxMirrorValue: function() {
+    var parseFunction = this.get('mirrorValueParseFunction');
+    var max = this.widgetValueByConfigAttributes(this.get('config.stackConfigProperty.valueAttributes.maximum'));
+    return parseFunction(max);
+  }.property('config.stackConfigProperty.valueAttributes.maximum'),
+
+  /**
+   * min allowed value transformed form config unit to widget unit
+   * @type {Number}
+   */
+  minMirrorValue: function() {
+    var parseFunction = this.get('mirrorValueParseFunction');
+    var min = this.widgetValueByConfigAttributes(this.get('config.stackConfigProperty.valueAttributes.minimum'));
+    return parseFunction(min);
+  }.property('config.stackConfigProperty.valueAttributes.minimum'),
+
+  /**
+   * step transformed form config units to widget units
+   * @type {Number}
+   */
+  mirrorStep: function() {
+    var parseFunction = this.get('mirrorValueParseFunction');
+    var step = this.widgetValueByConfigAttributes(this.get('config.stackConfigProperty.valueAttributes.increment_step'));
+    return step ? parseFunction(step) : this.get('unitType') === 'int' ? 1 : 0.1;
+  }.property('config.stackConfigProperty.valueAttributes.increment_step'),
+
+  /**
+   * unit type of widget
+   * @type {String}
+   */
+  unitType: function() {
+    return this.get('config.stackConfigProperty.widget.units.length') && this.get('config.stackConfigProperty.widget.units')[0]['unit-name'];
+  }.property('config.stackConfigProperty.widget.units.@each.unit-name'),
+
+  /**
+   * Function used to parse widget mirror value
+   * For integer - parseInt, for float - parseFloat
+   * @type {Function}
+   */
+  mirrorValueParseFunction: function () {
+    return this.get('unitType') === 'int' ? parseInt : parseFloat;
+  }.property('unitType'),
+
+  /**
+   * Function used to validate widget mirror value
+   * For integer - validator.isValidInt, for float - validator.isValidFloat
+   * @type {Function}
+   */
+  mirrorValueValidateFunction: function () {
+    return this.get('unitType') === 'int' ? validator.isValidInt : validator.isValidFloat;
+  }.property('unitType'),
+
   /**
   /**
    * Function used to parse config value (based on <code>config.stackConfigProperty.valueAttributes.type</code>)
    * Function used to parse config value (based on <code>config.stackConfigProperty.valueAttributes.type</code>)
    * For integer - parseInt, for float - parseFloat
    * For integer - parseInt, for float - parseFloat
@@ -92,20 +148,19 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
 
 
   didInsertElement: function () {
   didInsertElement: function () {
     this._super();
     this._super();
-    this.set('mirrorValue', this.widgetValueByConfigAttributes(this.get('config.value')));
-    this.prepareValueAttributes();
+    this.setValue();
     this.initSlider();
     this.initSlider();
     this.toggleWidgetState();
     this.toggleWidgetState();
     this.initPopover();
     this.initPopover();
-    this.addObserver('config.stackConfigProperty.valueAttributes.minimum', this, this.changeBoundaries);
-    this.addObserver('config.stackConfigProperty.valueAttributes.maximum', this, this.changeBoundaries);
-    this.addObserver('config.stackConfigProperty.valueAttributes.step', this, this.changeBoundaries);
+    this.addObserver('maxMirrorValue', this, this.changeBoundaries);
+    this.addObserver('minMirrorValue', this, this.changeBoundaries);
+    this.addObserver('mirrorStep', this, this.changeBoundaries);
   },
   },
 
 
   willDestroyElement: function() {
   willDestroyElement: function() {
-    this.removeObserver('config.stackConfigProperty.valueAttributes.step', this, this.changeBoundaries);
-    this.removeObserver('config.stackConfigProperty.valueAttributes.maximum', this, this.changeBoundaries);
-    this.removeObserver('config.stackConfigProperty.valueAttributes.minimum', this, this.changeBoundaries);
+    this.removeObserver('maxMirrorValue', this, this.changeBoundaries);
+    this.removeObserver('minMirrorValue', this, this.changeBoundaries);
+    this.removeObserver('mirrorStep', this, this.changeBoundaries);
   },
   },
 
 
   /**
   /**
@@ -126,10 +181,10 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
   mirrorValueObs: function () {
   mirrorValueObs: function () {
     var mirrorValue = this.get('mirrorValue'),
     var mirrorValue = this.get('mirrorValue'),
       slider = this.get('slider'),
       slider = this.get('slider'),
-      min = this.widgetValueByConfigAttributes(this.get('config.stackConfigProperty.valueAttributes.minimum')),
-      max = this.widgetValueByConfigAttributes(this.get('config.stackConfigProperty.valueAttributes.maximum')),
-      validationFunction = this.get('validateFunction'),
-      parseFunction = this.get('parseFunction');
+      min = this.get('minMirrorValue'),
+      max = this.get('maxMirrorValue'),
+      validationFunction = this.get('mirrorValueValidateFunction'),
+      parseFunction = this.get('mirrorValueParseFunction');
     if (validationFunction(mirrorValue)) {
     if (validationFunction(mirrorValue)) {
       var parsed = parseFunction(mirrorValue);
       var parsed = parseFunction(mirrorValue);
       if (parsed >= min && parsed <= max) {
       if (parsed >= min && parsed <= max) {
@@ -139,13 +194,11 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
         if (slider) {
         if (slider) {
           slider.setValue(parsed);
           slider.setValue(parsed);
         }
         }
-      }
-      else {
+      } else {
         this.set('isMirrorValueValid', false);
         this.set('isMirrorValueValid', false);
         this.set('config.errorMessage', 'Invalid value');
         this.set('config.errorMessage', 'Invalid value');
       }
       }
-    }
-    else {
+    } else {
       this.set('isMirrorValueValid', false);
       this.set('isMirrorValueValid', false);
       this.set('config.errorMessage', 'Invalid value');
       this.set('config.errorMessage', 'Invalid value');
     }
     }
@@ -156,22 +209,10 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
    * @method setValue
    * @method setValue
    * set widget value same as config value
    * set widget value same as config value
    */
    */
-  setValue: function() {
+  setValue: function(value) {
     var parseFunction = this.get('parseFunction');
     var parseFunction = this.get('parseFunction');
-    this.set('mirrorValue', this.widgetValueByConfigAttributes(parseFunction(this.get('config.value'))));
-  },
-
-  /**
-   * valueAttributes are strings, but should be numbers
-   * parse them using <code>parseFunction</code>
-   * @method prepareValueAttributes
-   */
-  prepareValueAttributes: function () {
-    var valueAttributes = this.get('config.stackConfigProperty.valueAttributes'),
-      parseFunction = this.get('parseFunction');
-    if (!valueAttributes) return;
-    Em.set(valueAttributes, 'maximum', parseFunction(valueAttributes.maximum));
-    Em.set(valueAttributes, 'minimum', parseFunction(valueAttributes.minimum));
+    value = value || parseFunction(this.get('config.value'));
+    this.set('mirrorValue', this.widgetValueByConfigAttributes(value));
   },
   },
 
 
   /**
   /**
@@ -196,7 +237,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
       config = this.get('config'),
       config = this.get('config'),
       valueAttributes = config.get('stackConfigProperty.valueAttributes'),
       valueAttributes = config.get('stackConfigProperty.valueAttributes'),
       parseFunction = this.get('parseFunction'),
       parseFunction = this.get('parseFunction'),
-      ticks = [this.widgetValueByConfigAttributes(valueAttributes.minimum)],
+      ticks = [this.get('minMirrorValue')],
       ticksLabels = [],
       ticksLabels = [],
       defaultValue = this.widgetValueByConfigAttributes(this.valueForTick(+config.get('defaultValue'))),
       defaultValue = this.widgetValueByConfigAttributes(this.valueForTick(+config.get('defaultValue'))),
       defaultValueMirroredId,
       defaultValueMirroredId,
@@ -204,11 +245,11 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
 
 
     // ticks and labels
     // ticks and labels
     for (var i = 1; i <= 3; i++) {
     for (var i = 1; i <= 3; i++) {
-      var val = this.widgetValueByConfigAttributes((valueAttributes.minimum + valueAttributes.maximum)) / 4 * i;
+      var val = (this.get('maxMirrorValue') + this.get('minMirrorValue')) / 4 * i;
       // if value's type is float, ticks may be float too
       // if value's type is float, ticks may be float too
       ticks.push(this.valueForTick(val));
       ticks.push(this.valueForTick(val));
     }
     }
-    ticks.push(this.widgetValueByConfigAttributes(valueAttributes.maximum));
+    ticks.push(this.get('maxMirrorValue'));
     ticks.forEach(function (tick, index) {
     ticks.forEach(function (tick, index) {
       ticksLabels.push(index % 2 === 0 ? tick + ' ' + self.get('unitLabel') : '');
       ticksLabels.push(index % 2 === 0 ? tick + ' ' + self.get('unitLabel') : '');
     });
     });
@@ -233,17 +274,16 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
     } else {
     } else {
       defaultValueId = ticks.indexOf(defaultValue);
       defaultValueId = ticks.indexOf(defaultValue);
     }
     }
-    var increment_step = Em.get(valueAttributes, 'increment_step');
     var slider = new Slider(this.$('input.slider-input')[0], {
     var slider = new Slider(this.$('input.slider-input')[0], {
-      value: this.widgetValueByConfigAttributes(parseFunction(this.get('config.value'))),
+      value: this.get('mirrorValue'),
       ticks: ticks,
       ticks: ticks,
       tooltip: 'always',
       tooltip: 'always',
       ticks_labels: ticksLabels,
       ticks_labels: ticksLabels,
-      step: increment_step ? this.widgetValueByConfigAttributes(increment_step) : (Em.get(valueAttributes, 'type') === 'int' ? 1 : 0.1)
+      step: this.get('mirrorStep')
     });
     });
 
 
     slider.on('change', function (obj) {
     slider.on('change', function (obj) {
-      var val = parseFunction(obj.newValue);
+      var val = self.get('mirrorValueParseFunction')(obj.newValue);
       self.set('config.value', '' + self.configValueByWidget(val));
       self.set('config.value', '' + self.configValueByWidget(val));
       self.set('mirrorValue', val);
       self.set('mirrorValue', val);
     }).on('slideStop', function() {
     }).on('slideStop', function() {
@@ -284,7 +324,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
    * @returns {Number}
    * @returns {Number}
    */
    */
   valueForTick: function(val) {
   valueForTick: function(val) {
-    return this.get('config.stackConfigProperty.valueAttributes').type === 'int' ? Math.round(val) : parseFloat(val.toFixed(2));
+    return this.get('unitType') === 'int' ? Math.round(val) : parseFloat(val.toFixed(3));
   },
   },
 
 
   /**
   /**
@@ -294,10 +334,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
    */
    */
   restoreValue: function () {
   restoreValue: function () {
     this._super();
     this._super();
-    var parseFunction = this.get('parseFunction'),
-      val = this.widgetValueByConfigAttributes(parseFunction(this.get('config.value')));
-    this.get('slider').setValue(val);
-    this.set('mirrorValue', val);
+    this.get('slider').setValue();
   },
   },
 
 
   /**
   /**
@@ -317,20 +354,16 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({
       //temp fix as it can broke test that doesn't have any connection with this method
       //temp fix as it can broke test that doesn't have any connection with this method
       return;
       return;
     }
     }
-    var self = this;
-    var valueAttributes = this.get('config.stackConfigProperty.valueAttributes');
-
-    self.prepareValueAttributes();
-    if (self.get('slider')) {
-      self.get('slider').destroy();
-      self.initSlider();
-      if (self.get('config.value') > Em.get(valueAttributes, 'maximum')) {
-        self.set('mirrorValue', this.widgetValueByConfigAttributes(Em.get(valueAttributes, 'maximum')));
+    if (this.get('slider')) {
+      this.get('slider').destroy();
+      if (this.get('mirrorValue') > this.get('maxMirrorValue')) {
+        this.setValue(this.get('maxMirrorValue'));
       }
       }
-      if (self.get('config.value') < Em.get(valueAttributes, 'minimum')) {
-        self.set('mirrorValue', this.widgetValueByConfigAttributes(Em.get(valueAttributes, 'minimum')));
+      if (this.get('mirrorValue') < this.get('minMirrorValue')) {
+        this.setValue(this.get('minMirrorValue'));
       }
       }
-      self.toggleWidgetState();
+      this.initSlider();
+      this.toggleWidgetState();
     }
     }
   }
   }
 
 

+ 0 - 28
ambari-web/test/views/common/configs/widgets/slider_config_widget_view_test.js

@@ -172,32 +172,4 @@ describe('App.SliderConfigWidgetView', function () {
     });
     });
   });
   });
 
 
-  describe('#prepareValueAttributes', function () {
-
-    it('should parse string to int', function () {
-
-      var max = viewInt.get('config.stackConfigProperty.valueAttributes.maximum'),
-        min = viewInt.get('config.stackConfigProperty.valueAttributes.minimum');
-      viewInt.set('config.stackConfigProperty.valueAttributes.maximum', '' + max);
-      viewInt.set('config.stackConfigProperty.valueAttributes.minimum', '' + min);
-      viewInt.prepareValueAttributes();
-      expect(viewInt.get('config.stackConfigProperty.valueAttributes.maximum')).to.equal(max);
-      expect(viewInt.get('config.stackConfigProperty.valueAttributes.minimum')).to.equal(min);
-
-    });
-
-    it('should parse string to float', function () {
-
-      var max = viewFloat.get('config.stackConfigProperty.valueAttributes.maximum'),
-        min = viewFloat.get('config.stackConfigProperty.valueAttributes.minimum');
-      viewFloat.set('config.stackConfigProperty.valueAttributes.maximum', '' + max);
-      viewFloat.set('config.stackConfigProperty.valueAttributes.minimum', '' + min);
-      viewFloat.prepareValueAttributes();
-      expect(viewFloat.get('config.stackConfigProperty.valueAttributes.maximum')).to.equal(max);
-      expect(viewFloat.get('config.stackConfigProperty.valueAttributes.minimum')).to.equal(min);
-
-    });
-
-  });
-
 });
 });