step8_controller.js 60 KB

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