step8_controller.js 35 KB

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