step8_controller.js 55 KB

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