step8_controller.js 61 KB

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