step3_controller.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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} nnHaConfigDependencies
  20. * @property {string} namespaceId
  21. * @property {object} serverConfigs
  22. * @property {string|number} nnHttpPort
  23. * @property {string|number} nnHttpsPort
  24. * @property {string|number} nnRpcPort
  25. * @property {string|number} zkClientPort
  26. */
  27. var App = require('app');
  28. require('utils/configs/nn_ha_config_initializer');
  29. App.HighAvailabilityWizardStep3Controller = Em.Controller.extend({
  30. name: "highAvailabilityWizardStep3Controller",
  31. selectedService: null,
  32. stepConfigs: [],
  33. serverConfigData: {},
  34. haConfig: $.extend(true, {}, require('data/HDP2/ha_properties').haConfig),
  35. once: false,
  36. isLoaded: false,
  37. versionLoaded: true,
  38. hideDependenciesInfoBar: true,
  39. /**
  40. * Map of sites and properties to delete
  41. * @type Object
  42. */
  43. configsToRemove: {
  44. 'hdfs-site': ['dfs.namenode.secondary.http-address', 'dfs.namenode.rpc-address']
  45. },
  46. clearStep: function () {
  47. this.get('stepConfigs').clear();
  48. this.set('serverConfigData', {});
  49. },
  50. loadStep: function () {
  51. this.clearStep();
  52. this.loadConfigsTags();
  53. },
  54. loadConfigsTags: function () {
  55. App.ajax.send({
  56. name: 'config.tags',
  57. sender: this,
  58. success: 'onLoadConfigsTags',
  59. error: 'onTaskError'
  60. });
  61. },
  62. onLoadConfigsTags: function (data) {
  63. var urlParams = [];
  64. var hdfsSiteTag = data.Clusters.desired_configs['hdfs-site'].tag;
  65. var coreSiteTag = data.Clusters.desired_configs['core-site'].tag;
  66. var zkSiteTag = data.Clusters.desired_configs['zoo.cfg'].tag;
  67. urlParams.push('(type=hdfs-site&tag=' + hdfsSiteTag + ')');
  68. urlParams.push('(type=core-site&tag=' + coreSiteTag + ')');
  69. urlParams.push('(type=zoo.cfg&tag=' + zkSiteTag + ')');
  70. this.set("hdfsSiteTag", {name : "hdfsSiteTag", value : hdfsSiteTag});
  71. this.set("coreSiteTag", {name : "coreSiteTag", value : coreSiteTag});
  72. this.set("zkSiteTag", {name : "zkSiteTag", value : zkSiteTag});
  73. if (App.Service.find().someProperty('serviceName', 'HBASE')) {
  74. var hbaseSiteTag = data.Clusters.desired_configs['hbase-site'].tag;
  75. urlParams.push('(type=hbase-site&tag=' + hbaseSiteTag + ')');
  76. this.set("hbaseSiteTag", {name : "hbaseSiteTag", value : hbaseSiteTag});
  77. }
  78. if (App.Service.find().someProperty('serviceName', 'ACCUMULO')) {
  79. var accumuloSiteTag = data.Clusters.desired_configs['accumulo-site'].tag;
  80. urlParams.push('(type=accumulo-site&tag=' + accumuloSiteTag + ')');
  81. this.set("accumuloSiteTag", {name : "accumuloSiteTag", value : accumuloSiteTag});
  82. }
  83. if (App.Service.find().someProperty('serviceName', 'AMBARI_METRICS')) {
  84. var amsHbaseSiteTag = data.Clusters.desired_configs['ams-hbase-site'].tag;
  85. urlParams.push('(type=ams-hbase-site&tag=' + amsHbaseSiteTag + ')');
  86. this.set("amsHbaseSiteTag", {name : "amsHbaseSiteTag", value : amsHbaseSiteTag});
  87. }
  88. if (App.Service.find().someProperty('serviceName', 'HAWQ')) {
  89. var hawqSiteTag = data.Clusters.desired_configs['hawq-site'].tag;
  90. urlParams.push('(type=hawq-site&tag=' + hawqSiteTag + ')');
  91. this.set("hawqSiteTag", {name : "hawqSiteTag", value : hawqSiteTag});
  92. }
  93. App.ajax.send({
  94. name: 'admin.get.all_configurations',
  95. sender: this,
  96. data: {
  97. urlParams: urlParams.join('|')
  98. },
  99. success: 'onLoadConfigs',
  100. error: 'onTaskError'
  101. });
  102. },
  103. onLoadConfigs: function (data) {
  104. this.set('serverConfigData',data);
  105. this.removeConfigs(this.get('configsToRemove'), this.get('serverConfigData'));
  106. this.tweakServiceConfigs(this.get('haConfig.configs'));
  107. this.renderServiceConfigs(this.get('haConfig'));
  108. this.set('isLoaded', true);
  109. },
  110. /**
  111. * Generate set of data used to correctly initialize config values and names
  112. *
  113. * @returns {nnHaConfigDependencies}
  114. * @private
  115. * @method _prepareDependencies
  116. */
  117. _prepareDependencies: function () {
  118. var ret = {};
  119. var configsFromServer = this.get('serverConfigData.items');
  120. ret.namespaceId = this.get('content.nameServiceId');
  121. ret.serverConfigs = configsFromServer;
  122. var hdfsConfigs = configsFromServer.findProperty('type','hdfs-site').properties;
  123. var zkConfigs = configsFromServer.findProperty('type','zoo.cfg').properties;
  124. var dfsHttpA = hdfsConfigs['dfs.namenode.http-address'];
  125. ret.nnHttpPort = dfsHttpA ? dfsHttpA.split(':')[1] : 50070;
  126. var dfsHttpsA = hdfsConfigs['dfs.namenode.https-address'];
  127. ret.nnHttpsPort = dfsHttpsA ? dfsHttpsA.split(':')[1] : 50470;
  128. var dfsRpcA = hdfsConfigs['dfs.namenode.rpc-address'];
  129. ret.nnRpcPort = dfsRpcA ? dfsRpcA.split(':')[1] : 8020;
  130. ret.zkClientPort = zkConfigs['clientPort'] ? zkConfigs['clientPort'] : 2181;
  131. return ret;
  132. },
  133. /**
  134. * Generate set of data with information about cluster topology
  135. * Used in the configs' initialization process
  136. *
  137. * @returns {extendedTopologyLocalDB}
  138. * @private
  139. * @method _prepareLocalDB
  140. */
  141. _prepareLocalDB: function () {
  142. var localDB = this.get('content').getProperties(['masterComponentHosts', 'slaveComponentHosts', 'hosts']);
  143. localDB.installedServices = App.Service.find().mapProperty('serviceName');
  144. return localDB;
  145. },
  146. tweakServiceConfigs: function(configs) {
  147. var localDB = this._prepareLocalDB();
  148. var dependencies = this._prepareDependencies();
  149. configs.forEach(function (config) {
  150. App.NnHaConfigInitializer.initialValue(config, localDB, dependencies);
  151. });
  152. return configs;
  153. },
  154. /**
  155. * Find and remove config properties in <code>serverConfigData</code>
  156. * @param configsToRemove - map of config sites and properties to remove
  157. * @param configs - configuration object
  158. * @returns {Object}
  159. */
  160. removeConfigs:function (configsToRemove, configs) {
  161. Em.keys(configsToRemove).forEach(function(site){
  162. var siteConfigs = configs.items.findProperty('type', site);
  163. if (siteConfigs) {
  164. configsToRemove[site].forEach(function (property) {
  165. delete siteConfigs.properties[property];
  166. });
  167. }
  168. });
  169. return configs;
  170. },
  171. renderServiceConfigs: function (_serviceConfig) {
  172. var serviceConfig = App.ServiceConfig.create({
  173. serviceName: _serviceConfig.serviceName,
  174. displayName: _serviceConfig.displayName,
  175. configCategories: [],
  176. showConfig: true,
  177. configs: []
  178. });
  179. _serviceConfig.configCategories.forEach(function (_configCategory) {
  180. if (App.Service.find().someProperty('serviceName', _configCategory.name)) {
  181. serviceConfig.configCategories.pushObject(_configCategory);
  182. }
  183. }, this);
  184. this.loadComponentConfigs(_serviceConfig, serviceConfig);
  185. this.get('stepConfigs').pushObject(serviceConfig);
  186. this.set('selectedService', this.get('stepConfigs').objectAt(0));
  187. this.once = true;
  188. },
  189. /**
  190. * Load child components to service config object
  191. * @param _componentConfig
  192. * @param componentConfig
  193. */
  194. loadComponentConfigs: function (_componentConfig, componentConfig) {
  195. _componentConfig.configs.forEach(function (_serviceConfigProperty) {
  196. var serviceConfigProperty = App.ServiceConfigProperty.create(_serviceConfigProperty);
  197. componentConfig.configs.pushObject(serviceConfigProperty);
  198. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  199. serviceConfigProperty.validate();
  200. }, this);
  201. },
  202. isNextDisabled: Em.computed.not('isLoaded')
  203. });