step8_controller.js 54 KB

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