step8_controller.js 54 KB

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