Repository: ambari Updated Branches: refs/heads/trunk 533c8ee11 -> 1271328c0
AMBARI-12064 Going over maximum in config-group shows errors in default-config-group. (ababiichuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/1271328c Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/1271328c Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/1271328c Branch: refs/heads/trunk Commit: 1271328c0349471c7d16590f9be469fb658a0a63 Parents: 533c8ee Author: aBabiichuk <[email protected]> Authored: Mon Jun 22 14:22:55 2015 +0300 Committer: aBabiichuk <[email protected]> Committed: Mon Jun 22 14:22:55 2015 +0300 ---------------------------------------------------------------------- .../main/admin/serviceAccounts_controller.js | 38 ++ .../controllers/main/service/info/configs.js | 517 ++----------------- ambari-web/app/mixins.js | 1 + .../mixins/common/configs/configs_comparator.js | 326 ++++++++++++ .../app/mixins/common/configs/configs_loader.js | 43 +- .../mixins/common/configs/enhanced_configs.js | 57 +- .../models/configs/objects/service_config.js | 4 +- ambari-web/app/utils/config.js | 26 +- .../configs/widgets/config_widget_view.js | 4 +- .../widgets/slider_config_widget_view.js | 55 +- .../main/service/info/config_test.js | 128 +---- .../widgets/slider_config_widget_view_test.js | 17 +- 12 files changed, 532 insertions(+), 684 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/controllers/main/admin/serviceAccounts_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/serviceAccounts_controller.js b/ambari-web/app/controllers/main/admin/serviceAccounts_controller.js index 1b1b674..3fcb1df 100644 --- a/ambari-web/app/controllers/main/admin/serviceAccounts_controller.js +++ b/ambari-web/app/controllers/main/admin/serviceAccounts_controller.js @@ -24,6 +24,7 @@ require('controllers/main/service/info/configs'); App.MainAdminServiceAccountsController = App.MainServiceInfoConfigsController.extend({ name: 'mainAdminServiceAccountsController', users: null, + serviceConfigTags: [], content: Em.Object.create({ serviceName: 'MISC' }), @@ -69,6 +70,43 @@ App.MainAdminServiceAccountsController = App.MainServiceInfoConfigsController.ex }); }, + + /** + * Changes format from Object to Array + * + * { + * 'core-site': 'version1', + * 'hdfs-site': 'version1', + * ... + * } + * + * to + * + * [ + * { + * siteName: 'core-site', + * tagName: 'version1', + * newTageName: null + * }, + * ... + * ] + * + * set tagnames for configuration of the *-site.xml + * @private + * @method setServiceConfigTags + */ + setServiceConfigTags: function (desiredConfigsSiteTags) { + var newServiceConfigTags = []; + for (var index in desiredConfigsSiteTags) { + newServiceConfigTags.pushObject({ + siteName: index, + tagName: desiredConfigsSiteTags[index], + newTagName: null + }, this); + } + this.set('serviceConfigTags', newServiceConfigTags); + }, + /** * Generate configuration object that will be rendered * http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/controllers/main/service/info/configs.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/info/configs.js b/ambari-web/app/controllers/main/service/info/configs.js index 8a05117..1121507 100644 --- a/ambari-web/app/controllers/main/service/info/configs.js +++ b/ambari-web/app/controllers/main/service/info/configs.js @@ -21,7 +21,7 @@ require('controllers/wizard/slave_component_groups_controller'); var batchUtils = require('utils/batch_scheduled_requests'); var databaseUtils = require('utils/configs/database'); -App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, App.ServerValidatorMixin, App.EnhancedConfigsMixin, App.ThemesMappingMixin, App.VersionsMappingMixin, App.ConfigsSaverMixin, { +App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, App.ServerValidatorMixin, App.EnhancedConfigsMixin, App.ThemesMappingMixin, App.VersionsMappingMixin, App.ConfigsSaverMixin, App.ConfigsComparator, { name: 'mainServiceInfoConfigsController', @@ -37,8 +37,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A selectedService: null, - serviceConfigTags: null, - selectedConfigGroup: null, requestInProgress: null, @@ -70,8 +68,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A isCompareMode: false, - compareServiceVersion: null, - preSelectedConfigVersion: null, /** @@ -80,11 +76,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A overrideToAdd: null, /** - * version of default config group, configs of which currently applied - */ - currentDefaultVersion: null, - - /** * version selected to view */ selectedVersion: null, @@ -97,13 +88,14 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A versionLoaded: false, + dependentServiceNames: [], /** * defines which service configs need to be loaded to stepConfigs * @type {string[]} */ servicesToLoad: function() { return this.get('dependentServiceNames').concat([this.get('content.serviceName')]).uniq(); - }.property('content.serviceName', 'dependentServiceNames'), + }.property('content.serviceName', 'dependentServiceNames.length'), /** * defines which config groups need to be loaded @@ -134,8 +126,9 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A * @type {boolean} */ canEdit: function () { - return this.get('isCurrentSelected') && !this.get('isCompareMode') && App.isAccessible('MANAGER') && !this.get('isHostsConfigsPage'); - }.property('isCurrentSelected', 'isCompareMode'), + return (this.get('selectedVersion') == this.get('currentDefaultVersion') || !this.get('selectedConfigGroup.isDefault')) + && !this.get('isCompareMode') && App.isAccessible('MANAGER') && !this.get('isHostsConfigsPage'); + }.property('selectedVersion', 'isCompareMode', 'currentDefaultVersion'), serviceConfigs: function () { return App.config.get('preDefinedServiceConfigs'); @@ -149,8 +142,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A return App.config.get('preDefinedSiteProperties'); }.property('App.config.preDefinedSiteProperties'), - secureConfigs: require('data/HDP2/secure_mapping'), - showConfigHistoryFeature: true, /** @@ -285,9 +276,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A this.get('filterColumns').setEach('selected', false); this.get('stepConfigs').clear(); this.get('allConfigs').clear(); - if (this.get('serviceConfigTags')) { - this.set('serviceConfigTags', null); - } }, /** @@ -315,7 +303,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A * @method loadStep */ loadStep: function () { - console.log("TRACE: Loading configure for service"); var serviceName = this.get('content.serviceName'); this.set('dependentServiceNames', App.StackService.find(serviceName).get('dependentServiceNames')); this.clearStep(); @@ -370,8 +357,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A }); } }); - - var configs = App.config.mergePredefinedWithSaved(configGroups, this.get('advancedConfigs'), serviceName); + var configs = App.config.mergePredefinedWithSaved(configGroups, this.get('advancedConfigs'), serviceName, this.get('selectedConfigGroup'), this.get('canEdit')); configs = App.config.syncOrderWithPredefined(configs); /** * if property defined in stack but somehow it missed from cluster properties (can be after stack upgrade) @@ -459,6 +445,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A }, addOverrides: function(data, allConfigs) { + var self = this; data.items.forEach(function(group) { if (group.group_name != 'default') { var configGroup = App.ServiceConfigGroup.find().filterProperty('serviceName', group.service_name).findProperty('name', group.group_name); @@ -466,12 +453,18 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A for (var prop in config.properties) { var fileName = App.config.getOriginalFileName(config.type); var serviceConfig = allConfigs.filterProperty('name', prop).findProperty('filename', fileName); - var hostOverrideValue = App.config.formatOverrideValue(serviceConfig, config.properties[prop]); - var hostOverrideIsFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]); + var value = App.config.formatOverrideValue(serviceConfig, config.properties[prop]); + var isFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]); + if (serviceConfig) { - // Value of this property is different for this host. - if (!Em.get(serviceConfig, 'overrides')) Em.set(serviceConfig, 'overrides', []); - serviceConfig.overrides.pushObject({value: hostOverrideValue, group: configGroup, isFinal: hostOverrideIsFinal}); + if (self.get('selectedConfigGroup.isDefault') || configGroup.get('name') == self.get('selectedConfigGroup.name')) { + var override = self.createNewSCP({"value": value, "isFinal": isFinal, "group": configGroup}, serviceConfig, self.get('selectedConfigGroup.isDefault')); + override.set('isEditable', self.get('canEdit') && configGroup.get('name') == self.get('selectedConfigGroup.name')); + if (!serviceConfig.get('overrides')) serviceConfig.set('overrides', []); + serviceConfig.get('overrides').pushObject(override); + serviceConfig.set('overrideValues', serviceConfig.get('overrides').mapProperty('value')); + serviceConfig.set('overrideIsFinalValues', serviceConfig.get('overrides').mapProperty('isFinal')); + } } else { allConfigs.push(App.config.createCustomGroupConfig(prop, config, configGroup)); } @@ -480,301 +473,6 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A } }); }, - /** - * load version configs for comparison - * @param allConfigs - * @return {object} - * @private - * @method loadCompareVersionConfigs - */ - loadCompareVersionConfigs: function (allConfigs) { - var dfd = $.Deferred(); - var self = this; - var compareServiceVersions = []; - - if (this.get('compareServiceVersion')) { - if (!this.isVersionDefault(this.get('compareServiceVersion').get('version'))) { - compareServiceVersions = [this.get('compareServiceVersion').get('version'), this.get('selectedVersion')]; - } else { - compareServiceVersions = [this.get('compareServiceVersion').get('version')]; - } - - this.getCompareVersionConfigs(compareServiceVersions).done(function (json) { - self.initCompareConfig(allConfigs, json); - self.setProperties({ - compareServiceVersion: null, - isCompareMode: true - }); - dfd.resolve(true); - }).fail(function () { - self.set('compareServiceVersion', null); - dfd.resolve(true); - }); - } else { - self.set('isCompareMode', false); - allConfigs.setEach('isComparison', false); - dfd.resolve(false); - } - return dfd.promise(); - }, - - /** - * attach analogical config to each property for comparison - * @param allConfigs - * @param json - * @private - * @method initCompareConfig - */ - initCompareConfig: function(allConfigs, json) { - var serviceVersionMap = {}; - var configNamesMap = {}; - var serviceName = this.get('content.serviceName'); - var compareVersionNumber = this.get('compareServiceVersion').get('version'); - //indicate whether compared versions are from non-default group - var compareNonDefaultVersions = (json.items.length > 1); - - serviceVersionMap[compareVersionNumber] = {}; - if (compareNonDefaultVersions) { - serviceVersionMap[this.get('selectedVersion')] = {}; - } - allConfigs.mapProperty('name').forEach(function(name) { - configNamesMap[name] = true; - }); - - json.items.forEach(function (item) { - item.configurations.forEach(function (configuration) { - if (serviceName == 'YARN' && configuration.type == 'capacity-scheduler') { - var configsToSkip = this.get('advancedConfigs').filterProperty('filename', 'capacity-scheduler.xml').filterProperty('subSection').mapProperty('name'); - // put all properties in a single textarea for capacity-scheduler - var value = ''; - for (var prop in configuration.properties) { - if (configsToSkip.contains(prop)) { - serviceVersionMap[item.service_config_version][prop + '-' + configuration.type] = { - name: prop, - value: configuration.properties[prop], - type: configuration.type, - tag: configuration.tag, - version: configuration.version, - service_config_version: item.service_config_version - }; - } else { - value += prop + '=' + configuration.properties[prop] + '\n'; - } - } - serviceVersionMap[item.service_config_version][configuration.type + '-' + configuration.type] = { - name: configuration.type, - value: value, - type: configuration.type, - tag: configuration.tag, - version: configuration.version, - service_config_version: item.service_config_version - }; - } else { - for (var prop in configuration.properties) { - serviceVersionMap[item.service_config_version][prop + '-' + configuration.type] = { - name: prop, - value: configuration.properties[prop], - type: configuration.type, - tag: configuration.tag, - version: configuration.version, - service_config_version: item.service_config_version - }; - if (Em.isNone(configNamesMap[prop])) { - allConfigs.push(this.getMockConfig(prop, serviceName, App.config.getOriginalFileName(configuration.type))); - } - } - } - if (configuration.properties_attributes && configuration.properties_attributes.final) { - for (var final in configuration.properties_attributes.final) { - serviceVersionMap[item.service_config_version][final + '-' + configuration.type].isFinal = (configuration.properties_attributes.final[final] === 'true'); - } - } - }, this); - }, this); - - if (compareNonDefaultVersions) { - allConfigs.forEach(function (serviceConfig) { - this.setCompareConfigs(serviceConfig, serviceVersionMap, compareVersionNumber, this.get('selectedVersion')); - }, this); - } else { - allConfigs.forEach(function (serviceConfig) { - var serviceCfgVersionMap = serviceVersionMap[this.get('compareServiceVersion').get('version')]; - var compareConfig = serviceCfgVersionMap[serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)] - this.setCompareDefaultGroupConfig(serviceConfig, compareConfig); - }, this); - } - }, - - /** - * set compare properties to service config of non-default group - * @param serviceConfig - * @param serviceVersionMap - * @param compareVersion - * @param selectedVersion - * @private - * @method setCompareConfigs - */ - setCompareConfigs: function (serviceConfig, serviceVersionMap, compareVersion, selectedVersion) { - var compareConfig = serviceVersionMap[compareVersion][serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)]; - var selectedConfig = serviceVersionMap[selectedVersion][serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)]; - - serviceConfig.compareConfigs = []; - serviceConfig.isComparison = true; - - if (compareConfig && selectedConfig) { - serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, compareConfig)); - serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, selectedConfig)); - serviceConfig.hasCompareDiffs = this.hasCompareDiffs(serviceConfig.compareConfigs[0], serviceConfig.compareConfigs[1]); - } else if (compareConfig && !selectedConfig) { - serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, compareConfig)); - serviceConfig.compareConfigs.push(this.getMockComparisonConfig(selectedConfig, selectedVersion)); - serviceConfig.hasCompareDiffs = true; - } else if (!compareConfig && selectedConfig) { - serviceConfig.compareConfigs.push(this.getMockComparisonConfig(selectedConfig, compareVersion)); - serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, selectedConfig)); - serviceConfig.hasCompareDiffs = true; - } - }, - - /** - * init attributes and wrap mock compare config into App.ServiceConfigProperty - * @param serviceConfig - * @param compareServiceVersion - * @return {object} - * @private - * @method getMockComparisonConfig - */ - getMockComparisonConfig: function (serviceConfig, compareServiceVersion) { - var compareObject = $.extend(true, {isComparison: false}, serviceConfig); - compareObject.isEditable = false; - - compareObject.serviceVersion = App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + compareServiceVersion); - compareObject.isMock = true; - compareObject.displayType = 'label'; - compareObject = App.ServiceConfigProperty.create(compareObject); - compareObject.set('value', Em.I18n.t('common.property.undefined')); - return compareObject; - }, - - /** - * init attributes and wrap compare config into App.ServiceConfigProperty - * @param serviceConfig - * @param compareConfig - * @return {object} - * @private - * @method getComparisonConfig - */ - getComparisonConfig: function (serviceConfig, compareConfig) { - var compareObject = $.extend(true, {isComparison: false, isOriginalSCP: false}, serviceConfig); - compareObject.isEditable = false; - - if (compareConfig) { - if (serviceConfig.isMock) { - compareObject.displayType = 'string'; - compareObject.isMock = false; - } - compareObject.serviceVersion = App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + compareConfig.service_config_version); - compareObject = App.ServiceConfigProperty.create(compareObject); - compareObject.setProperties({ - isFinal: !!compareConfig.isFinal, - value: App.config.formatOverrideValue(serviceConfig, compareConfig.value), - compareConfigs: null - }); - } - return compareObject; - }, - - /** - * set compare properties to service config of default group - * @param serviceConfig - * @param compareConfig - * @private - * @method setCompareDefaultGroupConfig - */ - setCompareDefaultGroupConfig: function (serviceConfig, compareConfig) { - var compareObject = {}; - var isEmptyProp = App.isEmptyObject(serviceConfig); - - serviceConfig.compareConfigs = []; - serviceConfig.isComparison = true; - - //if config isn't reconfigurable then it can't have changed value to compare - if (compareConfig && (serviceConfig.isReconfigurable || serviceConfig.isUserProperty)) { - compareObject = this.getComparisonConfig(serviceConfig, compareConfig); - serviceConfig.hasCompareDiffs = serviceConfig.isMock || this.hasCompareDiffs(serviceConfig, compareObject); - serviceConfig.compareConfigs.push(compareObject); - // user custom property or property that was added during upgrade - } else if (serviceConfig.isUserProperty || (!isEmptyProp && !compareConfig && Em.get(serviceConfig, 'isRequiredByAgent') !== false)) { - serviceConfig.compareConfigs.push(this.getMockComparisonConfig(serviceConfig, this.get('compareServiceVersion.version'))); - serviceConfig.hasCompareDiffs = true; - } - return serviceConfig; - }, - - /** - * check value and final attribute of original and compare config for differences - * @param originalConfig - * @param compareConfig - * @return {Boolean} - * @private - * @method hasCompareDiffs - */ - hasCompareDiffs: function (originalConfig, compareConfig) { - return (originalConfig.value !== compareConfig.value) || (!!originalConfig.isFinal !== (compareConfig.isFinal == true)); - }, - - /** - * generate mock config object - * @param name - * @param serviceName - * @param filename - * @return {Object} - * @private - * @method getMockConfig - */ - getMockConfig: function (name, serviceName, filename) { - var undefinedConfig = { - description: name, - displayName: name, - id: "site property", - isOverridable: false, - isReconfigurable: false, - isRequired: false, - isRequiredByAgent: false, - isSecureConfig: false, - isUserProperty: true, - isVisible: true, - name: name, - filename: filename, - serviceName: serviceName, - value: Em.I18n.t('common.property.undefined'), - isMock: true, - displayType: 'label' - }; - var category = App.config.identifyCategory(undefinedConfig); - undefinedConfig.category = category && category.name; - return undefinedConfig; - }, - - /** - * get configs of chosen version from server to compare - * @param compareServiceVersions - * @return {$.ajax} - * @private - * @method getCompareVersionConfigs - */ - getCompareVersionConfigs: function (compareServiceVersions) { - this.set('versionLoaded', false); - - return App.ajax.send({ - name: 'service.serviceConfigVersions.get.multiple', - sender: this, - data: { - serviceName: this.get('content.serviceName'), - serviceConfigVersions: compareServiceVersions - } - }); - }, /** * @param serviceConfig @@ -842,18 +540,11 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A * @method onLoadOverrides */ onLoadOverrides: function (allConfigs) { - var self = this; this.get('servicesToLoad').forEach(function(serviceName) { - var serviceConfig = App.config.createServiceConfig(serviceName); - if (serviceName == this.get('content.serviceName')) { - serviceConfig.set('configGroups', this.get('configGroups')); - } else { - serviceConfig.set('configGroups', this.get('dependentConfigGroups').filterProperty('serviceName', serviceName)); - } - //Make SecondaryNameNode invisible on enabling namenode HA + var configGroups = serviceName == this.get('content.serviceName') ? this.get('configGroups') : this.get('dependentConfigGroups').filterProperty('serviceName', serviceName); var configsByService = this.get('allConfigs').filterProperty('serviceName', serviceName); databaseUtils.bootstrapDatabaseProperties(configsByService, serviceName); - this.loadConfigs(configsByService, serviceConfig); + var serviceConfig = App.config.createServiceConfig(serviceName, configGroups, configsByService, configsByService.length); if (serviceConfig.get('serviceName') === 'HDFS') { if (App.get('isHaEnabled')) { var c = serviceConfig.configs, @@ -868,27 +559,24 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A var selectedService = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName')); this.set('selectedService', selectedService); - this.setVisibilityForRangerProperties(selectedService); this.checkOverrideProperty(selectedService); this.checkDatabaseProperties(selectedService); - this.checkForSecureConfig(this.get('selectedService')); if (!App.Service.find().someProperty('serviceName', 'RANGER')) { App.config.removeRangerConfigs(this.get('stepConfigs')); - } - this._onLoadComplete(); - if (App.isAccessible('MANAGER')) { - this.getRecommendationsForDependencies(null, true, function(){ - self.set('hash', self.getHash()); - }); } else { - this.set('hash', this.getHash()); + this.setVisibilityForRangerProperties(selectedService); } + this._onLoadComplete(); + this.get('configGroups').forEach(function (configGroup) { + this.getRecommendationsForDependencies(null, true, Em.K, configGroup); + }, this); }, /** * @method _getRecommendationsForDependenciesCallback */ _onLoadComplete: function () { + var self = this; this.get('stepConfigs').forEach(function(serviceConfig){ serviceConfig.set('initConfigsLength', serviceConfig.get('configs.length')); }); @@ -897,99 +585,9 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A versionLoaded: true, isInit: false }); - }, - - /** - * Changes format from Object to Array - * - * { - * 'core-site': 'version1', - * 'hdfs-site': 'version1', - * ... - * } - * - * to - * - * [ - * { - * siteName: 'core-site', - * tagName: 'version1', - * newTageName: null - * }, - * ... - * ] - * - * set tagnames for configuration of the *-site.xml - * @private - * @method setServiceConfigTags - */ - setServiceConfigTags: function (desiredConfigsSiteTags) { - console.debug("setServiceConfigTags(): Trying to set ", desiredConfigsSiteTags); - var newServiceConfigTags = []; - for (var index in desiredConfigsSiteTags) { - newServiceConfigTags.pushObject({ - siteName: index, - tagName: desiredConfigsSiteTags[index], - newTagName: null - }, this); - } - console.debug("setServiceConfigTags(): Setting 'serviceConfigTags' to ", newServiceConfigTags); - this.set('serviceConfigTags', newServiceConfigTags); - }, - - /** - * check whether the config property is a security related knob - * @param serviceConfig - * @private - * @method checkForSecureConfig - */ - checkForSecureConfig: function (serviceConfig) { - serviceConfig.get('configs').forEach(function (_config) { - this.get('secureConfigs').forEach(function (_secureConfig) { - if (_config.get('name') === _secureConfig.name) { - _config.set('isSecureConfig', true); - } - }, this) - }, this) - }, - - /** - * Load child components to service config object - * @param {Array} configs - array of configs - * @param {Object} componentConfig - component config object - * @method loadConfigs - */ - loadConfigs: function (configs, componentConfig) { - var defaultGroupSelected = this.get('selectedConfigGroup.isDefault'); - configs.forEach(function (_serviceConfigProperty) { - var serviceConfigProperty = this.createConfigProperty(_serviceConfigProperty, defaultGroupSelected); - componentConfig.get('configs').pushObject(serviceConfigProperty); - serviceConfigProperty.validate(); - }, this); - }, - - /** - * create {Em.Object} service_cfg_property based on {Object}_serviceConfigProperty and additional info - * @param {Object} _serviceConfigProperty - config object - * @param {Boolean} defaultGroupSelected - true if selected cfg group is default - * @returns {Ember.Object|null} - * @private - * @method createConfigProperty - */ - createConfigProperty: function (_serviceConfigProperty, defaultGroupSelected) { - if (!_serviceConfigProperty) return null; - - var overrides = Em.get(_serviceConfigProperty, 'overrides'); - // we will populate the override properties below - Em.set(_serviceConfigProperty, 'overrides', null); - Em.set(_serviceConfigProperty, 'isOverridable', Em.isNone(Em.get(_serviceConfigProperty, 'isOverridable')) ? true : Em.get(_serviceConfigProperty, 'isOverridable')); - - var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty); - - this.setValuesForOverrides(overrides, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected); - this.setEditability(serviceConfigProperty, defaultGroupSelected); - - return serviceConfigProperty; + Em.run.next(function() { + self.set('hash', self.getHash()); + }); }, /** @@ -1016,7 +614,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A /** * trigger addOverrideProperty - * @param {Object} componentConfig + * @param {Object[]} configs * @private * @method checkOverrideProperty */ @@ -1036,63 +634,16 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A }, /** - * set isEditable property of config for admin - * if default cfg group and not on the host config page - * @param {Ember.Object} serviceConfigProperty - * @param {Boolean} defaultGroupSelected - * @private - * @method setEditability - */ - setEditability: function (serviceConfigProperty, defaultGroupSelected) { - serviceConfigProperty.set('isEditable', false); - if (serviceConfigProperty.get('isComparison')) return; - if (App.isAccessible('ADMIN') && defaultGroupSelected && !this.get('isHostsConfigsPage') && !serviceConfigProperty.get('group')) { - serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable')); - } else if (serviceConfigProperty.get('group') && this.get('selectedConfigGroup.name') === serviceConfigProperty.get('group.name')) { - serviceConfigProperty.set('isEditable', true); - } - }, - - /** - * set override values - * @param overrides - * @param _serviceConfigProperty - * @param serviceConfigProperty - * @param defaultGroupSelected - * @private - * @method setValuesForOverrides - */ - setValuesForOverrides: function (overrides, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected) { - if (Em.isNone(overrides)) return; - overrides.forEach(function (override) { - if (defaultGroupSelected || (Em.get(override, 'group') && this.get('selectedConfigGroup.name') === Em.get(override, 'group.name')) - || serviceConfigProperty.get('serviceName') !== this.get('content.serviceName')) { - var newSCP = this.createNewSCP(override, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected); - var parentOverridesArray = serviceConfigProperty.get('overrides'); - if (parentOverridesArray == null) { - parentOverridesArray = Em.A([]); - serviceConfigProperty.set('overrides', parentOverridesArray); - } - parentOverridesArray.pushObject(newSCP); - serviceConfigProperty.set('overrideValues', parentOverridesArray.mapProperty('value')); - serviceConfigProperty.set('overrideIsFinalValues', parentOverridesArray.mapProperty('isFinal')); - console.debug("createOverrideProperty(): Added override to main-property:", serviceConfigProperty.get('name')); - } - }, this); - }, - - /** * create new overridden property and set appropriate fields * @param override - * @param _serviceConfigProperty * @param serviceConfigProperty * @param defaultGroupSelected * @returns {*} * @private * @method createNewSCP */ - createNewSCP: function (override, _serviceConfigProperty, serviceConfigProperty, defaultGroupSelected) { - var newSCP = App.ServiceConfigProperty.create(_serviceConfigProperty, { + createNewSCP: function (override, serviceConfigProperty, defaultGroupSelected) { + var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty, { value: Em.get(override, 'value'), savedValue: Em.get(override, 'value'), recommendedValue: serviceConfigProperty.get('recommendedValue'), @@ -1273,7 +824,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, A var hostConfig = serviceConfigs.findProperty('name', hostProperty); if (hostConfig) { hostConfig.recommendedValue = this.getMasterComponentHostValue(componentName, multiple); - configs.push(hostConfig); + configs.push(App.ServiceConfigProperty.create(hostConfig)); } }, http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/mixins.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins.js b/ambari-web/app/mixins.js index 72e2531..ca5c633 100644 --- a/ambari-web/app/mixins.js +++ b/ambari-web/app/mixins.js @@ -45,6 +45,7 @@ require('mixins/wizard/assign_master_components'); require('mixins/common/configs/enhanced_configs'); require('mixins/common/configs/configs_saver'); require('mixins/common/configs/configs_loader'); +require('mixins/common/configs/configs_comparator'); require('mixins/common/configs/toggle_isrequired'); require('mixins/common/widgets/widget_mixin'); require('mixins/common/widgets/widget_section'); http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/mixins/common/configs/configs_comparator.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/configs/configs_comparator.js b/ambari-web/app/mixins/common/configs/configs_comparator.js new file mode 100644 index 0000000..ef48654 --- /dev/null +++ b/ambari-web/app/mixins/common/configs/configs_comparator.js @@ -0,0 +1,326 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var App = require('app'); + +App.ConfigsComparator = Em.Mixin.create({ + + isCompareMode: false, + + compareServiceVersion: null, + + selectedVersion: null, + + isVersionDefault: Em.K, + /** + * load version configs for comparison + * @param allConfigs + * @return {object} + * @public + * @method loadCompareVersionConfigs + */ + loadCompareVersionConfigs: function (allConfigs) { + var dfd = $.Deferred(); + var self = this; + var compareServiceVersions = []; + + if (this.get('compareServiceVersion')) { + if (!this.isVersionDefault(this.get('compareServiceVersion').get('version'))) { + compareServiceVersions = [this.get('compareServiceVersion').get('version'), this.get('selectedVersion')]; + } else { + compareServiceVersions = [this.get('compareServiceVersion').get('version')]; + } + + this.getCompareVersionConfigs(compareServiceVersions).done(function (json) { + self.initCompareConfig(allConfigs, json); + self.setProperties({ + compareServiceVersion: null, + isCompareMode: true + }); + dfd.resolve(true); + }).fail(function () { + self.set('compareServiceVersion', null); + dfd.resolve(true); + }); + } else { + self.set('isCompareMode', false); + allConfigs.setEach('isComparison', false); + dfd.resolve(false); + } + return dfd.promise(); + }, + + /** + * attach analogical config to each property for comparison + * @param allConfigs + * @param json + * @private + * @method initCompareConfig + */ + initCompareConfig: function(allConfigs, json) { + var serviceVersionMap = {}; + var configNamesMap = {}; + var serviceName = this.get('content.serviceName'); + var compareVersionNumber = this.get('compareServiceVersion').get('version'); + //indicate whether compared versions are from non-default group + var compareNonDefaultVersions = (json.items.length > 1); + + serviceVersionMap[compareVersionNumber] = {}; + if (compareNonDefaultVersions) { + serviceVersionMap[this.get('selectedVersion')] = {}; + } + allConfigs.mapProperty('name').forEach(function(name) { + configNamesMap[name] = true; + }); + + json.items.forEach(function (item) { + item.configurations.forEach(function (configuration) { + if (serviceName == 'YARN' && configuration.type == 'capacity-scheduler') { + var configsToSkip = this.get('advancedConfigs').filterProperty('filename', 'capacity-scheduler.xml').filterProperty('subSection').mapProperty('name'); + // put all properties in a single textarea for capacity-scheduler + var value = ''; + for (var prop in configuration.properties) { + if (configsToSkip.contains(prop)) { + serviceVersionMap[item.service_config_version][prop + '-' + configuration.type] = { + name: prop, + value: configuration.properties[prop], + type: configuration.type, + tag: configuration.tag, + version: configuration.version, + service_config_version: item.service_config_version + }; + } else { + value += prop + '=' + configuration.properties[prop] + '\n'; + } + } + serviceVersionMap[item.service_config_version][configuration.type + '-' + configuration.type] = { + name: configuration.type, + value: value, + type: configuration.type, + tag: configuration.tag, + version: configuration.version, + service_config_version: item.service_config_version + }; + } else { + for (var prop in configuration.properties) { + serviceVersionMap[item.service_config_version][prop + '-' + configuration.type] = { + name: prop, + value: configuration.properties[prop], + type: configuration.type, + tag: configuration.tag, + version: configuration.version, + service_config_version: item.service_config_version + }; + if (Em.isNone(configNamesMap[prop])) { + allConfigs.push(this.getMockConfig(prop, serviceName, App.config.getOriginalFileName(configuration.type))); + } + } + } + if (configuration.properties_attributes && configuration.properties_attributes.final) { + for (var final in configuration.properties_attributes.final) { + serviceVersionMap[item.service_config_version][final + '-' + configuration.type].isFinal = (configuration.properties_attributes.final[final] === 'true'); + } + } + }, this); + }, this); + + if (compareNonDefaultVersions) { + allConfigs.forEach(function (serviceConfig) { + this.setCompareConfigs(serviceConfig, serviceVersionMap, compareVersionNumber, this.get('selectedVersion')); + }, this); + } else { + allConfigs.forEach(function (serviceConfig) { + var serviceCfgVersionMap = serviceVersionMap[this.get('compareServiceVersion').get('version')]; + var compareConfig = serviceCfgVersionMap[serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)] + this.setCompareDefaultGroupConfig(serviceConfig, compareConfig); + }, this); + } + }, + + /** + * set compare properties to service config of non-default group + * @param serviceConfig + * @param serviceVersionMap + * @param compareVersion + * @param selectedVersion + * @private + * @method setCompareConfigs + */ + setCompareConfigs: function (serviceConfig, serviceVersionMap, compareVersion, selectedVersion) { + var compareConfig = serviceVersionMap[compareVersion][serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)]; + var selectedConfig = serviceVersionMap[selectedVersion][serviceConfig.name + '-' + App.config.getConfigTagFromFileName(serviceConfig.filename)]; + + serviceConfig.compareConfigs = []; + serviceConfig.isComparison = true; + + if (compareConfig && selectedConfig) { + serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, compareConfig)); + serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, selectedConfig)); + serviceConfig.hasCompareDiffs = this.hasCompareDiffs(serviceConfig.compareConfigs[0], serviceConfig.compareConfigs[1]); + } else if (compareConfig && !selectedConfig) { + serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, compareConfig)); + serviceConfig.compareConfigs.push(this.getMockComparisonConfig(selectedConfig, selectedVersion)); + serviceConfig.hasCompareDiffs = true; + } else if (!compareConfig && selectedConfig) { + serviceConfig.compareConfigs.push(this.getMockComparisonConfig(selectedConfig, compareVersion)); + serviceConfig.compareConfigs.push(this.getComparisonConfig(serviceConfig, selectedConfig)); + serviceConfig.hasCompareDiffs = true; + } + }, + + /** + * init attributes and wrap mock compare config into App.ServiceConfigProperty + * @param serviceConfig + * @param compareServiceVersion + * @return {object} + * @private + * @method getMockComparisonConfig + */ + getMockComparisonConfig: function (serviceConfig, compareServiceVersion) { + var compareObject = $.extend(true, {isComparison: false}, serviceConfig); + compareObject.isEditable = false; + + compareObject.serviceVersion = App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + compareServiceVersion); + compareObject.isMock = true; + compareObject.displayType = 'label'; + compareObject = App.ServiceConfigProperty.create(compareObject); + compareObject.set('value', Em.I18n.t('common.property.undefined')); + return compareObject; + }, + + /** + * init attributes and wrap compare config into App.ServiceConfigProperty + * @param serviceConfig + * @param compareConfig + * @return {object} + * @private + * @method getComparisonConfig + */ + getComparisonConfig: function (serviceConfig, compareConfig) { + var compareObject = $.extend(true, {isComparison: false, isOriginalSCP: false}, serviceConfig); + compareObject.isEditable = false; + + if (compareConfig) { + if (serviceConfig.isMock) { + compareObject.displayType = 'string'; + compareObject.isMock = false; + } + compareObject.serviceVersion = App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + compareConfig.service_config_version); + compareObject = App.ServiceConfigProperty.create(compareObject); + compareObject.setProperties({ + isFinal: !!compareConfig.isFinal, + value: App.config.formatOverrideValue(serviceConfig, compareConfig.value), + compareConfigs: null + }); + } + return compareObject; + }, + + /** + * set compare properties to service config of default group + * @param serviceConfig + * @param compareConfig + * @private + * @method setCompareDefaultGroupConfig + */ + setCompareDefaultGroupConfig: function (serviceConfig, compareConfig) { + var compareObject = {}; + var isEmptyProp = App.isEmptyObject(serviceConfig); + + serviceConfig.compareConfigs = []; + serviceConfig.isComparison = true; + + //if config isn't reconfigurable then it can't have changed value to compare + if (compareConfig && (serviceConfig.isReconfigurable || serviceConfig.isUserProperty)) { + compareObject = this.getComparisonConfig(serviceConfig, compareConfig); + serviceConfig.hasCompareDiffs = serviceConfig.isMock || this.hasCompareDiffs(serviceConfig, compareObject); + serviceConfig.compareConfigs.push(compareObject); + // user custom property or property that was added during upgrade + } else if (serviceConfig.isUserProperty || (!isEmptyProp && !compareConfig && Em.get(serviceConfig, 'isRequiredByAgent') !== false)) { + serviceConfig.compareConfigs.push(this.getMockComparisonConfig(serviceConfig, this.get('compareServiceVersion.version'))); + serviceConfig.hasCompareDiffs = true; + } + return serviceConfig; + }, + + /** + * check value and final attribute of original and compare config for differences + * @param originalConfig + * @param compareConfig + * @return {Boolean} + * @private + * @method hasCompareDiffs + */ + hasCompareDiffs: function (originalConfig, compareConfig) { + return (originalConfig.value !== compareConfig.value) || (!!originalConfig.isFinal !== (compareConfig.isFinal == true)); + }, + + /** + * generate mock config object + * @param name + * @param serviceName + * @param filename + * @return {Object} + * @private + * @method getMockConfig + */ + getMockConfig: function (name, serviceName, filename) { + var undefinedConfig = { + description: name, + displayName: name, + id: "site property", + isOverridable: false, + isReconfigurable: false, + isRequired: false, + isRequiredByAgent: false, + isSecureConfig: false, + isUserProperty: true, + isVisible: true, + name: name, + filename: filename, + serviceName: serviceName, + value: Em.I18n.t('common.property.undefined'), + isMock: true, + displayType: 'label' + }; + var category = App.config.identifyCategory(undefinedConfig); + undefinedConfig.category = category && category.name; + return App.ServiceConfigProperty.create(undefinedConfig); + }, + + /** + * get configs of chosen version from server to compare + * @param compareServiceVersions + * @return {$.ajax} + * @private + * @method getCompareVersionConfigs + */ + getCompareVersionConfigs: function (compareServiceVersions) { + this.set('versionLoaded', false); + + return App.ajax.send({ + name: 'service.serviceConfigVersions.get.multiple', + sender: this, + data: { + serviceName: this.get('content.serviceName'), + serviceConfigVersions: compareServiceVersions + } + }); + } + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/mixins/common/configs/configs_loader.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/configs/configs_loader.js b/ambari-web/app/mixins/common/configs/configs_loader.js index 3864b47..6b07d80 100644 --- a/ambari-web/app/mixins/common/configs/configs_loader.js +++ b/ambari-web/app/mixins/common/configs/configs_loader.js @@ -21,6 +21,11 @@ var App = require('app'); App.ConfigsLoader = Em.Mixin.create(App.GroupsMappingMixin, { /** + * version of default config group, configs of which currently applied + */ + currentDefaultVersion: null, + + /** * the highest version number that is stored in <code>App.ServiceConfigVersion<code> * @type {number} */ @@ -126,25 +131,29 @@ App.ConfigsLoader = Em.Mixin.create(App.GroupsMappingMixin, { loadSelectedVersion: function (version, switchToGroup) { this.set('versionLoaded', false); version = version || this.get('currentDefaultVersion'); - //version of non-default group require properties from current version of default group to correctly display page - var versions = (this.isVersionDefault(version)) ? [version] : [this.get('currentDefaultVersion'), version]; - switchToGroup = (this.isVersionDefault(version) && !switchToGroup) ? this.get('configGroups').findProperty('isDefault') : switchToGroup; + if (version === this.get('currentDefaultVersion') && (!switchToGroup || switchToGroup.get('isDefault'))) { + this.loadCurrentVersions(); + } else { + //version of non-default group require properties from current version of default group to correctly display page + var versions = (this.isVersionDefault(version)) ? [version] : [this.get('currentDefaultVersion'), version]; + switchToGroup = (this.isVersionDefault(version) && !switchToGroup) ? this.get('configGroups').findProperty('isDefault') : switchToGroup; - if (this.get('dataIsLoaded') && switchToGroup) { - this.set('selectedConfigGroup', switchToGroup); + if (this.get('dataIsLoaded') && switchToGroup) { + this.set('selectedConfigGroup', switchToGroup); + } + var selectedVersion = versions.length > 1 ? versions[1] : versions[0]; + this.set('selectedVersion', selectedVersion); + this.trackRequest(App.ajax.send({ + name: 'service.serviceConfigVersions.get.multiple', + sender: this, + data: { + serviceName: this.get('content.serviceName'), + serviceConfigVersions: versions, + additionalParams: App.get('isClusterSupportsEnhancedConfigs') && this.get('dependentServiceNames.length') ? '|service_name.in(' + this.get('dependentServiceNames') + ')&is_current=true' : '' + }, + success: 'loadSelectedVersionsSuccess' + })); } - var selectedVersion = versions.length > 1 ? versions[1] : versions[0]; - this.set('selectedVersion', selectedVersion); - this.trackRequest(App.ajax.send({ - name: 'service.serviceConfigVersions.get.multiple', - sender: this, - data: { - serviceName: this.get('content.serviceName'), - serviceConfigVersions: versions, - additionalParams: App.get('isClusterSupportsEnhancedConfigs') && this.get('dependentServiceNames.length') ? '|service_name.in(' + this.get('dependentServiceNames') + ')&is_current=true' : '' - }, - success: 'loadSelectedVersionsSuccess' - })); }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/mixins/common/configs/enhanced_configs.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/configs/enhanced_configs.js b/ambari-web/app/mixins/common/configs/enhanced_configs.js index 9b30a72..c6dd967 100644 --- a/ambari-web/app/mixins/common/configs/enhanced_configs.js +++ b/ambari-web/app/mixins/common/configs/enhanced_configs.js @@ -218,10 +218,14 @@ App.EnhancedConfigsMixin = Em.Mixin.create({ * @param {{type: string, name: string}[]} changedConfigs - list of changed configs to track recommendations * @param {Boolean} initial * @param {Function} onComplete + * @param {App.ConfigGroup|null} [configGroup=null] * @returns {$.ajax|null} */ - getRecommendationsForDependencies: function(changedConfigs, initial, onComplete) { + getRecommendationsForDependencies: function(changedConfigs, initial, onComplete, configGroup) { if (Em.isArray(changedConfigs) && changedConfigs.length > 0 || initial) { + if (!configGroup) { + configGroup = this.get('selectedConfigGroup'); + } var recommendations = this.get('hostGroups'); recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(this.get('services'), this.get('stepConfigs')); delete recommendations.config_groups; @@ -236,8 +240,8 @@ App.EnhancedConfigsMixin = Em.Mixin.create({ dataToSend.recommend = 'configuration-dependencies'; dataToSend.changed_configurations = changedConfigs; } - if (!this.get('selectedConfigGroup.isDefault') && this.get('selectedConfigGroup.hosts.length') > 0) { - var configGroups = this.buildConfigGroupJSON(this.get('selectedService.configs'), this.get('selectedConfigGroup')); + if (!configGroup.get('isDefault') && configGroup.get('hosts.length') > 0) { + var configGroups = this.buildConfigGroupJSON(this.get('selectedService.configs'), configGroup); recommendations.config_groups = [configGroups]; } } @@ -248,7 +252,7 @@ App.EnhancedConfigsMixin = Em.Mixin.create({ data: { stackVersionUrl: App.get('stackVersionURL'), dataToSend: dataToSend, - selectedConfigGroup: this.get('selectedConfigGroup.isDefault') ? null : this.get('selectedConfigGroup.name'), + selectedConfigGroup: configGroup.get('isDefault') ? null : configGroup.get('name'), initial: initial }, success: 'dependenciesSuccess', @@ -458,33 +462,34 @@ App.EnhancedConfigsMixin = Em.Mixin.create({ } else { cp && cp.set('recommendedValue', recommendedValue); } - - /** - * clear _dependentPropertyValues from - * properties that wasn't changed while recommendations - */ - - if ((initialValue == recommendedValue) || (Em.isNone(initialValue) && Em.isNone(recommendedValue))) { - /** if recommended value same as default we shouldn't show it in popup **/ - if (notDefaultGroup) { - if (override) { - if (override.get('isNotSaved')) { - cp.get('overrides').removeObject(override); - } else { - override.set('value', initialValue); + if (!updateOnlyBoundaries) { + /** + * clear _dependentPropertyValues from + * properties that wasn't changed while recommendations + */ + + if ((initialValue == recommendedValue) || (Em.isNone(initialValue) && Em.isNone(recommendedValue))) { + /** if recommended value same as default we shouldn't show it in popup **/ + if (notDefaultGroup) { + if (override) { + if (override.get('isNotSaved')) { + cp.get('overrides').removeObject(override); + } else { + override.set('value', initialValue); + } + if (dependentProperty) { + this.get('_dependentConfigValues').removeObject(dependentProperty); + } + } + } else { + cp.set('value', initialValue); + if (!this.useInitialValue(serviceName)) { + cp.set('savedValue', initialValue); } if (dependentProperty) { this.get('_dependentConfigValues').removeObject(dependentProperty); } } - } else { - cp.set('value', initialValue); - if (!this.useInitialValue(serviceName)) { - cp.set('savedValue', initialValue); - } - if (dependentProperty) { - this.get('_dependentConfigValues').removeObject(dependentProperty); - } } } } http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/models/configs/objects/service_config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/configs/objects/service_config.js b/ambari-web/app/models/configs/objects/service_config.js index b1a1d43..507fbb5 100644 --- a/ambari-web/app/models/configs/objects/service_config.js +++ b/ambari-web/app/models/configs/objects/service_config.js @@ -72,7 +72,7 @@ App.ServiceConfig = Ember.Object.extend({ var kdcType = configs.findProperty('name', 'kdc_type'); if (!kdcType) { - return true; + return configs.someProperty('isNotDefaultValue') } // if there is only one value changed and that value is for kdc_type, check if the value has really changed or just @@ -83,7 +83,7 @@ App.ServiceConfig = Ember.Object.extend({ } } - return true; + return configs.someProperty('isNotDefaultValue'); }, isPropertiesChanged: function() { http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/utils/config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js index cd8a4e3..14c1c5f 100644 --- a/ambari-web/app/utils/config.js +++ b/ambari-web/app/utils/config.js @@ -118,6 +118,8 @@ App.config = Em.Object.create({ this.set('preDefinedServiceConfigs', services); }, + secureConfigs: require('data/HDP2/secure_mapping'), + configMapping: require('data/HDP2/config_mapping'), preDefinedSiteProperties: function () { @@ -277,7 +279,7 @@ App.config = Em.Object.create({ }, - mergePredefinedWithSaved: function (configCategories, advancedConfigs, serviceName) { + mergePredefinedWithSaved: function (configCategories, advancedConfigs, serviceName, selectedConfigGroup, canEdit) { var configs = []; var contentProperties = this.createContentProperties(advancedConfigs); var preDefinedConfigs = this.get('preDefinedSiteProperties').concat(contentProperties); @@ -300,7 +302,7 @@ App.config = Em.Object.create({ configsPropertyDef = advancedConfig; } var value = this.parseValue(properties[index], configsPropertyDef, advancedConfig); - var serviceConfigObj = App.ServiceConfig.create({ + var serviceConfigObj = Em.Object.create({ name: index, value: value, savedValue: value, @@ -351,7 +353,13 @@ App.config = Em.Object.create({ }); this.calculateConfigProperties(serviceConfigObj, isAdvanced, advancedConfig); this.setValueByDisplayType(serviceConfigObj); - configs.push(serviceConfigObj); + if (this.get('secureConfigs').mapProperty('name').contains(serviceConfigObj.get('name'))) { + serviceConfigObj.set('isSecure', true); + } + serviceConfigObj.set('isEditable', canEdit && selectedConfigGroup.get('isDefault') && serviceConfigObj.get('isReconfigurable')); + var serviceConfigProperty = App.ServiceConfigProperty.create(serviceConfigObj); + serviceConfigProperty.validate(); + configs.push(serviceConfigProperty); } } }, this); @@ -888,17 +896,21 @@ App.config = Em.Object.create({ /** * create new ServiceConfig object by service name * @param {string} serviceName + * @param {App.ServiceConfigGroup[]} configGroups + * @param {App.ServiceConfigProperty[]} configs + * @param {Number} initConfigsLength * @return {App.ServiceConfig} * @method createServiceConfig */ - createServiceConfig: function (serviceName) { + createServiceConfig: function (serviceName, configGroups, configs, initConfigsLength) { var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName); return App.ServiceConfig.create({ serviceName: preDefinedServiceConfig.get('serviceName'), displayName: preDefinedServiceConfig.get('displayName'), configCategories: preDefinedServiceConfig.get('configCategories'), - configs: [], - configGroups: [] + configs: configs || [], + configGroups: configGroups || [], + initConfigsLength: initConfigsLength || 0 }); }, @@ -1535,7 +1547,7 @@ App.config = Em.Object.create({ configs = configs.filter(function (_config) { return _config.filename !== filename || (configsToSkip && configsToSkip.someProperty('name', _config.name)); }); - configs.push(complexConfig); + configs.push(App.ServiceConfigProperty.create(complexConfig)); } return configs; }, http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/views/common/configs/widgets/config_widget_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/configs/widgets/config_widget_view.js b/ambari-web/app/views/common/configs/widgets/config_widget_view.js index 4cf30b4..5fcf777 100644 --- a/ambari-web/app/views/common/configs/widgets/config_widget_view.js +++ b/ambari-web/app/views/common/configs/widgets/config_widget_view.js @@ -407,9 +407,7 @@ App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPo * Initialize widget with incompatible value as textbox */ initIncompatibleWidgetAsTextBox : function() { - if (!this.isValueCompatibleWithWidget()) { - this.get('config').set('showAsTextBox', true); - } + this.get('config').set('showAsTextBox', !this.isValueCompatibleWithWidget()); }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js b/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js index f3ba5df..7712804 100644 --- a/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js +++ b/ambari-web/app/views/common/configs/widgets/slider_config_widget_view.js @@ -82,9 +82,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({ */ maxMirrorValue: function() { var parseFunction = this.get('mirrorValueParseFunction'); - var defaultGroupAttr = this.get('config.stackConfigProperty.valueAttributes'); - var groupAttr = this.get('configGroup') && this.get('config.stackConfigProperty.valueAttributes')[this.get('configGroup.name')]; - var maximum = (groupAttr && !Em.isNone(groupAttr['maximum'])) ? groupAttr['maximum'] : defaultGroupAttr['maximum']; + var maximum = this.getValueAttributeByGroup('maximum'); var max = this.widgetValueByConfigAttributes(maximum); return parseFunction(max); }.property('config.stackConfigProperty.valueAttributes.maximum', 'controller.forceUpdateBoundaries'), @@ -95,14 +93,27 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({ */ minMirrorValue: function() { var parseFunction = this.get('mirrorValueParseFunction'); - var defaultGroupAttr = this.get('config.stackConfigProperty.valueAttributes'); - var groupAttr = this.get('configGroup') && this.get('config.stackConfigProperty.valueAttributes')[this.get('configGroup.name')]; - var minimum = (groupAttr && !Em.isNone(groupAttr['minimum'])) ? groupAttr['minimum'] : defaultGroupAttr['minimum']; + var minimum = this.getValueAttributeByGroup('minimum'); var min = this.widgetValueByConfigAttributes(minimum); return parseFunction(min); }.property('config.stackConfigProperty.valueAttributes.minimum', 'controller.forceUpdateBoundaries'), /** + * + * if group is default look into (ex. for maximum) + * <code>config.stackConfigProperty.valueAttributes.maximum<code> + * if group is not default look into + * <code>config.stackConfigProperty.valueAttributes.{group.name}.maximum<code> + * @param {String} attribute - name of attribute, for current moment + * can be ["maximum","minimum","increment_step"] but allows to use other it there will be available + * @returns {*} + */ + getValueAttributeByGroup: function(attribute) { + var defaultGroupAttr = this.get('config.stackConfigProperty.valueAttributes'); + var groupAttr = this.get('configGroup') && this.get('config.stackConfigProperty.valueAttributes')[this.get('configGroup.name')]; + return (groupAttr && !Em.isNone(groupAttr[attribute])) ? groupAttr[attribute] : defaultGroupAttr[attribute]; + }, + /** * step transformed form config units to widget units * @type {Number} */ @@ -214,7 +225,13 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({ }); this.removeObserver('mirrorValue', this, this.mirrorValueObs); if (this.get('slider')) { - this.get('slider').destroy(); + try { + if (self.get('slider')) { + self.get('slider').destroy(); + } + } catch (e) { + console.error('error while clearing slider for config: ' + self.get('config.name')); + } } }, @@ -508,16 +525,18 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({ //temp fix as it can broke test that doesn't have any connection with this method return; } - if (this.get('slider')) { - this.get('slider').destroy(); - if (this.get('mirrorValue') > this.get('maxMirrorValue')) { - this.setValue(this.get('maxMirrorValue')); - } - if (this.get('mirrorValue') < this.get('minMirrorValue')) { - this.setValue(this.get('minMirrorValue')); + if (this.get('config')) { + try { + if (this.get('slider')) { + this.get('slider').destroy(); + } + this.initIncompatibleWidgetAsTextBox(); + this.initSlider(); + this.toggleWidgetState(); + this.refreshSliderObserver(); + } catch (e) { + console.error('error while rebuilding slider for config: ' + this.get('config.name')); } - this.initSlider(); - this.toggleWidgetState(); } }, @@ -547,7 +566,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({ } var configValue = this.get('parseFunction')(this.get('config.value')); if (this.get('config.stackConfigProperty.valueAttributes.minimum')) { - var min = this.get('parseFunction')(this.get('config.stackConfigProperty.valueAttributes.minimum')); + var min = this.get('parseFunction')(this.getValueAttributeByGroup('minimum')); if (configValue < min) { min = this.widgetValueByConfigAttributes(min); this.updateWarningsForCompatibilityWithWidget(Em.I18n.t('config.warnMessage.outOfBoundaries.less').format(min + this.get('unitLabel'))); @@ -555,7 +574,7 @@ App.SliderConfigWidgetView = App.ConfigWidgetView.extend({ } } if (this.get('config.stackConfigProperty.valueAttributes.maximum')) { - var max = this.get('parseFunction')(this.get('config.stackConfigProperty.valueAttributes.maximum')); + var max = this.get('parseFunction')(this.getValueAttributeByGroup('maximum')); if (configValue > max) { max = this.widgetValueByConfigAttributes(max); this.updateWarningsForCompatibilityWithWidget(Em.I18n.t('config.warnMessage.outOfBoundaries.greater').format(max + this.get('unitLabel'))); http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/ambari-web/test/controllers/main/service/info/config_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/info/config_test.js b/ambari-web/test/controllers/main/service/info/config_test.js index 50d7116..8911743 100644 --- a/ambari-web/test/controllers/main/service/info/config_test.js +++ b/ambari-web/test/controllers/main/service/info/config_test.js @@ -679,70 +679,6 @@ describe("App.MainServiceInfoConfigsController", function () { }); }); - describe("#setEditability", function () { - - var tests = [ - { - isAdmin: true, - isHostsConfigsPage: false, - defaultGroupSelected: true, - isReconfigurable: true, - isEditable: true, - m: "" - }, - { - isAdmin: false, - isHostsConfigsPage: false, - defaultGroupSelected: true, - isReconfigurable: true, - isEditable: false, - m: "(non admin)" - }, - { - isAdmin: true, - isHostsConfigsPage: true, - defaultGroupSelected: true, - isReconfigurable: true, - isEditable: false, - m: "(isHostsConfigsPage)" - }, - { - isAdmin: true, - isHostsConfigsPage: false, - defaultGroupSelected: false, - isReconfigurable: true, - isEditable: false, - m: "(defaultGroupSelected is false)" - }, - { - isAdmin: true, - isHostsConfigsPage: false, - defaultGroupSelected: true, - isReconfigurable: false, - isEditable: false, - m: "(isReconfigurable is false)" - } - ]; - - beforeEach(function(){ - this.mock = sinon.stub(App, 'isAccessible'); - }); - afterEach(function () { - this.mock.restore(); - }); - tests.forEach(function(t) { - it("set isEditable " + t.isEditable + t.m, function(){ - this.mock.returns(t.isAdmin); - mainServiceInfoConfigsController.set("isHostsConfigsPage", t.isHostsConfigsPage); - var serviceConfigProperty = Em.Object.create({ - isReconfigurable: t.isReconfigurable - }); - mainServiceInfoConfigsController.setEditability(serviceConfigProperty, t.defaultGroupSelected); - expect(serviceConfigProperty.get("isEditable")).to.equal(t.isEditable); - }); - }); - }); - describe("#checkOverrideProperty", function () { var tests = [{ overrideToAdd: { @@ -831,67 +767,6 @@ describe("App.MainServiceInfoConfigsController", function () { }); }); - describe("#setValuesForOverrides", function() { - var tests = [ - { - overrides: [ - {name: "override1"}, - {name: "override2"} - ], - _serviceConfigProperty: {}, - serviceConfigProperty: Em.Object.create({overrides: Em.A([])}), - defaultGroupSelected: true - } - ]; - beforeEach(function() { - sinon.stub(mainServiceInfoConfigsController, "createNewSCP", function(override) {return {name: override.name}}) - }); - afterEach(function() { - mainServiceInfoConfigsController.createNewSCP.restore(); - }); - tests.forEach(function(t) { - it("set values for overrides. use createNewSCP method to do this", function() { - var serviceConfigProperty = t.serviceConfigProperty; - mainServiceInfoConfigsController.setValuesForOverrides(t.overrides, serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected); - expect(serviceConfigProperty.get("overrides")[0]).to.eql(t.overrides[0]); - expect(serviceConfigProperty.get("overrides")[1]).to.eql(t.overrides[1]); - }); - }); - }); - - describe("#createConfigProperty", function() { - var tests = [ - { - _serviceConfigProperty: { - overrides: { - - } - }, - defaultGroupSelected: true, - restartData: {}, - serviceConfigsData: {}, - serviceConfigProperty: { - overrides: null, - isOverridable: true - } - }]; - beforeEach(function() { - sinon.stub(mainServiceInfoConfigsController, "setValuesForOverrides", Em.K); - sinon.stub(mainServiceInfoConfigsController, "setEditability", Em.K); - }); - afterEach(function() { - mainServiceInfoConfigsController.setValuesForOverrides.restore(); - mainServiceInfoConfigsController.setEditability.restore(); - }); - tests.forEach(function(t) { - it("create service config. run methods to correctly set object fileds", function() { - var result = mainServiceInfoConfigsController.createConfigProperty(t._serviceConfigProperty, t.defaultGroupSelected, t.restartData, t.serviceConfigsData); - expect(mainServiceInfoConfigsController.setValuesForOverrides.calledWith(t._serviceConfigProperty.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected)); - expect(result.getProperties('overrides','isOverridable')).to.eql(t.serviceConfigProperty); - }); - }); - }); - describe("#createNewSCP", function() { var tests = [ { @@ -901,7 +776,6 @@ describe("App.MainServiceInfoConfigsController", function () { value: "group1" } }, - _serviceConfigProperty: {}, serviceConfigProperty: Em.Object.create({ value: "parentSCP", supportsFinal: true @@ -924,7 +798,7 @@ describe("App.MainServiceInfoConfigsController", function () { ]; tests.forEach(function(t) { it("", function() { - var newSCP = mainServiceInfoConfigsController.createNewSCP(t.overrides, t._serviceConfigProperty, t.serviceConfigProperty, t.defaultGroupSelected); + var newSCP = mainServiceInfoConfigsController.createNewSCP(t.overrides, t.serviceConfigProperty, t.defaultGroupSelected); expect(newSCP.getProperties("value", "isOriginalSCP", "parentSCP", "group", "isEditable")).to.eql(t.newSCP); }); }); http://git-wip-us.apache.org/repos/asf/ambari/blob/1271328c/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 2d2b98e..b008909 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 @@ -41,7 +41,10 @@ describe('App.SliderConfigWidgetView', function () { type: 'int', minimum: '0', maximum: '2096', - unit: 'MB' + unit: 'MB', + group1: { + maximum: '3072' + } }), widget: Em.Object.create({ type: 'slider', @@ -184,6 +187,18 @@ describe('App.SliderConfigWidgetView', function () { }); }); + describe('#getValueAttributeByGroup', function() { + it('returns default max value', function() { + viewInt.set('config.group', null); + expect(viewInt.getValueAttributeByGroup('maximum')).to.equal('2096'); + }); + + it('returns max value for group1', function() { + viewInt.set('config.group', {name: 'group1'}); + expect(viewInt.getValueAttributeByGroup('maximum')).to.equal('3072'); + }); + }); + describe('#initSlider', function() { beforeEach(function() { this.view = App.SliderConfigWidgetView;
