You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2016/07/01 21:53:15 UTC

ambari git commit: AMBARI-17536 The FE should always send the cluster-env config when invoking the Recommendations REST API. (akovalenko)

Repository: ambari
Updated Branches:
  refs/heads/trunk cf27e5db0 -> b92524547


AMBARI-17536 The FE should always send the cluster-env config when invoking the Recommendations REST API. (akovalenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b9252454
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b9252454
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b9252454

Branch: refs/heads/trunk
Commit: b9252454774d67dbdfb47487fde4e77574d8c0b0
Parents: cf27e5d
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Fri Jul 1 19:41:56 2016 +0300
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Sat Jul 2 00:53:03 2016 +0300

----------------------------------------------------------------------
 .../mixins/common/configs/enhanced_configs.js   | 64 +++++++++++++-------
 ambari-web/app/mixins/common/serverValidator.js | 37 +----------
 ambari-web/app/utils/blueprint.js               |  2 +-
 ambari-web/app/utils/config.js                  | 31 ++++++++++
 .../test/controllers/main/service/item_test.js  |  2 +-
 .../common/configs/enhanced_configs_test.js     | 23 +++++++
 6 files changed, 98 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b9252454/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 50c4339..60bf6e1 100644
--- a/ambari-web/app/mixins/common/configs/enhanced_configs.js
+++ b/ambari-web/app/mixins/common/configs/enhanced_configs.js
@@ -149,8 +149,10 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
    * @param {Function} [onComplete]
    * @returns {$.ajax|null}
    */
-  loadConfigRecommendations: function(changedConfigs, onComplete) {
+  loadConfigRecommendations: function (changedConfigs, onComplete) {
+    var self = this;
     var updateDependencies = Em.isArray(changedConfigs) && changedConfigs.length > 0;
+    var stepConfigs = this.get('stepConfigs');
     if (updateDependencies || Em.isNone(this.get('recommendationsConfigs'))) {
       var configGroup = this.get('selectedConfigGroup');
       var recommendations = this.get('hostGroups');
@@ -164,34 +166,28 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
         dataToSend.changed_configurations = changedConfigs;
       }
 
-      recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(this.get('stepConfigs'));
-
       if (configGroup && !configGroup.get('isDefault') && configGroup.get('hosts.length') > 0) {
         recommendations.config_groups = [this.buildConfigGroupJSON(this.get('selectedService.configs'), configGroup)];
       } else {
         delete recommendations.config_groups;
       }
 
-      dataToSend.recommendations = recommendations;
-      var self = this;
-      this.set('recommendationsInProgress', true);
-      return App.ajax.send({
-        name: 'config.recommendations',
-        sender: this,
-        data: {
-          stackVersionUrl: App.get('stackVersionURL'),
-          dataToSend: dataToSend
-        },
-        success: 'loadRecommendationsSuccess',
-        error: 'loadRecommendationsError',
-        callback: function() {
-          self.set('recommendationsInProgress', false);
-          self.set('recommendationTimeStamp', (new Date).getTime());
-          if (onComplete) {
-            onComplete()
-          }
-        }
-      });
+      if (stepConfigs.someProperty('serviceName', 'MISC')) {
+        recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(stepConfigs);
+        dataToSend.recommendations = recommendations;
+        return this.getRecommendationsRequest(dataToSend, onComplete);
+      } else {
+        App.config.getClusterEnvConfigs().done(function (clusterEnvConfigs) {
+          stepConfigs = stepConfigs.concat(Em.Object.create({
+            serviceName: 'MISC',
+            configs: clusterEnvConfigs
+          }));
+
+          recommendations.blueprint.configurations = blueprintUtils.buildConfigsJSON(stepConfigs);
+          dataToSend.recommendations = recommendations;
+          return self.getRecommendationsRequest(dataToSend, onComplete);
+        });
+      }
     } else {
       if (onComplete) {
         onComplete()
@@ -200,6 +196,28 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP
     }
   },
 
+  getRecommendationsRequest: function (dataToSend, callback) {
+    var self = this;
+    this.set('recommendationsInProgress', true);
+    return App.ajax.send({
+      name: 'config.recommendations',
+      sender: self,
+      data: {
+        stackVersionUrl: App.get('stackVersionURL'),
+        dataToSend: dataToSend
+      },
+      success: 'loadRecommendationsSuccess',
+      error: 'loadRecommendationsError',
+      callback: function () {
+        self.set('recommendationsInProgress', false);
+        self.set('recommendationTimeStamp', (new Date).getTime());
+        if (callback) {
+          callback()
+        }
+      }
+    });
+  },
+
   /**
    * Defines if there is any changes made by user.
    * Check all properties except recommended properties from popup

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9252454/ambari-web/app/mixins/common/serverValidator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/mixins/common/serverValidator.js b/ambari-web/app/mixins/common/serverValidator.js
index 428b0cd..e18c0a9 100644
--- a/ambari-web/app/mixins/common/serverValidator.js
+++ b/ambari-web/app/mixins/common/serverValidator.js
@@ -38,13 +38,6 @@ App.ServerValidatorMixin = Em.Mixin.create({
   recommendationsConfigs: null,
 
   /**
-   * array of cluster-env configs
-   * used for validation request
-   * @type {Array}
-   */
-  clusterEnvConfigs: [],
-
-  /**
    * Collection of all config validation errors
    *
    * @type {Object[]}
@@ -162,7 +155,7 @@ App.ServerValidatorMixin = Em.Mixin.create({
 
     // check if we have configs from 'cluster-env', if not, then load them, as they are mandatory for validation request
     if (!stepConfigs.findProperty('serviceName', 'MISC')) {
-      this.getClusterEnvConfigsForValidation().done(function(clusterEnvConfigs){
+      App.config.getClusterEnvConfigs().done(function(clusterEnvConfigs){
         stepConfigs = stepConfigs.concat(Em.Object.create({
           serviceName: 'MISC',
           configs: clusterEnvConfigs
@@ -175,34 +168,6 @@ App.ServerValidatorMixin = Em.Mixin.create({
     return dfd.promise();
   },
 
-  getClusterEnvConfigsForValidation: function () {
-    var dfd = $.Deferred();
-    App.ajax.send({
-      name: 'config.cluster_env_site',
-      sender: this,
-      error: 'validationError'
-    }).done(function (data) {
-      App.router.get('configurationController').getConfigsByTags([{
-        siteName: data.items[data.items.length - 1].type,
-        tagName: data.items[data.items.length - 1].tag
-      }]).done(function (clusterEnvConfigs) {
-        var configsObject = clusterEnvConfigs[0].properties;
-        var configsArray = [];
-        for (var property in configsObject) {
-          if (configsObject.hasOwnProperty(property)) {
-            configsArray.push(Em.Object.create({
-              name: property,
-              value: configsObject[property],
-              filename: 'cluster-env.xml'
-            }));
-          }
-        }
-        dfd.resolve(configsArray);
-      });
-    });
-    return dfd.promise();
-  },
-
   /**
    * Creates config validation error object
    *

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9252454/ambari-web/app/utils/blueprint.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/blueprint.js b/ambari-web/app/utils/blueprint.js
index 4201e3f..696f7a4 100644
--- a/ambari-web/app/utils/blueprint.js
+++ b/ambari-web/app/utils/blueprint.js
@@ -320,7 +320,7 @@ module.exports = {
     var configurations = {};
     stepConfigs.forEach(function (stepConfig) {
       stepConfig.get('configs').forEach(function (config) {
-        if (config.get('isRequiredByAgent')) {
+        if (config.get('filename') === 'cluster-env.xml' || config.get('isRequiredByAgent')) {
           var type = App.config.getConfigTagFromFileName(config.get('filename'));
           if (!configurations[type]) {
             configurations[type] = {properties: {}}

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9252454/ambari-web/app/utils/config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js
index 840e3c2..4fa8aa8 100644
--- a/ambari-web/app/utils/config.js
+++ b/ambari-web/app/utils/config.js
@@ -1218,5 +1218,36 @@ App.config = Em.Object.create({
     }
     siteConfigs[propertyName] = value;
     return value;
+  },
+
+  /**
+   * Load cluster-env configs mapped to array
+   * @return {*|{then}}
+   */
+  getClusterEnvConfigs: function () {
+    var dfd = $.Deferred();
+    App.ajax.send({
+      name: 'config.cluster_env_site',
+      sender: this
+    }).done(function (data) {
+      App.router.get('configurationController').getConfigsByTags([{
+        siteName: data.items[data.items.length - 1].type,
+        tagName: data.items[data.items.length - 1].tag
+      }]).done(function (clusterEnvConfigs) {
+        var configsObject = clusterEnvConfigs[0].properties;
+        var configsArray = [];
+        for (var property in configsObject) {
+          if (configsObject.hasOwnProperty(property)) {
+            configsArray.push(Em.Object.create({
+              name: property,
+              value: configsObject[property],
+              filename: 'cluster-env.xml'
+            }));
+          }
+        }
+        dfd.resolve(configsArray);
+      });
+    });
+    return dfd.promise();
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9252454/ambari-web/test/controllers/main/service/item_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/service/item_test.js b/ambari-web/test/controllers/main/service/item_test.js
index 5c2b34a..809986d 100644
--- a/ambari-web/test/controllers/main/service/item_test.js
+++ b/ambari-web/test/controllers/main/service/item_test.js
@@ -1658,7 +1658,7 @@ describe('App.MainServiceItemController', function () {
 
     beforeEach(function() {
       mainServiceItemController = App.MainServiceItemController.create({});
-      sinon.spy(mainServiceItemController, 'loadConfigRecommendations');
+      sinon.stub(mainServiceItemController, 'loadConfigRecommendations', Em.K);
       sinon.stub(mainServiceItemController, 'deleteServiceCall', Em.K);
       mainServiceItemController.reopen({
         interDependentServices: []

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9252454/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
index 7f503b9..e68cb94 100644
--- a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
+++ b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js
@@ -173,6 +173,15 @@ describe('App.EnhancedConfigsMixin', function() {
         }
       });
       this.mockedCallback = sinon.stub();
+      sinon.stub(App.config, 'getClusterEnvConfigs').returns({
+        done: function (callback) {
+          callback([]);
+        }
+      });
+    });
+
+    afterEach(function(){
+      App.config.getClusterEnvConfigs.restore();
     });
 
     it("should call callback if changedConfigs is empty array", function() {
@@ -188,6 +197,20 @@ describe('App.EnhancedConfigsMixin', function() {
       args[0].callback();
       expect(this.mockedCallback.calledOnce).to.be.true;
     });
+
+    it("should call getClusterEnvConfigs if there is no cluster-env configs in stepConfigs", function() {
+      mixinInstance.loadConfigRecommendations([{}]);
+      expect(App.config.getClusterEnvConfigs.calledOnce).to.be.true;
+    });
+
+    it("should not call getClusterEnvConfigs if there is cluster-env configs in stepConfigs", function() {
+      mixinInstance.set('stepConfigs', [Em.Object.create({
+        serviceName: 'MISC',
+        configs: []
+      })]);
+      mixinInstance.loadConfigRecommendations([{}]);
+      expect(App.config.getClusterEnvConfigs.calledOnce).to.be.false;
+    });
   });
 });