step8_controller.js 60 KB

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