step8_controller.js 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591
  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 = App.StackServiceComponent.find();
  882. this.get('selectedServices').forEach(function (_service) {
  883. var serviceName = _service.get('serviceName');
  884. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  885. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  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. if (this.get('content.controllerName') == 'addServiceController' && !App.testMode) {
  896. // Add service-components which show up in newer versions but did not
  897. // exist in older ones.
  898. var self = this;
  899. var newServiceComponents = {}
  900. if (App.get('isHadoop21Stack')) {
  901. newServiceComponents['APP_TIMELINE_SERVER'] = 'YARN';
  902. }
  903. for (var componentName in newServiceComponents) {
  904. var serviceName = newServiceComponents[componentName];
  905. // Create only if it doesnt exist
  906. var serviceComponentChecker = {
  907. success: function(){},
  908. error: function(){
  909. var componentsData = [{
  910. "ServiceComponentInfo": {
  911. "component_name": componentName
  912. }
  913. }];
  914. self.addRequestToAjaxQueue({
  915. type: 'POST',
  916. url: App.apiPrefix + '/clusters/' + self.get('clusterName') + '/services?ServiceInfo/service_name=' + serviceName,
  917. data: JSON.stringify({"components": componentsData})
  918. });
  919. }
  920. }
  921. App.ajax.send({
  922. name: 'service.service_component',
  923. sender: serviceComponentChecker,
  924. data: {
  925. serviceName: serviceName,
  926. componentName: componentName,
  927. async: false
  928. },
  929. success: 'success',
  930. error: 'error'
  931. });
  932. }
  933. }
  934. },
  935. /**
  936. * Register hosts
  937. * Queued request
  938. */
  939. registerHostsToCluster: function () {
  940. var data = this.createRegisterHostData();
  941. if (!data.length) return;
  942. this.addRequestToAjaxQueue({
  943. type: 'POST',
  944. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts',
  945. data: JSON.stringify(data)
  946. });
  947. },
  948. /**
  949. * Format request-data for <code>registerHostsToCluster</code>
  950. * @returns {Object}
  951. */
  952. createRegisterHostData: function () {
  953. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  954. return {"Hosts": { "host_name": host.hostName}};
  955. });
  956. },
  957. /**
  958. * Register master components
  959. * @uses registerHostsToComponent
  960. */
  961. createMasterHostComponents: function() {
  962. var masterHosts = this.get('content.masterComponentHosts');
  963. masterHosts.mapProperty('component').uniq().forEach(function (component) {
  964. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  965. this.registerHostsToComponent(hostNames, component);
  966. }, this);
  967. },
  968. /**
  969. * Register slave components and clients
  970. * @uses registerHostsToComponent
  971. */
  972. createSlaveAndClientsHostComponents: function() {
  973. var masterHosts = this.get('content.masterComponentHosts');
  974. var slaveHosts = this.get('content.slaveComponentHosts');
  975. var clients = this.get('content.clients');
  976. /**
  977. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  978. * @type {Object}
  979. * Format:
  980. * <code>
  981. * {
  982. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  983. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  984. * ...
  985. * }
  986. * </code>
  987. */
  988. var clientsToMasterMap = {
  989. HDFS_CLIENT: Em.A(['HBASE_MASTER', 'HBASE_REGIONSERVER', 'WEBHCAT_SERVER', 'HISTORYSERVER', 'OOZIE_SERVER']),
  990. MAPREDUCE_CLIENT: Em.A(['HIVE_SERVER', 'OOZIE_SERVER', 'NAGIOS_SERVER', 'WEBHCAT_SERVER']),
  991. OOZIE_CLIENT: Em.A(['NAGIOS_SERVER']),
  992. ZOOKEEPER_CLIENT: Em.A(['WEBHCAT_SERVER']),
  993. HIVE_CLIENT: Em.A(['WEBHCAT_SERVER','HIVE_SERVER']),
  994. HCAT: Em.A(['NAGIOS_SERVER']),
  995. YARN_CLIENT: Em.A(['NAGIOS_SERVER','HIVE_SERVER','OOZIE_SERVER','WEBHCAT_SERVER']),
  996. TEZ_CLIENT: Em.A(['NAGIOS_SERVER','HIVE_SERVER'])
  997. };
  998. slaveHosts.forEach(function (_slave) {
  999. if (_slave.componentName !== 'CLIENT') {
  1000. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1001. this.registerHostsToComponent(hostNames, _slave.componentName);
  1002. }
  1003. else {
  1004. clients.forEach(function (_client) {
  1005. var hostNames = _slave.hosts.mapProperty('hostName');
  1006. if (clientsToMasterMap[_client.component_name]) {
  1007. clientsToMasterMap[_client.component_name].forEach(function(componentName) {
  1008. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1009. hostNames.pushObject(_masterHost.hostName);
  1010. });
  1011. });
  1012. }
  1013. hostNames = hostNames.uniq();
  1014. if (_client.isInstalled) {
  1015. //check whether clients are already installed on selected master hosts!!!
  1016. _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName').forEach(function (host) {
  1017. if (hostNames.contains(host)) {
  1018. hostNames.splice(hostNames.indexOf(host), 1);
  1019. }
  1020. }, this);
  1021. }
  1022. this.registerHostsToComponent(hostNames, _client.component_name);
  1023. }, this);
  1024. }
  1025. }, this);
  1026. },
  1027. /**
  1028. * Register additional components
  1029. * Based on availability of some services
  1030. * @uses registerHostsToComponent
  1031. */
  1032. createAdditionalHostComponents: function() {
  1033. var masterHosts = this.get('content.masterComponentHosts');
  1034. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  1035. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  1036. if (gangliaService) {
  1037. var hosts = this.getRegisteredHosts();
  1038. if (gangliaService.get('isInstalled')) {
  1039. hosts = hosts.filterProperty('isInstalled', false);
  1040. }
  1041. if (hosts.length) {
  1042. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  1043. }
  1044. }
  1045. // add MySQL Server if Hive is selected
  1046. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1047. if (hiveService) {
  1048. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1049. if(hiveDb.value == "New MySQL Database") {
  1050. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1051. }
  1052. }
  1053. },
  1054. /**
  1055. * Register component to hosts
  1056. * Queued request
  1057. * @param {String[]} hostNames
  1058. * @param {String} componentName
  1059. */
  1060. registerHostsToComponent: function (hostNames, componentName) {
  1061. if (!hostNames.length) return;
  1062. var queryStr = '';
  1063. hostNames.forEach(function (hostName) {
  1064. queryStr += 'Hosts/host_name=' + hostName + '|';
  1065. });
  1066. //slice off last symbol '|'
  1067. queryStr = queryStr.slice(0, -1);
  1068. var data = {
  1069. "RequestInfo": {
  1070. "query": queryStr
  1071. },
  1072. "Body": {
  1073. "host_components": [
  1074. {
  1075. "HostRoles": {
  1076. "component_name": componentName
  1077. }
  1078. }
  1079. ]
  1080. }
  1081. };
  1082. this.addRequestToAjaxQueue({
  1083. type: 'POST',
  1084. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts',
  1085. data: JSON.stringify(data)
  1086. });
  1087. },
  1088. /**
  1089. * Create config objects for cluster and services
  1090. */
  1091. createConfigurations: function () {
  1092. var self = this;
  1093. var selectedServices = this.get('selectedServices');
  1094. var coreSiteObject = this.createCoreSiteObj();
  1095. if (this.get('content.controllerName') == 'installerController') {
  1096. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1097. this.get('serviceConfigTags').pushObject(this.createSiteObj('hdfs-site',false));
  1098. this.get('serviceConfigTags').pushObject(this.createLog4jObj('hdfs'));
  1099. }
  1100. var globalSiteObj = this.createGlobalSiteObj();
  1101. if (this.get('content.controllerName') == 'addServiceController') {
  1102. globalSiteObj.tag = 'version' + (new Date).getTime();
  1103. coreSiteObject.tag = 'version' + (new Date).getTime();
  1104. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1105. }
  1106. this.get('serviceConfigTags').pushObject(globalSiteObj);
  1107. var objMap = {
  1108. MAPREDUCE: {site: [{filename: 'mapred-site',isXmlFile: true}], log4j: ['mapreduce']},
  1109. MAPREDUCE2: {site: [{filename:'mapred-site',isXmlFile: true}], log4j: ['mapreduce2']},
  1110. YARN: {site: [{filename:'yarn-site',isXmlFile: true},{filename:'capacity-scheduler',isXmlFile: true}], log4j: ['yarn']},
  1111. HBASE: {site: [{filename:'hbase-site',isXmlFile: true}], log4j: ['hbase']},
  1112. OOZIE: {site: [{filename:'oozie-site',isXmlFile: true}], log4j: ['oozie']},
  1113. HIVE: {site: [{filename:'hive-site',isXmlFile: true}], log4j: ['hive','hive-exec']},
  1114. WEBHCAT: {site: [{filename:'webhcat-site',isXmlFile: true}], log4j: []},
  1115. HUE: {site: [{filename:'hue-site',isXmlFile: true}], log4j: []},
  1116. PIG: {site: [], log4j: ['pig']},
  1117. FALCON: {site: [{filename:'falcon-startup.properties',isXmlFile: false},{filename:'falcon-runtime.properties',isXmlFile: false}], log4j: []},
  1118. TEZ: {site: [{filename:'tez-site',isXmlFile: true}], log4j: []},
  1119. ZOOKEEPER: {site: [], log4j: ['zookeeper']},
  1120. FLUME: {site: [], log4j: []}
  1121. };
  1122. if (App.supports.capacitySchedulerUi) {
  1123. objMap['MAPREDUCE'].site.pushObjects([{filename:'capacity-scheduler',isXmlFile: true},{filename:'mapred-queue-acls',isXmlFile: true}]);
  1124. }
  1125. for(var serviceName in objMap) {
  1126. if (objMap.hasOwnProperty(serviceName)) {
  1127. if (selectedServices.someProperty('serviceName', serviceName)) {
  1128. objMap[serviceName].site.forEach(function(site) {
  1129. self.get('serviceConfigTags').pushObject(self.createSiteObj(site.filename,!site.isXmlFile));
  1130. });
  1131. objMap[serviceName].log4j.forEach(function(log4j) {
  1132. self.get('serviceConfigTags').pushObject(self.createLog4jObj(log4j));
  1133. });
  1134. }
  1135. }
  1136. }
  1137. if (selectedServices.someProperty('serviceName', 'STORM')) {
  1138. this.get('serviceConfigTags').pushObject(this.createStormSiteObj());
  1139. }
  1140. if (selectedServices.someProperty('serviceName', 'ZOOKEEPER')) {
  1141. this.get('serviceConfigTags').pushObject(this.createZooCfgObj());
  1142. }
  1143. if (selectedServices.someProperty('serviceName', 'FLUME')) {
  1144. this.get('serviceConfigTags').pushObject(this.createFlumeConfObj());
  1145. }
  1146. },
  1147. /**
  1148. * Send <code>serviceConfigTags</code> to server
  1149. * Queued request
  1150. * One request for each service config tag
  1151. */
  1152. applyConfigurationsToCluster: function() {
  1153. var configData = this.get('serviceConfigTags').map(function (_serviceConfig) {
  1154. return JSON.stringify({
  1155. Clusters: {
  1156. desired_config: {
  1157. type: _serviceConfig.type,
  1158. tag: _serviceConfig.tag,
  1159. properties: _serviceConfig.properties
  1160. }
  1161. }
  1162. });
  1163. }, this).toString();
  1164. this.addRequestToAjaxQueue({
  1165. type: 'PUT',
  1166. url: App.apiPrefix + '/clusters/' + this.get('clusterName'),
  1167. data: '[' + configData + ']'
  1168. });
  1169. },
  1170. /**
  1171. * Create and update config groups
  1172. */
  1173. createConfigurationGroups: function () {
  1174. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1175. var clusterName = this.get('clusterName');
  1176. var sendData = [];
  1177. var updateData = [];
  1178. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1179. var timeTag = (new Date).getTime();
  1180. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1181. if (groupsToDelete && groupsToDelete.length > 0) {
  1182. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1183. }
  1184. configGroups.forEach(function (configGroup) {
  1185. var groupConfigs = [];
  1186. var groupData = {
  1187. "cluster_name": clusterName,
  1188. "group_name": configGroup.name,
  1189. "tag": configGroup.service.id,
  1190. "description": configGroup.description,
  1191. "hosts": [],
  1192. "desired_configs": []
  1193. };
  1194. configGroup.hosts.forEach(function (hostName) {
  1195. groupData.hosts.push({"host_name": hostName});
  1196. });
  1197. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1198. configGroup.properties.forEach(function (property) {
  1199. groupConfigs.push(Em.Object.create(property));
  1200. });
  1201. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1202. // check for group from installed service
  1203. if (configGroup.isForUpdate === true) {
  1204. // if group is a new one, create it
  1205. if (!configGroup.id) {
  1206. sendData.push({"ConfigGroup": groupData});
  1207. } else {
  1208. // update an existing group
  1209. groupData.id = configGroup.id;
  1210. updateData.push({"ConfigGroup": groupData});
  1211. }
  1212. } else {
  1213. sendData.push({"ConfigGroup": groupData});
  1214. }
  1215. //each group should have unique tag to prevent overriding configs from common sites
  1216. timeTag++;
  1217. }, this);
  1218. if (sendData.length > 0) {
  1219. this.applyConfigurationGroups(sendData);
  1220. }
  1221. if (updateData.length > 0) {
  1222. this.applyInstalledServicesConfigurationGroup(updateData);
  1223. }
  1224. },
  1225. /**
  1226. * Create new config groups request
  1227. * Queued request
  1228. * @param {Object[]} sendData
  1229. */
  1230. applyConfigurationGroups: function (sendData) {
  1231. this.addRequestToAjaxQueue({
  1232. type: 'POST',
  1233. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/config_groups',
  1234. data: JSON.stringify(sendData)
  1235. });
  1236. },
  1237. /**
  1238. * Update existed config groups
  1239. * @param {Object[]} updateData
  1240. */
  1241. applyInstalledServicesConfigurationGroup: function (updateData) {
  1242. updateData.forEach(function(item) {
  1243. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1244. });
  1245. },
  1246. /**
  1247. * Delete selected config groups
  1248. * @param {Object[]} groupsToDelete
  1249. */
  1250. removeInstalledServicesConfigurationGroups: function(groupsToDelete) {
  1251. groupsToDelete.forEach(function(item) {
  1252. App.config.deleteConfigGroup(Em.Object.create(item));
  1253. });
  1254. },
  1255. /**
  1256. * Create Global Site object
  1257. * @returns {{type: string, tag: string, properties: {}}}
  1258. */
  1259. createGlobalSiteObj: function () {
  1260. var globalSiteProperties = {};
  1261. var globalSiteObj = this.get('globals');
  1262. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1263. // screen out the GLUSTERFS-specific global config entries when they are not required
  1264. if (!isGLUSTERFSSelected) {
  1265. globalSiteObj = globalSiteObj.filter(function(_config) {
  1266. return _config.name.indexOf("fs_glusterfs") < 0;
  1267. });
  1268. }
  1269. globalSiteObj.forEach(function (_globalSiteObj) {
  1270. var heapsizeException = ['hadoop_heapsize','yarn_heapsize','nodemanager_heapsize','resourcemanager_heapsize', 'apptimelineserver_heapsize'];
  1271. // do not pass any globals whose name ends with _host or _hosts
  1272. if (_globalSiteObj.isRequiredByAgent !== false) {
  1273. // append "m" to JVM memory options except for hadoop_heapsize
  1274. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && !heapsizeException.contains(_globalSiteObj.name)) {
  1275. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1276. } else {
  1277. globalSiteProperties[_globalSiteObj.name] = App.config.escapeXMLCharacters(_globalSiteObj.value);
  1278. }
  1279. }
  1280. }, this);
  1281. // we don't expose gmond_user to the user; it needs to be the same as gmetad_user
  1282. globalSiteProperties['gmond_user'] = globalSiteProperties['gmetad_user'];
  1283. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1284. },
  1285. /**
  1286. * Create Core Site object
  1287. * @returns {{type: string, tag: string, properties: {}}}
  1288. */
  1289. createCoreSiteObj: function () {
  1290. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1291. var coreSiteProperties = {};
  1292. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1293. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1294. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  1295. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1296. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  1297. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1298. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  1299. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1300. // screen out the GLUSTERFS-specific core-site.xml entries when they are not needed
  1301. if (!isGLUSTERFSSelected) {
  1302. coreSiteObj = coreSiteObj.filter(function(_config) {
  1303. return _config.name.indexOf("fs.glusterfs") < 0;
  1304. });
  1305. }
  1306. coreSiteObj.forEach(function (_coreSiteObj) {
  1307. 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'))) {
  1308. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1309. }
  1310. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1311. 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;
  1312. }
  1313. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1314. coreSiteProperties[_coreSiteObj.name] = this.get('globals').someProperty('name', 'glusterfs_defaultFS_name') ? App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'glusterfs_defaultFS_name').value) : null;
  1315. }
  1316. }, this);
  1317. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1318. },
  1319. /**
  1320. * Create siteObj for custom service with it own configs
  1321. * @param {string} site
  1322. * @param {Boolean} isNonXmlFile
  1323. * @returns {{type: string, tag: string, properties: {}}}
  1324. */
  1325. createSiteObj: function(site,isNonXmlFile) {
  1326. var properties = {};
  1327. if (!!isNonXmlFile) {
  1328. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1329. properties[_configProperty.name] = _configProperty.value;
  1330. },this);
  1331. } else {
  1332. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1333. properties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1334. },this);
  1335. }
  1336. return {"type": site, "tag": "version1", "properties": properties };
  1337. },
  1338. /**
  1339. * Create log4j object for custom service with it own configs
  1340. * @param {string} site
  1341. * @returns {{type: string, tag: string, properties: {}}}
  1342. */
  1343. createLog4jObj: function (site) {
  1344. return this.createSiteObj(site + '-log4j',true);
  1345. },
  1346. /**
  1347. * Create ZooKeeper Cfg Object
  1348. * @returns {{type: string, tag: string, properties: {}}}
  1349. */
  1350. createZooCfgObj: function () {
  1351. var configs = this.get('configs').filterProperty('filename', 'zoo.cfg');
  1352. var csProperties = {};
  1353. configs.forEach(function (_configProperty) {
  1354. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1355. }, this);
  1356. return {type: 'zoo.cfg', tag: 'version1', properties: csProperties};
  1357. },
  1358. /**
  1359. * Create flume.conf Object
  1360. * @returns {{type: string, tag: string, properties: {}}}
  1361. */
  1362. createFlumeConfObj: function () {
  1363. var configs = this.get('configs').filterProperty('filename', 'flume.conf');
  1364. var csProperties = {};
  1365. configs.forEach(function (_configProperty) {
  1366. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1367. }, this);
  1368. return {type: 'flume.conf', tag: 'version1', properties: csProperties};
  1369. },
  1370. /**
  1371. * Create site obj for Storm
  1372. * Some config-properties should be modified in custom way
  1373. * @returns {{type: string, tag: string, properties: {}}}
  1374. */
  1375. createStormSiteObj: function () {
  1376. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1377. var stormProperties = {};
  1378. var specialProperties = ["storm.zookeeper.servers", "nimbus.childopts", "supervisor.childopts", "worker.childopts"];
  1379. configs.forEach(function (_configProperty) {
  1380. if (specialProperties.contains(_configProperty.name)) {
  1381. if (_configProperty.name == "storm.zookeeper.servers") {
  1382. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1383. } else {
  1384. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g,"");
  1385. }
  1386. } else {
  1387. stormProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1388. }
  1389. }, this);
  1390. return {type: 'storm-site', tag: 'version1', properties: stormProperties};
  1391. },
  1392. /**
  1393. * Navigate to next step after all requests are sended
  1394. */
  1395. ajaxQueueFinished: function () {
  1396. console.log('everything is loaded');
  1397. App.router.send('next');
  1398. },
  1399. /**
  1400. * Do ajax-call with data in <code>ajaxQueue[0]</code> and shift <code>ajaxQueue</code>
  1401. */
  1402. doNextAjaxCall: function () {
  1403. if (this.get('ajaxBusy')) return;
  1404. var queue = this.get('ajaxQueue');
  1405. if (!queue.length) {
  1406. this.ajaxQueueFinished();
  1407. return;
  1408. }
  1409. var first = queue[0];
  1410. this.set('ajaxQueue', queue.slice(1));
  1411. this.set('ajaxQueueLeft', this.get('ajaxQueue').length);
  1412. this.set('ajaxBusy', true);
  1413. $.ajax(first);
  1414. },
  1415. /**
  1416. * We need to do a lot of ajax calls async in special order. To do this,
  1417. * generate array of ajax objects and then send requests step by step. All
  1418. * ajax objects are stored in <code>ajaxQueue</code>
  1419. *
  1420. * Each ajax-request success callback contains call of <code>doNextAjaxCall</code>
  1421. *
  1422. * @param {Object} params object with ajax-request parameters like url, type, data etc
  1423. */
  1424. addRequestToAjaxQueue: function (params) {
  1425. if (App.testMode) return;
  1426. var self = this;
  1427. params = jQuery.extend({
  1428. async: true,
  1429. dataType: 'text',
  1430. statusCode: require('data/statusCodes'),
  1431. timeout: App.timeout,
  1432. error: function () {
  1433. console.log('Step8: In Error ');
  1434. },
  1435. success: function () {
  1436. console.log("TRACE: Step8 -> In success function");
  1437. }
  1438. }, params);
  1439. var success = params.success;
  1440. var error = params.error;
  1441. params.success = function () {
  1442. if (success) {
  1443. success();
  1444. }
  1445. self.set('ajaxBusy', false);
  1446. self.doNextAjaxCall();
  1447. };
  1448. params.error = function (xhr, status, error) {
  1449. var responseText = JSON.parse(xhr.responseText);
  1450. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1451. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1452. self.set('hasErrorOccurred', true);
  1453. // an error will break the ajax call chain and allow submission again
  1454. self.set('isSubmitDisabled', false);
  1455. self.set('isBackBtnDisabled', false);
  1456. App.router.get(self.get('content.controllerName')).setStepsEnable();
  1457. self.get('ajaxQueue').clear();
  1458. self.set('ajaxBusy', false);
  1459. };
  1460. this.get('ajaxQueue').pushObject(params);
  1461. }
  1462. });