Forráskód Böngészése

AMBARI-16127. Call stack advisor during enabling RM HA (wizard) (alexantonenko)

Alex Antonenko 9 éve
szülő
commit
f3cb35cf6c

+ 73 - 10
ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js

@@ -24,9 +24,10 @@
  */
 
 var App = require('app');
+var blueprintUtils = require('utils/blueprint');
 require('utils/configs/rm_ha_config_initializer');
 
-App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend({
+App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend(App.BlueprintMixin, {
   name: "rMHighAvailabilityWizardStep3Controller",
 
   selectedService: null,
@@ -94,12 +95,19 @@ App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend({
   },
 
   loadConfigsSuccessCallback: function (data, opt, params) {
+    var self = this;
+    var blueprintConfigurations = Em.getWithDefault(data || {}, 'items', []).reduce(function(prev, cur) {
+      prev[cur.type] = { properties: cur.properties };
+      return prev;
+    }, {});
     params = params.serviceConfig ? params.serviceConfig : arguments[4].serviceConfig;
-
     this.setDynamicConfigValues(params, data);
-    this.setProperties({
-      selectedService: params,
-      isLoaded: true
+    this.loadRecommendations(blueprintConfigurations).always(function(recommendations) {
+      self.applyRecommendedConfigurations(recommendations, data, params);
+      self.setProperties({
+        selectedService: params,
+        isLoaded: true
+      });
     });
   },
 
@@ -140,10 +148,10 @@ App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend({
       yarnUser: yarnUser
     });
     var dependencies = this._prepareDependencies(data);
-    /** add dynamic property 'hadoop.proxyuser.' + yarnUser + '.hosts' **/
-    var proxyUserConfig = App.ServiceConfigProperty.create(App.config.createDefaultConfig('hadoop.proxyuser.' + yarnUser + '.hosts',
-      'core-site', false,  {category : "HDFS", isUserProperty: false, isEditable: false, isOverridable: false, serviceName: 'MISC'}));
-    configs.configs.pushObject(proxyUserConfig);
+    // /** add dynamic property 'hadoop.proxyuser.' + yarnUser + '.hosts' **/
+    // var proxyUserConfig = App.ServiceConfigProperty.create(App.config.createDefaultConfig('hadoop.proxyuser.' + yarnUser + '.hosts',
+    //   'core-site', false,  {category : "HDFS", isUserProperty: false, isEditable: false, isOverridable: false, serviceName: 'MISC'}));
+    // configs.configs.pushObject(proxyUserConfig);
 
     configs.configs.forEach(function (config) {
       App.RmHaConfigInitializer.initialValue(config, topologyLocalDB, dependencies);
@@ -172,6 +180,61 @@ App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend({
         App.router.send("next");
       });
     }
+  },
+
+  loadRecommendations: function(blueprintConfigurations) {
+    var dfd = $.Deferred();
+    var blueprint = this.getCurrentMasterSlaveBlueprint();
+    // host group where new ResourceManager will be added
+    var hostGroupName = blueprintUtils.getHostGroupByFqdn(blueprint, this.get('content.rmHosts.additionalRM'));
+    var dataToSend = {
+      recommend: 'configurations',
+      hosts: App.get('allHostNames'),
+      services: App.Service.find().mapProperty('serviceName').uniq(),
+      recommendations: {}
+    };
+    if (!!hostGroupName) {
+      blueprintUtils.addComponentToHostGroup(blueprint, 'RESOURCEMANAGER', hostGroupName);
+    }
+    blueprint.blueprint.configurations = blueprintConfigurations;
+    dataToSend.recommendations = blueprint;
+    return App.ajax.send({
+      name: 'config.recommendations',
+      sender: this,
+      data: {
+        stackVersionUrl: App.get('stackVersionURL'),
+        dataToSend: dataToSend
+      }
+    });
+  },
+
+  applyRecommendedConfigurations: function(recommendations, configurations, stepConfigs) {
+    var yarnEnv = Em.getWithDefault(configurations || {}, 'items', []).findProperty('type', 'yarn-env') || {},
+        yarnUser = Em.getWithDefault(yarnEnv, 'properties.yarn_user', false),
+        coreSite = Em.getWithDefault(recommendations, 'resources.0.recommendations.blueprint.configurations.core-site.properties', {}),
+        proxyHostName = 'hadoop.proxyuser.' + yarnUser + '.hosts',
+        recommendedHosts = coreSite[proxyHostName] || false,
+        newProp;
+
+    if (yarnUser && recommendedHosts) {
+      if (stepConfigs.get('configs').someProperty('name', proxyHostName)) {
+        stepConfigs.get('configs').findProperty('name', proxyHostName).setProperties({
+          recommendedValue: recommendedHosts,
+          value: recommendedHosts
+        });
+      } else {
+        newProp = App.config.createDefaultConfig(proxyHostName, 'core-site', false, {
+          category : "HDFS",
+          isUserProperty: false,
+          isEditable: false,
+          isOverridable: false,
+          serviceName: 'MISC',
+          value: recommendedHosts,
+          recommendedValue: recommendedHosts
+        });
+        newProp.filename = App.config.getConfigTagFromFileName(newProp.filename);
+        stepConfigs.get('configs').pushObject(App.ServiceConfigProperty.create(newProp));
+      }
+    }
   }
 });
-

+ 36 - 0
ambari-web/app/utils/blueprint.js

@@ -451,5 +451,41 @@ module.exports = {
         hostsMap[componentToBeDeleted.hostName].splice(index, 1);
       }
     }
+  },
+  /**
+   * Returns host-group name by fqdn.
+   * Returns <code>null</code> when not found.
+   *
+   * @param  {object} blueprint
+   * @param  {string} fqdn
+   * @returns {string|null}
+   */
+  getHostGroupByFqdn: function(blueprint, fqdn) {
+    return Em.getWithDefault(blueprint || {}, 'blueprint_cluster_binding.host_groups', [])
+      .filter(function(i) {
+        return Em.getWithDefault(i, 'hosts', []).mapProperty('fqdn').contains(fqdn);
+      })
+      .mapProperty('name')[0] || null;
+  },
+
+  /**
+   * Add component to specified host group.
+   *
+   * @param  {object} blueprint
+   * @param  {string} componentName
+   * @param  {string} hostGroupName
+   * @return {object}
+   */
+  addComponentToHostGroup: function(blueprint, componentName, hostGroupName) {
+    var hostGroup = blueprint.blueprint.host_groups.findProperty('name', hostGroupName);
+    if (hostGroup) {
+      if (!hostGroup.hasOwnProperty('components')) {
+        hostGroup.components = [];
+      }
+      if (!hostGroup.components.someProperty('name', componentName)) {
+        hostGroup.components.pushObject({name: componentName});
+      }
+    }
+    return blueprint;
   }
 };

+ 116 - 0
ambari-web/test/utils/blueprint_test.js

@@ -452,4 +452,120 @@ describe('utils/blueprint', function() {
       }).to.throw(Error);
     });
   });
+
+  describe('#getHostGroupByFqdn', function() {
+    it('should return `null` if blueprint undefined', function() {
+      expect(blueprintUtils.getHostGroupByFqdn(undefined, 'host1')).to.be.null;
+    });
+
+    it('should return `null` if blueprint not valid', function() {
+      expect(blueprintUtils.getHostGroupByFqdn({not_valid_object: {}}, 'host1')).to.be.null;
+    });
+
+    it('should find host1-group by host1.name', function() {
+      var bp = {
+        blueprint_cluster_binding: {
+          host_groups: [
+            {
+              hosts: [
+                {fqdn: 'host2.name'}
+              ],
+              name: 'host2-group'
+            },
+            {
+              hosts: [
+                {fqdn: 'host1.name'}
+              ],
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      expect(blueprintUtils.getHostGroupByFqdn(bp, 'host1.name')).to.be.eql('host1-group');
+    });
+  });
+
+  describe('#addComponentToHostGroup', function() {
+    it('should add new component to host1-group', function() {
+      var bp = {
+        blueprint: {
+          host_groups: [
+            {
+              components: [
+                { name: 'COMPONENT1'}
+              ],
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      var expected = {
+        blueprint: {
+          host_groups: [
+            {
+              components: [
+                { name: 'COMPONENT1'},
+                { name: 'COMPONENT2'}
+              ],
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      expect(blueprintUtils.addComponentToHostGroup(bp, 'COMPONENT2', 'host1-group').toString()).to.eql(expected.toString());
+    });
+
+    it('should skip adding component since it already in host1-group', function() {
+      var bp = {
+        blueprint: {
+          host_groups: [
+            {
+              components: [
+                { name: 'COMPONENT1'}
+              ],
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      var expected = {
+        blueprint: {
+          host_groups: [
+            {
+              components: [
+                { name: 'COMPONENT1'}
+              ],
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      expect(blueprintUtils.addComponentToHostGroup(bp, 'COMPONENT1', 'host1-group').toString()).to.eql(expected.toString());
+    });
+
+    it('should create components attribute and add component to host1-group', function() {
+      var bp = {
+        blueprint: {
+          host_groups: [
+            {
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      var expected = {
+        blueprint: {
+          host_groups: [
+            {
+              components: [
+                { name: 'COMPONENT1'}
+              ],
+              name: 'host1-group'
+            }
+          ]
+        }
+      };
+      expect(blueprintUtils.addComponentToHostGroup(bp, 'COMPONENT1', 'host1-group').toString()).to.eql(expected.toString());
+    });
+  });
 });