step3_controller.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. /**
  19. * @typedef {object} rmHaConfigDependencies
  20. * @property {string|number} webAddressPort
  21. * @property {string|number} httpsWebAddressPort
  22. * @property {string|number} zkClientPort
  23. */
  24. var App = require('app');
  25. var blueprintUtils = require('utils/blueprint');
  26. require('utils/configs/rm_ha_config_initializer');
  27. App.RMHighAvailabilityWizardStep3Controller = Em.Controller.extend(App.BlueprintMixin, {
  28. name: "rMHighAvailabilityWizardStep3Controller",
  29. selectedService: null,
  30. versionLoaded: true,
  31. hideDependenciesInfoBar: true,
  32. isLoaded: false,
  33. isSubmitDisabled: Em.computed.not('isLoaded'),
  34. loadStep: function () {
  35. this.renderConfigs();
  36. },
  37. /**
  38. * Render configs to show them in <code>App.ServiceConfigView</code>
  39. */
  40. renderConfigs: function () {
  41. var configs = $.extend(true, {}, require('data/HDP2/rm_ha_properties').haConfig);
  42. var serviceConfig = App.ServiceConfig.create({
  43. serviceName: configs.serviceName,
  44. displayName: configs.displayName,
  45. configCategories: [],
  46. showConfig: true,
  47. configs: []
  48. });
  49. configs.configCategories.forEach(function (configCategory) {
  50. if (App.Service.find().someProperty('serviceName', configCategory.name)) {
  51. serviceConfig.configCategories.pushObject(configCategory);
  52. }
  53. }, this);
  54. this.renderConfigProperties(configs, serviceConfig);
  55. App.ajax.send({
  56. name: 'config.tags',
  57. sender: this,
  58. success: 'loadConfigTagsSuccessCallback',
  59. error: 'loadConfigsErrorCallback',
  60. data: {
  61. serviceConfig: serviceConfig
  62. }
  63. });
  64. },
  65. loadConfigTagsSuccessCallback: function (data, opt, params) {
  66. var urlParams = '(type=zoo.cfg&tag=' + data.Clusters.desired_configs['zoo.cfg'].tag + ')|' +
  67. '(type=yarn-site&tag=' + data.Clusters.desired_configs['yarn-site'].tag + ')|' +
  68. '(type=yarn-env&tag=' + data.Clusters.desired_configs['yarn-env'].tag + ')';
  69. App.ajax.send({
  70. name: 'reassign.load_configs',
  71. sender: this,
  72. data: {
  73. urlParams: urlParams,
  74. serviceConfig: params.serviceConfig
  75. },
  76. success: 'loadConfigsSuccessCallback',
  77. error: 'loadConfigsSuccessCallback'
  78. });
  79. },
  80. loadConfigsSuccessCallback: function (data, opt, params) {
  81. var self = this;
  82. var blueprintConfigurations = Em.getWithDefault(data || {}, 'items', []).reduce(function(prev, cur) {
  83. prev[cur.type] = { properties: cur.properties };
  84. return prev;
  85. }, {});
  86. params = params.serviceConfig ? params.serviceConfig : arguments[4].serviceConfig;
  87. this.setDynamicConfigValues(params, data);
  88. this.loadRecommendations(blueprintConfigurations).always(function(recommendations) {
  89. self.applyRecommendedConfigurations(recommendations, data, params);
  90. self.setProperties({
  91. selectedService: params,
  92. isLoaded: true
  93. });
  94. });
  95. },
  96. /**
  97. * Get dependencies for new configs
  98. *
  99. * @param {{items: object[]}} data
  100. * @returns {rmHaConfigDependencies}
  101. * @private
  102. * @method _prepareDependencies
  103. */
  104. _prepareDependencies: function (data) {
  105. var ret = {};
  106. var zooCfg = data && data.items ? data.items.findProperty('type', 'zoo.cfg') : null;
  107. var yarnSite = data && data.items ? data.items.findProperty('type', 'yarn-site') : null;
  108. var portValue = zooCfg && Em.get(zooCfg, 'properties.clientPort');
  109. var webAddressPort = yarnSite && yarnSite.properties ? yarnSite.properties['yarn.resourcemanager.webapp.address'] : '';
  110. var httpsWebAddressPort = yarnSite && yarnSite.properties ? yarnSite. properties['yarn.resourcemanager.webapp.https.address'] : '';
  111. ret.webAddressPort = webAddressPort && webAddressPort.contains(':') ? webAddressPort.split(':')[1] : '8088';
  112. ret.httpsWebAddressPort = httpsWebAddressPort && httpsWebAddressPort.contains(':') ? httpsWebAddressPort.split(':')[1] : '8090';
  113. ret.zkClientPort = portValue ? portValue : '2181';
  114. return ret;
  115. },
  116. /**
  117. * Set values to the new configs
  118. *
  119. * @param {object} configs
  120. * @param {object} data
  121. * @returns {object}
  122. * @method setDynamicConfigValues
  123. */
  124. setDynamicConfigValues: function (configs, data) {
  125. var topologyLocalDB = this.get('content').getProperties(['masterComponentHosts', 'slaveComponentHosts', 'hosts']);
  126. var yarnUser = data.items.findProperty('type', 'yarn-env').properties.yarn_user;
  127. App.RmHaConfigInitializer.setup({
  128. yarnUser: yarnUser
  129. });
  130. var dependencies = this._prepareDependencies(data);
  131. // /** add dynamic property 'hadoop.proxyuser.' + yarnUser + '.hosts' **/
  132. // var proxyUserConfig = App.ServiceConfigProperty.create(App.config.createDefaultConfig('hadoop.proxyuser.' + yarnUser + '.hosts',
  133. // 'core-site', false, {category : "HDFS", isUserProperty: false, isEditable: false, isOverridable: false, serviceName: 'MISC'}));
  134. // configs.configs.pushObject(proxyUserConfig);
  135. configs.configs.forEach(function (config) {
  136. App.RmHaConfigInitializer.initialValue(config, topologyLocalDB, dependencies);
  137. });
  138. App.RmHaConfigInitializer.cleanup();
  139. return configs;
  140. },
  141. /**
  142. * Load child components to service config object
  143. * @param _componentConfig
  144. * @param componentConfig
  145. */
  146. renderConfigProperties: function (_componentConfig, componentConfig) {
  147. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  148. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  149. componentConfig.configs.pushObject(serviceConfigProperty);
  150. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  151. }, this);
  152. },
  153. submit: function () {
  154. if (!this.get('isSubmitDisabled')) {
  155. App.get('router.mainAdminKerberosController').getKDCSessionState(function() {
  156. App.router.send("next");
  157. });
  158. }
  159. },
  160. loadRecommendations: function(blueprintConfigurations) {
  161. var dfd = $.Deferred();
  162. var blueprint = this.getCurrentMasterSlaveBlueprint();
  163. // host group where new ResourceManager will be added
  164. var hostGroupName = blueprintUtils.getHostGroupByFqdn(blueprint, this.get('content.rmHosts.additionalRM'));
  165. var dataToSend = {
  166. recommend: 'configurations',
  167. hosts: App.get('allHostNames'),
  168. services: App.Service.find().mapProperty('serviceName').uniq(),
  169. recommendations: {}
  170. };
  171. if (!!hostGroupName) {
  172. blueprintUtils.addComponentToHostGroup(blueprint, 'RESOURCEMANAGER', hostGroupName);
  173. }
  174. blueprint.blueprint.configurations = blueprintConfigurations;
  175. dataToSend.recommendations = blueprint;
  176. return App.ajax.send({
  177. name: 'config.recommendations',
  178. sender: this,
  179. data: {
  180. stackVersionUrl: App.get('stackVersionURL'),
  181. dataToSend: dataToSend
  182. }
  183. });
  184. },
  185. applyRecommendedConfigurations: function(recommendations, configurations, stepConfigs) {
  186. var yarnEnv = Em.getWithDefault(configurations || {}, 'items', []).findProperty('type', 'yarn-env') || {},
  187. yarnUser = Em.getWithDefault(yarnEnv, 'properties.yarn_user', false),
  188. coreSite = Em.getWithDefault(recommendations, 'resources.0.recommendations.blueprint.configurations.core-site.properties', {}),
  189. proxyHostName = 'hadoop.proxyuser.' + yarnUser + '.hosts',
  190. recommendedHosts = coreSite[proxyHostName] || false,
  191. newProp;
  192. if (yarnUser && recommendedHosts) {
  193. if (stepConfigs.get('configs').someProperty('name', proxyHostName)) {
  194. stepConfigs.get('configs').findProperty('name', proxyHostName).setProperties({
  195. recommendedValue: recommendedHosts,
  196. value: recommendedHosts
  197. });
  198. } else {
  199. newProp = App.config.createDefaultConfig(proxyHostName, 'core-site', false, {
  200. category : "HDFS",
  201. isUserProperty: false,
  202. isEditable: false,
  203. isOverridable: false,
  204. serviceName: 'MISC',
  205. value: recommendedHosts,
  206. recommendedValue: recommendedHosts
  207. });
  208. newProp.filename = App.config.getConfigTagFromFileName(newProp.filename);
  209. stepConfigs.get('configs').pushObject(App.ServiceConfigProperty.create(newProp));
  210. }
  211. }
  212. }
  213. });