step8_controller.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874
  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. App.WizardStep8Controller = Em.Controller.extend(App.AddSecurityConfigs, App.wizardDeployProgressControllerMixin, {
  21. name: 'wizardStep8Controller',
  22. /**
  23. * List of raw data about cluster that should be displayed
  24. * @type {Array}
  25. */
  26. rawContent: [
  27. {
  28. config_name: 'Admin',
  29. display_name: 'Admin Name',
  30. config_value: ''
  31. },
  32. {
  33. config_name: 'cluster',
  34. display_name: 'Cluster Name',
  35. config_value: ''
  36. },
  37. {
  38. config_name: 'hosts',
  39. display_name: 'Total Hosts',
  40. config_value: ''
  41. },
  42. {
  43. config_name: 'Repo',
  44. display_name: 'Local Repository',
  45. config_value: ''
  46. }
  47. ],
  48. /**
  49. * List of data about cluster (based on formatted <code>rawContent</code>)
  50. * @type {Object[]}
  51. */
  52. clusterInfo: [],
  53. /**
  54. * List of services with components assigned to hosts
  55. * @type {Object[]}
  56. */
  57. services: [],
  58. /**
  59. * @type {Object[]}
  60. */
  61. configs: [],
  62. /**
  63. * All configs
  64. * @type {Array}
  65. */
  66. configMapping: function () {
  67. return App.config.get('configMapping').all(true);
  68. }.property('App.config.configMapping'),
  69. /**
  70. *
  71. */
  72. slaveComponentConfig: null,
  73. /**
  74. * Should Submit button be disabled
  75. * @type {bool}
  76. */
  77. isSubmitDisabled: false,
  78. /**
  79. * Should Back button be disabled
  80. * @type {bool}
  81. */
  82. isBackBtnDisabled: false,
  83. /**
  84. * This flag when turned to true launches deploy progress bar
  85. */
  86. isDeployStarted: function() {
  87. this.get('isSubmitDisabled');
  88. }.property('isSubmitDisabled'),
  89. /**
  90. * Is error appears while <code>ajaxQueue</code> executes
  91. * @type {bool}
  92. */
  93. hasErrorOccurred: false,
  94. /**
  95. * Are services installed
  96. * Used to hide Deploy Progress Bar
  97. * @type {bool}
  98. */
  99. servicesInstalled: false,
  100. /**
  101. * List of service config tags
  102. * @type {Object[]}
  103. */
  104. serviceConfigTags: [],
  105. /**
  106. * Is cluster security enabled
  107. * @type {bool}
  108. */
  109. securityEnabled: function () {
  110. return App.router.get('mainAdminSecurityController.securityEnabled');
  111. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  112. /**
  113. * Selected config group
  114. * @type {Object}
  115. */
  116. selectedConfigGroup: null,
  117. /**
  118. * List of config groups
  119. * @type {Object[]}
  120. */
  121. configGroups: [],
  122. /**
  123. * List of selected but not installed services
  124. * @type {Object[]}
  125. */
  126. selectedServices: function () {
  127. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  128. }.property('content.services.@each.isSelected','content.services.@each.isInstalled').cacheable(),
  129. /**
  130. * List of installed services
  131. * @type {Object[]}
  132. */
  133. installedServices: function () {
  134. return this.get('content.services').filterProperty('isInstalled');
  135. }.property('content.services').cacheable(),
  136. /**
  137. * Current cluster name
  138. * @type {string}
  139. */
  140. clusterName: function () {
  141. return this.get('content.cluster.name');
  142. }.property('content.cluster.name'),
  143. /**
  144. * List of existing cluster names
  145. * @type {string[]}
  146. */
  147. clusterNames: [],
  148. /**
  149. * Clear current step data
  150. * @method clearStep
  151. */
  152. clearStep: function () {
  153. this.get('services').clear();
  154. this.get('configs').clear();
  155. this.get('clusterInfo').clear();
  156. this.get('serviceConfigTags').clear();
  157. this.set('servicesInstalled', false);
  158. this.set('ajaxQueueLength', 0);
  159. this.set('ajaxRequestsQueue', App.ajaxQueue.create());
  160. this.set('ajaxRequestsQueue.finishedCallback', this.ajaxQueueFinished);
  161. },
  162. /**
  163. * Load current step data
  164. * @method loadStep
  165. */
  166. loadStep: function () {
  167. console.log("TRACE: Loading step8: Review Page");
  168. this.clearStep();
  169. if (this.get('content.serviceConfigProperties')) {
  170. this.formatProperties();
  171. this.loadConfigs();
  172. if (this.get('content.controllerName') != 'installerController' && this.get('securityEnabled')) {
  173. this.prepareSecureConfigs();
  174. this.get('content.services').filterProperty('isSelected', true)
  175. .mapProperty('serviceName').forEach(function (serviceName) {
  176. var config = this.get('secureConfigs').findProperty('serviceName', serviceName);
  177. if (config) {
  178. this.setPrincipalValue(serviceName, config.name);
  179. }
  180. }, this);
  181. }
  182. }
  183. this.loadClusterInfo();
  184. this.loadServices();
  185. this.set('isSubmitDisabled', false);
  186. this.set('isBackBtnDisabled', false);
  187. },
  188. /**
  189. * replace whitespace character with coma between directories
  190. * @method formatProperties
  191. */
  192. formatProperties: function () {
  193. this.get('content.serviceConfigProperties').forEach(function (_configProperty) {
  194. _configProperty.value = App.config.trimProperty(_configProperty, false);
  195. });
  196. },
  197. /**
  198. * Remove unused Sink configs
  199. * @param {Ember.Enumerable} configs
  200. * @returns {Ember.Enumerable}
  201. * @method removeSinkConfigs
  202. */
  203. removeSinkConfigs: function (configs) {
  204. var sinkDb = configs.findProperty('name', 'sink_database');
  205. var sinkDbType = configs.findProperty('name', 'sink_database_type');
  206. if (sinkDbType) {
  207. var sink_properties = Em.A([]);
  208. switch (sinkDb.value) {
  209. case 'Existing MSSQL Server database with integrated authentication':
  210. configs.findProperty('name', 'sink.dbservername').value = configs.findProperty('name', 'sink_existing_mssql_server_host').value;
  211. sinkDbType.value = 'mssql';
  212. sink_properties = Em.A(['sink_existing_mssql_server_2_database', 'sink_existing_mssql_server_2_host']);
  213. break;
  214. case 'Existing MSSQL Server database with sql auth':
  215. configs.findProperty('name', 'sink.dbservername').value = configs.findProperty('name', 'sink_existing_mssql_server_2_host').value;
  216. sinkDbType.value = 'mssql';
  217. sink_properties = Em.A(['sink_existing_mssql_server_database', 'sink_existing_mssql_server_host']);
  218. break;
  219. }
  220. sink_properties.forEach(function (property) {
  221. configs = configs.without(configs.findProperty('name', property));
  222. });
  223. }
  224. return configs;
  225. },
  226. /**
  227. * Remove unused Hive configs
  228. * @param {Ember.Enumerable} configs
  229. * @returns {Ember.Enumerable}
  230. * @method removeHiveConfigs
  231. */
  232. removeHiveConfigs: function (configs) {
  233. var hiveDb = configs.findProperty('name', 'hive_database');
  234. var hiveDbType = configs.findProperty('name', 'hive_database_type');
  235. if (hiveDbType) {
  236. var hive_properties = Em.A([]);
  237. switch (hiveDb.value) {
  238. case 'New MySQL Database':
  239. if (configs.someProperty('name', 'hive_ambari_host')) {
  240. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_ambari_host').value;
  241. }
  242. hive_properties = Em.A(['hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host',
  243. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database',
  244. 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host',
  245. 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host']);
  246. break;
  247. case 'New PostgreSQL Database':
  248. if (configs.someProperty('name', 'hive_ambari_host')) {
  249. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_ambari_host').value;
  250. }
  251. hive_properties = Em.A(['hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host',
  252. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']);
  253. break;
  254. case 'Existing MySQL Database':
  255. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_existing_mysql_host').value;
  256. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  257. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database',
  258. 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host',
  259. 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host']);
  260. break;
  261. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  262. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_existing_postgresql_host').value;
  263. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  264. 'hive_existing_oracle_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database',
  265. 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host',
  266. 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host']);
  267. break;
  268. case 'Existing MSSQL Server database with integrated authentication':
  269. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_existing_mssql_server_2_host').value;
  270. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  271. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database',
  272. 'hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_mssql_server_database',
  273. 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host']);
  274. break;
  275. case 'Existing MSSQL Server database with sql auth':
  276. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_existing_mssql_server_host').value;
  277. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  278. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database',
  279. 'hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_mssql_server_database',
  280. 'hive_existing_mssql_server_host', 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host']);
  281. break;
  282. default:
  283. configs.findProperty('name', 'hive_hostname').value = configs.findProperty('name', 'hive_existing_oracle_host').value;
  284. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_mysql_host',
  285. 'hive_existing_mysql_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database',
  286. 'hive_existing_mssql_server_database', 'hive_existing_mssql_server_host',
  287. 'hive_existing_mssql_server_2_database', 'hive_existing_mssql_server_2_host']);
  288. break;
  289. }
  290. hive_properties.forEach(function (property) {
  291. configs = configs.without(configs.findProperty('name', property));
  292. });
  293. }
  294. return configs;
  295. },
  296. /**
  297. * Remove unused Oozie configs
  298. * @param {Ember.Enumerable} configs
  299. * @returns {Ember.Enumerable}
  300. * @method removeOozieConfigs
  301. */
  302. removeOozieConfigs: function (configs) {
  303. var oozieDb = configs.findProperty('name', 'oozie_database');
  304. var oozieDbType = configs.findProperty('name', 'oozie_database_type');
  305. if (oozieDbType) {
  306. var oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database']);
  307. switch (oozieDb.value) {
  308. case 'New Derby Database':
  309. configs.findProperty('name', 'oozie_hostname').value = configs.findProperty('name', 'oozie_ambari_host').value;
  310. oozieDbType.value = 'derby';
  311. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_mysql_host',
  312. 'oozie_existing_mysql_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database',
  313. 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database',
  314. 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host',
  315. 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host']);
  316. break;
  317. case 'Existing MySQL Database':
  318. configs.findProperty('name', 'oozie_hostname').value = configs.findProperty('name', 'oozie_existing_mysql_host').value;
  319. oozieDbType.value = 'mysql';
  320. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_oracle_host',
  321. 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database',
  322. 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host',
  323. 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host']);
  324. break;
  325. case Em.I18n.t('services.service.config.hive.oozie.postgresql'):
  326. configs.findProperty('name', 'oozie_hostname').value = configs.findProperty('name', 'oozie_existing_postgresql_host').value;
  327. oozieDbType.value = 'postgresql';
  328. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_oracle_host',
  329. 'oozie_existing_oracle_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database',
  330. 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host',
  331. 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host']);
  332. break;
  333. case 'Existing MSSQL Server database with integrated authentication':
  334. configs.findProperty('name', 'oozie_hostname').value = configs.findProperty('name', 'oozie_existing_mysql_host').value;
  335. oozieDbType.value = 'mssql';
  336. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'oozie_existing_oracle_host',
  337. 'oozie_existing_oracle_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database',
  338. 'oozie_existing_mysql_host', 'oozie_existing_mysql_database',
  339. 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host',
  340. 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host']);
  341. break;
  342. case 'Existing MSSQL Server database with sql auth':
  343. configs.findProperty('name', 'oozie_hostname').value = configs.findProperty('name', 'oozie_existing_mysql_host').value;
  344. oozieDbType.value = 'mssql';
  345. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'oozie_existing_oracle_host',
  346. 'oozie_existing_oracle_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database',
  347. 'oozie_existing_mysql_host', 'oozie_existing_mysql_database',
  348. 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host',
  349. 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host']);
  350. break;
  351. default:
  352. configs.findProperty('name', 'oozie_hostname').value = configs.findProperty('name', 'oozie_existing_oracle_host').value;
  353. oozieDbType.value = 'oracle';
  354. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_mysql_host',
  355. 'oozie_existing_mysql_database', 'oozie_derby_database', 'oozie_existing_postgresql_host',
  356. 'oozie_existing_postgresql_database', 'oozie_existing_mssql_server_database', 'oozie_existing_mssql_server_host',
  357. 'oozie_existing_mssql_server_2_database', 'oozie_existing_mssql_server_2_host']);
  358. break;
  359. }
  360. oozie_properties.forEach(function (property) {
  361. configs = configs.without(configs.findProperty('name', property));
  362. });
  363. }
  364. return configs;
  365. },
  366. /**
  367. * Load all site properties
  368. * @method loadConfigs
  369. */
  370. loadConfigs: function () {
  371. //storedConfigs contains custom configs as well
  372. var configs = this.get('content.serviceConfigProperties');
  373. if (configs.someProperty('name', 'hive_database')) {
  374. configs = this.removeHiveConfigs(configs);
  375. }
  376. if (configs.someProperty('name', 'sink_database')) {
  377. configs = this.removeSinkConfigs(configs);
  378. }
  379. if (configs.someProperty('name', 'oozie_database')) {
  380. configs = this.removeOozieConfigs(configs);
  381. }
  382. configs.forEach(function (_config) {
  383. _config.value = (typeof _config.value === "boolean") ? _config.value.toString() : _config.value;
  384. });
  385. var mappedConfigs = App.config.excludeUnsupportedConfigs(this.get('configMapping'), this.get('selectedServices').mapProperty('serviceName'));
  386. var uiConfigs = this.loadUiSideConfigs(mappedConfigs);
  387. var customGroupConfigs = [];
  388. var allConfigs = configs.concat(uiConfigs).filter(function (config) {
  389. if (config.group) {
  390. customGroupConfigs.push(config);
  391. return false;
  392. } else {
  393. return true;
  394. }
  395. });
  396. this.set('customNonDefaultGroupConfigs', customGroupConfigs);
  397. this.set('configs', allConfigs);
  398. },
  399. /**
  400. * Load UI configs
  401. * @param {Array} configMapping
  402. * @return {Array}
  403. * @method loadUiSideConfigs
  404. */
  405. loadUiSideConfigs: function (configMapping) {
  406. var uiConfig = [];
  407. var configs = configMapping.filterProperty('foreignKey', null);
  408. this.addDynamicProperties(configs);
  409. configs.forEach(function (_config) {
  410. var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value, _config.name);
  411. uiConfig.pushObject({
  412. "id": "site property",
  413. "name": _config.name,
  414. "value": valueWithOverrides.value,
  415. "filename": _config.filename,
  416. "overrides": valueWithOverrides.overrides
  417. });
  418. }, this);
  419. var dependentConfig = $.extend(true, [], configMapping.filterProperty('foreignKey'));
  420. dependentConfig.forEach(function (_config) {
  421. App.config.setConfigValue(uiConfig, this.get('content.serviceConfigProperties'), _config);
  422. if(!_config.noMatchSoSkipThisConfig)
  423. uiConfig.pushObject({
  424. "id": "site property",
  425. "name": _config._name || _config.name,
  426. "value": _config.value,
  427. "filename": _config.filename
  428. });
  429. }, this);
  430. return uiConfig;
  431. },
  432. /**
  433. * Add dynamic properties to configs
  434. * @param {Array} configs
  435. * @method addDynamicProperties
  436. */
  437. addDynamicProperties: function (configs) {
  438. var templetonHiveProperty = this.get('content.serviceConfigProperties').someProperty('name', 'templeton.hive.properties');
  439. if (!templetonHiveProperty) {
  440. configs.pushObject({
  441. "name": "templeton.hive.properties",
  442. "templateName": ["hivemetastore_host"],
  443. "foreignKey": null,
  444. "value": "hive.metastore.local=false,hive.metastore.uris=thrift://<templateName[0]>:9083,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse",
  445. "filename": "webhcat-site.xml"
  446. });
  447. }
  448. },
  449. /**
  450. * Format <code>content.hosts</code> from Object to Array
  451. * @returns {Array}
  452. * @method getRegisteredHosts
  453. */
  454. getRegisteredHosts: function () {
  455. var allHosts = this.get('content.hosts');
  456. var hosts = [];
  457. for (var hostName in allHosts) {
  458. if (allHosts.hasOwnProperty(hostName)) {
  459. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  460. allHosts[hostName].hostName = allHosts[hostName].name;
  461. hosts.pushObject(allHosts[hostName]);
  462. }
  463. }
  464. }
  465. return hosts;
  466. },
  467. /**
  468. * Set all site property that are derived from other puppet-variable
  469. * @param {String} templateName
  470. * @param {String} expression
  471. * @param {String} name
  472. * @return {Object}
  473. * example: <code>{
  474. * value: '...',
  475. * overrides: [
  476. * {
  477. * value: 'v1',
  478. * hosts: ['h1', 'h2']
  479. * },
  480. * {
  481. * value: 'v2',
  482. * hosts: ['h2', 'h3']
  483. * },
  484. * ....
  485. * ]
  486. * }</code>
  487. * @method getGlobConfigValueWithOverrides
  488. */
  489. getGlobConfigValueWithOverrides: function (templateName, expression, name) {
  490. var express = expression.match(/<(.*?)>/g);
  491. var value = expression;
  492. if (express == null) {
  493. return { value: expression, overrides: []}; // if site property do not map any global property then return the value
  494. }
  495. var overrideHostToValue = {};
  496. express.forEach(function (_express) {
  497. //console.log("The value of template is: " + _express);
  498. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  499. if (this.get('configs').someProperty('name', templateName[index])) {
  500. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  501. var globalObj = this.get('configs').findProperty('name', templateName[index]);
  502. var globValue = globalObj.value;
  503. // Hack for templeton.zookeeper.hosts
  504. var preReplaceValue = null;
  505. if (value !== null) { // if the property depends on more than one template name like <templateName[0]>/<templateName[1]> then don't proceed to the next if the prior is null or not found in the global configs
  506. preReplaceValue = value;
  507. value = this._replaceConfigValues(name, _express, value, globValue);
  508. }
  509. if (globalObj.overrides != null) {
  510. globalObj.overrides.forEach(function (override) {
  511. var ov = override.value;
  512. var hostsArray = override.hosts;
  513. hostsArray.forEach(function (host) {
  514. if (!(host in overrideHostToValue)) {
  515. overrideHostToValue[host] = this._replaceConfigValues(name, _express, preReplaceValue, ov);
  516. } else {
  517. overrideHostToValue[host] = this._replaceConfigValues(name, _express, overrideHostToValue[host], ov);
  518. }
  519. }, this);
  520. }, this);
  521. }
  522. } else {
  523. /*
  524. console.log("ERROR: The variable name is: " + templateName[index]);
  525. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  526. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  527. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  528. */
  529. value = null;
  530. }
  531. }, this);
  532. var valueWithOverrides = {
  533. value: value,
  534. overrides: []
  535. };
  536. var overrideValueToHostMap = {};
  537. if (!jQuery.isEmptyObject(overrideHostToValue)) {
  538. for (var host in overrideHostToValue) {
  539. var hostVal = overrideHostToValue[host];
  540. if (!(hostVal in overrideValueToHostMap)) {
  541. overrideValueToHostMap[hostVal] = [];
  542. }
  543. overrideValueToHostMap[hostVal].push(host);
  544. }
  545. }
  546. for (var val in overrideValueToHostMap) {
  547. valueWithOverrides.overrides.push({
  548. value: val,
  549. hosts: overrideValueToHostMap[val]
  550. });
  551. }
  552. return valueWithOverrides;
  553. },
  554. /**
  555. * replace some values in config property
  556. * @param {string} name
  557. * @param {string} express
  558. * @param {string} value
  559. * @param {string} globValue
  560. * @return {string}
  561. * @private
  562. * @method _replaceConfigValues
  563. */
  564. _replaceConfigValues: function (name, express, value, globValue) {
  565. return value.replace(express, globValue);
  566. },
  567. /**
  568. * Load all info about cluster to <code>clusterInfo</code> variable
  569. * @method loadClusterInfo
  570. */
  571. loadClusterInfo: function () {
  572. //Admin name
  573. var admin = this.rawContent.findProperty('config_name', 'Admin');
  574. admin.config_value = App.db.getLoginName();
  575. console.log("STEP8: the value of content cluster name: " + App.db.getLoginName());
  576. if (admin.config_value) {
  577. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  578. }
  579. // cluster name
  580. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  581. cluster.config_value = this.get('content.cluster.name');
  582. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  583. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  584. //hosts
  585. var newHostsCount = 0;
  586. var totalHostsCount = 0;
  587. var hosts = this.get('content.hosts');
  588. for (var hostName in hosts) {
  589. newHostsCount += ~~(!hosts[hostName].isInstalled);
  590. totalHostsCount++;
  591. }
  592. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  593. totalHostsObj.config_value = totalHostsCount + ' (' + newHostsCount + ' new)';
  594. this.get('clusterInfo').pushObject(Em.Object.create(totalHostsObj));
  595. //repo
  596. if (['addHostController', 'addServiceController'].contains(this.get('content.controllerName'))) {
  597. this.loadRepoInfo();
  598. } else {
  599. // from install wizard
  600. var selectedStack = App.Stack.find().findProperty('isSelected');
  601. var allRepos = [];
  602. if (selectedStack && selectedStack.get('operatingSystems')) {
  603. selectedStack.get('operatingSystems').forEach(function (os) {
  604. if (os.get('isSelected')) {
  605. os.get('repositories').forEach(function(repo) {
  606. allRepos.push(Em.Object.create({
  607. base_url: repo.get('baseUrl'),
  608. os_type: repo.get('osType'),
  609. repo_id: repo.get('repoId')
  610. }));
  611. }, this);
  612. }
  613. }, this);
  614. }
  615. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  616. this.get('clusterInfo').set('repoInfo', allRepos);
  617. }
  618. },
  619. /**
  620. * Load repo info for add Service/Host wizard review page
  621. * @return {$.ajax|null}
  622. * @method loadRepoInfo
  623. */
  624. loadRepoInfo: function () {
  625. var nameVersionCombo = App.get('currentStackVersion').split('-');
  626. return App.ajax.send({
  627. name: 'cluster.load_repositories',
  628. sender: this,
  629. data: {
  630. stackName: nameVersionCombo[0],
  631. stackVersion: nameVersionCombo[1]
  632. },
  633. success: 'loadRepoInfoSuccessCallback',
  634. error: 'loadRepoInfoErrorCallback'
  635. });
  636. },
  637. /**
  638. * Save all repo base URL of all OS type to <code>repoInfo<code>
  639. * @param {object} data
  640. * @method loadRepoInfoSuccessCallback
  641. */
  642. loadRepoInfoSuccessCallback: function (data) {
  643. var allRepos = [];
  644. data.items.forEach(function (os) {
  645. os.repositories.forEach(function (repository) {
  646. allRepos.push(Em.Object.create({
  647. base_url: repository.Repositories.base_url,
  648. os_type: repository.Repositories.os_type,
  649. repo_id: repository.Repositories.repo_id
  650. }));
  651. });
  652. }, this);
  653. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  654. this.get('clusterInfo').set('repoInfo', allRepos);
  655. },
  656. /**
  657. * @param {object} request
  658. * @method loadRepoInfoErrorCallback
  659. */
  660. loadRepoInfoErrorCallback: function (request) {
  661. console.log('Error message is: ' + request.responseText);
  662. var allRepos = [];
  663. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  664. this.get('clusterInfo').set('repoInfo', allRepos);
  665. },
  666. /**
  667. * Load all info about services to <code>services</code> variable
  668. * @method loadServices
  669. */
  670. loadServices: function () {
  671. this.get('selectedServices').filterProperty('isHiddenOnSelectServicePage', false).forEach(function (service) {
  672. console.log('INFO: step8: Name of the service from getService function: ' + service.get('serviceName'));
  673. var serviceObj = Em.Object.create({
  674. service_name: service.get('serviceName'),
  675. display_name: service.get('displayNameOnSelectServicePage'),
  676. service_components: Em.A([])
  677. });
  678. service.get('serviceComponents').forEach(function (component) {
  679. // show clients for services that have only clients components
  680. if ((component.get('isClient') || component.get('isRequiredOnAllHosts')) && !service.get('isClientOnlyService')) return;
  681. // skip components that was hide on assign master page
  682. if (component.get('isMaster') && !component.get('isShownOnInstallerAssignMasterPage')) return;
  683. // no HA component
  684. if (component.get('isHAComponentOnly')) return;
  685. var displayName;
  686. if (component.get('isClient')) {
  687. displayName = Em.I18n.t('common.clients')
  688. } else {
  689. // remove service name from component display name
  690. displayName = App.format.role(component.get('componentName')).replace(new RegExp('^' + service.get('serviceName') + '\\s', 'i'), '');
  691. }
  692. serviceObj.get('service_components').pushObject(Em.Object.create({
  693. component_name: component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName'),
  694. display_name: displayName,
  695. component_value: this.assignComponentHosts(component)
  696. }));
  697. }, this);
  698. if (service.get('customReviewHandler')) {
  699. for (var displayName in service.get('customReviewHandler')) {
  700. serviceObj.get('service_components').pushObject(Em.Object.create({
  701. display_name: displayName,
  702. component_value: this.assignComponentHosts(Em.Object.create({
  703. customHandler: service.get('customReviewHandler.' + displayName)
  704. }))
  705. }));
  706. }
  707. }
  708. this.get('services').pushObject(serviceObj);
  709. }, this);
  710. },
  711. /**
  712. * Set <code>component_value</code> property to <code>component</code>
  713. * @param {Em.Object} component
  714. * @return {String}
  715. * @method assignComponentHosts
  716. */
  717. assignComponentHosts: function (component) {
  718. var componentValue;
  719. if (component.get('customHandler')) {
  720. componentValue = this[component.get('customHandler')].call(this, component);
  721. }
  722. else {
  723. if (component.get('isMaster')) {
  724. componentValue = this.getMasterComponentValue(component.get('componentName'));
  725. }
  726. else {
  727. console.log(' --- ---INFO: step8: NOT component isMaster');
  728. var componentName = component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName');
  729. var hostsLength = this.get('content.slaveComponentHosts')
  730. .findProperty('componentName', componentName).hosts.length;
  731. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  732. }
  733. }
  734. return componentValue;
  735. },
  736. getMasterComponentValue: function (componentName) {
  737. var masterComponents = this.get('content.masterComponentHosts');
  738. var hostsCount = masterComponents.filterProperty('component', componentName).length;
  739. return stringUtils.pluralize(hostsCount,
  740. masterComponents.findProperty('component', componentName).hostName,
  741. hostsCount + ' ' + Em.I18n.t('installer.step8.hosts'));
  742. },
  743. /**
  744. * Set displayed MetricsSink DB value based on DB type
  745. * @method loadSinkDbValue
  746. */
  747. loadSinkDbValue: function () {
  748. var db, serviceConfigProperties = this.get('wizardController').getDBProperty('serviceConfigProperties'),
  749. sinkDb = serviceConfigProperties.findProperty('name', 'sink_database');
  750. if (sinkDb.value === 'Existing MSSQL Server database with integrated authentication') {
  751. db = serviceConfigProperties.findProperty('name', 'sink_existing_mssql_server_database');
  752. return db.value + ' (' + sinkDb.value + ')';
  753. }
  754. else {
  755. if (sinkDb.value === 'Existing MSSQL Server database with sql auth') {
  756. db = serviceConfigProperties.findProperty('name', 'sink_existing_mssql_server_2_database');
  757. return db.value + ' (' + sinkDb.value + ')';
  758. }
  759. }
  760. },
  761. /**
  762. * Set displayed Hive DB value based on DB type
  763. * @method loadHiveDbValue
  764. */
  765. loadHiveDbValue: function () {
  766. var db, serviceConfigPreoprties = this.get('wizardController').getDBProperty('serviceConfigProperties'),
  767. hiveDb = serviceConfigPreoprties.findProperty('name', 'hive_database');
  768. if (hiveDb.value === 'New MySQL Database') {
  769. return 'MySQL (New Database)';
  770. } else if (hiveDb.value === 'New PostgreSQL Database') {
  771. return 'Postgres (New Database)';
  772. }
  773. else {
  774. if (hiveDb.value === 'Existing MySQL Database') {
  775. db = serviceConfigPreoprties.findProperty('name', 'hive_existing_mysql_database');
  776. return db.value + ' (' + hiveDb.value + ')';
  777. }
  778. else {
  779. if (hiveDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  780. db = serviceConfigPreoprties.findProperty('name', 'hive_existing_postgresql_database');
  781. return db.value + ' (' + hiveDb.value + ')';
  782. }
  783. else {
  784. if (hiveDb.value === 'Existing MSSQL Server database with integrated authentication') {
  785. db = serviceConfigPreoprties.findProperty('name', 'hive_existing_mssql_server_database');
  786. return db.value + ' (' + hiveDb.value + ')';
  787. }
  788. else {
  789. if (hiveDb.value === 'Existing MSSQL Server database with sql auth') {
  790. db = serviceConfigPreoprties.findProperty('name', 'hive_existing_mssql_server_2_database');
  791. return db.value + ' (' + hiveDb.value + ')';
  792. }
  793. else {
  794. // existing oracle database
  795. db = serviceConfigPreoprties.findProperty('name', 'hive_existing_oracle_database');
  796. return db.value + ' (' + hiveDb.value + ')';
  797. }
  798. }
  799. }
  800. }
  801. }
  802. },
  803. /**
  804. * Set displayed HBase master value
  805. * @param {Object} hbaseMaster
  806. * @method loadHbaseMasterValue
  807. */
  808. loadHbaseMasterValue: function (hbaseMaster) {
  809. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  810. if (hbaseHostName.length == 1) {
  811. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  812. } else {
  813. hbaseMaster.set('component_value', hbaseHostName[0].hostName + " " + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  814. }
  815. },
  816. /**
  817. * Set displayed ZooKeeper Server value
  818. * @param {Object} serverComponent
  819. * @method loadZkServerValue
  820. */
  821. loadZkServerValue: function (serverComponent) {
  822. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  823. var hostSuffix;
  824. if (zkHostNames === 1) {
  825. hostSuffix = Em.I18n.t('installer.step8.host');
  826. } else {
  827. hostSuffix = Em.I18n.t('installer.step8.hosts');
  828. }
  829. serverComponent.set('component_value', zkHostNames + hostSuffix);
  830. },
  831. /**
  832. * Set displayed Oozie DB value based on DB type
  833. * @method loadOozieDbValue
  834. */
  835. loadOozieDbValue: function () {
  836. var db, oozieDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_database');
  837. if (oozieDb.value === 'New Derby Database') {
  838. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_derby_database');
  839. return db.value + ' (' + oozieDb.value + ')';
  840. }
  841. else {
  842. if (oozieDb.value === 'Existing MySQL Database') {
  843. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mysql_database');
  844. return db.value + ' (' + oozieDb.value + ')';
  845. }
  846. else {
  847. if (oozieDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  848. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_postgresql_database');
  849. return db.value + ' (' + oozieDb.value + ')';
  850. }
  851. else {
  852. if (oozieDb.value === 'Existing MSSQL Server database with integrated authentication') {
  853. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mssql_server_database');
  854. return db.value + ' (' + oozieDb.value + ')';
  855. }
  856. else {
  857. if (oozieDb.value === 'Existing MSSQL Server database with sql auth') {
  858. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mssql_server_2_database');
  859. return db.value + ' (' + oozieDb.value + ')';
  860. }
  861. else {
  862. // existing oracle database
  863. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_oracle_database');
  864. return db.value + ' (' + oozieDb.value + ')';
  865. }
  866. }
  867. }
  868. }
  869. }
  870. },
  871. /**
  872. * Set displayed Nagion Admin value
  873. * @method loadNagiosAdminValue
  874. */
  875. loadNagiosAdminValue: function () {
  876. var config = this.get('content.serviceConfigProperties');
  877. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  878. var adminEmail = config.findProperty('name', 'nagios_contact');
  879. return adminLoginName.value + ' / (' + adminEmail.value + ')';
  880. },
  881. /**
  882. * Onclick handler for <code>next</code> button
  883. * @method submit
  884. * @return {App.ModalPopup|null}
  885. */
  886. submit: function () {
  887. if (this.get('isSubmitDisabled')) return null;
  888. if ((this.get('content.controllerName') == 'addHostController') && this.get('securityEnabled')) {
  889. var self = this;
  890. return App.showConfirmationPopup(function () {
  891. self.submitProceed();
  892. }, Em.I18n.t('installer.step8.securityConfirmationPopupBody'));
  893. } else {
  894. return this.submitProceed();
  895. }
  896. },
  897. /**
  898. * Update configurations for installed services.
  899. * Do separated PUT-request for each siteName for each service
  900. *
  901. * @param {Array} fileNamesToUpdate - file names that should be updated
  902. * @method updateConfigurations
  903. */
  904. updateConfigurations: function (fileNamesToUpdate) {
  905. var configurationController = App.router.get('mainServiceInfoConfigsController');
  906. var configs = this.get('configs').slice(0);
  907. var configsMap = [];
  908. fileNamesToUpdate.forEach(function (fileName) {
  909. if (!fileName || /^(core)/.test(fileName)) return;
  910. var tagName = 'version' + (new Date).getTime();
  911. var configsToSave = configs.filterProperty('filename', fileName);
  912. configsToSave.forEach(function (item) {
  913. item.value = App.config.trimProperty(item, false);
  914. });
  915. configsMap.push(configurationController.createSiteObj(fileName.replace(".xml", ""), tagName, configsToSave));
  916. }, this);
  917. if (!configsMap.length) return;
  918. this.applyConfigurationsToCluster(configsMap);
  919. },
  920. /**
  921. * Prepare <code>ajaxQueue</code> and start to execute it
  922. * @method submitProceed
  923. */
  924. submitProceed: function () {
  925. var self = this;
  926. this.set('isSubmitDisabled', true);
  927. this.set('isBackBtnDisabled', true);
  928. if (this.get('content.controllerName') == 'addHostController') {
  929. App.router.get('addHostController').setLowerStepsDisable(4);
  930. }
  931. // checkpoint the cluster status on the server so that the user can resume from where they left off
  932. switch (this.get('content.controllerName')) {
  933. case 'installerController':
  934. App.clusterStatus.setClusterStatus({
  935. clusterName: this.get('clusterName'),
  936. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  937. wizardControllerName: this.get('content.controllerName'),
  938. localdb: App.db.data
  939. });
  940. break;
  941. case 'addHostController':
  942. App.clusterStatus.setClusterStatus({
  943. clusterName: this.get('clusterName'),
  944. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  945. wizardControllerName: this.get('content.controllerName'),
  946. localdb: App.db.data
  947. });
  948. break;
  949. case 'addServiceController':
  950. App.clusterStatus.setClusterStatus({
  951. clusterName: this.get('clusterName'),
  952. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  953. wizardControllerName: this.get('content.controllerName'),
  954. localdb: App.db.data
  955. });
  956. break;
  957. default:
  958. break;
  959. }
  960. // delete any existing clusters to start from a clean slate
  961. // before creating a new cluster in install wizard
  962. // TODO: modify for multi-cluster support
  963. this.getExistingClusterNames().complete(function () {
  964. var clusterNames = self.get('clusterNames');
  965. if (self.get('content.controllerName') == 'installerController' && (!App.get('testMode')) && clusterNames.length) {
  966. self.deleteClusters(clusterNames);
  967. } else {
  968. self.deleteClustersCallback(null, null, {isLast: true});
  969. }
  970. });
  971. },
  972. /**
  973. * Get list of existing cluster names
  974. * @returns {object|null}
  975. * returns an array of existing cluster names.
  976. * returns an empty array if there are no existing clusters.
  977. * @method getExistingClusterNames
  978. */
  979. getExistingClusterNames: function () {
  980. return App.ajax.send({
  981. name: 'wizard.step8.existing_cluster_names',
  982. sender: this,
  983. success: 'getExistingClusterNamesSuccessCallBack',
  984. error: 'getExistingClusterNamesErrorCallback'
  985. });
  986. },
  987. /**
  988. * Save received list to <code>clusterNames</code>
  989. * @param {Object} data
  990. * @method getExistingClusterNamesSuccessCallBack
  991. */
  992. getExistingClusterNamesSuccessCallBack: function (data) {
  993. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  994. console.log("Got existing cluster names: " + clusterNames);
  995. this.set('clusterNames', clusterNames);
  996. },
  997. /**
  998. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  999. * @method getExistingClusterNamesErrorCallback
  1000. */
  1001. getExistingClusterNamesErrorCallback: function () {
  1002. console.log("Failed to get existing cluster names");
  1003. this.set('clusterNames', []);
  1004. },
  1005. /**
  1006. * Delete cluster by name
  1007. * One request for one cluster!
  1008. * @param {string[]} clusterNames
  1009. * @method deleteClusters
  1010. */
  1011. deleteClusters: function (clusterNames) {
  1012. clusterNames.forEach(function (clusterName, index) {
  1013. App.ajax.send({
  1014. name: 'common.delete.cluster',
  1015. sender: this,
  1016. data: {
  1017. name: clusterName,
  1018. isLast: index == clusterNames.length - 1
  1019. },
  1020. success: 'deleteClustersCallback',
  1021. error: 'deleteClustersCallback'
  1022. });
  1023. }, this);
  1024. },
  1025. deleteClustersCallback: function (response, request, data) {
  1026. if (data.isLast) {
  1027. this.createCluster();
  1028. this.createSelectedServices();
  1029. if (this.get('content.controllerName') !== 'addHostController') {
  1030. if (this.get('wizardController').getDBProperty('fileNamesToUpdate') && this.get('wizardController').getDBProperty('fileNamesToUpdate').length) {
  1031. this.updateConfigurations(this.get('wizardController').getDBProperty('fileNamesToUpdate'));
  1032. }
  1033. this.createConfigurations();
  1034. this.applyConfigurationsToCluster(this.get('serviceConfigTags'));
  1035. }
  1036. this.createComponents();
  1037. this.registerHostsToCluster();
  1038. this.createConfigurationGroups();
  1039. this.createMasterHostComponents();
  1040. this.createSlaveAndClientsHostComponents();
  1041. if (this.get('content.controllerName') === 'addServiceController') {
  1042. this.createAdditionalClientComponents();
  1043. }
  1044. this.createAdditionalHostComponents();
  1045. this.set('ajaxQueueLength', this.get('ajaxRequestsQueue.queue.length'));
  1046. this.get('ajaxRequestsQueue').start();
  1047. }
  1048. },
  1049. /**
  1050. * *******************************************************************
  1051. * The following create* functions are called upon submitting Step 8.
  1052. * *******************************************************************
  1053. */
  1054. /**
  1055. * Create cluster using selected stack version
  1056. * Queued request
  1057. * @method createCluster
  1058. */
  1059. createCluster: function () {
  1060. if (this.get('content.controllerName') !== 'installerController') return;
  1061. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  1062. this.addRequestToAjaxQueue({
  1063. name: 'wizard.step8.create_cluster',
  1064. data: {
  1065. data: JSON.stringify({ "Clusters": {"version": stackVersion }})
  1066. },
  1067. success: 'createClusterSuccess'
  1068. });
  1069. },
  1070. createClusterSuccess: function (data, xhr, params) {
  1071. App.set('clusterName', params.cluster)
  1072. },
  1073. /**
  1074. * Create selected to install services
  1075. * Queued request
  1076. * Skipped if no services where selected!
  1077. * @method createSelectedServices
  1078. */
  1079. createSelectedServices: function () {
  1080. var data = this.createSelectedServicesData();
  1081. if (!data.length) return;
  1082. this.addRequestToAjaxQueue({
  1083. name: 'wizard.step8.create_selected_services',
  1084. data: {
  1085. data: JSON.stringify(data)
  1086. }
  1087. });
  1088. },
  1089. /**
  1090. * Format data for <code>createSelectedServices</code> request
  1091. * @returns {Object[]}
  1092. * @method createSelectedServicesData
  1093. */
  1094. createSelectedServicesData: function () {
  1095. return this.get('selectedServices').map(function (_service) {
  1096. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  1097. });
  1098. },
  1099. /**
  1100. * Create components for selected services
  1101. * Queued requests
  1102. * One request for each service!
  1103. * @method createComponents
  1104. */
  1105. createComponents: function () {
  1106. var serviceComponents = App.StackServiceComponent.find();
  1107. this.get('selectedServices').forEach(function (_service) {
  1108. var serviceName = _service.get('serviceName');
  1109. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  1110. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  1111. });
  1112. // Service must be specified in terms of a query for creating multiple components at the same time.
  1113. // See AMBARI-1018.
  1114. this.addRequestToAjaxQueue({
  1115. name: 'wizard.step8.create_components',
  1116. data: {
  1117. data: JSON.stringify({"components": componentsData}),
  1118. serviceName: serviceName
  1119. }
  1120. });
  1121. }, this);
  1122. },
  1123. /**
  1124. * Error callback for new service component request
  1125. * So, if component doesn't exist we should create it
  1126. * @param {object} request
  1127. * @param {object} ajaxOptions
  1128. * @param {string} error
  1129. * @param {object} opt
  1130. * @param {object} params
  1131. * @method newServiceComponentErrorCallback
  1132. */
  1133. newServiceComponentErrorCallback: function (request, ajaxOptions, error, opt, params) {
  1134. this.addRequestToAjaxQueue({
  1135. name: 'wizard.step8.create_components',
  1136. data: {
  1137. serviceName: params.serviceName,
  1138. data: JSON.stringify({
  1139. "components": [
  1140. {
  1141. "ServiceComponentInfo": {
  1142. "component_name": params.componentName
  1143. }
  1144. }
  1145. ]
  1146. })
  1147. }
  1148. });
  1149. },
  1150. /**
  1151. * Register hosts
  1152. * Queued request
  1153. * @method registerHostsToCluster
  1154. */
  1155. registerHostsToCluster: function () {
  1156. var data = this.createRegisterHostData();
  1157. if (!data.length) return;
  1158. this.addRequestToAjaxQueue({
  1159. name: 'wizard.step8.register_host_to_cluster',
  1160. data: {
  1161. data: JSON.stringify(data)
  1162. }
  1163. });
  1164. },
  1165. /**
  1166. * Format request-data for <code>registerHostsToCluster</code>
  1167. * @returns {Object}
  1168. * @method createRegisterHostData
  1169. */
  1170. createRegisterHostData: function () {
  1171. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  1172. return {"Hosts": { "host_name": host.hostName}};
  1173. });
  1174. },
  1175. /**
  1176. * Register new master components
  1177. * @uses registerHostsToComponent
  1178. * @method createMasterHostComponents
  1179. */
  1180. createMasterHostComponents: function () {
  1181. // create master components for only selected services.
  1182. var selectedMasterComponents = this.get('content.masterComponentHosts').filter(function (_component) {
  1183. return this.get('selectedServices').mapProperty('serviceName').contains(_component.serviceId)
  1184. }, this);
  1185. selectedMasterComponents.mapProperty('component').uniq().forEach(function (component) {
  1186. var hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1187. this.registerHostsToComponent(hostNames, component);
  1188. }, this);
  1189. },
  1190. getClientsToMasterMap: function () {
  1191. var clientNames = App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName'),
  1192. clientsMap = {},
  1193. dependedComponents = App.StackServiceComponent.find().filterProperty('isMaster');
  1194. clientNames.forEach(function (clientName) {
  1195. clientsMap[clientName] = Em.A([]);
  1196. dependedComponents.forEach(function (component) {
  1197. if (component.get('dependencies').mapProperty('componentName').contains(clientName)) clientsMap[clientName].push(component.get('componentName'));
  1198. });
  1199. if (!clientsMap[clientName].length) delete clientsMap[clientName];
  1200. });
  1201. return clientsMap;
  1202. },
  1203. /**
  1204. * Register slave components and clients
  1205. * @uses registerHostsToComponent
  1206. * @method createSlaveAndClientsHostComponents
  1207. */
  1208. createSlaveAndClientsHostComponents: function () {
  1209. var masterHosts = this.get('content.masterComponentHosts');
  1210. var slaveHosts = this.get('content.slaveComponentHosts');
  1211. var clients = this.get('content.clients').filterProperty('isInstalled', false);
  1212. /**
  1213. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  1214. * @type {Object}
  1215. * Format:
  1216. * <code>
  1217. * {
  1218. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  1219. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  1220. * ...
  1221. * }
  1222. * </code>
  1223. */
  1224. var clientsToMasterMap = this.getClientsToMasterMap();
  1225. slaveHosts.forEach(function (_slave) {
  1226. if (_slave.componentName !== 'CLIENT') {
  1227. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1228. this.registerHostsToComponent(hostNames, _slave.componentName);
  1229. }
  1230. else {
  1231. clients.forEach(function (_client) {
  1232. var hostNames = _slave.hosts.mapProperty('hostName');
  1233. // The below logic to install clients to existing/New master hosts should not be applied to Add Host wizard.
  1234. // This is with the presumption that Add Host controller does not add any new Master component to the cluster
  1235. if (this.get('content.controllerName') !== 'addHostController') {
  1236. if (clientsToMasterMap[_client.component_name]) {
  1237. clientsToMasterMap[_client.component_name].forEach(function (componentName) {
  1238. masterHosts.filterProperty('component', componentName).forEach(function (_masterHost) {
  1239. hostNames.pushObject(_masterHost.hostName);
  1240. });
  1241. });
  1242. }
  1243. }
  1244. hostNames = hostNames.uniq();
  1245. this.registerHostsToComponent(hostNames, _client.component_name);
  1246. }, this);
  1247. }
  1248. }, this);
  1249. },
  1250. /**
  1251. * This function is specific to addServiceController
  1252. * Newly introduced master components requires some existing client components to be hosted along with them
  1253. */
  1254. createAdditionalClientComponents: function () {
  1255. var masterHosts = this.get('content.masterComponentHosts');
  1256. var clientsToMasterMap = this.getClientsToMasterMap();
  1257. var installedClients = [];
  1258. // Get all the installed Client components
  1259. this.get('content.services').filterProperty('isInstalled').forEach(function (_service) {
  1260. var serviceClients = App.StackServiceComponent.find().filterProperty('serviceName', _service.get('serviceName')).filterProperty('isClient');
  1261. serviceClients.forEach(function (client) {
  1262. installedClients.push(client.get('componentName'));
  1263. }, this);
  1264. }, this);
  1265. // Check if there is a dependency for being co-hosted between existing client and selected new master
  1266. installedClients.forEach(function (_clientName) {
  1267. if (clientsToMasterMap[_clientName]) {
  1268. var hostNames = [];
  1269. clientsToMasterMap[_clientName].forEach(function (componentName) {
  1270. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1271. hostNames.pushObject(_masterHost.hostName);
  1272. }, this);
  1273. }, this);
  1274. hostNames = hostNames.uniq();
  1275. if (hostNames.length > 0) {
  1276. this.get('content.additionalClients').pushObject({hostNames: hostNames, componentName: _clientName});
  1277. // If a dependency for being co-hosted is derived between existing client and selected new master but that
  1278. // dependency is already satisfied in the cluster then disregard the derived dependency
  1279. this.removeClientsFromList(_clientName, hostNames);
  1280. this.registerHostsToComponent(hostNames, _clientName);
  1281. }
  1282. }
  1283. }, this);
  1284. },
  1285. /**
  1286. *
  1287. * @param clientName
  1288. * @param hostList
  1289. */
  1290. removeClientsFromList: function (clientName, hostList) {
  1291. var clientHosts = [];
  1292. var installedHosts = this.get('content.hosts');
  1293. for (var hostName in installedHosts) {
  1294. if (installedHosts[hostName].isInstalled) {
  1295. if (installedHosts[hostName].hostComponents.mapProperty('HostRoles.component_name').contains(clientName)) {
  1296. clientHosts.push(hostName);
  1297. }
  1298. }
  1299. }
  1300. if (clientHosts.length > 0) {
  1301. clientHosts.forEach(function (hostName) {
  1302. if (hostList.contains(hostName)) {
  1303. hostList.splice(hostList.indexOf(hostName), 1);
  1304. }
  1305. }, this);
  1306. }
  1307. },
  1308. /**
  1309. * Register additional components
  1310. * Based on availability of some services
  1311. * @uses registerHostsToComponent
  1312. * @method createAdditionalHostComponents
  1313. */
  1314. createAdditionalHostComponents: function () {
  1315. var masterHosts = this.get('content.masterComponentHosts');
  1316. // add all components with cardinality == ALL of selected services
  1317. var registeredHosts = this.getRegisteredHosts();
  1318. var notInstalledHosts = registeredHosts.filterProperty('isInstalled', false);
  1319. this.get('content.services').filterProperty('isSelected').forEach(function (service) {
  1320. service.get('serviceComponents').filterProperty('isRequiredOnAllHosts').forEach(function (component) {
  1321. if (service.get('isInstalled') && notInstalledHosts.length) {
  1322. this.registerHostsToComponent(notInstalledHosts.mapProperty('hostName'), component.get('componentName'));
  1323. } else if (!service.get('isInstalled') && registeredHosts.length) {
  1324. this.registerHostsToComponent(registeredHosts.mapProperty('hostName'), component.get('componentName'));
  1325. }
  1326. }, this);
  1327. }, this);
  1328. // add MySQL Server if Hive is selected
  1329. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1330. if (hiveService) {
  1331. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1332. if (hiveDb.value == "New MySQL Database") {
  1333. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1334. } else if (hiveDb.value === "New PostgreSQL Database") {
  1335. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'POSTGRESQL_SERVER');
  1336. }
  1337. }
  1338. },
  1339. /**
  1340. * Register component to hosts
  1341. * Queued request
  1342. * @param {String[]} hostNames
  1343. * @param {String} componentName
  1344. * @method registerHostsToComponent
  1345. */
  1346. registerHostsToComponent: function (hostNames, componentName) {
  1347. if (!hostNames.length) return;
  1348. var queryStr = '';
  1349. hostNames.forEach(function (hostName) {
  1350. queryStr += 'Hosts/host_name=' + hostName + '|';
  1351. });
  1352. //slice off last symbol '|'
  1353. queryStr = queryStr.slice(0, -1);
  1354. var data = {
  1355. "RequestInfo": {
  1356. "query": queryStr
  1357. },
  1358. "Body": {
  1359. "host_components": [
  1360. {
  1361. "HostRoles": {
  1362. "component_name": componentName
  1363. }
  1364. }
  1365. ]
  1366. }
  1367. };
  1368. this.addRequestToAjaxQueue({
  1369. name: 'wizard.step8.register_host_to_component',
  1370. data: {
  1371. data: JSON.stringify(data)
  1372. }
  1373. });
  1374. },
  1375. /**
  1376. * Compare generated config object with current configs that were filled
  1377. * on "Customize Services" page.
  1378. *
  1379. * @param {Object} properties - generated by createSiteObj|createCoreSiteObj
  1380. * @param {Array} configs - current configs to compare
  1381. * @return {Boolean}
  1382. * @method isConfigsChanged
  1383. **/
  1384. isConfigsChanged: function (properties, configs) {
  1385. var isChanged = false;
  1386. for (var property in properties) {
  1387. var config = configs.findProperty('name', property);
  1388. // if config not found then it's looks like a new config
  1389. if (!config) {
  1390. isChanged = true;
  1391. } else {
  1392. if (!config.hasInitialValue || config.isNotDefaultValue) {
  1393. isChanged = true;
  1394. }
  1395. }
  1396. }
  1397. return isChanged;
  1398. },
  1399. /**
  1400. * Create config objects for cluster and services
  1401. * @method createConfigurations
  1402. */
  1403. createConfigurations: function () {
  1404. var selectedServices = this.get('selectedServices');
  1405. var coreSiteObject = this.createCoreSiteObj();
  1406. var tag = 'version1';
  1407. var clusterSiteObj = this.createSiteObj('cluster-env', tag);
  1408. if (this.get('content.controllerName') == 'installerController') {
  1409. this.get('serviceConfigTags').pushObject(clusterSiteObj);
  1410. }
  1411. if (this.get('content.controllerName') == 'addServiceController') {
  1412. tag = 'version' + (new Date).getTime();
  1413. coreSiteObject.tag = tag;
  1414. var coreSiteConfigs = this.get('configs').filterProperty('filename', 'core-site.xml');
  1415. if (this.isConfigsChanged(coreSiteObject.properties, coreSiteConfigs)) {
  1416. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1417. }
  1418. }
  1419. selectedServices.forEach(function (service) {
  1420. Object.keys(service.get('configTypes')).forEach(function (type) {
  1421. if (!this.get('serviceConfigTags').someProperty('type', type)) {
  1422. var serviceVersionNotes = Em.I18n.t('dashboard.configHistory.table.notes.default').format(service.get('displayName'));
  1423. if (service.get('serviceName') === 'MAPREDUCE' && (type === 'capacity-scheduler' || type === 'mapred-queue-acls')) {
  1424. return;
  1425. } else if (type === 'core-site') {
  1426. coreSiteObject.service_config_version_note = serviceVersionNotes;
  1427. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1428. } else if (type === 'storm-site') {
  1429. var obj = this.createStormSiteObj(tag);
  1430. obj.service_config_version_note = serviceVersionNotes;
  1431. this.get('serviceConfigTags').pushObject(obj);
  1432. } else {
  1433. var obj = this.createSiteObj(type, tag);
  1434. obj.service_config_version_note = serviceVersionNotes;
  1435. this.get('serviceConfigTags').pushObject(obj);
  1436. }
  1437. }
  1438. }, this);
  1439. }, this);
  1440. this.createNotification();
  1441. },
  1442. /**
  1443. * Send <code>serviceConfigTags</code> to server
  1444. * Queued request
  1445. * One request for each service config tag
  1446. * @param serviceConfigTags
  1447. * @method applyConfigurationsToCluster
  1448. */
  1449. applyConfigurationsToCluster: function (serviceConfigTags) {
  1450. var allServices = this.get('installedServices').concat(this.get('selectedServices'));
  1451. var allConfigData = [];
  1452. allServices.forEach(function (service) {
  1453. var serviceConfigData = [];
  1454. Object.keys(service.get('configTypesRendered')).forEach(function (type) {
  1455. var serviceConfigTag = serviceConfigTags.findProperty('type', type);
  1456. if (serviceConfigTag) {
  1457. serviceConfigData.pushObject(serviceConfigTag);
  1458. }
  1459. }, this);
  1460. if (serviceConfigData.length) {
  1461. allConfigData.pushObject(JSON.stringify({
  1462. Clusters: {
  1463. desired_config: serviceConfigData
  1464. }
  1465. }));
  1466. }
  1467. }, this);
  1468. var clusterConfig = serviceConfigTags.findProperty('type', 'cluster-env');
  1469. if (clusterConfig) {
  1470. allConfigData.pushObject(JSON.stringify({
  1471. Clusters: {
  1472. desired_config: [clusterConfig]
  1473. }
  1474. }));
  1475. }
  1476. this.addRequestToAjaxQueue({
  1477. name: 'common.across.services.configurations',
  1478. data: {
  1479. data: '[' + allConfigData.toString() + ']'
  1480. }
  1481. });
  1482. },
  1483. /**
  1484. * Create and update config groups
  1485. * @method createConfigurationGroups
  1486. */
  1487. createConfigurationGroups: function () {
  1488. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1489. var clusterName = this.get('clusterName');
  1490. var sendData = [];
  1491. var updateData = [];
  1492. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1493. var timeTag = (new Date).getTime();
  1494. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1495. if (groupsToDelete && groupsToDelete.length > 0) {
  1496. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1497. }
  1498. configGroups.forEach(function (configGroup) {
  1499. var groupConfigs = [];
  1500. var groupData = {
  1501. "cluster_name": clusterName,
  1502. "group_name": configGroup.name,
  1503. "tag": configGroup.service.id,
  1504. "description": configGroup.description,
  1505. "hosts": [],
  1506. "desired_configs": []
  1507. };
  1508. configGroup.hosts.forEach(function (hostName) {
  1509. groupData.hosts.push({"host_name": hostName});
  1510. });
  1511. // get properties that was created for non-default config group
  1512. configGroup.properties = configGroup.properties.concat(this.get('customNonDefaultGroupConfigs').filterProperty('group', configGroup.name));
  1513. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1514. configGroup.properties.forEach(function (property) {
  1515. groupConfigs.push(Em.Object.create(property));
  1516. });
  1517. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1518. // check for group from installed service
  1519. if (configGroup.isForInstalledService === true) {
  1520. // if group is a new one, create it
  1521. if (!configGroup.id) {
  1522. sendData.push({"ConfigGroup": groupData});
  1523. } else if (configGroup.isForUpdate){
  1524. // update an existing group
  1525. groupData.id = configGroup.id;
  1526. updateData.push({"ConfigGroup": groupData});
  1527. }
  1528. } else {
  1529. sendData.push({"ConfigGroup": groupData});
  1530. }
  1531. //each group should have unique tag to prevent overriding configs from common sites
  1532. timeTag++;
  1533. }, this);
  1534. if (sendData.length > 0) {
  1535. this.applyConfigurationGroups(sendData);
  1536. }
  1537. if (updateData.length > 0) {
  1538. this.applyInstalledServicesConfigurationGroup(updateData);
  1539. }
  1540. },
  1541. /**
  1542. * Create new config groups request
  1543. * Queued request
  1544. * @param {Object[]} sendData
  1545. * @method applyConfigurationGroups
  1546. */
  1547. applyConfigurationGroups: function (sendData) {
  1548. this.addRequestToAjaxQueue({
  1549. name: 'wizard.step8.apply_configuration_groups',
  1550. data: {
  1551. data: JSON.stringify(sendData)
  1552. }
  1553. });
  1554. },
  1555. /**
  1556. * Update existed config groups
  1557. * Separated request for each group
  1558. * @param {Object[]} updateData
  1559. * @method applyInstalledServicesConfigurationGroup
  1560. */
  1561. applyInstalledServicesConfigurationGroup: function (updateData) {
  1562. updateData.forEach(function (item) {
  1563. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1564. });
  1565. },
  1566. /**
  1567. * Delete selected config groups
  1568. * @param {Object[]} groupsToDelete
  1569. * @method removeInstalledServicesConfigurationGroups
  1570. */
  1571. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1572. groupsToDelete.forEach(function (item) {
  1573. App.config.deleteConfigGroup(Em.Object.create(item));
  1574. });
  1575. },
  1576. /**
  1577. * proxyuser configs which depend on service
  1578. * @type {{serviceName: string, user: string}[]}
  1579. */
  1580. optionalCoreSiteConfigs: [
  1581. {
  1582. serviceName: 'OOZIE',
  1583. user: 'oozie_user'
  1584. },
  1585. {
  1586. serviceName: 'HIVE',
  1587. user: 'hive_user'
  1588. },
  1589. {
  1590. serviceName: 'HIVE',
  1591. user: 'hcat_user'
  1592. },
  1593. {
  1594. serviceName: 'FALCON',
  1595. user: 'falcon_user'
  1596. }
  1597. ],
  1598. /**
  1599. * push proxyuser properties to core-site if they required by dependencies
  1600. * @param coreSiteObj
  1601. * @param installedAndSelectedServices
  1602. * @return {Object}
  1603. */
  1604. resolveProxyuserDependecies: function (coreSiteObj, installedAndSelectedServices) {
  1605. var coreSiteProperties = {};
  1606. var optionalCoreSiteConfigs = this.get('optionalCoreSiteConfigs');
  1607. var proxyuserGroup = this.get('configs').findProperty('name', 'proxyuser_group');
  1608. coreSiteObj.forEach(function (_coreSiteObj) {
  1609. //proxyuser_group property should be added only if proxyuser properties are used
  1610. if (proxyuserGroup && _coreSiteObj.name === proxyuserGroup.name) return;
  1611. // exclude some configs if service wasn't selected
  1612. var addProperty = optionalCoreSiteConfigs.every(function (config) {
  1613. var userValue = this.get('configs').someProperty('name', config.user) ? this.get('configs').findProperty('name', config.user).value : null
  1614. return (installedAndSelectedServices.someProperty('serviceName', config.serviceName) ||
  1615. (_coreSiteObj.name != 'hadoop.proxyuser.' + userValue + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + userValue + '.groups'))
  1616. }, this);
  1617. if (addProperty) {
  1618. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1619. }
  1620. }, this);
  1621. if (!App.isEmptyObject(coreSiteProperties) && proxyuserGroup) {
  1622. coreSiteProperties[proxyuserGroup.name] = proxyuserGroup.value;
  1623. }
  1624. return coreSiteProperties;
  1625. },
  1626. /**
  1627. * Create Core Site object
  1628. * @returns {{type: string, tag: string, properties: {}}}
  1629. * @method createCoreSiteObj
  1630. */
  1631. createCoreSiteObj: function () {
  1632. var installedAndSelectedServices = Em.A([]);
  1633. installedAndSelectedServices.pushObjects(this.get('installedServices'));
  1634. installedAndSelectedServices.pushObjects(this.get('selectedServices'));
  1635. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml'),
  1636. coreSiteProperties = this.resolveProxyuserDependecies(coreSiteObj, installedAndSelectedServices),
  1637. isGLUSTERFSSelected = installedAndSelectedServices.someProperty('serviceName', 'GLUSTERFS');
  1638. coreSiteObj.forEach(function (_coreSiteObj) {
  1639. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1640. coreSiteProperties[_coreSiteObj.name] =
  1641. this.get('configs').someProperty('name', 'fs_glusterfs_default_name') ?
  1642. this.get('configs').findProperty('name', 'fs_glusterfs_default_name').value : null;
  1643. }
  1644. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1645. coreSiteProperties[_coreSiteObj.name] =
  1646. this.get('configs').someProperty('name', 'glusterfs_defaultFS_name') ?
  1647. this.get('configs').findProperty('name', 'glusterfs_defaultFS_name').value : null;
  1648. }
  1649. }, this);
  1650. var attributes = App.router.get('mainServiceInfoConfigsController').getConfigAttributes(coreSiteObj);
  1651. var configObj = {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1652. if (attributes) {
  1653. configObj['properties_attributes'] = attributes;
  1654. }
  1655. return configObj;
  1656. },
  1657. /**
  1658. * Create siteObj for custom service with it own configs
  1659. * @param {string} site
  1660. * @param tag
  1661. * @returns {{type: string, tag: string, properties: {}}}
  1662. * @method createSiteObj
  1663. */
  1664. createSiteObj: function (site, tag) {
  1665. var properties = {};
  1666. var configs = this.get('configs').filterProperty('filename', site + '.xml');
  1667. var attributes = App.router.get('mainServiceInfoConfigsController').getConfigAttributes(configs);
  1668. configs.forEach(function (_configProperty) {
  1669. var heapsizeExceptions = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize', 'jobhistory_heapsize'];
  1670. // do not pass any globals whose name ends with _host or _hosts
  1671. if (_configProperty.isRequiredByAgent !== false) {
  1672. // append "m" to JVM memory options except for heapsizeExtensions
  1673. if (/_heapsize|_newsize|_maxnewsize|_permsize|_maxpermsize$/.test(_configProperty.name) && !heapsizeExceptions.contains(_configProperty.name) && !(_configProperty.value).endsWith("m")) {
  1674. properties[_configProperty.name] = _configProperty.value + "m";
  1675. } else {
  1676. properties[_configProperty.name] = _configProperty.value;
  1677. }
  1678. }
  1679. }, this);
  1680. var configObj = {"type": site, "tag": tag, "properties": properties };
  1681. if (attributes) {
  1682. configObj['properties_attributes'] = attributes;
  1683. }
  1684. return configObj;
  1685. },
  1686. /**
  1687. * Create site obj for Storm
  1688. * Some config-properties should be modified in custom way
  1689. * @param tag
  1690. * @returns {{type: string, tag: string, properties: {}}}
  1691. * @method createStormSiteObj
  1692. */
  1693. createStormSiteObj: function (tag) {
  1694. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1695. var stormProperties = {};
  1696. configs.forEach(function (_configProperty) {
  1697. if (_configProperty.name == "storm.zookeeper.servers") {
  1698. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1699. } else {
  1700. stormProperties[_configProperty.name] = _configProperty.value;
  1701. }
  1702. }, this);
  1703. return {type: 'storm-site', tag: tag, properties: stormProperties};
  1704. },
  1705. /**
  1706. * Create one Alert Notification (if user select this on step7)
  1707. * Only for Install Wizard and stack
  1708. * @method createNotification
  1709. */
  1710. createNotification: function () {
  1711. if (this.get('content.controllerName') !== 'installerController') return;
  1712. var miscConfigs = this.get('configs').filterProperty('serviceName', 'MISC'),
  1713. createNotification = miscConfigs.findProperty('name', 'create_notification').value;
  1714. if (createNotification !== 'yes') return;
  1715. var predefinedNotificationConfigNames = require('data/site_properties').configProperties.filterProperty('filename', 'alert_notification').mapProperty('name'),
  1716. configsForNotification = this.get('configs').filterProperty('filename', 'alert_notification');
  1717. var properties = {},
  1718. names = [
  1719. 'ambari.dispatch.recipients',
  1720. 'mail.smtp.host',
  1721. 'mail.smtp.port',
  1722. 'mail.smtp.from',
  1723. 'mail.smtp.starttls.enable',
  1724. 'mail.smtp.startssl.enable'
  1725. ];
  1726. if (miscConfigs.findProperty('name', 'smtp_use_auth').value == 'true') { // yes, it's not converted to boolean
  1727. names.pushObjects(['ambari.dispatch.credential.username', 'ambari.dispatch.credential.password']);
  1728. }
  1729. names.forEach(function (name) {
  1730. properties[name] = miscConfigs.findProperty('name', name).value;
  1731. });
  1732. properties['ambari.dispatch.recipients'] = properties['ambari.dispatch.recipients'].replace(/\s/g, '').split(',');
  1733. configsForNotification.forEach(function (config) {
  1734. if (predefinedNotificationConfigNames.contains(config.name)) return;
  1735. properties[config.name] = config.value;
  1736. });
  1737. var apiObject = {
  1738. AlertTarget: {
  1739. name: 'Initial Notification',
  1740. description: 'Notification created during cluster installing',
  1741. global: true,
  1742. notification_type: 'EMAIL',
  1743. alert_states: ['OK', 'WARNING', 'CRITICAL', 'UNKNOWN'],
  1744. properties: properties
  1745. }
  1746. };
  1747. this.addRequestToAjaxQueue({
  1748. name: 'alerts.create_alert_notification',
  1749. data: {
  1750. data: apiObject
  1751. }
  1752. });
  1753. }
  1754. });