step8_controller.js 65 KB

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