ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject [2/3] ambari git commit: AMBARI-16127. Call stack advisor during enabling RM HA (wizard) (alexantonenko)
Date Thu, 28 Apr 2016 16:53:55 GMT
AMBARI-16127. Call stack advisor during enabling RM HA (wizard) (alexantonenko)


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

Branch: refs/heads/trunk
Commit: f3cb35cf6c3d0df8b9a59b7cea65289a12edc753
Parents: c16c306
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Thu Apr 28 13:54:02 2016 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Thu Apr 28 19:53:48 2016 +0300

----------------------------------------------------------------------
 .../resourceManager/step3_controller.js         |  83 +++++++++++--
 ambari-web/app/utils/blueprint.js               |  36 ++++++
 ambari-web/test/utils/blueprint_test.js         | 116 +++++++++++++++++++
 3 files changed, 225 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/f3cb35cf/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
b/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
index 0ec632b..00ae0c3 100644
--- a/ambari-web/app/controllers/main/admin/highAvailability/resourceManager/step3_controller.js
+++ b/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));
+      }
+    }
   }
 });
-

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3cb35cf/ambari-web/app/utils/blueprint.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/blueprint.js b/ambari-web/app/utils/blueprint.js
index ca9a3e2..4201e3f 100644
--- a/ambari-web/app/utils/blueprint.js
+++ b/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;
   }
 };

http://git-wip-us.apache.org/repos/asf/ambari/blob/f3cb35cf/ambari-web/test/utils/blueprint_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/utils/blueprint_test.js b/ambari-web/test/utils/blueprint_test.js
index ffa9cdb..6ada088 100644
--- a/ambari-web/test/utils/blueprint_test.js
+++ b/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());
+    });
+  });
 });


Mime
View raw message