add_component_config_initializer.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. require('utils/configs/config_initializer_class');
  20. require('utils/configs/ha_config_initializer_class');
  21. require('utils/configs/hosts_based_initializer_mixin');
  22. require('utils/configs/control_flow_initializer_mixin');
  23. var _slice = Array.prototype.slice;
  24. /**
  25. * Main class responsible for properties computation.
  26. * This class contains all required info to manipulate properties regarding value updates
  27. * during removing/adding components.
  28. * To determine when component removed or added you just need to setup properly localDB object
  29. * and set `isInstalled` flag to `true` where selected component(s) will be located after adding/removing.
  30. * By default all initializer handlers filtering localDB by `isInstalled` `true`.
  31. *
  32. * @mixes App.ControlFlowInitializerMixin
  33. * @mixes App.HostsBasedInitializerMixin
  34. * @type {AddComponentConfigInitializer}
  35. * @augments {HaConfigInitializerClass}
  36. */
  37. App.AddComponentConfigInitializer = App.HaConfigInitializerClass.extend(App.HostsBasedInitializerMixin, App.ControlFlowInitializerMixin, {
  38. /**
  39. * All initializer properties definition.
  40. * Object format is the same as for App.ConfigInitializerClass.initializers
  41. * @see App.ConfigInitializerClass.initializers
  42. *
  43. * @return {object} property name - initializer map
  44. */
  45. __defaultInitializers: function() {
  46. return {
  47. 'ha.zookeeper.quorum': this.getNameNodeHAOnlyHostsPortConfig('ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  48. 'hbase.zookeeper.quorum': this.getHostsListComponentConfig('ZOOKEEPER_SERVER', true),
  49. 'instance.zookeeper.host': this.getHostsWithPortConfig('ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  50. 'templeton.zookeeper.hosts': this.getHostsWithPortConfig('ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  51. 'hive.cluster.delegation.token.store.zookeeper.connectString': this.getHostsWithPortConfig('ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  52. 'storm.zookeeper.servers': this.getHostsListComponentJSONStringifiedConfig('ZOOKEEPER_SERVER', true),
  53. 'hive.zookeeper.quorum': this.getHDPStackOnlyHostsPortConfig('2.2', 'ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  54. 'hadoop.registry.zk.quorum': this.getHDPStackOnlyHostsPortConfig('2.2', 'ZOOKEEPER_SERVER', '', '', ',', 'zkClientPort', true),
  55. 'nimbus.seeds': this.getHostsListComponentJSONStringifiedConfig('NIMBUS', true),
  56. 'hadoop.proxyuser.{{hiveUser}}.hosts': this.getComponentsHostsConfig(['HIVE_SERVER', 'WEBHCAT_SERVER', 'HIVE_METASTORE'], false),
  57. 'hadoop.proxyuser.{{webhcatUser}}.hosts': this.getComponentsHostsConfig(['HIVE_SERVER', 'WEBHCAT_SERVER', 'HIVE_METASTORE'], false, true),
  58. 'hadoop.proxyuser.{{hiveUser}}.hosts': this.getComponentsHostsConfig(['HIVE_SERVER', 'WEBHCAT_SERVER', 'HIVE_METASTORE'], false, true),
  59. 'hive.metastore.uris': this.getHostsWithPortConfig(['WEBHCAT_SERVER', 'HIVE_METASTORE'], 'thrift://', '', ',thrift://', 'hiveMetastorePort', true)
  60. };
  61. },
  62. /**
  63. * All unique initializer definition.
  64. * Object format is the same as for App.ConfigInitializerClass.uniqueInitializers
  65. * @see App.ConfigInitializerClass.uniqueInitializers
  66. *
  67. * @type {Object}
  68. */
  69. __defaultUniqueInitializers: {
  70. 'yarn.resourcemanager.zk-address': '_initYarnRMZkAdress',
  71. 'templeton.hive.properties': '_initTempletonHiveProperties'
  72. },
  73. /**
  74. * Property names to initialize. This attribute should be overrided in class instance.
  75. * `initializers` property will set up according this list from `__defaultUniqueInitializers` and
  76. * `__defaultInitializers`
  77. *
  78. * @type {string[]}
  79. */
  80. initializeForProperties: null,
  81. initializers: function() {
  82. return {};
  83. }.property(),
  84. uniqueInitializers: {},
  85. init: function() {
  86. this._super();
  87. this._bootstrapInitializers(this.get('initializeForProperties'));
  88. },
  89. initializerTypes: [
  90. {
  91. name: 'json_stringified_value',
  92. method: '_initAsJSONStrigifiedValueConfig'
  93. }
  94. ],
  95. /**
  96. * @override
  97. * @param {object} settings
  98. */
  99. setup: function (settings) {
  100. this._updateInitializers(settings);
  101. },
  102. /**
  103. * @override
  104. */
  105. cleanup: function () {
  106. this._restoreInitializers();
  107. },
  108. getJSONStringifiedValueConfig: function() {
  109. return {
  110. type: 'json_stringified_value'
  111. };
  112. },
  113. _initAsJSONStrigifiedValueConfig: function(configProperty, localDB, dependencies, initializer) {
  114. var hostsValue = Em.get(configProperty, 'value').split(Em.getWithDefault(initializer, 'modifier.delimiter', ','));
  115. var propertyValue = JSON.stringify(hostsValue).replace(/"/g, "'");
  116. Em.setProperties(configProperty, {
  117. value: propertyValue,
  118. recommendedValue: propertyValue
  119. });
  120. return configProperty;
  121. },
  122. /**
  123. * Perform value update according to hosts. Mutate <code>siteConfigs</code>
  124. *
  125. * @param {object} siteConfigs
  126. * @param {configProperty} configProperty
  127. * @returns {boolean}
  128. */
  129. updateSiteObj: function(siteConfigs, configProperty) {
  130. if (!siteConfigs || !configProperty) return false;
  131. App.config.updateHostsListValue(siteConfigs, configProperty.name, configProperty.value);
  132. return true;
  133. },
  134. /**
  135. * @see App.ControlFlowInitializerMixin.getNameNodeHAControl
  136. * @see App.HostsBasedInitializerMixin.getComponentsHostsConfig
  137. */
  138. getNameNodeHAOnlyHostsConfig: function(components, asArray) {
  139. return [
  140. this.getNameNodeHAControl(),
  141. this.getComponentsHostsConfig.apply(this, _slice.call(arguments))
  142. ];
  143. },
  144. /**
  145. * @override
  146. **/
  147. getHostsWithPortConfig: function (component, prefix, suffix, delimiter, port, portFromDependencies) {
  148. var ret = this._super.apply(this, _slice.call(arguments));
  149. ret.componentExists = true;
  150. return ret;
  151. },
  152. /**
  153. * @see App.ControlFlowInitializerMixin.getNameNodeHAControl
  154. * @see App.HostsBasedInitializerMixin.getHostsWithPortConfig
  155. */
  156. getNameNodeHAOnlyHostsPortConfig: function(component, prefix, suffix, delimiter, port, portFromDependencies) {
  157. return [
  158. this.getNameNodeHAControl(),
  159. this.getHostsWithPortConfig.apply(this, _slice.call(arguments))
  160. ];
  161. },
  162. /**
  163. * @see App.ControlFlowInitializerMixin.getResourceManagerHAControl
  164. * @see App.HostsBasedInitializerMixin.getHostsWithPortConfig
  165. */
  166. getResourceManagerHAOnlyHostsPortConfig: function(component, prefix, suffix, delimiter, port, portFromDependencies) {
  167. return [
  168. this.getResourceManagerHAControl(),
  169. this.getHostsWithPortConfig.apply(this, _slice.call(arguments))
  170. ];
  171. },
  172. /**
  173. * @see App.HostsBasedInitializerMixin.getHostsListComponentConfig
  174. * @see getJSONStringifiedValueConfig
  175. */
  176. getHostsListComponentJSONStringifiedConfig: function(component, componentExists, delimiter) {
  177. return [
  178. this.getHostsListComponentConfig.apply(this, _slice.call(arguments)),
  179. this.getJSONStringifiedValueConfig()
  180. ];
  181. },
  182. /**
  183. * @see App.ControlFlowInitializerMixin.getHDPStackVersionControl
  184. * @see App.HostsBasedInitializerMixin.getHostsWithPortConfig
  185. */
  186. getHDPStackOnlyHostsPortConfig: function(minStackVersion, component, prefix, suffix, delimiter, port, portFromDependencies) {
  187. return [
  188. this.getHDPStackVersionControl(minStackVersion),
  189. this.getHostsWithPortConfig.apply(this, _slice.call(arguments, 1))
  190. ];
  191. },
  192. _initYarnRMZkAdress: function(configProperty, localDB, dependencies) {
  193. if (App.get('isRMHaEnabled') || App.get('isHadoop22Stack')) {
  194. return this._initAsHostsWithPort(configProperty, localDB, dependencies, {
  195. component: 'ZOOKEEPER_SERVER',
  196. componentExists: true,
  197. modifier: {
  198. prefix: '',
  199. suffix: '',
  200. delimiter: ','
  201. },
  202. portKey: 'zkClientPort'
  203. });
  204. } else {
  205. return configProperty;
  206. }
  207. },
  208. _initTempletonHiveProperties: function(configProperty, localDB, dependecies, initializer) {
  209. var hostNames = localDB.masterComponentHosts.filter(function(masterComponent) {
  210. return ['WEBHCAT_SERVER', 'HIVE_METASTORE'].contains(masterComponent.component) && masterComponent.isInstalled === true;
  211. }).mapProperty('hostName').uniq().sort();
  212. var hiveMSHosts = hostNames.map(function(hostName) {
  213. return "thrift://" + hostName + ":" + dependecies.hiveMetastorePort;
  214. }).join('\\,');
  215. var value = configProperty.value.replace(/thrift.+[0-9]{2,},/i, hiveMSHosts + ",");
  216. Em.setProperties(configProperty, {
  217. value: value,
  218. recommendedValue: value
  219. });
  220. return configProperty;
  221. },
  222. /**
  223. * Set up `this.initializers` and `this.uniqueInitializers` properties according
  224. * to property list names.
  225. *
  226. * @param {string[]} properties list of property names
  227. */
  228. _bootstrapInitializers: function(properties) {
  229. var initializers = {},
  230. uniqueInitializers = {},
  231. defaultInitializers = this.__defaultInitializers(),
  232. defaultUniqueInitializers = this.get('__defaultUniqueInitializers');
  233. if (Em.isNone(properties)) {
  234. initializers = this.__defaultInitializers();
  235. uniqueInitializer = this.get('__defaultUniqueInitializers');
  236. } else {
  237. properties.forEach(function(propertyName) {
  238. if (defaultInitializers[propertyName]) {
  239. initializers[propertyName] = defaultInitializers[propertyName];
  240. } else if (defaultUniqueInitializers[propertyName]) {
  241. uniqueInitializers[propertyName] = defaultUniqueInitializers[propertyName];
  242. }
  243. });
  244. }
  245. this._setForComputed('initializers', initializers);
  246. this.set('uniqueInitializers', uniqueInitializers);
  247. }
  248. });
  249. /**
  250. * ZooKeeper service add/remove components initializer.
  251. * @instance App.AddComponentConfigInitializer
  252. */
  253. App.AddZooKeeperComponentsInitializer = App.AddComponentConfigInitializer.create({
  254. initializeForProperties: [
  255. 'ha.zookeeper.quorum',
  256. 'hbase.zookeeper.quorum',
  257. 'instance.zookeeper.host',
  258. 'templeton.zookeeper.hosts',
  259. 'hive.cluster.delegation.token.store.zookeeper.connectString',
  260. 'yarn.resourcemanager.zk-address',
  261. 'hive.zookeeper.quorum',
  262. 'storm.zookeeper.servers',
  263. 'hadoop.registry.zk.quorum'
  264. ]
  265. });
  266. /**
  267. * Hive service add/remove components initializer.
  268. * @instance App.AddComponentConfigInitializer
  269. */
  270. App.AddHiveComponentsInitializer = App.AddComponentConfigInitializer.create({
  271. initializeForProperties: [
  272. 'hive.metastore.uris',
  273. 'templeton.hive.properties',
  274. 'hadoop.proxyuser.{{webhcatUser}}.hosts',
  275. 'hadoop.proxyuser.{{hiveUser}}.hosts'
  276. ]
  277. });