step8_controller.js 63 KB

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