config_initializer.js 16 KB

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