Repository: ambari Updated Branches: refs/heads/trunk b714027dc -> af4d8aceb
AMBARI-13630 Incorrect error count for Ranger service while adding another service via add service wizard. (atkach) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/af4d8ace Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/af4d8ace Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/af4d8ace Branch: refs/heads/trunk Commit: af4d8acebb4a994bea8f525d57dac18dfdf52344 Parents: b714027 Author: Andrii Tkach <[email protected]> Authored: Fri Oct 30 11:49:21 2015 +0200 Committer: Andrii Tkach <[email protected]> Committed: Fri Oct 30 11:49:21 2015 +0200 ---------------------------------------------------------------------- .../app/controllers/wizard/step7_controller.js | 39 ++++++++++++++++++++ ambari-web/app/utils/config.js | 38 +++++++++++++++++++ .../configs/widgets/config_widget_view.js | 29 +-------------- 3 files changed, 78 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/af4d8ace/ambari-web/app/controllers/wizard/step7_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/wizard/step7_controller.js b/ambari-web/app/controllers/wizard/step7_controller.js index 4e6ab19..587bb04 100644 --- a/ambari-web/app/controllers/wizard/step7_controller.js +++ b/ambari-web/app/controllers/wizard/step7_controller.js @@ -624,6 +624,8 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E : App.config.mergePreDefinedWithStack(this.get('selectedServiceNames').concat(this.get('installedServiceNames'))); App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage')); + this.resolveConfigThemeConditions(configs); + this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []); if (this.get('wizardController.name') === 'addServiceController') { App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function (loadedConfigs) { @@ -635,6 +637,43 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E } }, + /** + * Resolve config theme conditions + * in order to correctly calculate config errors number of service + * @param {Array} configs + */ + resolveConfigThemeConditions: function (configs) { + App.ThemeCondition.find().forEach(function (configCondition) { + var _configs = Em.A(configCondition.get('configs')); + if (configCondition.get("resource") === 'config' && _configs.length > 0) { + var isConditionTrue = App.config.calculateConfigCondition(configCondition.get("if"), configs); + var action = isConditionTrue ? configCondition.get("then") : configCondition.get("else"); + if (configCondition.get('id')) { + var valueAttributes = action.property_value_attributes; + if (valueAttributes && !Em.none(valueAttributes['visible'])) { + var themeResource; + if (configCondition.get('type') === 'subsection') { + themeResource = App.SubSection.find().findProperty('name', configCondition.get('name')); + } else if (configCondition.get('type') === 'subsectionTab') { + themeResource = App.SubSectionTab.find().findProperty('name', configCondition.get('name')); + } + if (themeResource) { + themeResource.get('configProperties').forEach(function (_config) { + configs.find(function (item) { + if (item.name === _config.get('name') && item.filename === _config.get('fileName')) { + item.hiddenBySection = !valueAttributes['visible']; + return true; + } + return false; + }); + }, this); + } + } + } + } + }); + }, + applyServicesConfigs: function (configs, storedConfigs) { if (this.get('allSelectedServiceNames').contains('YARN')) { configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml', []); http://git-wip-us.apache.org/repos/asf/ambari/blob/af4d8ace/ambari-web/app/utils/config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js index b168763..7df1c90 100644 --- a/ambari-web/app/utils/config.js +++ b/ambari-web/app/utils/config.js @@ -628,6 +628,7 @@ App.config = Em.Object.create({ if (advanced.get('id')) { configData = this.mergeStaticProperties(configData, advanced, null, ['name', 'filename']); configData.value = configData.recommendedValue = this.formatPropertyValue(advanced, advanced.get('value')); + configData.widget = advanced.get('widget'); } mergedConfigs.push(configData); @@ -637,6 +638,43 @@ App.config = Em.Object.create({ return mergedConfigs; }, + /** + * + * @param {string} ifStatement + * @param {Array} serviceConfigs + * @returns {boolean} + */ + calculateConfigCondition: function(ifStatement, serviceConfigs) { + // Split `if` statement if it has logical operators + var ifStatementRegex = /(&&|\|\|)/; + var IfConditions = ifStatement.split(ifStatementRegex); + var allConditionResult = []; + IfConditions.forEach(function(_condition){ + var condition = _condition.trim(); + if (condition === '&&' || condition === '||') { + allConditionResult.push(_condition); + } else { + var splitIfCondition = condition.split('==='); + var ifCondition = splitIfCondition[0]; + var result = splitIfCondition[1] || "true"; + var parseIfConditionVal = ifCondition; + var regex = /\$\{.*?\}/g; + var configStrings = ifCondition.match(regex); + configStrings.forEach(function (_configString) { + var configObject = _configString.substring(2, _configString.length - 1).split("/"); + var config = serviceConfigs.filterProperty('filename', configObject[0] + '.xml').findProperty('name', configObject[1]); + if (config) { + var configValue = config.get('value'); + parseIfConditionVal = parseIfConditionVal.replace(_configString, configValue); + } + }, this); + var conditionResult = window.eval(JSON.stringify(parseIfConditionVal.trim())) === result.trim(); + allConditionResult.push(conditionResult); + } + }, this); + return Boolean(window.eval(allConditionResult.join(''))); + }, + miscConfigVisibleProperty: function (configs, serviceToShow) { configs.forEach(function (item) { if (item.get('isVisible') && item.belongsToService && item.belongsToService.length) { http://git-wip-us.apache.org/repos/asf/ambari/blob/af4d8ace/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 934d9a9..f0499db 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 @@ -402,34 +402,7 @@ App.ConfigWidgetView = Em.View.extend(App.SupportsDependentConfigs, App.WidgetPo configConditions.forEach(function(configCondition){ var ifStatement = configCondition.get("if"); if (configCondition.get("resource") === 'config') { - // Split `if` statement if it has logical operators - var ifStatementRegex = /(&&|\|\|)/; - var IfConditions = ifStatement.split(ifStatementRegex); - var allConditionResult = []; - IfConditions.forEach(function(_condition){ - var condition = _condition.trim(); - if (condition === '&&' || condition === '||') { - allConditionResult.push(_condition); - } else { - var splitIfCondition = condition.split('==='); - var ifCondition = splitIfCondition[0]; - var result = splitIfCondition[1] || "true"; - var parseIfConditionVal = ifCondition; - var regex = /\$\{.*?\}/g; - var configStrings = ifCondition.match(regex); - configStrings.forEach(function (_configString) { - var configObject = _configString.substring(2, _configString.length - 1).split("/"); - var config = serviceConfigs.filterProperty('filename', configObject[0] + '.xml').findProperty('name', configObject[1]); - if (config) { - var configValue = config.get('value'); - parseIfConditionVal = parseIfConditionVal.replace(_configString, configValue); - } - }, this); - var conditionResult = window.eval(JSON.stringify(parseIfConditionVal.trim())) === result.trim(); - allConditionResult.push(conditionResult); - } - }, this); - isConditionTrue = window.eval(allConditionResult.join('')); + isConditionTrue = App.config.calculateConfigCondition(ifStatement, serviceConfigs); if (configCondition.get("type") === 'subsection' || configCondition.get("type") === 'subsectionTab') { this.changeSubsectionAttribute(configCondition, isConditionTrue); } else {
