step8_controller.js 69 KB

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