step8_controller.js 62 KB

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