step8_controller.js 70 KB

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