step8_controller.js 62 KB

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