step8_controller.js 36 KB

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