step8_controller.js 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  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_host', '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(Em.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. * @return {$.ajax|null}
  539. * @method loadRepoInfo
  540. */
  541. loadRepoInfo: function () {
  542. var nameVersionCombo = App.get('currentStackVersion').split('-');
  543. return App.ajax.send({
  544. name: 'cluster.load_repositories',
  545. sender: this,
  546. data: {
  547. stackName: nameVersionCombo[0],
  548. stackVersion: nameVersionCombo[1]
  549. },
  550. success: 'loadRepoInfoSuccessCallback',
  551. error: 'loadRepoInfoErrorCallback'
  552. });
  553. },
  554. /**
  555. *
  556. * @param {object} data
  557. * @method loadRepoInfoSuccessCallback
  558. */
  559. loadRepoInfoSuccessCallback: function (data) {
  560. var allRepos = [];
  561. var supportedOs = ['redhat5', 'redhat6', 'sles11'];
  562. data.items.forEach(function (item) {
  563. var os = item.repositories[0].Repositories;
  564. if (supportedOs.contains(os.os_type)) {
  565. allRepos.push(Em.Object.create({
  566. base_url: os.base_url,
  567. os_type: Em.I18n.t("installer.step8.repoInfo.osType." + os.os_type)
  568. }));
  569. }
  570. }, this);
  571. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  572. this.get('clusterInfo').set('repoInfo', allRepos);
  573. },
  574. /**
  575. *
  576. * @param {object} request
  577. * @method loadRepoInfoErrorCallback
  578. */
  579. loadRepoInfoErrorCallback: function (request) {
  580. console.log('Error message is: ' + request.responseText);
  581. var allRepos = [];
  582. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  583. this.get('clusterInfo').set('repoInfo', allRepos);
  584. },
  585. /**
  586. * Load all info about services to <code>services</code> variable
  587. * @method loadServices
  588. */
  589. loadServices: function () {
  590. var reviewService = this.rawContent.findProperty('config_name', 'services');
  591. this.get('selectedServices').forEach(function (_service) {
  592. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  593. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  594. if (serviceObj) {
  595. serviceObj.get('service_components').forEach(function (_component) {
  596. this.assignComponentHosts(_component);
  597. }, this);
  598. this.get('services').pushObject(serviceObj);
  599. }
  600. }, this);
  601. },
  602. /**
  603. *
  604. * @param {Em.Object} component
  605. * @method assignComponentHosts
  606. */
  607. assignComponentHosts: function (component) {
  608. var componentValue;
  609. if (component.get('customHandler')) {
  610. this[component.get('customHandler')].call(this, component);
  611. }
  612. else {
  613. if (component.get('isMaster')) {
  614. componentValue = this.get('content.masterComponentHosts')
  615. .findProperty('component', component.component_name).hostName;
  616. }
  617. else {
  618. var hostsLength = this.get('content.slaveComponentHosts')
  619. .findProperty('componentName', component.component_name)
  620. .hosts.length;
  621. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  622. }
  623. component.set('component_value', componentValue);
  624. }
  625. },
  626. /**
  627. * Set dispalyed Hive DB value based on DB type
  628. * @param {Ember.Object} dbComponent
  629. * @method loadHiveDbValue
  630. */
  631. loadHiveDbValue: function (dbComponent) {
  632. var db,
  633. serviceConfigPreoprties = this.get('wizardController').getDBProperty('serviceConfigProperties'),
  634. hiveDb = serviceConfigPreoprties .findProperty('name', 'hive_database');
  635. if (hiveDb.value === 'New MySQL Database') {
  636. dbComponent.set('component_value', 'MySQL (New Database)');
  637. }
  638. else {
  639. if (hiveDb.value === 'Existing MySQL Database') {
  640. db = serviceConfigPreoprties .findProperty('name', 'hive_existing_mysql_database');
  641. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  642. }
  643. else {
  644. if (hiveDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  645. db = serviceConfigPreoprties .findProperty('name', 'hive_existing_postgresql_database');
  646. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  647. }
  648. else { // existing oracle database
  649. db = serviceConfigPreoprties .findProperty('name', 'hive_existing_oracle_database');
  650. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  651. }
  652. }
  653. }
  654. },
  655. /**
  656. * Set displayed HBase master value
  657. * @param {Object} hbaseMaster
  658. * @method loadHbaseMasterValue
  659. */
  660. loadHbaseMasterValue: function (hbaseMaster) {
  661. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  662. if (hbaseHostName.length == 1) {
  663. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  664. } else {
  665. hbaseMaster.set('component_value', hbaseHostName[0].hostName + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  666. }
  667. },
  668. /**
  669. * Set displayed ZooKeeper Server value
  670. * @param {Object} serverComponent
  671. * @method loadZkServerValue
  672. */
  673. loadZkServerValue: function (serverComponent) {
  674. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  675. var hostSuffix;
  676. if (zkHostNames === 1) {
  677. hostSuffix = Em.I18n.t('installer.step8.host');
  678. } else {
  679. hostSuffix = Em.I18n.t('installer.step8.hosts');
  680. }
  681. serverComponent.set('component_value', zkHostNames + hostSuffix);
  682. },
  683. /**
  684. * Set displayed Oozie DB value based on DB type
  685. * @param {Object} dbComponent
  686. * @method loadOozieDbValue
  687. */
  688. loadOozieDbValue: function (dbComponent) {
  689. var db, oozieDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_database');
  690. if (oozieDb.value === 'New Derby Database') {
  691. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_derby_database');
  692. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  693. }
  694. else {
  695. if (oozieDb.value === 'Existing MySQL Database') {
  696. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mysql_database');
  697. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  698. }
  699. else {
  700. if (oozieDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  701. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_postgresql_database');
  702. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  703. }
  704. else { // existing oracle database
  705. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_oracle_database');
  706. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  707. }
  708. }
  709. }
  710. },
  711. /**
  712. * Set displayed Nagion Admin value
  713. * @param {Object} nagiosAdmin
  714. * @method loadNagiosAdminValue
  715. */
  716. loadNagiosAdminValue: function (nagiosAdmin) {
  717. var config = this.get('content.serviceConfigProperties');
  718. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  719. var adminEmail = config.findProperty('name', 'nagios_contact');
  720. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  721. },
  722. /**
  723. * Onclick handler for <code>next</code> button
  724. * @method submit
  725. * @return {App.ModalPopup|null}
  726. */
  727. submit: function () {
  728. if (this.get('isSubmitDisabled')) return null;
  729. if ((this.get('content.controllerName') == 'addHostController') && this.get('securityEnabled')) {
  730. var self = this;
  731. return App.showConfirmationPopup(function () {
  732. self.submitProceed();
  733. }, Em.I18n.t('installer.step8.securityConfirmationPopupBody'));
  734. }
  735. else {
  736. return this.submitProceed();
  737. }
  738. },
  739. /**
  740. * Update configurations for installed services.
  741. *
  742. * @param {Array} configsToUpdate - configs need to update
  743. * @method updateConfigurations
  744. */
  745. updateConfigurations: function (configsToUpdate) {
  746. var configurationController = App.router.get('mainServiceInfoConfigsController');
  747. var serviceNames = configsToUpdate.mapProperty('serviceName').uniq();
  748. serviceNames.forEach(function (serviceName) {
  749. var configs = configsToUpdate.filterProperty('serviceName', serviceName);
  750. configurationController.setNewTagNames(configs);
  751. var tagName = configs.objectAt(0).newTagName;
  752. var siteConfigs = configs.filterProperty('id', 'site property');
  753. siteConfigs.mapProperty('filename').uniq().forEach(function (siteName) {
  754. var formattedConfigs = configurationController.createSiteObj(siteName.replace(".xml", ""), tagName, configs.filterProperty('filename', siteName));
  755. configurationController.doPUTClusterConfigurationSite(formattedConfigs);
  756. });
  757. });
  758. },
  759. /**
  760. * Prepare <code>ajaxQueue</code> and start to execute it
  761. * @method submitProceed
  762. */
  763. submitProceed: function () {
  764. this.set('isSubmitDisabled', true);
  765. this.set('isBackBtnDisabled', true);
  766. if (this.get('content.controllerName') == 'addHostController') {
  767. App.router.get('addHostController').setLowerStepsDisable(4);
  768. }
  769. // checkpoint the cluster status on the server so that the user can resume from where they left off
  770. switch (this.get('content.controllerName')) {
  771. case 'installerController':
  772. App.clusterStatus.setClusterStatus({
  773. clusterName: this.get('clusterName'),
  774. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  775. wizardControllerName: this.get('content.controllerName'),
  776. localdb: App.db.data
  777. });
  778. break;
  779. case 'addHostController':
  780. App.clusterStatus.setClusterStatus({
  781. clusterName: this.get('clusterName'),
  782. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  783. wizardControllerName: this.get('content.controllerName'),
  784. localdb: App.db.data
  785. });
  786. break;
  787. case 'addServiceController':
  788. App.clusterStatus.setClusterStatus({
  789. clusterName: this.get('clusterName'),
  790. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  791. wizardControllerName: this.get('content.controllerName'),
  792. localdb: App.db.data
  793. });
  794. break;
  795. default:
  796. break;
  797. }
  798. // delete any existing clusters to start from a clean slate
  799. // before creating a new cluster in install wizard
  800. // TODO: modify for multi-cluster support
  801. if (this.get('content.controllerName') == 'installerController' && (!App.testMode)) {
  802. this.deleteClusters(this.getExistingClusterNames());
  803. }
  804. if (this.get('wizardController').getDBProperty('configsToUpdate')) {
  805. this.updateConfigurations(this.get('wizardController').getDBProperty('configsToUpdate'));
  806. }
  807. this.setLocalRepositories();
  808. this.createCluster();
  809. this.createSelectedServices();
  810. if (this.get('content.controllerName') !== 'addHostController') {
  811. this.createConfigurations();
  812. this.applyConfigurationsToCluster();
  813. }
  814. this.createComponents();
  815. this.registerHostsToCluster();
  816. if (App.supports.hostOverridesInstaller) {
  817. this.createConfigurationGroups();
  818. }
  819. this.createMasterHostComponents();
  820. this.createSlaveAndClientsHostComponents();
  821. this.createAdditionalHostComponents();
  822. this.set('ajaxQueueLength', this.get('ajaxRequestsQueue.queue.length'));
  823. this.get('ajaxRequestsQueue').start();
  824. },
  825. /**
  826. * Get list of existing cluster names
  827. * @returns {string[]}
  828. * returns an array of existing cluster names.
  829. * returns an empty array if there are no existing clusters.
  830. * @method getExistingClusterNames
  831. */
  832. getExistingClusterNames: function () {
  833. App.ajax.send({
  834. name: 'wizard.step8.existing_cluster_names',
  835. sender: this,
  836. success: 'getExistingClusterNamesSuccessCallBack',
  837. error: 'getExistingClusterNamesErrorCallback'
  838. });
  839. return this.get('clusterNames');
  840. },
  841. /**
  842. * Save received list to <code>clusterNames</code>
  843. * @param {Object} data
  844. * @method getExistingClusterNamesSuccessCallBack
  845. */
  846. getExistingClusterNamesSuccessCallBack: function (data) {
  847. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  848. console.log("Got existing cluster names: " + clusterNames);
  849. this.set('clusterNames', clusterNames);
  850. },
  851. /**
  852. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  853. * @method getExistingClusterNamesErrorCallback
  854. */
  855. getExistingClusterNamesErrorCallback: function () {
  856. console.log("Failed to get existing cluster names");
  857. this.set('clusterNames', []);
  858. },
  859. /**
  860. * Delete cluster by name
  861. * One request for one cluster!
  862. * @param {string[]} clusterNames
  863. * @method deleteClusters
  864. */
  865. deleteClusters: function (clusterNames) {
  866. clusterNames.forEach(function (clusterName) {
  867. App.ajax.send({
  868. name: 'wizard.step8.delete_cluster',
  869. sender: this,
  870. data: {
  871. name: clusterName
  872. }
  873. });
  874. }, this);
  875. },
  876. /**
  877. * Updates local repositories for the Ambari server.
  878. * @method setLocalRepositories
  879. */
  880. setLocalRepositories: function () {
  881. if (this.get('content.controllerName') !== 'installerController' || !App.supports.localRepositories) return;
  882. var self = this;
  883. var stack = this.get('content.stacks').findProperty('isSelected', true);
  884. stack.operatingSystems.forEach(function (os) {
  885. if (os.baseUrl !== os.originalBaseUrl) {
  886. console.log("Updating local repository URL from " + os.originalBaseUrl + " -> " + os.baseUrl + ". ", os);
  887. self.addRequestToAjaxQueue({
  888. name: 'wizard.step8.set_local_repos',
  889. data: {
  890. osType: os.osType,
  891. name: stack.name,
  892. stack2VersionURL: App.get('stack2VersionURL'),
  893. data: JSON.stringify({
  894. "Repositories": {
  895. "base_url": os.baseUrl,
  896. "verify_base_url": false
  897. }
  898. })
  899. }
  900. });
  901. }
  902. });
  903. },
  904. /**
  905. * *******************************************************************
  906. * The following create* functions are called upon submitting Step 8.
  907. * *******************************************************************
  908. */
  909. /**
  910. * Create cluster using selected stack version
  911. * Queued request
  912. * @method createCluster
  913. */
  914. createCluster: function () {
  915. if (this.get('content.controllerName') !== 'installerController') return;
  916. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  917. this.addRequestToAjaxQueue({
  918. name: 'wizard.step8.create_cluster',
  919. data: {
  920. data: JSON.stringify({ "Clusters": {"version": stackVersion }})
  921. }
  922. });
  923. },
  924. /**
  925. * Create selected to install services
  926. * Queued request
  927. * Skipped if no services where selected!
  928. * @method createSelectedServices
  929. */
  930. createSelectedServices: function () {
  931. var data = this.createSelectedServicesData();
  932. if (!data.length) return;
  933. this.addRequestToAjaxQueue({
  934. name: 'wizard.step8.create_selected_services',
  935. data: {
  936. data: JSON.stringify(data)
  937. }
  938. });
  939. },
  940. /**
  941. * Format data for <code>createSelectedServices</code> request
  942. * @returns {Object[]}
  943. * @method createSelectedServicesData
  944. */
  945. createSelectedServicesData: function () {
  946. return this.get('selectedServices').map(function (_service) {
  947. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  948. });
  949. },
  950. /**
  951. * Create components for selected services
  952. * Queued requests
  953. * One request for each service!
  954. * @method createComponents
  955. */
  956. createComponents: function () {
  957. var serviceComponents = App.StackServiceComponent.find();
  958. this.get('selectedServices').forEach(function (_service) {
  959. var serviceName = _service.get('serviceName');
  960. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  961. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  962. });
  963. // Service must be specified in terms of a query for creating multiple components at the same time.
  964. // See AMBARI-1018.
  965. this.addRequestToAjaxQueue({
  966. name: 'wizard.step8.create_components',
  967. data: {
  968. data: JSON.stringify({"components": componentsData}),
  969. serviceName: serviceName
  970. }
  971. });
  972. }, this);
  973. if (this.get('content.controllerName') == 'addServiceController' && !App.testMode) {
  974. // Add service-components which show up in newer versions but did not
  975. // exist in older ones.
  976. var self = this;
  977. var newServiceComponents = {};
  978. if (App.get('isHadoop21Stack')) {
  979. if (App.YARNService.find().objectAt(0)) {
  980. newServiceComponents['APP_TIMELINE_SERVER'] = 'YARN';
  981. }
  982. }
  983. for (var componentName in newServiceComponents) {
  984. if (newServiceComponents.hasOwnProperty(componentName)) {
  985. var serviceName = newServiceComponents[componentName];
  986. // Create only if it doesnt exist
  987. App.ajax.send({
  988. name: 'service.service_component',
  989. sender: self,
  990. data: {
  991. serviceName: serviceName,
  992. componentName: componentName,
  993. async: false
  994. },
  995. error: 'newServiceComponentErrorCallback'
  996. });
  997. }
  998. }
  999. }
  1000. },
  1001. /**
  1002. * Error callback for new service component request
  1003. * So, if component doesn't exist we should create it
  1004. * @param {object} request
  1005. * @param {object} ajaxOptions
  1006. * @param {string} error
  1007. * @param {object} opt
  1008. * @param {object} params
  1009. * @method newServiceComponentErrorCallback
  1010. */
  1011. newServiceComponentErrorCallback: function (request, ajaxOptions, error, opt, params) {
  1012. this.addRequestToAjaxQueue({
  1013. name: 'wizard.step8.create_components',
  1014. data: {
  1015. serviceName: params.serviceName,
  1016. data: JSON.stringify({
  1017. "components": [
  1018. {
  1019. "ServiceComponentInfo": {
  1020. "component_name": params.componentName
  1021. }
  1022. }
  1023. ]
  1024. })
  1025. }
  1026. });
  1027. },
  1028. /**
  1029. * Register hosts
  1030. * Queued request
  1031. * @method registerHostsToCluster
  1032. */
  1033. registerHostsToCluster: function () {
  1034. var data = this.createRegisterHostData();
  1035. if (!data.length) return;
  1036. this.addRequestToAjaxQueue({
  1037. name: 'wizard.step8.register_host_to_cluster',
  1038. data: {
  1039. data: JSON.stringify(data)
  1040. }
  1041. });
  1042. },
  1043. /**
  1044. * Format request-data for <code>registerHostsToCluster</code>
  1045. * @returns {Object}
  1046. * @method createRegisterHostData
  1047. */
  1048. createRegisterHostData: function () {
  1049. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  1050. return {"Hosts": { "host_name": host.hostName}};
  1051. });
  1052. },
  1053. /**
  1054. * Register master components
  1055. * @uses registerHostsToComponent
  1056. * @method createMasterHostComponents
  1057. */
  1058. createMasterHostComponents: function () {
  1059. var masterHosts = this.get('content.masterComponentHosts');
  1060. masterHosts.mapProperty('component').uniq().forEach(function (component) {
  1061. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1062. this.registerHostsToComponent(hostNames, component);
  1063. }, this);
  1064. },
  1065. /**
  1066. * Register slave components and clients
  1067. * @uses registerHostsToComponent
  1068. * @method createSlaveAndClientsHostComponents
  1069. */
  1070. createSlaveAndClientsHostComponents: function () {
  1071. var masterHosts = this.get('content.masterComponentHosts');
  1072. var slaveHosts = this.get('content.slaveComponentHosts');
  1073. var clients = this.get('content.clients');
  1074. /**
  1075. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  1076. * @type {Object}
  1077. * Format:
  1078. * <code>
  1079. * {
  1080. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  1081. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  1082. * ...
  1083. * }
  1084. * </code>
  1085. */
  1086. var clientsToMasterMap = {
  1087. HDFS_CLIENT: Em.A(['HBASE_MASTER', 'HBASE_REGIONSERVER', 'WEBHCAT_SERVER', 'HISTORYSERVER', 'OOZIE_SERVER']),
  1088. MAPREDUCE_CLIENT: Em.A(['HIVE_SERVER', 'OOZIE_SERVER', 'NAGIOS_SERVER', 'WEBHCAT_SERVER']),
  1089. OOZIE_CLIENT: Em.A(['NAGIOS_SERVER']),
  1090. ZOOKEEPER_CLIENT: Em.A(['WEBHCAT_SERVER']),
  1091. HIVE_CLIENT: Em.A(['WEBHCAT_SERVER', 'HIVE_SERVER']),
  1092. HCAT: Em.A(['NAGIOS_SERVER']),
  1093. YARN_CLIENT: Em.A(['NAGIOS_SERVER', 'HIVE_SERVER', 'OOZIE_SERVER', 'WEBHCAT_SERVER']),
  1094. TEZ_CLIENT: Em.A(['NAGIOS_SERVER', 'HIVE_SERVER'])
  1095. };
  1096. slaveHosts.forEach(function (_slave) {
  1097. if (_slave.componentName !== 'CLIENT') {
  1098. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1099. this.registerHostsToComponent(hostNames, _slave.componentName);
  1100. }
  1101. else {
  1102. clients.forEach(function (_client) {
  1103. var hostNames = _slave.hosts.mapProperty('hostName');
  1104. if (clientsToMasterMap[_client.component_name]) {
  1105. clientsToMasterMap[_client.component_name].forEach(function (componentName) {
  1106. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1107. hostNames.pushObject(_masterHost.hostName);
  1108. });
  1109. });
  1110. }
  1111. hostNames = hostNames.uniq();
  1112. if (_client.isInstalled) {
  1113. //check whether clients are already installed on selected master hosts!!!
  1114. _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName').forEach(function (host) {
  1115. if (hostNames.contains(host)) {
  1116. hostNames.splice(hostNames.indexOf(host), 1);
  1117. }
  1118. }, this);
  1119. }
  1120. this.registerHostsToComponent(hostNames, _client.component_name);
  1121. }, this);
  1122. }
  1123. }, this);
  1124. },
  1125. /**
  1126. * Register additional components
  1127. * Based on availability of some services
  1128. * @uses registerHostsToComponent
  1129. * @method createAdditionalHostComponents
  1130. */
  1131. createAdditionalHostComponents: function () {
  1132. var masterHosts = this.get('content.masterComponentHosts');
  1133. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  1134. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  1135. if (gangliaService) {
  1136. var hosts = this.getRegisteredHosts();
  1137. if (gangliaService.get('isInstalled')) {
  1138. hosts = hosts.filterProperty('isInstalled', false);
  1139. }
  1140. if (hosts.length) {
  1141. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  1142. }
  1143. }
  1144. // add MySQL Server if Hive is selected
  1145. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1146. if (hiveService) {
  1147. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1148. if (hiveDb.value == "New MySQL Database") {
  1149. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1150. }
  1151. }
  1152. },
  1153. /**
  1154. * Register component to hosts
  1155. * Queued request
  1156. * @param {String[]} hostNames
  1157. * @param {String} componentName
  1158. * @method registerHostsToComponent
  1159. */
  1160. registerHostsToComponent: function (hostNames, componentName) {
  1161. if (!hostNames.length) return;
  1162. var queryStr = '';
  1163. hostNames.forEach(function (hostName) {
  1164. queryStr += 'Hosts/host_name=' + hostName + '|';
  1165. });
  1166. //slice off last symbol '|'
  1167. queryStr = queryStr.slice(0, -1);
  1168. var data = {
  1169. "RequestInfo": {
  1170. "query": queryStr
  1171. },
  1172. "Body": {
  1173. "host_components": [
  1174. {
  1175. "HostRoles": {
  1176. "component_name": componentName
  1177. }
  1178. }
  1179. ]
  1180. }
  1181. };
  1182. this.addRequestToAjaxQueue({
  1183. name: 'wizard.step8.register_host_to_component',
  1184. data: {
  1185. data: JSON.stringify(data)
  1186. }
  1187. });
  1188. },
  1189. /**
  1190. * Create config objects for cluster and services
  1191. * @method createConfigurations
  1192. */
  1193. createConfigurations: function () {
  1194. var self = this;
  1195. var selectedServices = this.get('selectedServices');
  1196. var coreSiteObject = this.createCoreSiteObj();
  1197. if (this.get('content.controllerName') == 'installerController') {
  1198. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1199. this.get('serviceConfigTags').pushObject(this.createSiteObj('hdfs-site', false));
  1200. this.get('serviceConfigTags').pushObject(this.createLog4jObj('hdfs'));
  1201. }
  1202. var globalSiteObj = this.createGlobalSiteObj();
  1203. if (this.get('content.controllerName') == 'addServiceController') {
  1204. globalSiteObj.tag = 'version' + (new Date).getTime();
  1205. coreSiteObject.tag = 'version' + (new Date).getTime();
  1206. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1207. }
  1208. this.get('serviceConfigTags').pushObject(globalSiteObj);
  1209. var objMap = {
  1210. MAPREDUCE: {site: [
  1211. {filename: 'mapred-site', isXmlFile: true}
  1212. ], log4j: ['mapreduce']},
  1213. MAPREDUCE2: {site: [
  1214. {filename: 'mapred-site', isXmlFile: true}
  1215. ], log4j: ['mapreduce2']},
  1216. YARN: {site: [
  1217. {filename: 'yarn-site', isXmlFile: true},
  1218. {filename: 'capacity-scheduler', isXmlFile: true}
  1219. ], log4j: ['yarn']},
  1220. HBASE: {site: [
  1221. {filename: 'hbase-site', isXmlFile: true}
  1222. ], log4j: ['hbase']},
  1223. OOZIE: {site: [
  1224. {filename: 'oozie-site', isXmlFile: true}
  1225. ], log4j: ['oozie']},
  1226. HIVE: {site: [
  1227. {filename: 'hive-site', isXmlFile: true}
  1228. ], log4j: ['hive', 'hive-exec']},
  1229. WEBHCAT: {site: [
  1230. {filename: 'webhcat-site', isXmlFile: true}
  1231. ], log4j: []},
  1232. HUE: {site: [
  1233. {filename: 'hue-site', isXmlFile: true}
  1234. ], log4j: []},
  1235. PIG: {site: [], log4j: ['pig']},
  1236. FALCON: {site: [
  1237. {filename: 'falcon-startup.properties', isXmlFile: false},
  1238. {filename: 'falcon-runtime.properties', isXmlFile: false}
  1239. ], log4j: []},
  1240. TEZ: {site: [
  1241. {filename: 'tez-site', isXmlFile: true}
  1242. ], log4j: []},
  1243. ZOOKEEPER: {site: [], log4j: ['zookeeper']},
  1244. FLUME: {site: [
  1245. {filename: 'flume-conf', isXmlFile: false}
  1246. ], log4j: []}
  1247. };
  1248. if (App.supports.capacitySchedulerUi) {
  1249. objMap['MAPREDUCE'].site.pushObjects([
  1250. {filename: 'capacity-scheduler', isXmlFile: true},
  1251. {filename: 'mapred-queue-acls', isXmlFile: true}
  1252. ]);
  1253. }
  1254. for (var serviceName in objMap) {
  1255. if (objMap.hasOwnProperty(serviceName)) {
  1256. if (selectedServices.someProperty('serviceName', serviceName)) {
  1257. objMap[serviceName].site.forEach(function (site) {
  1258. self.get('serviceConfigTags').pushObject(self.createSiteObj(site.filename, !site.isXmlFile));
  1259. });
  1260. objMap[serviceName].log4j.forEach(function (log4j) {
  1261. self.get('serviceConfigTags').pushObject(self.createLog4jObj(log4j));
  1262. });
  1263. }
  1264. }
  1265. }
  1266. if (selectedServices.someProperty('serviceName', 'STORM')) {
  1267. this.get('serviceConfigTags').pushObject(this.createStormSiteObj());
  1268. }
  1269. if (selectedServices.someProperty('serviceName', 'ZOOKEEPER')) {
  1270. this.get('serviceConfigTags').pushObject(this.createZooCfgObj());
  1271. }
  1272. },
  1273. /**
  1274. * Send <code>serviceConfigTags</code> to server
  1275. * Queued request
  1276. * One request for each service config tag
  1277. * @method applyConfigurationsToCluster
  1278. */
  1279. applyConfigurationsToCluster: function () {
  1280. var configData = this.get('serviceConfigTags').map(function (_serviceConfig) {
  1281. return JSON.stringify({
  1282. Clusters: {
  1283. desired_config: {
  1284. type: _serviceConfig.type,
  1285. tag: _serviceConfig.tag,
  1286. properties: _serviceConfig.properties
  1287. }
  1288. }
  1289. });
  1290. }, this).toString();
  1291. this.addRequestToAjaxQueue({
  1292. name: 'wizard.step8.apply_configuration_to_cluster',
  1293. data: {
  1294. data: '[' + configData + ']'
  1295. }
  1296. });
  1297. },
  1298. /**
  1299. * Create and update config groups
  1300. * @method createConfigurationGroups
  1301. */
  1302. createConfigurationGroups: function () {
  1303. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1304. var clusterName = this.get('clusterName');
  1305. var sendData = [];
  1306. var updateData = [];
  1307. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1308. var timeTag = (new Date).getTime();
  1309. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1310. if (groupsToDelete && groupsToDelete.length > 0) {
  1311. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1312. }
  1313. configGroups.forEach(function (configGroup) {
  1314. var groupConfigs = [];
  1315. var groupData = {
  1316. "cluster_name": clusterName,
  1317. "group_name": configGroup.name,
  1318. "tag": configGroup.service.id,
  1319. "description": configGroup.description,
  1320. "hosts": [],
  1321. "desired_configs": []
  1322. };
  1323. configGroup.hosts.forEach(function (hostName) {
  1324. groupData.hosts.push({"host_name": hostName});
  1325. });
  1326. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1327. configGroup.properties.forEach(function (property) {
  1328. groupConfigs.push(Em.Object.create(property));
  1329. });
  1330. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1331. // check for group from installed service
  1332. if (configGroup.isForUpdate === true) {
  1333. // if group is a new one, create it
  1334. if (!configGroup.id) {
  1335. sendData.push({"ConfigGroup": groupData});
  1336. } else {
  1337. // update an existing group
  1338. groupData.id = configGroup.id;
  1339. updateData.push({"ConfigGroup": groupData});
  1340. }
  1341. } else {
  1342. sendData.push({"ConfigGroup": groupData});
  1343. }
  1344. //each group should have unique tag to prevent overriding configs from common sites
  1345. timeTag++;
  1346. }, this);
  1347. if (sendData.length > 0) {
  1348. this.applyConfigurationGroups(sendData);
  1349. }
  1350. if (updateData.length > 0) {
  1351. this.applyInstalledServicesConfigurationGroup(updateData);
  1352. }
  1353. },
  1354. /**
  1355. * Create new config groups request
  1356. * Queued request
  1357. * @param {Object[]} sendData
  1358. * @method applyConfigurationGroups
  1359. */
  1360. applyConfigurationGroups: function (sendData) {
  1361. this.addRequestToAjaxQueue({
  1362. name: 'wizard.step8.apply_configuration_groups',
  1363. data: {
  1364. data: JSON.stringify(sendData)
  1365. }
  1366. });
  1367. },
  1368. /**
  1369. * Update existed config groups
  1370. * @param {Object[]} updateData
  1371. * @method applyInstalledServicesConfigurationGroup
  1372. */
  1373. applyInstalledServicesConfigurationGroup: function (updateData) {
  1374. updateData.forEach(function (item) {
  1375. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1376. });
  1377. },
  1378. /**
  1379. * Delete selected config groups
  1380. * @param {Object[]} groupsToDelete
  1381. * @method removeInstalledServicesConfigurationGroups
  1382. */
  1383. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1384. groupsToDelete.forEach(function (item) {
  1385. App.config.deleteConfigGroup(Em.Object.create(item));
  1386. });
  1387. },
  1388. /**
  1389. * Create Global Site object
  1390. * @returns {{type: string, tag: string, properties: {}}}
  1391. * @method createGlobalSiteObj
  1392. */
  1393. createGlobalSiteObj: function () {
  1394. var globalSiteProperties = {};
  1395. var globalSiteObj = this.get('globals');
  1396. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1397. // screen out the GLUSTERFS-specific global config entries when they are not required
  1398. if (!isGLUSTERFSSelected) {
  1399. globalSiteObj = globalSiteObj.filter(function (_config) {
  1400. return _config.name.indexOf("fs_glusterfs") < 0;
  1401. });
  1402. }
  1403. globalSiteObj.forEach(function (_globalSiteObj) {
  1404. var heapsizeException = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize', 'jobhistory_heapsize'];
  1405. // do not pass any globals whose name ends with _host or _hosts
  1406. if (_globalSiteObj.isRequiredByAgent !== false) {
  1407. // append "m" to JVM memory options except for hadoop_heapsize
  1408. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && !heapsizeException.contains(_globalSiteObj.name)) {
  1409. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1410. } else {
  1411. globalSiteProperties[_globalSiteObj.name] = App.config.escapeXMLCharacters(_globalSiteObj.value);
  1412. }
  1413. }
  1414. }, this);
  1415. // we don't expose gmond_user to the user; it needs to be the same as gmetad_user
  1416. globalSiteProperties['gmond_user'] = globalSiteProperties['gmetad_user'];
  1417. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1418. },
  1419. /**
  1420. * Create Core Site object
  1421. * @returns {{type: string, tag: string, properties: {}}}
  1422. * @method createCoreSiteObj
  1423. */
  1424. createCoreSiteObj: function () {
  1425. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1426. var coreSiteProperties = {};
  1427. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1428. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1429. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  1430. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1431. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  1432. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1433. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  1434. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1435. // screen out the GLUSTERFS-specific core-site.xml entries when they are not needed
  1436. if (!isGLUSTERFSSelected) {
  1437. coreSiteObj = coreSiteObj.filter(function (_config) {
  1438. return _config.name.indexOf("fs.glusterfs") < 0;
  1439. });
  1440. }
  1441. coreSiteObj.forEach(function (_coreSiteObj) {
  1442. 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'))) {
  1443. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1444. }
  1445. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1446. 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;
  1447. }
  1448. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1449. coreSiteProperties[_coreSiteObj.name] = this.get('globals').someProperty('name', 'glusterfs_defaultFS_name') ? App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'glusterfs_defaultFS_name').value) : null;
  1450. }
  1451. }, this);
  1452. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1453. },
  1454. /**
  1455. * Create siteObj for custom service with it own configs
  1456. * @param {string} site
  1457. * @param {bool} isNonXmlFile
  1458. * @returns {{type: string, tag: string, properties: {}}}
  1459. * @method createSiteObj
  1460. */
  1461. createSiteObj: function (site, isNonXmlFile) {
  1462. var properties = {};
  1463. if (!!isNonXmlFile) {
  1464. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1465. properties[_configProperty.name] = _configProperty.value;
  1466. }, this);
  1467. } else {
  1468. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1469. properties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1470. }, this);
  1471. }
  1472. return {"type": site, "tag": "version1", "properties": properties };
  1473. },
  1474. /**
  1475. * Create log4j object for custom service with it own configs
  1476. * @param {string} site
  1477. * @returns {{type: string, tag: string, properties: {}}}
  1478. * @method createLog4jObj
  1479. */
  1480. createLog4jObj: function (site) {
  1481. return this.createSiteObj(site + '-log4j', true);
  1482. },
  1483. /**
  1484. * Create ZooKeeper Cfg Object
  1485. * @returns {{type: string, tag: string, properties: {}}}
  1486. * @method createZooCfgObj
  1487. */
  1488. createZooCfgObj: function () {
  1489. var configs = this.get('configs').filterProperty('filename', 'zoo.cfg');
  1490. var csProperties = {};
  1491. configs.forEach(function (_configProperty) {
  1492. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1493. }, this);
  1494. return {type: 'zoo.cfg', tag: 'version1', properties: csProperties};
  1495. },
  1496. /**
  1497. * Create site obj for Storm
  1498. * Some config-properties should be modified in custom way
  1499. * @returns {{type: string, tag: string, properties: {}}}
  1500. * @method createStormSiteObj
  1501. */
  1502. createStormSiteObj: function () {
  1503. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1504. var stormProperties = {};
  1505. var specialProperties = ["storm.zookeeper.servers", "nimbus.childopts", "supervisor.childopts", "worker.childopts"];
  1506. configs.forEach(function (_configProperty) {
  1507. if (specialProperties.contains(_configProperty.name)) {
  1508. if (_configProperty.name == "storm.zookeeper.servers") {
  1509. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1510. } else {
  1511. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "");
  1512. }
  1513. } else {
  1514. stormProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1515. }
  1516. }, this);
  1517. return {type: 'storm-site', tag: 'version1', properties: stormProperties};
  1518. },
  1519. /**
  1520. * Navigate to next step after all requests are sent
  1521. * @method ajaxQueueFinished
  1522. */
  1523. ajaxQueueFinished: function () {
  1524. console.log('everything is loaded');
  1525. App.router.send('next');
  1526. },
  1527. /**
  1528. * We need to do a lot of ajax calls async in special order. To do this,
  1529. * generate array of ajax objects and then send requests step by step. All
  1530. * ajax objects are stored in <code>ajaxRequestsQueue</code>
  1531. *
  1532. * @param {Object} params object with ajax-request parameters like url, type, data etc
  1533. * @method addRequestToAjaxQueue
  1534. */
  1535. addRequestToAjaxQueue: function (params) {
  1536. if (App.get('testMode')) return;
  1537. params = jQuery.extend({
  1538. sender: this,
  1539. error: 'ajaxQueueRequestErrorCallback'
  1540. }, params);
  1541. params.data['cluster'] = this.get('clusterName');
  1542. this.get('ajaxRequestsQueue').addRequest(params);
  1543. },
  1544. /**
  1545. * Error callback for each queued ajax-request
  1546. * @param {object} xhr
  1547. * @param {string} status
  1548. * @param {string} error
  1549. * @method ajaxQueueRequestErrorCallback
  1550. */
  1551. ajaxQueueRequestErrorCallback: function (xhr, status, error) {
  1552. var responseText = JSON.parse(xhr.responseText);
  1553. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1554. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1555. this.set('hasErrorOccurred', true);
  1556. // an error will break the ajax call chain and allow submission again
  1557. this.set('isSubmitDisabled', false);
  1558. this.set('isBackBtnDisabled', false);
  1559. App.router.get(this.get('content.controllerName')).setStepsEnable();
  1560. }
  1561. });