step8_controller.js 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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. App.WizardStep8Controller = Em.Controller.extend({
  20. name: 'wizardStep8Controller',
  21. rawContent: require('data/review_configs'),
  22. totalHosts: [],
  23. clusterInfo: [],
  24. services: [],
  25. configs: [],
  26. globals: [],
  27. configMapping: require('data/config_mapping'),
  28. slaveComponentConfig: null,
  29. isSubmitDisabled: false,
  30. hasErrorOccurred: false,
  31. selectedServices: function () {
  32. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  33. }.property('content.services').cacheable(),
  34. clearStep: function () {
  35. this.get('services').clear();
  36. this.get('configs').clear();
  37. this.get('globals').clear();
  38. this.get('clusterInfo').clear();
  39. },
  40. loadStep: function () {
  41. console.log("TRACE: Loading step8: Review Page");
  42. this.clearStep();
  43. this.loadGlobals();
  44. this.loadConfigs();
  45. this.setCustomConfigs();
  46. //this.loadSlaveConfiguration();
  47. this.loadClusterInfo();
  48. this.loadServices();
  49. this.set('isSubmitDisabled', false);
  50. },
  51. loadGlobals: function () {
  52. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  53. if (globals.someProperty('name', 'hive_database')) {
  54. //TODO: Hive host depends on the type of db selected. Change puppet variable name if postgres is not the default db
  55. var hiveDb = globals.findProperty('name', 'hive_database');
  56. if (hiveDb.value === 'New MySQL Database') {
  57. if (globals.someProperty('name', 'hive_ambari_host')) {
  58. globals.findProperty('name', 'hive_ambari_host').name = 'hive_mysql_hostname';
  59. }
  60. globals = globals.without(globals.findProperty('name', 'hive_existing_host'));
  61. globals = globals.without(globals.findProperty('name', 'hive_existing_database'));
  62. } else {
  63. globals.findProperty('name', 'hive_existing_host').name = 'hive_mysql_hostname';
  64. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  65. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  66. }
  67. }
  68. this.set('globals', globals);
  69. },
  70. loadConfigs: function () {
  71. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property').filterProperty('value');
  72. var uiConfigs = this.loadUiSideConfigs();
  73. this.set('configs', storedConfigs.concat(uiConfigs));
  74. },
  75. loadUiSideConfigs: function () {
  76. var uiConfig = [];
  77. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  78. configs.forEach(function (_config) {
  79. var value = this.getGlobConfigValue(_config.templateName, _config.value, _config.name);
  80. uiConfig.pushObject({
  81. "id": "site property",
  82. "name": _config.name,
  83. "value": value,
  84. "filename": _config.filename
  85. });
  86. }, this);
  87. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  88. dependentConfig.forEach(function (_config) {
  89. this.setConfigValue(uiConfig, _config);
  90. uiConfig.pushObject({
  91. "id": "site property",
  92. "name": _config.name,
  93. "value": _config.value,
  94. "filename": _config.filename
  95. });
  96. }, this);
  97. return uiConfig;
  98. },
  99. getRegisteredHosts: function () {
  100. var allHosts = this.get('content.hosts');
  101. var hosts = [];
  102. for (var hostName in allHosts) {
  103. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  104. allHosts[hostName].hostName = allHosts[hostName].name;
  105. hosts.pushObject(allHosts[hostName]);
  106. }
  107. }
  108. return hosts;
  109. },
  110. /**
  111. * Set all site property that are derived from other puppet-variable
  112. */
  113. getGlobConfigValue: function (templateName, expression, name) {
  114. var express = expression.match(/<(.*?)>/g);
  115. var value = expression;
  116. if (express == null) {
  117. return expression;
  118. }
  119. express.forEach(function (_express) {
  120. //console.log("The value of template is: " + _express);
  121. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  122. if (this.get('globals').someProperty('name', templateName[index])) {
  123. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  124. var globValue = this.get('globals').findProperty('name', templateName[index]).value;
  125. // Hack for templeton.zookeeper.hosts
  126. 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
  127. if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
  128. var zooKeeperPort = '2181';
  129. if (typeof globValue === 'string') {
  130. var temp = [];
  131. temp.push(globValue);
  132. globValue = temp;
  133. }
  134. if (name === "templeton.zookeeper.hosts") {
  135. globValue.forEach(function (_host, index) {
  136. globValue[index] = globValue[index] + ':' + zooKeeperPort;
  137. }, this);
  138. }
  139. value = value.replace(_express, globValue.toString());
  140. } else {
  141. value = value.replace(_express, globValue);
  142. }
  143. }
  144. } else {
  145. /*
  146. console.log("ERROR: The variable name is: " + templateName[index]);
  147. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  148. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  149. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  150. */
  151. value = null;
  152. }
  153. }, this);
  154. return value;
  155. },
  156. /**
  157. * Set all site property that are derived from other site-properties
  158. */
  159. setConfigValue: function (uiConfig, config) {
  160. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  161. if (fkValue) {
  162. fkValue.forEach(function (_fkValue) {
  163. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  164. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  165. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  166. config.value = config.value.replace(_fkValue, globalValue);
  167. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  168. var globalValue;
  169. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  170. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  171. } else {
  172. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  173. }
  174. config.value = config.value.replace(_fkValue, globalValue);
  175. }
  176. }, this);
  177. }
  178. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  179. fkValue.forEach(function (_fkValue) {
  180. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  181. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  182. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  183. config.name = config.name.replace(_fkValue, globalValue);
  184. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  185. var globalValue;
  186. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  187. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  188. } else {
  189. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  190. }
  191. config.name = config.name.replace(_fkValue, globalValue);
  192. }
  193. }, this);
  194. }
  195. //For properties in the configMapping file having foreignKey and templateName properties.
  196. var templateValue = config.value.match(/<(templateName.*?)>/g);
  197. if (templateValue) {
  198. templateValue.forEach(function (_value) {
  199. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  200. if (this.get('globals').someProperty('name', config.templateName[index])) {
  201. var globalValue = this.get('globals').findProperty('name', config.templateName[index]).value;
  202. config.value = config.value.replace(_value, globalValue);
  203. } else {
  204. config.value = null;
  205. }
  206. }, this);
  207. }
  208. },
  209. /**
  210. * override site properties with the entered key-value pair in *-site.xml
  211. */
  212. setCustomConfigs: function () {
  213. var site = this.get('content.serviceConfigProperties').filterProperty('id', 'conf-site');
  214. site.forEach(function (_site) {
  215. var keyValue = _site.value.split(/\n+/);
  216. if (keyValue) {
  217. keyValue.forEach(function (_keyValue) {
  218. console.log("The value of the keyValue is: " + _keyValue.trim());
  219. _keyValue = _keyValue.trim();
  220. var key = _keyValue.match(/(.+)=/);
  221. var value = _keyValue.match(/=(.*)/);
  222. if (key) {
  223. this.setSiteProperty(key[1], value[1], _site.name + '.xml');
  224. }
  225. }, this);
  226. }
  227. }, this);
  228. },
  229. /**
  230. * Set property of the site variable
  231. */
  232. setSiteProperty: function (key, value, filename) {
  233. if (this.get('configs').someProperty('name', key)) {
  234. this.get('configs').findProperty('name', key).value = value;
  235. } else {
  236. this.get('configs').pushObject({
  237. "id": "site property",
  238. "name": key,
  239. "value": value,
  240. "filename": filename
  241. });
  242. }
  243. },
  244. loadSlaveConfiguration: function () {
  245. var slaveComponentConfig = this.convertSlaveConfig(this.get('content.slaveGroupProperties'));
  246. this.set("slaveComponentConfig", slaveComponentConfig);
  247. },
  248. convertSlaveConfig: function (slaveContent) {
  249. var dest = {
  250. "version": "1.0",
  251. "components": [
  252. ],
  253. "slaveHostComponents": []
  254. };
  255. slaveContent.forEach(function (_slaveContent) {
  256. var newComponent = {};
  257. newComponent.componentName = _slaveContent.componentName;
  258. newComponent.serviceName = this.getServiceInfo(newComponent.componentName).name;
  259. newComponent.groups = [];
  260. var index = 2;
  261. if (_slaveContent.groups) {
  262. _slaveContent.groups.forEach(function (_group) {
  263. var newGroup = {};
  264. newGroup.groupName = _group.name;
  265. newGroup.configVersion = {config: {'global': 'version1', 'core-site': 'version1'}}; // TODO : every time a new version should be generated
  266. if (this.getServiceInfo(_slaveContent.componentName)) {
  267. newGroup.configVersion.config[this.getServiceInfo(_slaveContent.componentName).domain] = 'version' + index;
  268. newGroup.configVersion.config[this.getServiceInfo(_slaveContent.componentName).siteName] = 'version' + index;
  269. }
  270. newGroup.siteVersion = 'version' + index;
  271. newGroup.hostNames = _slaveContent.hosts.filterProperty("group", newGroup.groupName).mapProperty('hostName');
  272. newGroup.properties = _group.properties;
  273. if (!Ember.empty(newGroup.hostNames)) {
  274. newComponent.groups.push(newGroup);
  275. }
  276. index++;
  277. }, this);
  278. }
  279. dest.components.push(newComponent);
  280. }, this);
  281. var hostsInfo = this.get('content.hosts');
  282. for (var index in hostsInfo) {
  283. var hostIndex = 2;
  284. var slaveHost = {name: null, configVersion: null, slaveComponents: []};
  285. dest.components.forEach(function (_component) {
  286. _component.groups.forEach(function (_group) {
  287. if (_group.hostNames.contains(hostsInfo[index].name)) {
  288. var slaveComponent = {};
  289. slaveHost.name = hostsInfo[index].name;
  290. slaveComponent.componentName = _component.componentName;
  291. slaveComponent.groupName = _group.groupName;
  292. slaveComponent.properties = _group.properties;
  293. slaveHost.slaveComponents.pushObject(slaveComponent);
  294. }
  295. }, this);
  296. }, this);
  297. hostIndex++;
  298. if (!Ember.none(slaveHost.name)) {
  299. dest.slaveHostComponents.pushObject(slaveHost);
  300. }
  301. }
  302. return dest;
  303. },
  304. getServiceInfo: function (componentName) {
  305. var serviceConfig;
  306. switch (componentName) {
  307. case 'DATANODE':
  308. serviceConfig = {
  309. name: 'HDFS',
  310. siteName: 'hdfs-site',
  311. domain: 'datanode-global'
  312. };
  313. break;
  314. case 'TASKTRACKER':
  315. serviceConfig = {
  316. name: 'MAPREDUCE',
  317. siteName: 'mapred-site',
  318. domain: 'tasktracker-global'
  319. };
  320. break;
  321. case 'HBASE_REGIONSERVER':
  322. serviceConfig = {
  323. name: 'HBASE',
  324. siteName: 'hbase-site',
  325. domain: 'regionserver-global'
  326. };
  327. break;
  328. default:
  329. serviceConfig = {};
  330. }
  331. return serviceConfig;
  332. },
  333. /**
  334. * Load all info about cluster to <code>clusterInfo</code> variable
  335. */
  336. loadClusterInfo: function () {
  337. // cluster name
  338. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  339. cluster.config_value = this.get('content.cluster.name');
  340. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  341. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  342. //hosts
  343. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  344. var slaveHosts = this.get('content.slaveComponentHosts');
  345. var hostObj = [];
  346. slaveHosts.forEach(function (_hosts) {
  347. hostObj = hostObj.concat(_hosts.hosts);
  348. }, this);
  349. slaveHosts = hostObj.mapProperty('hostName').uniq();
  350. var componentHosts = masterHosts.concat(slaveHosts).uniq();
  351. var totalHosts = App.Host.find().mapProperty('hostName').concat(componentHosts).uniq();
  352. var newHostsCount = totalHosts.length - App.Host.find().content.length;
  353. this.set('totalHosts', totalHosts);
  354. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  355. totalHostsObj.config_value = totalHosts.length + ' (' + newHostsCount + ' new)';
  356. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  357. //repo
  358. var repoOption = this.get('content.installOption.localRepo');
  359. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  360. if (repoOption) {
  361. repoObj.config_value = 'Yes';
  362. } else {
  363. repoObj.config_value = 'No';
  364. }
  365. this.get('clusterInfo').pushObject(Ember.Object.create(repoObj));
  366. },
  367. /**
  368. * Load all info about services to <code>services</code> variable
  369. */
  370. loadServices: function () {
  371. var selectedServices = this.get('selectedServices');
  372. this.set('services', selectedServices.mapProperty('serviceName'));
  373. selectedServices.forEach(function (_service) {
  374. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  375. var reviewService = this.rawContent.findProperty('config_name', 'services');
  376. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  377. if (serviceObj) {
  378. switch (serviceObj.service_name) {
  379. case 'HDFS':
  380. this.loadHDFS(serviceObj);
  381. break;
  382. case 'MAPREDUCE':
  383. this.loadMapReduce(serviceObj);
  384. break;
  385. case 'HIVE':
  386. this.loadHive(serviceObj);
  387. break;
  388. case 'HBASE':
  389. this.loadHbase(serviceObj);
  390. break;
  391. case 'ZOOKEEPER':
  392. this.loadZk(serviceObj);
  393. break;
  394. case 'OOZIE':
  395. this.loadOozie(serviceObj);
  396. break;
  397. case 'NAGIOS':
  398. this.loadNagios(serviceObj);
  399. break;
  400. case 'GANGLIA':
  401. this.loadGanglia(serviceObj);
  402. break;
  403. /* case 'PIG':
  404. this.loadPig(serviceObj);
  405. break;
  406. case 'SQOOP':
  407. this.loadSqoop(serviceObj);
  408. break;
  409. */
  410. case 'HCATALOG':
  411. break;
  412. default:
  413. }
  414. }
  415. }, this);
  416. },
  417. /**
  418. * load all info about HDFS service
  419. * @param hdfsObj
  420. */
  421. loadHDFS: function (hdfsObj) {
  422. hdfsObj.get('service_components').forEach(function (_component) {
  423. switch (_component.get('display_name')) {
  424. case 'NameNode':
  425. this.loadNnValue(_component);
  426. break;
  427. case 'SecondaryNameNode':
  428. this.loadSnnValue(_component);
  429. break;
  430. case 'DataNodes':
  431. this.loadDnValue(_component);
  432. break;
  433. default:
  434. }
  435. }, this);
  436. //var
  437. this.get('services').pushObject(hdfsObj);
  438. },
  439. loadNnValue: function (nnComponent) {
  440. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  441. nnComponent.set('component_value', nnHostName.hostName);
  442. },
  443. loadSnnValue: function (snnComponent) {
  444. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  445. snnComponent.set('component_value', snnHostName.hostName);
  446. },
  447. loadDnValue: function (dnComponent) {
  448. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  449. var totalDnHosts = dnHosts.hosts.length;
  450. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'DATANODE').groups.length;
  451. var groupLabel;
  452. if (totalGroups == 1) {
  453. groupLabel = 'group';
  454. } else {
  455. groupLabel = 'groups';
  456. }
  457. */
  458. dnComponent.set('component_value', totalDnHosts + ' hosts');
  459. },
  460. /**
  461. * Load all info about mapReduce service
  462. * @param mrObj
  463. */
  464. loadMapReduce: function (mrObj) {
  465. mrObj.get('service_components').forEach(function (_component) {
  466. switch (_component.get('display_name')) {
  467. case 'JobTracker':
  468. this.loadJtValue(_component);
  469. break;
  470. case 'TaskTrackers':
  471. this.loadTtValue(_component);
  472. break;
  473. default:
  474. }
  475. }, this);
  476. this.get('services').pushObject(mrObj);
  477. },
  478. loadJtValue: function (jtComponent) {
  479. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  480. jtComponent.set('component_value', jtHostName.hostName);
  481. },
  482. loadTtValue: function (ttComponent) {
  483. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  484. var totalTtHosts = ttHosts.hosts.length;
  485. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'TASKTRACKER').groups.length;
  486. var groupLabel;
  487. if (totalGroups == 1) {
  488. groupLabel = 'group';
  489. } else {
  490. groupLabel = 'groups';
  491. }
  492. */
  493. ttComponent.set('component_value', totalTtHosts + ' hosts');
  494. },
  495. /**
  496. * Load all info about Hive service
  497. * @param hiveObj
  498. */
  499. loadHive: function (hiveObj) {
  500. hiveObj.get('service_components').forEach(function (_component) {
  501. switch (_component.get('display_name')) {
  502. case 'Hive Metastore':
  503. this.loadHiveMetaStoreValue(_component);
  504. break;
  505. case 'Database':
  506. this.loadHiveDbValue(_component);
  507. break;
  508. default:
  509. }
  510. }, this);
  511. this.get('services').pushObject(hiveObj);
  512. },
  513. loadHiveMetaStoreValue: function (metaStoreComponent) {
  514. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hive Server');
  515. metaStoreComponent.set('component_value', hiveHostName.hostName);
  516. },
  517. loadHiveDbValue: function (dbComponent) {
  518. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  519. if (hiveDb.value === 'New MySQL Database') {
  520. dbComponent.set('component_value', 'MySQL (New Database)');
  521. } else {
  522. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  523. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  524. }
  525. },
  526. /**
  527. * Load all info about Hbase
  528. * @param hbaseObj
  529. */
  530. loadHbase: function (hbaseObj) {
  531. hbaseObj.service_components.forEach(function (_component) {
  532. switch (_component.display_name) {
  533. case 'Master':
  534. this.loadMasterValue(_component);
  535. break;
  536. case 'Region Servers':
  537. this.loadRegionServerValue(_component);
  538. break;
  539. default:
  540. }
  541. }, this);
  542. this.get('services').pushObject(hbaseObj);
  543. },
  544. loadMasterValue: function (hbaseMaster) {
  545. var hbaseHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HBase Master');
  546. hbaseMaster.set('component_value', hbaseHostName.hostName);
  547. },
  548. loadRegionServerValue: function (rsComponent) {
  549. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  550. var totalRsHosts = rsHosts.hosts.length;
  551. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'HBASE_REGIONSERVER').groups.length;
  552. var groupLabel;
  553. if (totalGroups == 1) {
  554. groupLabel = 'group';
  555. } else {
  556. groupLabel = 'groups';
  557. } */
  558. rsComponent.set('component_value', totalRsHosts + ' hosts');
  559. },
  560. /**
  561. * Load all info about ZooKeeper service
  562. * @param zkObj
  563. */
  564. loadZk: function (zkObj) {
  565. zkObj.get('service_components').forEach(function (_component) {
  566. switch (_component.get('display_name')) {
  567. case 'Servers':
  568. this.loadZkServerValue(_component);
  569. break;
  570. default:
  571. }
  572. }, this);
  573. this.get('services').pushObject(zkObj);
  574. },
  575. loadZkServerValue: function (serverComponent) {
  576. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  577. var hostSuffix;
  578. if (zkHostNames === 1) {
  579. hostSuffix = 'host';
  580. } else {
  581. hostSuffix = 'hosts';
  582. }
  583. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  584. },
  585. /**
  586. * Load all info about Oozie services
  587. * @param oozieObj
  588. */
  589. loadOozie: function (oozieObj) {
  590. oozieObj.get('service_components').forEach(function (_component) {
  591. switch (_component.get('display_name')) {
  592. case 'Server':
  593. this.loadOozieServerValue(_component);
  594. break;
  595. case 'Database':
  596. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  597. // this.loadOozieDbValue(_component);
  598. break;
  599. default:
  600. }
  601. }, this);
  602. this.get('services').pushObject(oozieObj);
  603. },
  604. loadOozieServerValue: function (oozieServer) {
  605. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  606. oozieServer.set('component_value', oozieServerName.hostName);
  607. },
  608. loadOozieDbValue: function (dbComponent) {
  609. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  610. if (oozieDb.value === 'New PostgreSQL Database') {
  611. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  612. } else {
  613. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  614. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  615. }
  616. },
  617. /**
  618. * Load all info about Nagios service
  619. * @param nagiosObj
  620. */
  621. loadNagios: function (nagiosObj) {
  622. nagiosObj.service_components.forEach(function (_component) {
  623. switch (_component.display_name) {
  624. case 'Server':
  625. this.loadNagiosServerValue(_component);
  626. break;
  627. case 'Administrator':
  628. this.loadNagiosAdminValue(_component);
  629. break;
  630. default:
  631. }
  632. }, this);
  633. this.get('services').pushObject(nagiosObj);
  634. },
  635. loadNagiosServerValue: function (nagiosServer) {
  636. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  637. nagiosServer.set('component_value', nagiosServerName.hostName);
  638. },
  639. loadNagiosAdminValue: function (nagiosAdmin) {
  640. var config = this.get('content.serviceConfigProperties');
  641. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  642. var adminEmail = config.findProperty('name', 'nagios_contact');
  643. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  644. },
  645. /**
  646. * Load all info about ganglia
  647. * @param gangliaObj
  648. */
  649. loadGanglia: function (gangliaObj) {
  650. gangliaObj.get('service_components').forEach(function (_component) {
  651. switch (_component.get('display_name')) {
  652. case 'Server':
  653. this.loadGangliaServerValue(_component);
  654. break;
  655. default:
  656. }
  657. }, this);
  658. this.get('services').pushObject(gangliaObj);
  659. },
  660. loadGangliaServerValue: function (gangliaServer) {
  661. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  662. gangliaServer.set('component_value', gangliaServerName.hostName);
  663. },
  664. loadSqoop: function (sqoopObj) {
  665. this.get('services').pushObject(sqoopObj);
  666. },
  667. loadPig: function (pigObj) {
  668. this.get('services').pushObject(pigObj);
  669. },
  670. /**
  671. * Onclick handler for <code>next</code> button
  672. */
  673. submit: function () {
  674. if (this.get('isSubmitDisabled')) {
  675. return;
  676. }
  677. this.set('isSubmitDisabled', true);
  678. if (App.testMode || !this.get('content.cluster.requestId')) {
  679. // For recovery : set the cluster status
  680. // We need to do recovery based on whether we are in Add Host or Installer wizard
  681. switch (this.get('content.controllerName')) {
  682. case 'installerController' :
  683. App.clusterStatus.set('value', {
  684. clusterName: this.get('clusterName'),
  685. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  686. wizardControllerName: this.get('content.controllerName'),
  687. localdb: App.db.data,
  688. });
  689. break;
  690. case 'addHostController' :
  691. App.clusterStatus.set('value', {
  692. clusterName: this.get('clusterName'),
  693. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  694. wizardControllerName: this.get('content.controllerName'),
  695. localdb: App.db.data
  696. });
  697. break;
  698. default :
  699. break;
  700. }
  701. this.createCluster();
  702. this.createSelectedServices();
  703. //this.setAmbariUIDb();
  704. this.createConfigurations();
  705. this.applyCreatedConfToServices();
  706. this.createComponents();
  707. this.registerHostsToCluster();
  708. this.createAllHostComponents();
  709. //this.applyCreatedConfToSlaveGroups();
  710. this.ajaxQueueFinished = function () {
  711. console.log('everything is loaded')
  712. App.router.send('next');
  713. };
  714. this.doNextAjaxCall();
  715. } else {
  716. App.router.send('next');
  717. }
  718. },
  719. setAmbariUIDb: function () {
  720. var dbContent = this.get('content.slaveGroupProperties');
  721. var slaveComponentConfig = this.get("slaveComponentConfig");
  722. this.persistKeyValues(slaveComponentConfig.version, dbContent);
  723. this.persistKeyValues('current_version', slaveComponentConfig.version);
  724. },
  725. persistKeyValues: function (key, value) {
  726. var str = "{ '" + key + "' : '" + JSON.stringify(value) + "'}";
  727. var obj = eval("(" + str + ")");
  728. this.ajax({
  729. type: "POST",
  730. url: App.apiPrefix + '/persist',
  731. data: JSON.stringify(obj),
  732. beforeSend: function () {
  733. console.log('BeforeSend: persistKeyValues', obj);
  734. }
  735. });
  736. },
  737. clusterName: function () {
  738. return this.get('content.cluster.name');
  739. }.property('content.cluster.name'),
  740. /**
  741. * The following create* functions are called upon submitting Step 8.
  742. */
  743. createCluster: function () {
  744. if (this.get('content.isWizard')) {
  745. return false;
  746. }
  747. var clusterName = this.get('clusterName');
  748. var url = App.apiPrefix + '/clusters/' + clusterName;
  749. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.defaultLocalStackVersion : App.defaultStackVersion;
  750. this.ajax({
  751. type: 'POST',
  752. url: url,
  753. data: JSON.stringify({ "Clusters": {"version": stackVersion }}),
  754. beforeSend: function () {
  755. console.log("BeforeSend: createCluster for " + clusterName);
  756. }
  757. });
  758. },
  759. createSelectedServices: function () {
  760. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  761. var data = this.createServiceData();
  762. var httpMethod = 'POST';
  763. if (!data.length) {
  764. return;
  765. }
  766. this.ajax({
  767. type: httpMethod,
  768. url: url,
  769. data: JSON.stringify(data),
  770. beforeSend: function () {
  771. console.log('BeforeSend: createSelectedServices ', data);
  772. }
  773. });
  774. },
  775. createServiceData: function () {
  776. var services = this.get('selectedServices').mapProperty('serviceName');
  777. var data = [];
  778. services.forEach(function (_service) {
  779. data.pushObject({"ServiceInfo": { "service_name": _service }});
  780. }, this);
  781. return data;
  782. },
  783. createComponents: function () {
  784. var serviceComponents = require('data/service_components');
  785. var services = this.get('selectedServices').mapProperty('serviceName');
  786. services.forEach(function (_service) {
  787. var components = serviceComponents.filterProperty('service_name', _service);
  788. var componentsData = components.map(function (_component) {
  789. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  790. });
  791. // Service must be specified in terms of a query for creating multiple components at the same time.
  792. // See AMBARI-1018.
  793. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  794. var data = {
  795. "components": componentsData
  796. }
  797. this.ajax({
  798. type: 'POST',
  799. url: url,
  800. data: JSON.stringify(data),
  801. beforeSend: function () {
  802. console.log('BeforeSend: createComponents for ' + _service, componentsData);
  803. }
  804. });
  805. }, this);
  806. },
  807. registerHostsToCluster: function () {
  808. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  809. var data = this.createRegisterHostData();
  810. if (data.length == 0) {
  811. return;
  812. }
  813. this.ajax({
  814. type: 'POST',
  815. url: url,
  816. data: JSON.stringify(data),
  817. beforeSend: function () {
  818. console.log('BeforeSend: registerHostsToCluster', data);
  819. }
  820. });
  821. },
  822. createRegisterHostData: function () {
  823. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  824. if (!hosts.length) {
  825. return [];
  826. }
  827. return hosts.map(function (host) {
  828. return {"Hosts": { "host_name": host.hostName}};
  829. });
  830. },
  831. // TODO: review the code for add hosts / add services scenarios...
  832. createAllHostComponents: function () {
  833. var masterHosts = this.get('content.masterComponentHosts');
  834. var slaveHosts = this.get('content.slaveComponentHosts');
  835. var clients = this.get('content.clients');
  836. var clientHosts = slaveHosts.filterProperty('componentName', "CLIENT").objectAt(0).hosts;
  837. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  838. var masterComponents = masterHosts.mapProperty('component').uniq();
  839. masterComponents.forEach(function (component) {
  840. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  841. this.registerHostsToComponent(hostNames, component);
  842. }, this);
  843. slaveHosts.forEach(function (_slave) {
  844. if (_slave.componentName !== 'CLIENT') {
  845. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  846. this.registerHostsToComponent(hostNames, _slave.componentName);
  847. } else {
  848. this.get('content.clients').forEach(function (_client) {
  849. if (!_client.isInstalled) {
  850. var hostNames = clientHosts.mapProperty('hostName').splice(0);
  851. switch (_client.component_name) {
  852. case 'HDFS_CLIENT':
  853. // install HDFS_CLIENT on HBASE_MASTER, HBASE_REGIONSERVER, and WEBHCAT_SERVER hosts
  854. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  855. hostNames.pushObject(_masterHost.hostName);
  856. }, this);
  857. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  858. hostNames.pushObject(_masterHost.hostName);
  859. }, this);
  860. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  861. hostNames.pushObject(_masterHost.hostName);
  862. }, this);
  863. break;
  864. case 'MAPREDUCE_CLIENT':
  865. // install MAPREDUCE_CLIENT on HIVE_SERVER, OOZIE_SERVER, NAGIOS_SERVER, and WEBHCAT_SERVER hosts
  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', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  873. hostNames.pushObject(_masterHost.hostName);
  874. }, this);
  875. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  876. hostNames.pushObject(_masterHost.hostName);
  877. }, this);
  878. break;
  879. case 'OOZIE_CLIENT':
  880. // install OOZIE_CLIENT on NAGIOS_SERVER host
  881. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  882. hostNames.pushObject(_masterHost.hostName);
  883. }, this);
  884. break;
  885. case 'ZOOKEEPER_CLIENT':
  886. // install ZOOKEEPER_CLIENT on WEBHCAT_SERVER host
  887. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  888. hostNames.pushObject(_masterHost.hostName);
  889. }, this);
  890. break;
  891. case 'HCAT':
  892. // install HCAT (client) on NAGIOS_SERVER host
  893. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  894. hostNames.pushObject(_masterHost.hostName);
  895. }, this);
  896. break;
  897. }
  898. hostNames = hostNames.uniq();
  899. this.registerHostsToComponent(hostNames, _client.component_name);
  900. }
  901. }, this);
  902. }
  903. }, this);
  904. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  905. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  906. if (gangliaService) {
  907. var hosts = this.getRegisteredHosts();
  908. if (gangliaService.get('isInstalled')) {
  909. hosts = hosts.filterProperty('isInstalled', false);
  910. }
  911. if (hosts.length) {
  912. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  913. }
  914. }
  915. // add MySQL Server if Hive is selected
  916. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  917. if (hiveService) {
  918. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  919. }
  920. },
  921. registerHostsToComponent: function (hostNames, componentName) {
  922. if (hostNames.length == 0) {
  923. return;
  924. }
  925. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  926. // currently we are specifying the predicate as a query string.
  927. // this can hit a ~4000-character limit in Jetty server.
  928. // chunk to multiple calls if needed
  929. // var hostsPredicate = hostNames.map(function (hostName) {
  930. // return 'Hosts/host_name=' + hostName;
  931. // }).join('|');
  932. var queryStrArr = [];
  933. var queryStr = '';
  934. hostNames.forEach(function (hostName) {
  935. queryStr += 'Hosts/host_name=' + hostName + '|';
  936. if (queryStr.length > 3500) {
  937. queryStrArr.push(queryStr.slice(0, -1));
  938. queryStr = '';
  939. }
  940. });
  941. if (queryStr.length > 0) {
  942. queryStrArr.push(queryStr.slice(0, -1));
  943. }
  944. queryStrArr.forEach(function (queryStr) {
  945. // console.log('creating host components for ' + queryStr);
  946. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + queryStr;
  947. var data = {
  948. "host_components": [
  949. {
  950. "HostRoles": {
  951. "component_name": componentName
  952. }
  953. }
  954. ]
  955. };
  956. this.ajax({
  957. type: 'POST',
  958. url: url,
  959. data: JSON.stringify(data),
  960. beforeSend: function () {
  961. console.log('BeforeSend: registerHostsToComponent for ' + queryStr + ' and component ' + componentName);
  962. }
  963. });
  964. }, this);
  965. },
  966. createConfigurations: function () {
  967. var selectedServices = this.get('selectedServices');
  968. if (!this.get('content.isWizard')) {
  969. this.createConfigSiteForService(this.createGlobalSiteObj());
  970. // this.createGlobalSitePerSlaveGroup();
  971. this.createConfigSiteForService(this.createCoreSiteObj());
  972. this.createConfigSiteForService(this.createHdfsSiteObj());
  973. //this.createHdfsSitePerSlaveGroup('HDFS');
  974. }
  975. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  976. this.createConfigSiteForService(this.createMrSiteObj());
  977. //this.createMrSitePerSlaveGroup('MAPREDUCE');
  978. }
  979. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  980. this.createConfigSiteForService(this.createHbaseSiteObj());
  981. //this.createHbaseSitePerSlaveGroup('HBASE');
  982. }
  983. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  984. this.createConfigSiteForService(this.createOozieSiteObj('OOZIE'));
  985. }
  986. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  987. this.createConfigSiteForService(this.createHiveSiteObj('HIVE'));
  988. }
  989. if (selectedServices.someProperty('serviceName', 'WEBHCAT')) {
  990. this.createConfigSiteForService(this.createWebHCatSiteObj('WEBHCAT'));
  991. }
  992. },
  993. createConfigSiteForService: function (data) {
  994. console.log("Inside createConfigSiteForService");
  995. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/configurations';
  996. this.ajax({
  997. type: 'POST',
  998. url: url,
  999. data: JSON.stringify(data),
  1000. beforeSend: function () {
  1001. console.log("BeforeSend: createConfigSiteForService for " + data.type);
  1002. }
  1003. });
  1004. },
  1005. createGlobalSiteObj: function () {
  1006. var globalSiteProperties = {};
  1007. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  1008. this.get('globals').forEach(function (_globalSiteObj) {
  1009. // do not pass any globals whose name ends with _host or _hosts
  1010. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  1011. // append "m" to JVM memory options
  1012. var value = null;
  1013. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  1014. value = _globalSiteObj.value + "m";
  1015. globalSiteProperties[_globalSiteObj.name] = value;
  1016. } else {
  1017. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  1018. }
  1019. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  1020. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  1021. }
  1022. if (_globalSiteObj.name == 'java64_home') {
  1023. globalSiteProperties['java64_home'] = this.get('content.installOptions.javaHome');
  1024. }
  1025. }, this);
  1026. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1027. },
  1028. createGlobalSitePerSlaveGroup: function () {
  1029. this.get('slaveComponentConfig.components').forEach(function (_component) {
  1030. _component.groups.forEach(function (_group) {
  1031. var globalSiteProperties = {};
  1032. var properties = _group.properties;
  1033. properties.forEach(function (_property) {
  1034. if (!/_hosts?$/.test(_property.name)) {
  1035. // append "m" to JVM memory options
  1036. var value = null;
  1037. if (/_heapsize|_newsize|_maxnewsize$/.test(_property.name)) {
  1038. value = _property.value + "m";
  1039. globalSiteProperties[_property.name] = value;
  1040. } else {
  1041. globalSiteProperties[_property.name] = _property.storeValue;
  1042. }
  1043. console.log("STEP8: name of the global property is: " + _property.name);
  1044. console.log("STEP8: value of the global property is: " + _property.storeValue);
  1045. }
  1046. }, this);
  1047. var config = _group.configVersion.config;
  1048. for (var index in config) {
  1049. if (index === 'datanode-global' || index === 'tasktracker-global' || index === 'regionserver-global') {
  1050. var data = {"type": index, "tag": config[index], "properties": globalSiteProperties};
  1051. this.createConfigSiteForService(data);
  1052. }
  1053. }
  1054. }, this);
  1055. }, this);
  1056. },
  1057. createCoreSiteObj: function () {
  1058. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1059. var coreSiteProperties = {};
  1060. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1061. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1062. coreSiteObj.forEach(function (_coreSiteObj) {
  1063. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  1064. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1065. }
  1066. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  1067. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  1068. }, this);
  1069. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1070. },
  1071. createHdfsSiteObj: function () {
  1072. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  1073. var hdfsProperties = {};
  1074. hdfsSiteObj.forEach(function (_configProperty) {
  1075. hdfsProperties[_configProperty.name] = _configProperty.value;
  1076. console.log("STEP*: name of the property is: " + _configProperty.name);
  1077. console.log("STEP8: value of the property is: " + _configProperty.value);
  1078. }, this);
  1079. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  1080. },
  1081. createHdfsSitePerSlaveGroup: function (serviceName) {
  1082. var hdfsSite = this.createHdfsSiteObj();
  1083. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1084. component.groups.forEach(function (_group) {
  1085. var siteProperties = hdfsSite.properties;
  1086. _group.properties.forEach(function (_property) {
  1087. this.get('configMapping').forEach(function (_config) {
  1088. if (_config.templateName.contains(_property.name)) {
  1089. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1090. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1091. if (siteProperties[_config.name]) {
  1092. siteProperties[_config.name] = value;
  1093. }
  1094. }
  1095. }, this);
  1096. }, this);
  1097. var data = {"type": hdfsSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1098. console.log("The value of globalConfig is: " + JSON.stringify(siteProperties));
  1099. this.createConfigSiteForService(data);
  1100. }, this);
  1101. },
  1102. createMrSiteObj: function () {
  1103. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  1104. var mrProperties = {};
  1105. configs.forEach(function (_configProperty) {
  1106. mrProperties[_configProperty.name] = _configProperty.value;
  1107. console.log("STEP*: name of the property is: " + _configProperty.name);
  1108. console.log("STEP8: value of the property is: " + _configProperty.value);
  1109. }, this);
  1110. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  1111. },
  1112. createMrSitePerSlaveGroup: function (serviceName) {
  1113. var mrSite = this.createMrSiteObj();
  1114. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1115. component.groups.forEach(function (_group) {
  1116. var siteProperties = mrSite.properties;
  1117. _group.properties.forEach(function (_property) {
  1118. this.get('configMapping').forEach(function (_config) {
  1119. if (_config.templateName.contains(_property.name)) {
  1120. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1121. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1122. if (siteProperties[_config.name]) {
  1123. siteProperties[_config.name] = value;
  1124. }
  1125. }
  1126. }, this);
  1127. }, this);
  1128. var data = {"type": mrSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1129. this.createConfigSiteForService(data);
  1130. }, this);
  1131. },
  1132. createHbaseSiteObj: function () {
  1133. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  1134. var hbaseProperties = {};
  1135. configs.forEach(function (_configProperty) {
  1136. hbaseProperties[_configProperty.name] = _configProperty.value;
  1137. }, this);
  1138. var masterHosts = App.db.getMasterComponentHosts();
  1139. // TODO: should filter on "component" but that gives unexpected results
  1140. var zkServers = masterHosts.filterProperty('display_name', 'ZooKeeper').mapProperty('hostName');
  1141. hbaseProperties['hbase.zookeeper.quorum'] = zkServers.join(',');
  1142. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  1143. },
  1144. createHbaseSitePerSlaveGroup: function (serviceName) {
  1145. var hbaseSite = this.createHbaseSiteObj();
  1146. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1147. component.groups.forEach(function (_group) {
  1148. var siteProperties = hbaseSite.properties;
  1149. _group.properties.forEach(function (_property) {
  1150. this.get('configMapping').forEach(function (_config) {
  1151. if (_config.templateName.contains(_property.name)) {
  1152. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1153. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1154. if (siteProperties[_config.name]) {
  1155. siteProperties[_config.name] = value;
  1156. }
  1157. }
  1158. }, this);
  1159. }, this);
  1160. var data = {"type": hbaseSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1161. this.createConfigSiteForService(data);
  1162. }, this);
  1163. },
  1164. createOozieSiteObj: function (serviceName) {
  1165. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  1166. var oozieProperties = {};
  1167. configs.forEach(function (_configProperty) {
  1168. oozieProperties[_configProperty.name] = _configProperty.value;
  1169. }, this);
  1170. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  1171. },
  1172. createHiveSiteObj: function (serviceName) {
  1173. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  1174. var hiveProperties = {};
  1175. configs.forEach(function (_configProperty) {
  1176. hiveProperties[_configProperty.name] = _configProperty.value;
  1177. }, this);
  1178. hiveProperties['hive.metastore.uris'] = 'thrift://' + this.get('globals').findProperty('name', 'hivemetastore_host').value + ':9083';
  1179. hiveProperties['javax.jdo.option.ConnectionURL'] =
  1180. 'jdbc:mysql://' + this.get('globals').findProperty('name', 'hive_mysql_hostname').value +
  1181. '/' + this.get('globals').findProperty('name', 'hive_database_name').value + '?createDatabaseIfNotExist=true';
  1182. return {type: 'hive-site', tag: 'version1', properties: hiveProperties};
  1183. },
  1184. createWebHCatSiteObj: function (serviceName) {
  1185. var configs = this.get('configs').filterProperty('filename', 'webhcat-site.xml');
  1186. var webHCatProperties = {};
  1187. configs.forEach(function (_configProperty) {
  1188. webHCatProperties[_configProperty.name] = _configProperty.value;
  1189. }, this);
  1190. return {type: 'webhcat-site', tag: 'version1', properties: webHCatProperties};
  1191. },
  1192. applyCreatedConfToServices: function () {
  1193. var services = this.get('selectedServices').mapProperty('serviceName');
  1194. services.forEach(function (_service) {
  1195. var data = this.getConfigForService(_service);
  1196. this.applyCreatedConfToService(_service, 'PUT', data);
  1197. }, this);
  1198. },
  1199. applyCreatedConfToService: function (service, httpMethod, data) {
  1200. console.log("Inside applyCreatedConfToService");
  1201. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services/' + service;
  1202. this.ajax({
  1203. type: httpMethod,
  1204. url: url,
  1205. data: JSON.stringify(data),
  1206. beforeSend: function () {
  1207. console.log("BeforeSend: applyCreatedConfToService for " + service);
  1208. }
  1209. });
  1210. },
  1211. applyCreatedConfToSlaveGroups: function () {
  1212. this.get('slaveComponentConfig.components').forEach(function (_component) {
  1213. _component.groups.forEach(function (_group) {
  1214. var aggregatedHostNames = '';
  1215. _group.hostNames.forEach(function (_hostName, index) {
  1216. aggregatedHostNames += 'HostRoles/host_name=' + _hostName;
  1217. if (index !== _group.hostNames.length - 1) {
  1218. aggregatedHostNames += '|';
  1219. }
  1220. }, this);
  1221. console.log("The aggregated hostNames value is: " + aggregatedHostNames);
  1222. this.applyCreatedConfToSlaveGroup(aggregatedHostNames, 'PUT', _group.configVersion, _group.groupName);
  1223. }, this);
  1224. }, this);
  1225. },
  1226. applyCreatedConfToSlaveGroup: function (aggregatedHostNames, httpMethod, data, groupName) {
  1227. console.log("Inside applyCreatedConfToHost");
  1228. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/host_components?' + aggregatedHostNames;
  1229. this.ajax({
  1230. type: httpMethod,
  1231. url: url,
  1232. data: JSON.stringify(data),
  1233. beforeSend: function () {
  1234. console.log("BeforeSend: applyCreatedConfToSlaveGroup for group: " + groupName);
  1235. }
  1236. });
  1237. },
  1238. getConfigForService: function (serviceName) {
  1239. switch (serviceName) {
  1240. case 'HDFS':
  1241. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  1242. case 'MAPREDUCE':
  1243. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  1244. case 'HBASE':
  1245. return {config: {'global': 'version1', 'core-site': 'version1', 'hbase-site': 'version1'}};
  1246. case 'OOZIE':
  1247. return {config: {'global': 'version1', 'core-site': 'version1', 'oozie-site': 'version1'}};
  1248. case 'HIVE':
  1249. return {config: {'global': 'version1', 'core-site': 'version1', 'hive-site': 'version1'}};
  1250. case 'WEBHCAT':
  1251. return {config: {'global': 'version1', 'core-site': 'version1', 'webhcat-site': 'version1'}};
  1252. default:
  1253. return {config: {'global': 'version1'}};
  1254. }
  1255. },
  1256. ajaxQueue: [],
  1257. ajaxQueueFinished: function () {
  1258. //do something
  1259. },
  1260. doNextAjaxCall: function () {
  1261. if (this.get('ajaxBusy')) {
  1262. return;
  1263. }
  1264. var queue = this.get('ajaxQueue');
  1265. if (!queue.length) {
  1266. this.ajaxQueueFinished();
  1267. return;
  1268. }
  1269. var first = queue[0];
  1270. this.set('ajaxQueue', queue.slice(1));
  1271. this.set('ajaxBusy', true);
  1272. console.log('AJAX send ' + first.url);
  1273. $.ajax(first);
  1274. },
  1275. registerErrPopup: function (header, message) {
  1276. App.ModalPopup.show({
  1277. header: header,
  1278. secondary: false,
  1279. onPrimary: function () {
  1280. this.hide();
  1281. },
  1282. bodyClass: Ember.View.extend({
  1283. template: Ember.Handlebars.compile(['<p>{{view.message}}</p>'].join('\n')),
  1284. message: message
  1285. })
  1286. });
  1287. },
  1288. /**
  1289. * We need to do a lot of ajax calls(about 10 or more) async in special order.
  1290. * To do this i generate array of ajax objects and then send requests step by step.
  1291. * All ajax objects are stored in <code>ajaxQueue</code>
  1292. * @param params
  1293. */
  1294. ajax: function (params) {
  1295. if (App.testMode) return;
  1296. var self = this;
  1297. params = jQuery.extend({
  1298. async: true,
  1299. dataType: 'text',
  1300. statusCode: require('data/statusCodes'),
  1301. timeout: App.timeout,
  1302. error: function (request, ajaxOptions, error) {
  1303. console.log('Step8: In Error ');
  1304. // console.log('Step8: Error message is: ' + request.responseText);
  1305. },
  1306. success: function (data) {
  1307. var jsonData = jQuery.parseJSON(data);
  1308. console.log("TRACE: STep8 -> In success function");
  1309. console.log("TRACE: STep8 -> value of the url is: " + params.url);
  1310. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  1311. }
  1312. }, params);
  1313. var success = params.success;
  1314. var error = params.error;
  1315. params.success = function () {
  1316. if (success) {
  1317. success();
  1318. }
  1319. self.set('ajaxBusy', false);
  1320. self.doNextAjaxCall();
  1321. }
  1322. params.error = function (xhr, status, error) {
  1323. var responseText = JSON.parse(xhr.responseText);
  1324. self.registerErrPopup("Error", responseText.message);
  1325. self.set('isSubmitDisabled', true);
  1326. self.set('hasErrorOccurred', true);
  1327. }
  1328. this.get('ajaxQueue').pushObject(params);
  1329. }
  1330. })