step8_controller.js 51 KB

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