You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by at...@apache.org on 2015/10/30 10:44:55 UTC

ambari git commit: AMBARI-13630 Incorrect error count for Ranger service while adding another service via add service wizard. (atkach)

Repository: ambari
Updated Branches:
  refs/heads/branch-2.1 fee0af148 -> 222384428


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/22238442
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/22238442
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/22238442

Branch: refs/heads/branch-2.1
Commit: 222384428ab08db9a14febfa5c84b9a8133ad22c
Parents: fee0af1
Author: Andrii Tkach <at...@hortonworks.com>
Authored: Thu Oct 29 15:53:59 2015 +0200
Committer: Andrii Tkach <at...@hortonworks.com>
Committed: Fri Oct 30 11:44:09 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/22238442/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 d24d978..66fdac0 100644
--- a/ambari-web/app/controllers/wizard/step7_controller.js
+++ b/ambari-web/app/controllers/wizard/step7_controller.js
@@ -640,6 +640,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) {
@@ -651,6 +653,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/22238442/ambari-web/app/utils/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js
index 1519a8b..3cbd141 100644
--- a/ambari-web/app/utils/config.js
+++ b/ambari-web/app/utils/config.js
@@ -635,6 +635,7 @@ App.config = Em.Object.create({
         if (advanced.get('id')) {
           configData = this.mergeStaticProperties(configData, advanced, null, ['name', 'filename']);
           configData.value = this.formatPropertyValue(advanced, advanced.get('value'));
+          configData.widget = advanced.get('widget');
         }
 
         mergedConfigs.push(configData);
@@ -644,6 +645,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/22238442/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 {