step8_controller.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712
  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 selectedServices = this.get('selectedServices');
  1287. var coreSiteObject = this.createCoreSiteObj();
  1288. var tag = 'version1';
  1289. if (this.get('content.controllerName') == 'addServiceController') {
  1290. tag = 'version' + (new Date).getTime();
  1291. coreSiteObject.tag = tag;
  1292. var coreSiteConfigs = this.get('configs').filterProperty('filename', 'core-site.xml');
  1293. if (this.isConfigsChanged(coreSiteObject.properties, coreSiteConfigs))
  1294. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1295. }
  1296. selectedServices.forEach(function (service) {
  1297. Object.keys(service.get('configTypes')).forEach(function (type) {
  1298. if (!this.get('serviceConfigTags').someProperty('type', type)) {
  1299. if (!App.supports.capacitySchedulerUi && service.get('serviceName') === 'MAPREDUCE' && (type === 'capacity-scheduler' || type === 'mapred-queue-acls')) {
  1300. return;
  1301. } else if (type === 'core-site') {
  1302. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1303. } else if (type === 'storm-site') {
  1304. this.get('serviceConfigTags').pushObject(this.createStormSiteObj(tag));
  1305. } else if (type === 'zoo.cfg') {
  1306. this.get('serviceConfigTags').pushObject(this.createZooCfgObj(tag));
  1307. } else {
  1308. var isNonXmlFile = type.endsWith('log4j') || type.endsWith('env') || type.endsWith('properties') || type.endsWith('conf');
  1309. this.get('serviceConfigTags').pushObject(this.createSiteObj(type, isNonXmlFile, tag));
  1310. }
  1311. }
  1312. }, this);
  1313. }, this);
  1314. },
  1315. /**
  1316. * Send <code>serviceConfigTags</code> to server
  1317. * Queued request
  1318. * One request for each service config tag
  1319. * @method applyConfigurationsToCluster
  1320. */
  1321. applyConfigurationsToCluster: function () {
  1322. var configData = this.get('serviceConfigTags').map(function (_serviceConfig) {
  1323. return JSON.stringify({
  1324. Clusters: {
  1325. desired_config: {
  1326. type: _serviceConfig.type,
  1327. tag: _serviceConfig.tag,
  1328. properties: _serviceConfig.properties,
  1329. properties_attributes: _serviceConfig.properties_attributes
  1330. }
  1331. }
  1332. });
  1333. }, this).toString();
  1334. this.addRequestToAjaxQueue({
  1335. name: 'wizard.step8.apply_configuration_to_cluster',
  1336. data: {
  1337. data: '[' + configData + ']'
  1338. }
  1339. });
  1340. },
  1341. /**
  1342. * Create and update config groups
  1343. * @method createConfigurationGroups
  1344. */
  1345. createConfigurationGroups: function () {
  1346. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1347. var clusterName = this.get('clusterName');
  1348. var sendData = [];
  1349. var updateData = [];
  1350. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1351. var timeTag = (new Date).getTime();
  1352. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1353. if (groupsToDelete && groupsToDelete.length > 0) {
  1354. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1355. }
  1356. configGroups.forEach(function (configGroup) {
  1357. var groupConfigs = [];
  1358. var groupData = {
  1359. "cluster_name": clusterName,
  1360. "group_name": configGroup.name,
  1361. "tag": configGroup.service.id,
  1362. "description": configGroup.description,
  1363. "hosts": [],
  1364. "desired_configs": []
  1365. };
  1366. configGroup.hosts.forEach(function (hostName) {
  1367. groupData.hosts.push({"host_name": hostName});
  1368. });
  1369. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1370. configGroup.properties.forEach(function (property) {
  1371. groupConfigs.push(Em.Object.create(property));
  1372. });
  1373. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1374. // check for group from installed service
  1375. if (configGroup.isForUpdate === true) {
  1376. // if group is a new one, create it
  1377. if (!configGroup.id) {
  1378. sendData.push({"ConfigGroup": groupData});
  1379. } else {
  1380. // update an existing group
  1381. groupData.id = configGroup.id;
  1382. updateData.push({"ConfigGroup": groupData});
  1383. }
  1384. } else {
  1385. sendData.push({"ConfigGroup": groupData});
  1386. }
  1387. //each group should have unique tag to prevent overriding configs from common sites
  1388. timeTag++;
  1389. }, this);
  1390. if (sendData.length > 0) {
  1391. this.applyConfigurationGroups(sendData);
  1392. }
  1393. if (updateData.length > 0) {
  1394. this.applyInstalledServicesConfigurationGroup(updateData);
  1395. }
  1396. },
  1397. /**
  1398. * Create new config groups request
  1399. * Queued request
  1400. * @param {Object[]} sendData
  1401. * @method applyConfigurationGroups
  1402. */
  1403. applyConfigurationGroups: function (sendData) {
  1404. this.addRequestToAjaxQueue({
  1405. name: 'wizard.step8.apply_configuration_groups',
  1406. data: {
  1407. data: JSON.stringify(sendData)
  1408. }
  1409. });
  1410. },
  1411. /**
  1412. * Update existed config groups
  1413. * Separated request for each group
  1414. * @param {Object[]} updateData
  1415. * @method applyInstalledServicesConfigurationGroup
  1416. */
  1417. applyInstalledServicesConfigurationGroup: function (updateData) {
  1418. updateData.forEach(function (item) {
  1419. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1420. });
  1421. },
  1422. /**
  1423. * Delete selected config groups
  1424. * @param {Object[]} groupsToDelete
  1425. * @method removeInstalledServicesConfigurationGroups
  1426. */
  1427. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1428. groupsToDelete.forEach(function (item) {
  1429. App.config.deleteConfigGroup(Em.Object.create(item));
  1430. });
  1431. },
  1432. /**
  1433. * Create Core Site object
  1434. * @returns {{type: string, tag: string, properties: {}}}
  1435. * @method createCoreSiteObj
  1436. */
  1437. createCoreSiteObj: function () {
  1438. var installedAndSelectedServices = Em.A([]);
  1439. installedAndSelectedServices.pushObjects(this.get('installedServices'));
  1440. installedAndSelectedServices.pushObjects(this.get('selectedServices'));
  1441. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml'),
  1442. coreSiteProperties = {},
  1443. // some configs needs to be skipped if services are not selected
  1444. isOozieSelected = installedAndSelectedServices.someProperty('serviceName', 'OOZIE'),
  1445. oozieUser = this.get('configs').someProperty('name', 'oozie_user') ? this.get('configs').findProperty('name', 'oozie_user').value : null,
  1446. isHiveSelected = installedAndSelectedServices.someProperty('serviceName', 'HIVE'),
  1447. hiveUser = this.get('configs').someProperty('name', 'hive_user') ? this.get('configs').findProperty('name', 'hive_user').value : null,
  1448. isHcatSelected = installedAndSelectedServices.someProperty('serviceName', 'WEBHCAT'),
  1449. hcatUser = this.get('configs').someProperty('name', 'hcat_user') ? this.get('configs').findProperty('name', 'hcat_user').value : null,
  1450. isGLUSTERFSSelected = installedAndSelectedServices.someProperty('serviceName', 'GLUSTERFS');
  1451. // screen out the GLUSTERFS-specific core-site.xml entries when they are not needed
  1452. if (!isGLUSTERFSSelected) {
  1453. coreSiteObj = coreSiteObj.filter(function (_config) {
  1454. return !_config.name.contains("fs.glusterfs");
  1455. });
  1456. }
  1457. coreSiteObj.forEach(function (_coreSiteObj) {
  1458. // exclude some configs if service wasn't selected
  1459. if (
  1460. (isOozieSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.groups')) &&
  1461. (isHiveSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.groups')) &&
  1462. (isHcatSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.groups'))) {
  1463. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1464. }
  1465. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1466. coreSiteProperties[_coreSiteObj.name] =
  1467. this.get('configs').someProperty('name', 'fs_glusterfs_default_name') ?
  1468. App.config.escapeXMLCharacters(this.get('configs').findProperty('name', 'fs_glusterfs_default_name').value) : null;
  1469. }
  1470. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1471. coreSiteProperties[_coreSiteObj.name] =
  1472. this.get('configs').someProperty('name', 'glusterfs_defaultFS_name') ?
  1473. App.config.escapeXMLCharacters(this.get('configs').findProperty('name', 'glusterfs_defaultFS_name').value) : null;
  1474. }
  1475. }, this);
  1476. var attributes = App.router.get('mainServiceInfoConfigsController').getConfigAttributes(coreSiteObj);
  1477. var configObj = {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1478. if (attributes) {
  1479. configObj['properties_attributes'] = attributes;
  1480. }
  1481. return configObj;
  1482. },
  1483. /**
  1484. * Create siteObj for custom service with it own configs
  1485. * @param {string} site
  1486. * @param {bool} isNonXmlFile
  1487. * @param tag
  1488. * @returns {{type: string, tag: string, properties: {}}}
  1489. * @method createSiteObj
  1490. */
  1491. createSiteObj: function (site, isNonXmlFile, tag) {
  1492. var properties = {};
  1493. var configs = this.get('configs').filterProperty('filename', site + '.xml');
  1494. var attributes = App.router.get('mainServiceInfoConfigsController').getConfigAttributes(configs);
  1495. configs.forEach(function (_configProperty) {
  1496. if (isNonXmlFile) {
  1497. var heapsizeExceptions = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize', 'jobhistory_heapsize'];
  1498. // do not pass any globals whose name ends with _host or _hosts
  1499. if (_configProperty.isRequiredByAgent !== false) {
  1500. // append "m" to JVM memory options except for heapsizeExtensions
  1501. if (/_heapsize|_newsize|_maxnewsize$/.test(_configProperty.name) && !heapsizeExceptions.contains(_configProperty.name)) {
  1502. properties[_configProperty.name] = _configProperty.value + "m";
  1503. } else {
  1504. properties[_configProperty.name] = _configProperty.value;
  1505. }
  1506. }
  1507. } else {
  1508. properties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1509. }
  1510. }, this);
  1511. var configObj = {"type": site, "tag": tag, "properties": properties };
  1512. if (attributes) {
  1513. configObj['properties_attributes'] = attributes;
  1514. }
  1515. return configObj;
  1516. },
  1517. /**
  1518. * Create ZooKeeper Cfg Object
  1519. * @param tag
  1520. * @returns {{type: string, tag: string, properties: {}}}
  1521. * @method createZooCfgObj
  1522. */
  1523. createZooCfgObj: function (tag) {
  1524. var configs = this.get('configs').filterProperty('filename', 'zoo.cfg');
  1525. var csProperties = {};
  1526. configs.forEach(function (_configProperty) {
  1527. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1528. }, this);
  1529. return {type: 'zoo.cfg', tag: tag, properties: csProperties};
  1530. },
  1531. /**
  1532. * Create site obj for Storm
  1533. * Some config-properties should be modified in custom way
  1534. * @param tag
  1535. * @returns {{type: string, tag: string, properties: {}}}
  1536. * @method createStormSiteObj
  1537. */
  1538. createStormSiteObj: function (tag) {
  1539. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1540. var stormProperties = {};
  1541. var specialProperties = ["storm.zookeeper.servers", "nimbus.childopts", "supervisor.childopts", "worker.childopts"];
  1542. configs.forEach(function (_configProperty) {
  1543. if (specialProperties.contains(_configProperty.name)) {
  1544. if (_configProperty.name == "storm.zookeeper.servers") {
  1545. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1546. } else {
  1547. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "");
  1548. }
  1549. } else {
  1550. stormProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1551. }
  1552. }, this);
  1553. return {type: 'storm-site', tag: tag, properties: stormProperties};
  1554. },
  1555. /**
  1556. * Navigate to next step after all requests are sent
  1557. * @method ajaxQueueFinished
  1558. */
  1559. ajaxQueueFinished: function () {
  1560. console.log('everything is loaded');
  1561. App.router.send('next');
  1562. },
  1563. /**
  1564. * We need to do a lot of ajax calls async in special order. To do this,
  1565. * generate array of ajax objects and then send requests step by step. All
  1566. * ajax objects are stored in <code>ajaxRequestsQueue</code>
  1567. *
  1568. * @param {Object} params object with ajax-request parameters like url, type, data etc
  1569. * @method addRequestToAjaxQueue
  1570. */
  1571. addRequestToAjaxQueue: function (params) {
  1572. if (App.get('testMode')) return;
  1573. params = jQuery.extend({
  1574. sender: this,
  1575. error: 'ajaxQueueRequestErrorCallback'
  1576. }, params);
  1577. params.data['cluster'] = this.get('clusterName');
  1578. this.get('ajaxRequestsQueue').addRequest(params);
  1579. },
  1580. /**
  1581. * Error callback for each queued ajax-request
  1582. * @param {object} xhr
  1583. * @param {string} status
  1584. * @param {string} error
  1585. * @method ajaxQueueRequestErrorCallback
  1586. */
  1587. ajaxQueueRequestErrorCallback: function (xhr, status, error) {
  1588. var responseText = JSON.parse(xhr.responseText);
  1589. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1590. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1591. this.set('hasErrorOccurred', true);
  1592. // an error will break the ajax call chain and allow submission again
  1593. this.set('isSubmitDisabled', false);
  1594. this.set('isBackBtnDisabled', false);
  1595. App.router.get(this.get('content.controllerName')).setStepsEnable();
  1596. }
  1597. });