step8_controller.js 61 KB

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