step8_controller.js 69 KB

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