step8_controller.js 56 KB

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