config_initializer.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. require('utils/configs/config_initializer_class');
  21. require('utils/configs/hosts_based_initializer_mixin');
  22. /**
  23. * Zookeeper-based configs don't have any customization settings
  24. *
  25. * @see _initAsZookeeperServersList
  26. * @returns {{type: string}}
  27. */
  28. function getZKBasedConfig() {
  29. return {
  30. type: 'zookeeper_based'
  31. };
  32. }
  33. /**
  34. * Initializer for configs
  35. * Used on the cluster install
  36. *
  37. * Usage:
  38. * <pre>
  39. * var configProperty = Object.create({});
  40. * var localDB = {
  41. * hosts: [],
  42. * masterComponentHosts: [],
  43. * slaveComponentHosts: []
  44. * };
  45. * var dependencies = {};
  46. * App.ConfigInitializer.initialValue(configProperty, localDB, dependencies);
  47. * </pre>
  48. *
  49. * @instance ConfigInitializer
  50. */
  51. App.ConfigInitializer = App.ConfigInitializerClass.create(App.HostsBasedInitializerMixin, {
  52. initializers: function() {
  53. return {
  54. 'dfs.namenode.rpc-address': this.getSimpleComponentConfig('NAMENODE'),
  55. 'dfs.http.address': this.getSimpleComponentConfig('NAMENODE'),
  56. 'dfs.namenode.http-address': this.getSimpleComponentConfig('NAMENODE'),
  57. 'dfs.https.address': this.getSimpleComponentConfig('NAMENODE'),
  58. 'dfs.namenode.https-address': this.getSimpleComponentConfig('NAMENODE'),
  59. 'dfs.secondary.http.address': this.getSimpleComponentConfig('SECONDARY_NAMENODE'),
  60. 'dfs.namenode.secondary.http-address': this.getSimpleComponentConfig('SECONDARY_NAMENODE'),
  61. 'yarn.resourcemanager.hostname': this.getSimpleComponentConfig('RESOURCEMANAGER', false),
  62. 'yarn.resourcemanager.resource-tracker.address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  63. 'yarn.resourcemanager.webapp.https.address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  64. 'yarn.resourcemanager.webapp.address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  65. 'yarn.resourcemanager.scheduler.address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  66. 'yarn.resourcemanager.address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  67. 'yarn.resourcemanager.admin.address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  68. 'yarn.timeline-service.webapp.address': this.getSimpleComponentConfig('APP_TIMELINE_SERVER'),
  69. 'yarn.timeline-service.webapp.https.address': this.getSimpleComponentConfig('APP_TIMELINE_SERVER'),
  70. 'yarn.timeline-service.address': this.getSimpleComponentConfig('APP_TIMELINE_SERVER'),
  71. 'mapred.job.tracker': this.getSimpleComponentConfig('JOBTRACKER'),
  72. 'mapred.job.tracker.http.address': this.getSimpleComponentConfig('JOBTRACKER'),
  73. 'mapreduce.history.server.http.address': this.getSimpleComponentConfig('HISTORYSERVER'),
  74. 'oozie.base.url': this.getComponentConfigWithAffixes('OOZIE_SERVER', '://'),
  75. 'hawq_dfs_url': this.getSimpleComponentConfig('NAMENODE'),
  76. 'hawq_rm_yarn_address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  77. 'hawq_rm_yarn_scheduler_address': this.getSimpleComponentConfig('RESOURCEMANAGER'),
  78. 'fs.default.name': this.getComponentConfigWithAffixes('NAMENODE', '://'),
  79. 'fs.defaultFS': this.getComponentConfigWithAffixes('NAMENODE', '://'),
  80. 'hbase.rootdir': this.getComponentConfigWithAffixes('NAMENODE', '://'),
  81. 'instance.volumes': this.getComponentConfigWithAffixes('NAMENODE', '://'),
  82. 'yarn.log.server.url': this.getComponentConfigWithAffixes('HISTORYSERVER', '://'),
  83. 'mapreduce.jobhistory.webapp.address': this.getSimpleComponentConfig('HISTORYSERVER'),
  84. 'mapreduce.jobhistory.address': this.getSimpleComponentConfig('HISTORYSERVER'),
  85. 'kafka.ganglia.metrics.host': this.getSimpleComponentConfig('GANGLIA_SERVER', false),
  86. 'hive_master_hosts': this.getComponentsHostsConfig(['HIVE_METASTORE', 'HIVE_SERVER']),
  87. 'hadoop_host': this.getSimpleComponentConfig('NAMENODE', false),
  88. 'nimbus.host': this.getSimpleComponentConfig('NIMBUS', false),
  89. 'nimbus.seeds': this.getComponentsHostsConfig('NIMBUS', true),
  90. 'storm.zookeeper.servers': this.getComponentsHostsConfig('ZOOKEEPER_SERVER', true),
  91. 'hawq_master_address_host': this.getSimpleComponentConfig('HAWQMASTER', false),
  92. 'hawq_standby_address_host': this.getSimpleComponentConfig('HAWQSTANDBY', false),
  93. '*.broker.url': {
  94. type: 'host_with_component',
  95. component: 'FALCON_SERVER',
  96. modifier: {
  97. type: 'regexp',
  98. regex: 'localhost'
  99. }
  100. },
  101. 'zookeeper.connect': getZKBasedConfig(),
  102. 'hive.zookeeper.quorum': getZKBasedConfig(),
  103. 'templeton.zookeeper.hosts': getZKBasedConfig(),
  104. 'hadoop.registry.zk.quorum': getZKBasedConfig(),
  105. 'hive.cluster.delegation.token.store.zookeeper.connectString': getZKBasedConfig(),
  106. 'instance.zookeeper.host': getZKBasedConfig()
  107. }
  108. }.property(''),
  109. uniqueInitializers: {
  110. 'ranger_admin_password': '_setRangerAdminPassword',
  111. 'hive_database': '_initHiveDatabaseValue',
  112. 'templeton.hive.properties': '_initTempletonHiveProperties',
  113. 'hbase.zookeeper.quorum': '_initHBaseZookeeperQuorum',
  114. 'yarn.resourcemanager.zk-address': '_initYarnRMzkAddress',
  115. 'RANGER_HOST': '_initRangerHost',
  116. 'hive.metastore.uris': '_initHiveMetastoreUris',
  117. 'atlas.rest.address': '_initAtlasRestAddress'
  118. },
  119. initializerTypes: [
  120. {name: 'zookeeper_based', method: '_initAsZookeeperServersList'}
  121. ],
  122. /**
  123. * Some strange method that should define <code>ranger_admin_password</code>
  124. * TODO DELETE as soon as <code>ranger_admin_password</code> will be fetched from stack adviser!
  125. *
  126. * @param {configProperty} configProperty
  127. * @private
  128. */
  129. _setRangerAdminPassword: function(configProperty) {
  130. var value = 'P1!q' + stringUtils.getRandomString(12);
  131. Em.setProperties(configProperty, {'value': value, 'recommendedValue': value, 'retypedPassword': value});
  132. return configProperty;
  133. },
  134. /**
  135. * Unique initializer for <code>hive_database</code>-config
  136. *
  137. * @param {configProperty} configProperty
  138. * @returns {Object}
  139. * @private
  140. */
  141. _initHiveDatabaseValue: function (configProperty) {
  142. var newMySQLDBOption = Em.get(configProperty, 'options').findProperty('displayName', 'New MySQL Database');
  143. if (newMySQLDBOption) {
  144. var isNewMySQLDBOptionHidden = !App.get('supports.alwaysEnableManagedMySQLForHive') && App.get('router.currentState.name') !== 'configs' &&
  145. !App.get('isManagedMySQLForHiveEnabled');
  146. if (isNewMySQLDBOptionHidden && Em.get(configProperty, 'value') === 'New MySQL Database') {
  147. Em.set(configProperty, 'value', 'Existing MySQL Database');
  148. }
  149. Em.set(newMySQLDBOption, 'hidden', isNewMySQLDBOptionHidden);
  150. }
  151. return configProperty;
  152. },
  153. /**
  154. * Initializer for configs with value equal to hostNames-list where ZOOKEEPER_SERVER is installed
  155. * Value example: 'host1:2020,host2:2020,host3:2020'
  156. *
  157. * @param {configProperty} configProperty
  158. * @param {topologyLocalDB} localDB
  159. * @returns {Object}
  160. * @private
  161. */
  162. _initAsZookeeperServersList: function (configProperty, localDB) {
  163. var zkHosts = localDB.masterComponentHosts.filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  164. var zkHostPort = zkHosts;
  165. var regex = '\\w*:(\\d+)'; //regex to fetch the port
  166. var portValue = Em.get(configProperty, 'recommendedValue') && Em.get(configProperty, 'recommendedValue').match(new RegExp(regex));
  167. if (!portValue) {
  168. return configProperty;
  169. }
  170. if (portValue[1]) {
  171. for ( var i = 0; i < zkHosts.length; i++ ) {
  172. zkHostPort[i] = zkHosts[i] + ':' + portValue[1];
  173. }
  174. }
  175. this.setRecommendedValue(configProperty, '(.*)', zkHostPort);
  176. return configProperty;
  177. },
  178. /**
  179. * Unique initializer for <code>templeton.hive.properties</code>
  180. *
  181. * @param {configProperty} configProperty
  182. * @param {topologyLocalDB} localDB
  183. * @param {object} dependencies
  184. * @returns {Object}
  185. * @private
  186. */
  187. _initTempletonHiveProperties: function (configProperty, localDB, dependencies) {
  188. var hiveMSUris = this.getHiveMetastoreUris(localDB.masterComponentHosts, dependencies['hive.metastore.uris']).replace(',', '\\,');
  189. if (/\/\/localhost:/g.test(Em.get(configProperty, 'value'))) {
  190. Em.set(configProperty, 'recommendedValue', Em.get(configProperty, 'value') + ',hive.metastore.execute.setugi=true');
  191. }
  192. this.setRecommendedValue(configProperty, "(hive\\.metastore\\.uris=)([^\\,]+)", "$1" + hiveMSUris);
  193. return configProperty;
  194. },
  195. /**
  196. * Unique initializer for <code>hbase.zookeeper.quorum</code>
  197. *
  198. * @param {configProperty} configProperty
  199. * @param {topologyLocalDB} localDB
  200. * @returns {Object}
  201. * @private
  202. */
  203. _initHBaseZookeeperQuorum: function (configProperty, localDB) {
  204. if ('hbase-site.xml' === Em.get(configProperty, 'filename')) {
  205. var zkHosts = localDB.masterComponentHosts.filterProperty('component', 'ZOOKEEPER_SERVER').mapProperty('hostName');
  206. this.setRecommendedValue(configProperty, "(.*)", zkHosts);
  207. }
  208. return configProperty;
  209. },
  210. /**
  211. * Unique initializer for <code>RANGER_HOST</code>
  212. * If RANGER_ADMIN-component isn't installed, this config becomes unneeded (isVisible - false, isRequired - false)
  213. * Value example: 'hostName'
  214. *
  215. * @param {configProperty} configProperty
  216. * @param {topologyLocalDB} localDB
  217. * @returns {Object}
  218. * @private
  219. */
  220. _initRangerHost: function (configProperty, localDB) {
  221. var rangerAdminHost = localDB.masterComponentHosts.findProperty('component', 'RANGER_ADMIN');
  222. if(rangerAdminHost) {
  223. Em.setProperties(configProperty, {
  224. value: rangerAdminHost.hostName,
  225. recommendedValue: rangerAdminHost.hostName
  226. });
  227. }
  228. else {
  229. Em.setProperties(configProperty, {
  230. isVisible: 'false',
  231. isRequired: 'false'
  232. });
  233. }
  234. return configProperty;
  235. },
  236. /**
  237. * Unique initializer for <code>yarn.resourcemanager.zk-address</code>
  238. * List of hosts where ZOOKEEPER_SERVER is installed
  239. * Port is taken from <code>dependencies.clientPort</code>
  240. * Value example: 'host1:111,host2:111,host3:111'
  241. *
  242. * @param {configProperty} configProperty
  243. * @param {topologyLocalDB} localDB
  244. * @param {object} dependencies
  245. * @returns {Object}
  246. * @private
  247. */
  248. _initYarnRMzkAddress: function (configProperty, localDB, dependencies) {
  249. var value = localDB.masterComponentHosts.filterProperty('component', 'ZOOKEEPER_SERVER').map(function (component) {
  250. return component.hostName + ':' + dependencies.clientPort;
  251. }).join(',');
  252. Em.setProperties(configProperty, {
  253. value: value,
  254. recommendedValue: value
  255. });
  256. return configProperty;
  257. },
  258. /**
  259. * Unique initializer for <code>hive.metastore.uris</code>
  260. *
  261. * @param {configProperty} configProperty
  262. * @param {topologyLocalDB} localDB
  263. * @param {object} dependencies
  264. * @returns {Object}
  265. * @private
  266. */
  267. _initHiveMetastoreUris: function (configProperty, localDB, dependencies) {
  268. if (App.config.getConfigTagFromFileName(Em.get(configProperty, 'filename')) === 'hive-site') {
  269. var hiveMSUris = this.getHiveMetastoreUris(localDB.masterComponentHosts, dependencies['hive.metastore.uris']);
  270. if (hiveMSUris) {
  271. this.setRecommendedValue(configProperty, "(.*)", hiveMSUris);
  272. }
  273. }
  274. return configProperty;
  275. },
  276. /**
  277. * Unique initializer for <code>atlas.rest.address</code>
  278. *
  279. * @param {configProperty} configProperty
  280. * @param {topologyLocalDB} localDB
  281. * @param {object} dependencies
  282. * @return {Object}
  283. * @private
  284. */
  285. _initAtlasRestAddress: function (configProperty, localDB, dependencies) {
  286. var atlasTls = dependencies['atlas.enableTLS'];
  287. var httpPort = dependencies['atlas.server.http.port'];
  288. var httpsPort = dependencies['atlas.server.https.port'];
  289. var protocol = atlasTls ? 'https': 'http';
  290. var port = atlasTls ? httpsPort : httpPort;
  291. var value = localDB.masterComponentHosts.filterProperty('component', 'ZOOKEEPER_SERVER').map(function (component) {
  292. return protocol + '://' + component.hostName + ':' + port;
  293. }).join(',');
  294. Em.setProperties(configProperty, {
  295. value: value,
  296. recommendedValue: value
  297. });
  298. return configProperty;
  299. },
  300. /**
  301. * Get hive.metastore.uris initial value
  302. *
  303. * @param {object[]} hosts
  304. * @param {string} recommendedValue
  305. * @returns {string}
  306. */
  307. getHiveMetastoreUris: function (hosts, recommendedValue) {
  308. var hiveMSHosts = hosts.filterProperty('component', 'HIVE_METASTORE').mapProperty('hostName'),
  309. hiveMSUris = hiveMSHosts,
  310. regex = "\\w*:(\\d+)",
  311. portValue = recommendedValue && recommendedValue.match(new RegExp(regex));
  312. if (!portValue) {
  313. return '';
  314. }
  315. if (portValue[1]) {
  316. for (var i = 0; i < hiveMSHosts.length; i++) {
  317. hiveMSUris[i] = "thrift://" + hiveMSHosts[i] + ":" + portValue[1];
  318. }
  319. }
  320. return hiveMSUris.join(',');
  321. },
  322. /**
  323. * Set <code>value</code> and <code>recommendedValue</code> for <code>configProperty</code>
  324. * basing on <code>recommendedValue</code> with replacing <code>regex</code> for <code>replaceWith</code>
  325. *
  326. * @param {configProperty} configProperty
  327. * @param {string} regex
  328. * @param {string} replaceWith
  329. * @return {Object}
  330. */
  331. setRecommendedValue: function (configProperty, regex, replaceWith) {
  332. var recommendedValue = Em.get(configProperty, 'recommendedValue');
  333. recommendedValue = Em.isNone(recommendedValue) ? '' : recommendedValue;
  334. var re = new RegExp(regex);
  335. recommendedValue = recommendedValue.replace(re, replaceWith);
  336. Em.set(configProperty, 'recommendedValue', recommendedValue);
  337. var value = Em.isNone(Em.get(configProperty, 'recommendedValue')) ? '' : recommendedValue;
  338. Em.set(configProperty, 'value', value);
  339. Em.set(configProperty, 'initialValue', value);
  340. return configProperty;
  341. }
  342. });