Browse Source

AMBARI-15186 Config saving discards Capacity-scheduler changes. (ababiichuk)

ababiichuk 9 years ago
parent
commit
a5f81f8618

+ 3 - 0
ambari-web/app/controllers/wizard.js

@@ -889,6 +889,9 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM
     var installedServiceNames = stepController.get('installedServiceNames') || [];
     var installedServiceNames = stepController.get('installedServiceNames') || [];
     var installedServiceNamesMap = installedServiceNames.toWickMap();
     var installedServiceNamesMap = installedServiceNames.toWickMap();
     stepController.get('stepConfigs').forEach(function (_content) {
     stepController.get('stepConfigs').forEach(function (_content) {
+      if (_content.serviceName === 'YARN') {
+        _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml'));
+      }
       _content.get('configs').forEach(function (_configProperties) {
       _content.get('configs').forEach(function (_configProperties) {
         if (!Em.isNone(_configProperties.get('group'))) {
         if (!Em.isNone(_configProperties.get('group'))) {
           return false;
           return false;

+ 4 - 0
ambari-web/app/mixins/common/configs/configs_saver.js

@@ -313,6 +313,10 @@ App.ConfigsSaverMixin = Em.Mixin.create({
    */
    */
   getServiceConfigToSave: function(serviceName, configs) {
   getServiceConfigToSave: function(serviceName, configs) {
 
 
+    if (serviceName === 'YARN') {
+      configs = App.config.textareaIntoFileConfigs(configs, 'capacity-scheduler.xml');
+    }
+
     //generates list of properties that was changed
     //generates list of properties that was changed
     var modifiedConfigs = this.getModifiedConfigs(configs);
     var modifiedConfigs = this.getModifiedConfigs(configs);
     var serviceFilenames = Object.keys(App.StackService.find(serviceName).get('configTypes')).map(function (type) {
     var serviceFilenames = Object.keys(App.StackService.find(serviceName).get('configTypes')).map(function (type) {

+ 43 - 4
ambari-web/app/utils/config.js

@@ -280,7 +280,8 @@ App.config = Em.Object.create({
    * @returns {Object}
    * @returns {Object}
    */
    */
   createDefaultConfig: function(name, fileName, definedInStack, coreObject) {
   createDefaultConfig: function(name, fileName, definedInStack, coreObject) {
-    var serviceName = this.get('serviceByConfigTypeMap')[fileName] || 'MISC';
+    var service = this.get('serviceByConfigTypeMap')[App.config.getConfigTagFromFileName(fileName)];
+    var serviceName = service ? service.get('serviceName') : 'MISC';
     var tpl = {
     var tpl = {
       /** core properties **/
       /** core properties **/
       id: this.configId(name, fileName),
       id: this.configId(name, fileName),
@@ -626,7 +627,7 @@ App.config = Em.Object.create({
     var connectedConfigs = configs.filter(function(config) {
     var connectedConfigs = configs.filter(function(config) {
       return !excludedConfigs.contains(App.config.configId(config.get('name'), config.get('filename'))) && (config.get('filename') === 'capacity-scheduler.xml');
       return !excludedConfigs.contains(App.config.configId(config.get('name'), config.get('filename'))) && (config.get('filename') === 'capacity-scheduler.xml');
     });
     });
-    connectedConfigs.setEach('isVisible', false);
+    var names = connectedConfigs.mapProperty('name');
 
 
     connectedConfigs.forEach(function (config) {
     connectedConfigs.forEach(function (config) {
       value += config.get('name') + '=' + config.get('value') + '\n';
       value += config.get('name') + '=' + config.get('value') + '\n';
@@ -652,10 +653,12 @@ App.config = Em.Object.create({
       'recommendedIsFinal': recommendedIsFinal,
       'recommendedIsFinal': recommendedIsFinal,
       'displayName': 'Capacity Scheduler',
       'displayName': 'Capacity Scheduler',
       'description': 'Capacity Scheduler properties',
       'description': 'Capacity Scheduler properties',
-      'displayType': 'capacityScheduler',
-      'isRequiredByAgent': false
+      'displayType': 'capacityScheduler'
     });
     });
 
 
+    configs = configs.filter(function(c) {
+      return !(names.contains(c.get('name')) && (c.get('filename') === 'capacity-scheduler.xml'));
+    });
     configs.push(App.ServiceConfigProperty.create(cs));
     configs.push(App.ServiceConfigProperty.create(cs));
     return configs;
     return configs;
   },
   },
@@ -679,6 +682,42 @@ App.config = Em.Object.create({
     return properties;
     return properties;
   },
   },
 
 
+  /**
+   * transform one config with textarea content
+   * into set of configs of file
+   * @param configs
+   * @param filename
+   * @return {*}
+   */
+  textareaIntoFileConfigs: function (configs, filename) {
+    var configsTextarea = configs.findProperty('name', 'capacity-scheduler');
+    if (configsTextarea && !App.get('testMode')) {
+      var properties = configsTextarea.get('value').split('\n');
+
+      properties.forEach(function (_property) {
+        var name, value;
+        if (_property) {
+          _property = _property.split('=');
+          name = _property[0];
+          value = (_property[1]) ? _property[1] : "";
+          configs.push(Em.Object.create({
+            name: name,
+            value: value,
+            savedValue: value,
+            serviceName: configsTextarea.get('serviceName'),
+            filename: filename,
+            isFinal: configsTextarea.get('isFinal'),
+            isNotDefaultValue: configsTextarea.get('isNotDefaultValue'),
+            isRequiredByAgent: configsTextarea.get('isRequiredByAgent'),
+            group: null
+          }));
+        }
+      });
+      return configs.without(configsTextarea);
+    }
+    return configs;
+  },
+
   /**
   /**
    * trim trailing spaces for all properties.
    * trim trailing spaces for all properties.
    * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
    * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.

+ 21 - 61
ambari-web/app/views/common/controls_view.js

@@ -299,73 +299,33 @@ App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSuppor
 /**
 /**
  * Special config type for Capacity Scheduler
  * Special config type for Capacity Scheduler
  */
  */
-App.CapacitySceduler = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.SupportsDependentConfigs, {
+App.CapacitySceduler = App.ServiceConfigTextArea.extend({
 
 
-  configs: function() {
-    return this.get('controller.stepConfigs').findProperty('serviceName', 'YARN').get('configs');
-  }.property('controller.stepConfigs'),
-
-  valueBinding: 'serviceConfig.value',
-  excludedConfigs: function() {
-    return App.config.getPropertiesFromTheme('YARN');
-  }.property(),
   rows: 16,
   rows: 16,
-  classNames: ['directories'],
-  classNameBindings: ['widthClass'],
-  widthClass: 'span9',
 
 
-  connectedConfigs: function() {
-    return this.get('categoryConfigsAll').filter(function(config) {
-      return !this.get('excludedConfigs').contains(App.config.configId(config.get('name'), config.get('filename')))
-        && (config.get('name') !== this.get('serviceConfig.name'))
-        && (config.get('filename') === 'capacity-scheduler.xml');
-    }, this);
-  }.property('categoryConfigsAll.length'),
-
-  valueObserver: function () {
-    var self = this, controller = this.get('controller'),
-      names = [];
-    delay(function () {
-      self.get('serviceConfig.value').split('\n').forEach(function (_property) {
-        if (_property) {
-          _property = _property.split('=');
-          var name = _property[0];
-          var value = (_property[1]) ? _property[1] : "";
-
-          names.push(name);
-
-          var cfg = self.get('connectedConfigs').findProperty('name', name);
-          if (cfg) {
-            /** update configs **/
-            if (cfg.get('value') !== value) {
-              cfg.set('value', value);
-              self.sendRequestRorDependentConfigs(cfg, controller);
-            }
-          } else {
-            /** add configs **/
-            var newCfg = App.config.getDefaultConfig(name, 'YARN', 'capacity-scheduler', {
-              'value': value
-            });
-            self.get('configs').pushObject(App.ServiceConfigProperty.create(newCfg));
-          }
+  /**
+   * specific property handling for cs
+   *
+   * @param {App.ServiceConfigProperty} config
+   * @param [controller]
+   * @returns {$.Deferred}
+   * @override
+   */
+  sendRequestRorDependentConfigs: function(config, controller) {
+    if (!config.get('isValid') && config.get('isNotDefaultValue')) return $.Deferred().resolve().promise();
+    controller = controller || this.get('controller');
+    if (controller && ['mainServiceInfoConfigsController','wizardStep7Controller'].contains(controller.get('name'))) {
+      return controller.loadConfigRecommendations(config.get('value').split('\n').map(function (_property) {
+        return {
+          "type": 'capacity-scheduler',
+          "name": _property.split('=')[0]
         }
         }
-      });
+      }));
+    }
 
 
-      /** remove configs **/
-      self.get('connectedConfigs').filter(function(c) {
-        return !names.contains(c.get('name'));
-      }).forEach(function(c) {
-        self.get('configs').removeObject(c);
-      });
-    }, 500);
-  }.observes('serviceConfig.value'),
+    return $.Deferred().resolve().promise();
+  }
 
 
-  /**
-   * update fina; value for connected configs
-   */
-  isFinalObserver: function () {
-    this.get('connectedConfigs').setEach('isFinal', this.get('serviceConfig.isFinal'));
-  }.observes('serviceConfig.isFinal')
 });
 });
 
 
 /**
 /**

+ 1 - 1
ambari-web/test/utils/config_test.js

@@ -656,7 +656,7 @@ describe('App.config', function () {
       });
       });
       sinon.stub(App.config, 'get', function(param) {
       sinon.stub(App.config, 'get', function(param) {
         if (param === 'serviceByConfigTypeMap') {
         if (param === 'serviceByConfigTypeMap') {
-          return { 'pFileName': 'pServiceName' };
+          return { 'pFileName': Em.Object.create({serviceName: 'pServiceName' }) };
         }
         }
         return Em.get(App.config, param);
         return Em.get(App.config, param);
       });
       });