step8_controller.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097
  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. isSubmitDisabled : false,
  29. selectedServices: function () {
  30. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  31. }.property('content.services').cacheable(),
  32. clearStep: function () {
  33. this.get('services').clear();
  34. this.get('configs').clear();
  35. this.get('globals').clear();
  36. this.get('clusterInfo').clear();
  37. },
  38. loadStep: function () {
  39. console.log("TRACE: Loading step8: Review Page");
  40. this.clearStep();
  41. this.loadGlobals();
  42. this.loadConfigs();
  43. this.setCustomConfigs();
  44. this.loadClusterInfo();
  45. this.loadServices();
  46. },
  47. loadGlobals: function () {
  48. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  49. if (globals.someProperty('name', 'hive_database')) {
  50. //TODO: Hive host depends on the type of db selected. Change puppet variable name if postgress is not the default db
  51. var hiveDb = globals.findProperty('name', 'hive_database');
  52. if (hiveDb.value === 'New PostgreSQL Database') {
  53. globals.findProperty('name', 'hive_ambari_host').name = 'hive_mysql_host';
  54. globals = globals.without(globals.findProperty('name', 'hive_existing_host'));
  55. globals = globals.without(globals.findProperty('name', 'hive_existing_database'));
  56. } else {
  57. globals.findProperty('name', 'hive_existing_host').name = 'hive_mysql_host';
  58. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  59. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  60. }
  61. }
  62. this.set('globals', globals);
  63. },
  64. loadConfigs: function () {
  65. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property').filterProperty('value');
  66. var uiConfigs = this.loadUiSideConfigs();
  67. this.set('configs', storedConfigs.concat(uiConfigs));
  68. },
  69. loadUiSideConfigs: function () {
  70. var uiConfig = [];
  71. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  72. configs.forEach(function (_config) {
  73. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  74. uiConfig.pushObject({
  75. "id": "site property",
  76. "name": _config.name,
  77. "value": value,
  78. "filename": _config.filename
  79. });
  80. }, this);
  81. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  82. dependentConfig.forEach(function (_config) {
  83. this.setConfigValue(uiConfig, _config);
  84. uiConfig.pushObject({
  85. "id": "site property",
  86. "name": _config.name,
  87. "value": _config.value,
  88. "filename": _config.filename
  89. });
  90. }, this);
  91. return uiConfig;
  92. },
  93. getRegisteredHosts: function() {
  94. var allHosts = this.get('content.hostsInfo');
  95. var hosts = [];
  96. for (var hostName in allHosts) {
  97. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  98. allHosts[hostName].hostName = allHosts[hostName].name;
  99. hosts.pushObject(allHosts[hostName]);
  100. }
  101. }
  102. return hosts;
  103. },
  104. /**
  105. * Set all site property that are derived from other puppet-variable
  106. */
  107. getGlobConfigValue: function (templateName, expression) {
  108. var express = expression.match(/<(.*?)>/g);
  109. var value = expression;
  110. if (express == null) {
  111. return expression;
  112. }
  113. express.forEach(function (_express) {
  114. //console.log("The value of template is: " + _express);
  115. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  116. if (this.get('globals').someProperty('name', templateName[index])) {
  117. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  118. var globValue = this.get('globals').findProperty('name', templateName[index]).value;
  119. value = value.replace(_express, globValue);
  120. } else {
  121. /*
  122. console.log("ERROR: The variable name is: " + templateName[index]);
  123. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  124. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  125. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  126. */
  127. value = null;
  128. }
  129. }, this);
  130. return value;
  131. },
  132. /**
  133. * Set all site property that are derived from other site-properties
  134. */
  135. setConfigValue: function (uiConfig, config) {
  136. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  137. if (fkValue) {
  138. fkValue.forEach(function (_fkValue) {
  139. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  140. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  141. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  142. config.value = config.value.replace(_fkValue, globalValue);
  143. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  144. var globalValue;
  145. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  146. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  147. } else {
  148. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  149. }
  150. config.value = config.value.replace(_fkValue, globalValue);
  151. }
  152. }, this);
  153. }
  154. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  155. fkValue.forEach(function (_fkValue) {
  156. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  157. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  158. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  159. config.name = config.name.replace(_fkValue, globalValue);
  160. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  161. var globalValue;
  162. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  163. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  164. } else {
  165. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  166. }
  167. config.name = config.name.replace(_fkValue, globalValue);
  168. }
  169. }, this);
  170. }
  171. //For properties in the configMapping file having foreignKey and templateName properties.
  172. var templateValue = config.value.match(/<(templateName.*?)>/g);
  173. if (templateValue) {
  174. templateValue.forEach(function (_value) {
  175. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  176. if (this.get('globals').someProperty('name', config.templateName[index])) {
  177. var globalValue = this.get('globals').findProperty('name', config.templateName[index]).value;
  178. config.value = config.value.replace(_value, globalValue);
  179. }
  180. }, this);
  181. }
  182. },
  183. /**
  184. * override site properties with the entered key-value pair in *-site.xml
  185. */
  186. setCustomConfigs: function () {
  187. var site = this.get('content.serviceConfigProperties').filterProperty('id', 'conf-site');
  188. site.forEach(function (_site) {
  189. var keyValue = _site.value.split(/\n+/);
  190. if (keyValue) {
  191. keyValue.forEach(function (_keyValue) {
  192. console.log("The value of the keyValue is: " + _keyValue.trim());
  193. _keyValue = _keyValue.trim();
  194. var key = _keyValue.match(/(.+)=/);
  195. var value = _keyValue.match(/=(.*)/);
  196. if (key) {
  197. this.setSiteProperty(key[1], value[1], _site.filename);
  198. }
  199. }, this);
  200. }
  201. }, this);
  202. },
  203. /**
  204. * Set property of the site variable
  205. */
  206. setSiteProperty: function (key, value, filename) {
  207. if (this.get('configs').someProperty('name', key)) {
  208. this.get('configs').findProperty('name', key).value = value;
  209. } else {
  210. this.get('configs').pushObject({
  211. "id": "site property",
  212. "name": key,
  213. "value": value,
  214. "filename": filename
  215. });
  216. }
  217. },
  218. /**
  219. * Load all info about cluster to <code>clusterInfo</code> variable
  220. */
  221. loadClusterInfo: function () {
  222. // cluster name
  223. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  224. cluster.config_value = this.get('content.cluster.name');
  225. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  226. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  227. //hosts
  228. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  229. var slaveHosts = this.get('content.slaveComponentHosts');
  230. var hostObj = [];
  231. slaveHosts.forEach(function (_hosts) {
  232. hostObj = hostObj.concat(_hosts.hosts);
  233. }, this);
  234. slaveHosts = hostObj.mapProperty('hostName').uniq();
  235. var totalHosts = masterHosts.concat(slaveHosts).uniq();
  236. this.set('totalHosts', totalHosts);
  237. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  238. totalHostsObj.config_value = totalHosts.length;
  239. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  240. //repo
  241. var repoOption = this.get('content.hosts.localRepo');
  242. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  243. if (repoOption) {
  244. repoObj.config_value = 'Yes';
  245. } else {
  246. repoObj.config_value = 'No';
  247. }
  248. this.get('clusterInfo').pushObject(Ember.Object.create(repoObj));
  249. },
  250. /**
  251. * Load all info about services to <code>services</code> variable
  252. */
  253. loadServices: function () {
  254. var selectedServices = this.get('selectedServices');
  255. this.set('services', selectedServices.mapProperty('serviceName'));
  256. selectedServices.forEach(function (_service) {
  257. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  258. var reviewService = this.rawContent.findProperty('config_name', 'services');
  259. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  260. if (serviceObj) {
  261. switch (serviceObj.service_name) {
  262. case 'HDFS':
  263. this.loadHDFS(serviceObj);
  264. break;
  265. case 'MAPREDUCE':
  266. this.loadMapReduce(serviceObj);
  267. break;
  268. case 'HIVE':
  269. this.loadHive(serviceObj);
  270. break;
  271. case 'HBASE':
  272. this.loadHbase(serviceObj);
  273. break;
  274. case 'ZOOKEEPER':
  275. this.loadZk(serviceObj);
  276. break;
  277. case 'OOZIE':
  278. this.loadOozie(serviceObj);
  279. break;
  280. case 'NAGIOS':
  281. this.loadNagios(serviceObj);
  282. break;
  283. case 'GANGLIA':
  284. this.loadGanglia(serviceObj);
  285. break;
  286. case 'HCATALOG':
  287. break;
  288. default:
  289. }
  290. }
  291. }, this);
  292. },
  293. /**
  294. * load all info about HDFS service
  295. * @param hdfsObj
  296. */
  297. loadHDFS: function (hdfsObj) {
  298. hdfsObj.get('service_components').forEach(function (_component) {
  299. switch (_component.get('display_name')) {
  300. case 'NameNode':
  301. this.loadNnValue(_component);
  302. break;
  303. case 'SecondaryNameNode':
  304. this.loadSnnValue(_component);
  305. break;
  306. case 'DataNodes':
  307. this.loadDnValue(_component);
  308. break;
  309. default:
  310. }
  311. }, this);
  312. //var
  313. this.get('services').pushObject(hdfsObj);
  314. },
  315. loadNnValue: function (nnComponent) {
  316. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  317. nnComponent.set('component_value', nnHostName.hostName);
  318. },
  319. loadSnnValue: function (snnComponent) {
  320. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  321. snnComponent.set('component_value', snnHostName.hostName);
  322. },
  323. loadDnValue: function (dnComponent) {
  324. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  325. var totalDnHosts = dnHosts.hosts.length;
  326. var dnHostGroups = [];
  327. dnHosts.hosts.forEach(function (_dnHost) {
  328. dnHostGroups.push(_dnHost.group);
  329. }, this);
  330. var totalGroups = dnHostGroups.uniq().length;
  331. var groupLabel;
  332. if (totalGroups == 1) {
  333. groupLabel = 'group';
  334. } else {
  335. groupLabel = 'groups';
  336. }
  337. dnComponent.set('component_value', totalDnHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  338. },
  339. /**
  340. * Load all info about mapReduce service
  341. * @param mrObj
  342. */
  343. loadMapReduce: function (mrObj) {
  344. mrObj.get('service_components').forEach(function (_component) {
  345. switch (_component.get('display_name')) {
  346. case 'JobTracker':
  347. this.loadJtValue(_component);
  348. break;
  349. case 'TaskTrackers':
  350. this.loadTtValue(_component);
  351. break;
  352. default:
  353. }
  354. }, this);
  355. this.get('services').pushObject(mrObj);
  356. },
  357. loadJtValue: function (jtComponent) {
  358. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  359. jtComponent.set('component_value', jtHostName.hostName);
  360. },
  361. loadTtValue: function (ttComponent) {
  362. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  363. var totalTtHosts = ttHosts.hosts.length;
  364. var ttHostGroups = [];
  365. ttHosts.hosts.forEach(function (_ttHost) {
  366. ttHostGroups.push(_ttHost.group);
  367. }, this);
  368. var totalGroups = ttHostGroups.uniq().length;
  369. var groupLabel;
  370. if (totalGroups == 1) {
  371. groupLabel = 'group';
  372. } else {
  373. groupLabel = 'groups';
  374. }
  375. ttComponent.set('component_value', totalTtHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  376. },
  377. /**
  378. * Load all info about Hive service
  379. * @param hiveObj
  380. */
  381. loadHive: function (hiveObj) {
  382. hiveObj.get('service_components').forEach(function (_component) {
  383. switch (_component.get('display_name')) {
  384. case 'Hive Metastore Server':
  385. this.loadHiveMetaStoreValue(_component);
  386. break;
  387. case 'Database':
  388. this.loadHiveDbValue(_component);
  389. break;
  390. default:
  391. }
  392. }, this);
  393. this.get('services').pushObject(hiveObj);
  394. },
  395. loadHiveMetaStoreValue: function (metaStoreComponent) {
  396. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hive Metastore');
  397. metaStoreComponent.set('component_value', hiveHostName.hostName);
  398. },
  399. loadHiveDbValue: function (dbComponent) {
  400. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  401. if (hiveDb.value === 'New PostgreSQL Database') {
  402. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  403. } else {
  404. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  405. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  406. }
  407. },
  408. /**
  409. * Load all info about Hbase
  410. * @param hbaseObj
  411. */
  412. loadHbase: function (hbaseObj) {
  413. hbaseObj.service_components.forEach(function (_component) {
  414. switch (_component.display_name) {
  415. case 'Master':
  416. this.loadMasterValue(_component);
  417. break;
  418. case 'Region Servers':
  419. this.loadRegionServerValue(_component);
  420. break;
  421. default:
  422. }
  423. }, this);
  424. this.get('services').pushObject(hbaseObj);
  425. },
  426. loadMasterValue: function (hbaseMaster) {
  427. var hbaseHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HBase Master');
  428. hbaseMaster.set('component_value', hbaseHostName.hostName);
  429. },
  430. loadRegionServerValue: function (rsComponent) {
  431. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  432. var totalRsHosts = rsHosts.hosts.length;
  433. var rsHostGroups = [];
  434. rsHosts.hosts.forEach(function (_ttHost) {
  435. rsHostGroups.push(_ttHost.group);
  436. }, this);
  437. var totalGroups = rsHostGroups.uniq().length;
  438. var groupLabel;
  439. if (totalGroups == 1) {
  440. groupLabel = 'group';
  441. } else {
  442. groupLabel = 'groups';
  443. }
  444. rsComponent.set('component_value', totalRsHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  445. },
  446. /**
  447. * Load all info about ZooKeeper service
  448. * @param zkObj
  449. */
  450. loadZk: function (zkObj) {
  451. zkObj.get('service_components').forEach(function (_component) {
  452. switch (_component.get('display_name')) {
  453. case 'Servers':
  454. this.loadZkServerValue(_component);
  455. break;
  456. default:
  457. }
  458. }, this);
  459. this.get('services').pushObject(zkObj);
  460. },
  461. loadZkServerValue: function (serverComponent) {
  462. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  463. var hostSuffix;
  464. if (zkHostNames === 1) {
  465. hostSuffix = 'host';
  466. } else {
  467. hostSuffix = 'hosts';
  468. }
  469. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  470. },
  471. /**
  472. * Load all info about Oozie services
  473. * @param oozieObj
  474. */
  475. loadOozie: function (oozieObj) {
  476. oozieObj.get('service_components').forEach(function (_component) {
  477. switch (_component.get('display_name')) {
  478. case 'Server':
  479. this.loadOozieServerValue(_component);
  480. break;
  481. case 'Database':
  482. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  483. // this.loadOozieDbValue(_component);
  484. break;
  485. default:
  486. }
  487. }, this);
  488. this.get('services').pushObject(oozieObj);
  489. },
  490. loadOozieServerValue: function (oozieServer) {
  491. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  492. oozieServer.set('component_value', oozieServerName.hostName);
  493. },
  494. loadOozieDbValue: function (dbComponent) {
  495. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  496. if (oozieDb.value === 'New PostgreSQL Database') {
  497. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  498. } else {
  499. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  500. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  501. }
  502. },
  503. /**
  504. * Load all info about Nagios service
  505. * @param nagiosObj
  506. */
  507. loadNagios: function (nagiosObj) {
  508. nagiosObj.service_components.forEach(function (_component) {
  509. switch (_component.display_name) {
  510. case 'Server':
  511. this.loadNagiosServerValue(_component);
  512. break;
  513. case 'Administrator':
  514. this.loadNagiosAdminValue(_component);
  515. break;
  516. default:
  517. }
  518. }, this);
  519. this.get('services').pushObject(nagiosObj);
  520. },
  521. loadNagiosServerValue: function (nagiosServer) {
  522. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  523. nagiosServer.set('component_value', nagiosServerName.hostName);
  524. },
  525. loadNagiosAdminValue: function (nagiosAdmin) {
  526. var config = this.get('content.serviceConfigProperties');
  527. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  528. var adminEmail = config.findProperty('name', 'nagios_contact');
  529. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  530. },
  531. /**
  532. * Load all info about ganglia
  533. * @param gangliaObj
  534. */
  535. loadGanglia: function (gangliaObj) {
  536. gangliaObj.get('service_components').forEach(function (_component) {
  537. switch (_component.get('display_name')) {
  538. case 'Server':
  539. this.loadGangliaServerValue(_component);
  540. break;
  541. default:
  542. }
  543. }, this);
  544. this.get('services').pushObject(gangliaObj);
  545. },
  546. loadGangliaServerValue: function (gangliaServer) {
  547. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  548. gangliaServer.set('component_value', gangliaServerName.hostName);
  549. },
  550. /**
  551. * Onclick handler for <code>next</code> button
  552. */
  553. submit: function () {
  554. if (this.get('isSubmitDisabled')) {
  555. return;
  556. }
  557. this.set('isSubmitDisabled', true);
  558. if (App.testMode || !this.get('content.cluster.requestId')) {
  559. this.createCluster();
  560. this.createSelectedServices();
  561. this.createConfigurations();
  562. this.applyCreatedConfToServices();
  563. this.createComponents();
  564. this.registerHostsToCluster();
  565. this.createAllHostComponents();
  566. }
  567. App.router.send('next');
  568. },
  569. clusterName: function() {
  570. return this.get('content.cluster.name');
  571. }.property('content.cluster.name'),
  572. /**
  573. * The following create* functions are called upon submitting Step 8.
  574. */
  575. createCluster: function () {
  576. if (this.get('content.isWizard')) {
  577. return false;
  578. }
  579. var url = App.apiPrefix + '/clusters/' + this.get('clusterName');
  580. var stackVersion = (App.db.getSoftRepo().repoType == 'local') ? App.defaultStackVersion + '-local' : App.defaultStackVersion;
  581. $.ajax({
  582. type: 'POST',
  583. url: url,
  584. async: false,
  585. //accepts: 'text',
  586. dataType: 'text',
  587. data: JSON.stringify({ "Clusters": {"version" : stackVersion }}),
  588. timeout: App.timeout,
  589. success: function (data) {
  590. var jsonData = jQuery.parseJSON(data);
  591. console.log("TRACE: STep8 -> In success function for createCluster call");
  592. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  593. },
  594. error: function (request, ajaxOptions, error) {
  595. console.log('Step8: In Error ');
  596. console.log('Step8: Error message is: ' + request.responseText);
  597. },
  598. statusCode: require('data/statusCodes')
  599. });
  600. console.log("Exiting createCluster");
  601. },
  602. createSelectedServices: function (service, httpMethod) {
  603. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  604. var data = this.createServiceData();
  605. var httpMethod = 'POST';
  606. $.ajax({
  607. type: httpMethod,
  608. url: url,
  609. data: JSON.stringify(data),
  610. async: false,
  611. dataType: 'text',
  612. timeout: App.timeout,
  613. success: function (data) {
  614. var jsonData = jQuery.parseJSON(data);
  615. console.log("TRACE: STep8 -> In success function for the createService call");
  616. console.log("TRACE: STep8 -> value of the url is: " + url);
  617. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  618. },
  619. error: function (request, ajaxOptions, error) {
  620. console.log('Step8: In Error ');
  621. console.log('Step8: Error message is: ' + request.responseText);
  622. },
  623. statusCode: require('data/statusCodes')
  624. });
  625. },
  626. createServiceData: function () {
  627. var services = this.get('selectedServices').mapProperty('serviceName');
  628. var data = [];
  629. services.forEach(function (_service) {
  630. data.pushObject({"ServiceInfo": { "service_name": _service }});
  631. }, this);
  632. return data;
  633. },
  634. createComponents: function () {
  635. var serviceComponents = require('data/service_components');
  636. var services = this.get('selectedServices').mapProperty('serviceName');
  637. services.forEach(function (_service) {
  638. var components = serviceComponents.filterProperty('service_name', _service);
  639. var componentsData = components.map(function (_component) {
  640. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  641. });
  642. // Service must be specified in terms of a query for creating multiple components at the same time.
  643. // See AMBARI-1018.
  644. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  645. var data = {
  646. "components": componentsData
  647. }
  648. $.ajax({
  649. type: 'POST',
  650. url: url,
  651. async: false,
  652. dataType: 'text',
  653. data: JSON.stringify(data),
  654. timeout: App.timeout,
  655. success: function (data) {
  656. var jsonData = jQuery.parseJSON(data);
  657. console.log("TRACE: STep8 -> In success function for createComponent");
  658. console.log("TRACE: STep8 -> value of the url is: " + url);
  659. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  660. },
  661. error: function (request, ajaxOptions, error) {
  662. console.log('Step8: In Error ');
  663. console.log('Step8: Error message is: ' + request.responseText);
  664. },
  665. statusCode: require('data/statusCodes')
  666. });
  667. }, this);
  668. },
  669. registerHostsToCluster: function () {
  670. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  671. var data = this.createRegisterHostData();
  672. if (data.length == 0) {
  673. return;
  674. }
  675. $.ajax({
  676. type: 'POST',
  677. url: url,
  678. data: JSON.stringify(data),
  679. async: false,
  680. dataType: 'text',
  681. timeout: App.timeout,
  682. success: function (data) {
  683. var jsonData = jQuery.parseJSON(data);
  684. console.log("TRACE: STep8 -> In success function for registerHostToCluster");
  685. console.log("TRACE: STep8 -> value of the url is: " + url);
  686. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  687. },
  688. error: function (request, ajaxOptions, error) {
  689. console.log('Step8: In Error ');
  690. console.log('Step8: Error message is: ' + request.responseText);
  691. },
  692. statusCode: require('data/statusCodes')
  693. });
  694. },
  695. createRegisterHostData: function () {
  696. return this.getRegisteredHosts().map(function(host) {
  697. if (!host.isInstalled) {
  698. return {"Hosts": { "host_name": host.hostName}};
  699. }
  700. });
  701. },
  702. // TODO: review the code for add hosts / add services scenarios...
  703. createAllHostComponents: function () {
  704. var masterHosts = this.get('content.masterComponentHosts');
  705. var slaveHosts = this.get('content.slaveComponentHosts');
  706. var clients = this.get('content.clients');
  707. var clientHosts = slaveHosts.filterProperty('componentName', "CLIENT").objectAt(0).hosts;
  708. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  709. var masterComponents = masterHosts.mapProperty('component').uniq();
  710. masterComponents.forEach(function(component) {
  711. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  712. this.registerHostsToComponent(hostNames, component);
  713. }, this);
  714. slaveHosts.forEach(function (_slave) {
  715. if (_slave.componentName !== 'CLIENT') {
  716. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  717. this.registerHostsToComponent(hostNames, _slave.componentName);
  718. } else {
  719. this.get('content.clients').forEach(function (_client) {
  720. if (!_client.isInstalled) {
  721. var hostNames = clientHosts.mapProperty('hostName').splice(0);
  722. switch (_client.component_name) {
  723. case 'HDFS_CLIENT':
  724. // install HDFS_CLIENT on HBASE_MASTER and HBASE_REGIONSERVER hosts
  725. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  726. hostNames.pushObject(_masterHost.hostName);
  727. }, this);
  728. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  729. hostNames.pushObject(_masterHost.hostName);
  730. }, this);
  731. break;
  732. case 'MAPREDUCE_CLIENT':
  733. // install MAPREDUCE_CLIENT on HIVE_SERVER and OOZIE_SERVER hosts
  734. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  735. hostNames.pushObject(_masterHost.hostName);
  736. }, this);
  737. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  738. hostNames.pushObject(_masterHost.hostName);
  739. }, this);
  740. break;
  741. }
  742. hostNames = hostNames.uniq();
  743. this.registerHostsToComponent(hostNames, _client.component_name);
  744. }
  745. }, this);
  746. }
  747. }, this);
  748. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  749. if (this.get('selectedServices').someProperty('serviceName', 'GANGLIA')) {
  750. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  751. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  752. }
  753. },
  754. registerHostsToComponent: function (hostNames, componentName) {
  755. if (hostNames.length == 0) {
  756. return;
  757. }
  758. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  759. var hostsPredicate = hostNames.map(function(hostName) {
  760. return 'Hosts/host_name=' + hostName;
  761. }).join('|');
  762. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + hostsPredicate;
  763. var data = {
  764. "host_components": [{
  765. "HostRoles": {
  766. "component_name": componentName
  767. }
  768. }]
  769. };
  770. $.ajax({
  771. type: 'POST',
  772. url: url,
  773. async: false,
  774. dataType: 'text',
  775. timeout: App.timeout,
  776. data: JSON.stringify(data),
  777. success: function (data) {
  778. var jsonData = jQuery.parseJSON(data);
  779. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  780. console.log("TRACE: STep8 -> value of the url is: " + url);
  781. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  782. },
  783. error: function (request, ajaxOptions, error) {
  784. console.log('Step8: In Error ');
  785. console.log('Step8: Error message is: ' + request.responseText);
  786. },
  787. statusCode: require('data/statusCodes')
  788. });
  789. },
  790. createConfigurations: function () {
  791. var selectedServices = this.get('selectedServices');
  792. if (!this.get('content.isWizard')) {
  793. this.createConfigSite(this.createGlobalSiteObj());
  794. this.createConfigSite(this.createCoreSiteObj());
  795. this.createConfigSite(this.createHdfsSiteObj('HDFS'));
  796. }
  797. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  798. this.createConfigSite(this.createMrSiteObj('MAPREDUCE'));
  799. }
  800. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  801. this.createConfigSite(this.createHbaseSiteObj('HBASE'));
  802. }
  803. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  804. this.createConfigSite(this.createOozieSiteObj('OOZIE'));
  805. }
  806. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  807. // TODO
  808. // this.createConfigSite(this.createHiveSiteObj('HIVE'));
  809. }
  810. },
  811. createConfigSite: function (data) {
  812. console.log("Inside createConfigSite");
  813. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/configurations';
  814. $.ajax({
  815. type: 'POST',
  816. url: url,
  817. data: JSON.stringify(data),
  818. async: false,
  819. dataType: 'text',
  820. timeout: App.timeout,
  821. success: function (data) {
  822. var jsonData = jQuery.parseJSON(data);
  823. console.log("TRACE: STep8 -> In success function for the createConfigSite");
  824. console.log("TRACE: STep8 -> value of the url is: " + url);
  825. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  826. },
  827. error: function (request, ajaxOptions, error) {
  828. console.log('Step8: In Error ');
  829. console.log('Step8: Error message is: ' + request.responseText);
  830. console.log("TRACE: STep8 -> value of the url is: " + url);
  831. },
  832. statusCode: require('data/statusCodes')
  833. });
  834. console.log("Exiting createConfigSite");
  835. },
  836. createGlobalSiteObj: function () {
  837. var globalSiteProperties = {};
  838. this.get('globals').forEach(function (_globalSiteObj) {
  839. // do not pass any globals whose name ends with _host or _hosts
  840. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  841. // append "m" to JVM memory options
  842. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  843. _globalSiteObj.value += "m";
  844. }
  845. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  846. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  847. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  848. }
  849. }, this);
  850. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  851. },
  852. createCoreSiteObj: function () {
  853. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  854. var coreSiteProperties = {};
  855. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  856. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  857. coreSiteObj.forEach(function (_coreSiteObj) {
  858. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  859. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  860. }
  861. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  862. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  863. }, this);
  864. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  865. },
  866. createHdfsSiteObj: function (serviceName) {
  867. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  868. var hdfsProperties = {};
  869. hdfsSiteObj.forEach(function (_configProperty) {
  870. hdfsProperties[_configProperty.name] = _configProperty.value;
  871. console.log("STEP*: name of the property is: " + _configProperty.name);
  872. console.log("STEP8: value of the property is: " + _configProperty.value);
  873. }, this);
  874. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  875. },
  876. createMrSiteObj: function (serviceName) {
  877. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  878. var mrProperties = {};
  879. configs.forEach(function (_configProperty) {
  880. mrProperties[_configProperty.name] = _configProperty.value;
  881. console.log("STEP*: name of the property is: " + _configProperty.name);
  882. console.log("STEP8: value of the property is: " + _configProperty.value);
  883. }, this);
  884. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  885. },
  886. createHbaseSiteObj: function (serviceName) {
  887. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  888. var hbaseProperties = {};
  889. configs.forEach(function (_configProperty) {
  890. hbaseProperties[_configProperty.name] = _configProperty.value;
  891. }, this);
  892. var masterHosts = App.db.getMasterComponentHosts();
  893. // TODO: should filter on "component" but that gives unexpected results
  894. var zkServers = masterHosts.filterProperty('display_name', 'ZooKeeper').mapProperty('hostName');
  895. hbaseProperties['hbase.zookeeper.quorum'] = zkServers.join(',');
  896. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  897. },
  898. createOozieSiteObj: function (serviceName) {
  899. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  900. var oozieProperties = {};
  901. configs.forEach(function (_configProperty) {
  902. oozieProperties[_configProperty.name] = _configProperty.value;
  903. }, this);
  904. var baseUrl = oozieProperties['oozie.base.url'];
  905. oozieProperties = {
  906. "oozie.service.JPAService.jdbc.password": " ", "oozie.db.schema.name": "oozie", "oozie.service.JPAService.jdbc.url": "jdbc:derby:/var/data/oozie/oozie-db;create=true", "oozie.service.JPAService.jdbc.driver": "org.apache.derby.jdbc.EmbeddedDriver", "oozie.service.WorkflowAppService.system.libpath": "/user/oozie/share/lib", "oozie.service.JPAService.jdbc.username": "sa", "oozie.service.SchemaService.wf.ext.schemas": "shell-action-0.1.xsd,email-action-0.1.xsd,hive-action-0.2.xsd,sqoop-action-0.2.xsd,ssh-action-0.1.xsd,distcp-action-0.1.xsd", "oozie.service.JPAService.create.db.schema": "false", "use.system.libpath.for.mapreduce.and.pig.jobs": "false", "oozie.service.ActionService.executor.ext.classes": "org.apache.oozie.action.email.EmailActionExecutor,org.apache.oozie.action.hadoop.HiveActionExecutor,org.apache.oozie.action.hadoop.ShellActionExecutor,org.apache.oozie.action.hadoop.SqoopActionExecutor,org.apache.oozie.action.hadoop.DistcpActionExecutor", "oozie.service.HadoopAccessorService.hadoop.configurations": "*=/etc/hadoop/conf"
  907. };
  908. oozieProperties['oozie.base.url'] = baseUrl;
  909. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  910. },
  911. createHiveSiteObj: function (serviceName) {
  912. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  913. var hiveProperties = {};
  914. configs.forEach(function (_configProperty) {
  915. hiveProperties[_configProperty.name] = _configProperty.value;
  916. }, this);
  917. return {type: 'hbase-site', tag: 'version1', properties: hiveProperties};
  918. },
  919. applyCreatedConfToServices: function () {
  920. var services = this.get('selectedServices').mapProperty('serviceName');
  921. services.forEach(function (_service) {
  922. var data = this.getConfigForService(_service);
  923. this.applyCreatedConfToService(_service, 'PUT', data);
  924. }, this);
  925. },
  926. applyCreatedConfToService: function (service, httpMethod, data) {
  927. console.log("Inside applyCreatedConfToService");
  928. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services/' + service;
  929. $.ajax({
  930. type: httpMethod,
  931. url: url,
  932. async: false,
  933. dataType: 'text',
  934. data: JSON.stringify(data),
  935. timeout: App.timeout,
  936. success: function (data) {
  937. var jsonData = jQuery.parseJSON(data);
  938. console.log("TRACE: STep8 -> In success function for the applyCreatedConfToService call");
  939. console.log("TRACE: STep8 -> value of the url is: " + url);
  940. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  941. },
  942. error: function (request, ajaxOptions, error) {
  943. console.log('Step8: In Error ');
  944. console.log('Step8: Error message is: ' + request.responseText);
  945. },
  946. statusCode: require('data/statusCodes')
  947. });
  948. console.log("Exiting applyCreatedConfToService");
  949. },
  950. getConfigForService: function (serviceName) {
  951. switch (serviceName) {
  952. case 'HDFS':
  953. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  954. case 'MAPREDUCE':
  955. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  956. case 'HBASE':
  957. return {config: {'global': 'version1', 'core-site': 'version1', 'hbase-site': 'version1'}};
  958. case 'OOZIE':
  959. return {config: {'global': 'version1', 'core-site': 'version1', 'oozie-site': 'version1'}};
  960. default:
  961. return {config: {'global': 'version1'}};
  962. }
  963. }
  964. })