step8_controller.js 52 KB

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