step8_controller.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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. selectedServices: function () {
  26. return this.get('content.services').filterProperty('isSelected', true);
  27. }.property('content.services').cacheable(),
  28. clearStep: function () {
  29. this.get('services').clear();
  30. this.get('clusterInfo').clear();
  31. },
  32. loadStep: function () {
  33. console.log("TRACE: Loading step8: Review Page");
  34. this.clearStep();
  35. this.loadClusterInfo();
  36. this.loadServices();
  37. },
  38. /**
  39. * Load all info about cluster to <code>clusterInfo</code> variable
  40. */
  41. loadClusterInfo: function () {
  42. // cluster name
  43. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  44. cluster.config_value = this.get('content.cluster.name');
  45. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  46. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  47. //hosts
  48. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  49. var slaveHosts = this.get('content.slaveComponentHosts');
  50. var hostObj = [];
  51. slaveHosts.forEach(function (_hosts) {
  52. hostObj = hostObj.concat(_hosts.hosts);
  53. }, this);
  54. slaveHosts = hostObj.mapProperty('hostname').uniq();
  55. var totalHosts = masterHosts.concat(slaveHosts).uniq();
  56. this.set('totalHosts',totalHosts);
  57. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  58. totalHostsObj.config_value = totalHosts.length;
  59. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  60. //repo
  61. var repoOption = this.get('content.hosts.localRepo');
  62. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  63. if (repoOption) {
  64. repoObj.config_value = 'Yes';
  65. } else {
  66. repoObj.config_value = 'No';
  67. }
  68. this.get('clusterInfo').pushObject(Ember.Object.create(repoObj));
  69. },
  70. /**
  71. * Load all info about services to <code>services</code> variable
  72. */
  73. loadServices: function () {
  74. var selectedServices = this.get('selectedServices');
  75. this.set('services', selectedServices.mapProperty('serviceName'));
  76. selectedServices.forEach(function (_service) {
  77. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  78. var reviewService = this.rawContent.findProperty('config_name', 'services');
  79. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  80. if (serviceObj) {
  81. switch (serviceObj.service_name) {
  82. case 'HDFS':
  83. this.loadHDFS(serviceObj);
  84. break;
  85. case 'MAPREDUCE':
  86. this.loadMapReduce(serviceObj);
  87. break;
  88. case 'HIVE':
  89. this.loadHive(serviceObj);
  90. break;
  91. case 'HBASE':
  92. this.loadHbase(serviceObj);
  93. break;
  94. case 'ZOOKEEPER':
  95. this.loadZk(serviceObj);
  96. break;
  97. case 'OOZIE':
  98. this.loadOozie(serviceObj);
  99. break;
  100. case 'NAGIOS':
  101. this.loadNagios(serviceObj);
  102. break;
  103. case 'GANGLIA':
  104. this.loadGanglia(serviceObj);
  105. case 'HCATALOG':
  106. break;
  107. default:
  108. }
  109. }
  110. //serviceObj.displayName = tempObj.service_name;
  111. //serviceObj.componentNames = tempObj.service_components;
  112. }, this);
  113. },
  114. /**
  115. * load all info about HDFS service
  116. * @param hdfsObj
  117. */
  118. loadHDFS: function (hdfsObj) {
  119. hdfsObj.get('service_components').forEach(function (_component) {
  120. switch (_component.get('display_name')) {
  121. case 'NameNode':
  122. this.loadNnValue(_component);
  123. break;
  124. case 'SecondaryNameNode':
  125. this.loadSnnValue(_component);
  126. break;
  127. case 'DataNodes':
  128. this.loadDnValue(_component);
  129. break;
  130. default:
  131. }
  132. }, this);
  133. //var
  134. this.get('services').pushObject(hdfsObj);
  135. },
  136. loadNnValue: function (nnComponent) {
  137. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  138. nnComponent.set('component_value', nnHostName.hostName);
  139. },
  140. loadSnnValue: function (snnComponent) {
  141. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  142. snnComponent.set('component_value', snnHostName.hostName);
  143. },
  144. loadDnValue: function (dnComponent) {
  145. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  146. var totalDnHosts = dnHosts.hosts.length;
  147. var dnHostGroups = [];
  148. dnHosts.hosts.forEach(function (_dnHost) {
  149. dnHostGroups.push(_dnHost.group);
  150. }, this);
  151. var totalGroups = dnHostGroups.uniq().length;
  152. var groupLabel;
  153. if (totalGroups == 1) {
  154. groupLabel = 'group';
  155. } else {
  156. groupLabel = 'groups';
  157. }
  158. dnComponent.set('component_value', totalDnHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  159. },
  160. /**
  161. * Load all info about mapReduce service
  162. * @param mrObj
  163. */
  164. loadMapReduce: function (mrObj) {
  165. mrObj.get('service_components').forEach(function (_component) {
  166. switch (_component.get('display_name')) {
  167. case 'JobTracker':
  168. this.loadJtValue(_component);
  169. break;
  170. case 'TaskTrackers':
  171. this.loadTtValue(_component);
  172. break;
  173. default:
  174. }
  175. }, this);
  176. this.get('services').pushObject(mrObj);
  177. },
  178. loadJtValue: function (jtComponent) {
  179. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  180. jtComponent.set('component_value', jtHostName.hostName);
  181. },
  182. loadTtValue: function (ttComponent) {
  183. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  184. var totalTtHosts = ttHosts.hosts.length;
  185. var ttHostGroups = [];
  186. ttHosts.hosts.forEach(function (_ttHost) {
  187. ttHostGroups.push(_ttHost.group);
  188. }, this);
  189. var totalGroups = ttHostGroups.uniq().length;
  190. var groupLabel;
  191. if (totalGroups == 1) {
  192. groupLabel = 'group';
  193. } else {
  194. groupLabel = 'groups';
  195. }
  196. ttComponent.set('component_value', totalTtHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  197. },
  198. /**
  199. * Load all info about Hive service
  200. * @param hiveObj
  201. */
  202. loadHive: function (hiveObj) {
  203. hiveObj.get('service_components').forEach(function (_component) {
  204. switch (_component.get('display_name')) {
  205. case 'Hive Metastore Server':
  206. this.loadHiveMetaStoreValue(_component);
  207. break;
  208. case 'Database':
  209. this.loadHiveDbValue(_component);
  210. break;
  211. default:
  212. }
  213. }, this);
  214. this.get('services').pushObject(hiveObj);
  215. },
  216. loadHiveMetaStoreValue: function (metaStoreComponent) {
  217. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hive Metastore');
  218. metaStoreComponent.set('component_value', hiveHostName.hostName);
  219. },
  220. loadHiveDbValue: function (dbComponent) {
  221. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  222. if (hiveDb.value === 'New PostgreSQL Database') {
  223. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  224. } else {
  225. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  226. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  227. }
  228. },
  229. /**
  230. * Load all info about Hbase
  231. * @param hbaseObj
  232. */
  233. loadHbase: function (hbaseObj) {
  234. hbaseObj.service_components.forEach(function (_component) {
  235. switch (_component.display_name) {
  236. case 'Master':
  237. this.loadMasterValue(_component);
  238. break;
  239. case 'Region Servers':
  240. this.loadRegionServerValue(_component);
  241. break;
  242. default:
  243. }
  244. }, this);
  245. this.get('services').pushObject(hbaseObj);
  246. },
  247. loadMasterValue: function (hbaseMaster) {
  248. var hbaseHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HBase Master');
  249. hbaseMaster.set('component_value', hbaseHostName.hostName);
  250. },
  251. loadRegionServerValue: function (rsComponent) {
  252. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  253. var totalRsHosts = rsHosts.hosts.length;
  254. var rsHostGroups = [];
  255. rsHosts.hosts.forEach(function (_ttHost) {
  256. rsHostGroups.push(_ttHost.group);
  257. }, this);
  258. var totalGroups = rsHostGroups.uniq().length;
  259. var groupLabel;
  260. if (totalGroups == 1) {
  261. groupLabel = 'group';
  262. } else {
  263. groupLabel = 'groups';
  264. }
  265. rsComponent.set('component_value', totalRsHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  266. },
  267. /**
  268. * Load all info about ZooKeeper service
  269. * @param zkObj
  270. */
  271. loadZk: function (zkObj) {
  272. zkObj.get('service_components').forEach(function (_component) {
  273. switch (_component.get('display_name')) {
  274. case 'Servers':
  275. this.loadZkServerValue(_component);
  276. break;
  277. default:
  278. }
  279. }, this);
  280. this.get('services').pushObject(zkObj);
  281. },
  282. loadZkServerValue: function (serverComponent) {
  283. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  284. var hostSuffix;
  285. if (zkHostNames === 1) {
  286. hostSuffix = 'host';
  287. } else {
  288. hostSuffix = 'hosts';
  289. }
  290. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  291. },
  292. /**
  293. * Load all info about Oozie services
  294. * @param oozieObj
  295. */
  296. loadOozie: function (oozieObj) {
  297. oozieObj.get('service_components').forEach(function (_component) {
  298. switch (_component.get('display_name')) {
  299. case 'Server':
  300. this.loadOozieServerValue(_component);
  301. break;
  302. case 'Database':
  303. this.loadOozieDbValue(_component);
  304. break;
  305. default:
  306. }
  307. }, this);
  308. this.get('services').pushObject(oozieObj);
  309. },
  310. loadOozieServerValue: function (oozieServer) {
  311. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  312. oozieServer.set('component_value', oozieServerName.hostName);
  313. },
  314. loadOozieDbValue: function (dbComponent) {
  315. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  316. if (oozieDb.value === 'New PostgreSQL Database') {
  317. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  318. } else {
  319. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  320. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  321. }
  322. },
  323. /**
  324. * Load all info about Nagios service
  325. * @param nagiosObj
  326. */
  327. loadNagios: function (nagiosObj) {
  328. nagiosObj.service_components.forEach(function (_component) {
  329. switch (_component.display_name) {
  330. case 'Server':
  331. this.loadNagiosServerValue(_component);
  332. break;
  333. case 'Administrator':
  334. this.loadNagiosAdminValue(_component);
  335. break;
  336. default:
  337. }
  338. }, this);
  339. this.get('services').pushObject(nagiosObj);
  340. },
  341. loadNagiosServerValue: function (nagiosServer) {
  342. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  343. nagiosServer.set('component_value', nagiosServerName.hostName);
  344. },
  345. loadNagiosAdminValue: function (nagiosAdmin) {
  346. var config = this.get('content.serviceConfigProperties');
  347. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  348. var adminEmail = config.findProperty('name', 'nagios_contact');
  349. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  350. },
  351. /**
  352. * Load all info about ganglia
  353. * @param gangliaObj
  354. */
  355. loadGanglia: function (gangliaObj) {
  356. gangliaObj.get('service_components').forEach(function (_component) {
  357. switch (_component.get('display_name')) {
  358. case 'Server':
  359. this.loadGangliaServerValue(_component);
  360. break;
  361. default:
  362. }
  363. }, this);
  364. this.get('services').pushObject(gangliaObj);
  365. },
  366. loadGangliaServerValue: function (gangliaServer) {
  367. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  368. gangliaServer.set('component_value', gangliaServerName.hostName);
  369. },
  370. /**
  371. * Onclick handler for <code>next</code> button
  372. */
  373. submit: function () {
  374. if (App.testMode) {
  375. App.router.send('next');
  376. return;
  377. }
  378. this.createCluster();
  379. this.createSelectedServices();
  380. this.createConfigurations();
  381. this.applyCreatedConfToServices();
  382. this.createComponents();
  383. this.registerHostsToCluster();
  384. this.createHostComponents();
  385. App.router.send('next');
  386. },
  387. /* Following create* functions are called on submitting step8 */
  388. createCluster: function () {
  389. var self = this;
  390. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  391. var url = '/api/clusters/' + clusterName;
  392. $.ajax({
  393. type: 'POST',
  394. url: url,
  395. async: false,
  396. //accepts: 'text',
  397. dataType: 'text',
  398. timeout: 5000,
  399. success: function (data) {
  400. var jsonData = jQuery.parseJSON(data);
  401. console.log("TRACE: STep8 -> In success function for createCluster call");
  402. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  403. },
  404. error: function (request, ajaxOptions, error) {
  405. console.log('Step8: In Error ');
  406. console.log('Step8: Error message is: ' + request.responseText);
  407. },
  408. statusCode: require('data/statusCodes')
  409. });
  410. console.log("Exiting createCluster");
  411. },
  412. createSelectedServices: function () {
  413. var services = this.get('selectedServices').mapProperty('serviceName');
  414. services.forEach(function (_service) {
  415. this.createService(_service, 'POST');
  416. }, this);
  417. },
  418. createService: function (service, httpMethod) {
  419. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  420. var url = '/api/clusters/' + clusterName + '/services/' + service;
  421. $.ajax({
  422. type: httpMethod,
  423. url: url,
  424. async: false,
  425. dataType: 'text',
  426. timeout: 5000,
  427. success: function (data) {
  428. var jsonData = jQuery.parseJSON(data);
  429. console.log("TRACE: STep8 -> In success function for the createService call");
  430. console.log("TRACE: STep8 -> value of the url is: " + url);
  431. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  432. },
  433. error: function (request, ajaxOptions, error) {
  434. console.log('Step8: In Error ');
  435. console.log('Step8: Error message is: ' + request.responseText);
  436. },
  437. statusCode: require('data/statusCodes')
  438. });
  439. },
  440. createComponents: function () {
  441. //TODO: Uncomment following after hooking up with all services.
  442. var serviceComponents = require('data/service_components');
  443. var services = this.get('selectedServices').mapProperty('serviceName');
  444. services.forEach(function (_service) {
  445. var components = serviceComponents.filterProperty('service_name', _service);
  446. components.forEach(function (_component) {
  447. console.log("value of component is: " + _component.component_name);
  448. // TODO: Skipping CLIENT components as we have issues on the server side for integration purposes
  449. if (!_component.component_name.match(/CLIENT$/)) {
  450. this.createComponent(_service, _component.component_name);
  451. }
  452. }, this);
  453. }, this);
  454. //TODO: Remove below code after hooking up with all services.
  455. /* this.createComponent('HDFS','NAMENODE');
  456. this.createComponent('HDFS','DATANODE'); */
  457. },
  458. createComponent: function (service, component) {
  459. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  460. var url = '/api/clusters/' + clusterName + '/services/' + service + '/components/' + component;
  461. $.ajax({
  462. type: 'POST',
  463. url: url,
  464. async: false,
  465. dataType: 'text',
  466. timeout: 5000,
  467. success: function (data) {
  468. var jsonData = jQuery.parseJSON(data);
  469. console.log("TRACE: STep8 -> In success function for createComponent");
  470. console.log("TRACE: STep8 -> value of the url is: " + url);
  471. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  472. },
  473. error: function (request, ajaxOptions, error) {
  474. console.log('Step8: In Error ');
  475. console.log('Step8: Error message is: ' + request.responseText);
  476. },
  477. statusCode: require('data/statusCodes')
  478. });
  479. },
  480. registerHostsToCluster: function() {
  481. this.get('totalHosts').forEach(function(_hostname){
  482. this.registerHostToCluster(_hostname);
  483. },this);
  484. },
  485. registerHostToCluster: function(hostname) {
  486. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  487. var url = '/api/clusters/' + clusterName + '/hosts/' + hostname;
  488. $.ajax({
  489. type: 'POST',
  490. url: url,
  491. async: false,
  492. dataType: 'text',
  493. timeout: 5000,
  494. success: function (data) {
  495. var jsonData = jQuery.parseJSON(data);
  496. console.log("TRACE: STep8 -> In success function for registerHostToCluster");
  497. console.log("TRACE: STep8 -> value of the url is: " + url);
  498. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  499. },
  500. error: function (request, ajaxOptions, error) {
  501. console.log('Step8: In Error ');
  502. console.log('Step8: Error message is: ' + request.responseText);
  503. },
  504. statusCode: require('data/statusCodes')
  505. });
  506. },
  507. createHostComponents: function () {
  508. //TODO: Uncomment following after hooking up with all services.
  509. var masterHosts = this.get('content.masterComponentHosts');
  510. var slaveHosts = this.get('content.slaveComponentHosts');
  511. masterHosts.forEach(function (_masterHost) {
  512. this.createHostComponent(_masterHost);
  513. }, this);
  514. slaveHosts.forEach(function (_slaveHosts) {
  515. var slaveObj = {};
  516. if (_slaveHosts.componentName !== 'CLIENT') {
  517. slaveObj.component = _slaveHosts.componentName;
  518. _slaveHosts.hosts.forEach(function (_slaveHost) {
  519. slaveObj.hostName = _slaveHost.hostname;
  520. this.createHostComponent(slaveObj);
  521. }, this);
  522. } else {
  523. this.get('content.clients').forEach(function (_client) {
  524. slaveObj.component = _client.component_name;
  525. _slaveHosts.hosts.forEach(function (_slaveHost) {
  526. slaveObj.hostName = _slaveHost.hostname;
  527. // TODO: Skip creation of clients for integration purposes
  528. // this.createHostComponent(slaveObj);
  529. }, this);
  530. }, this);
  531. }
  532. }, this);
  533. //TODO: Remove following code after hooking up with all services
  534. //this.createHostComponent({hostName:'localhost.localdomain',component:'NAMENODE'});
  535. //this.createHostComponent({hostName:'localhost.localdomain',component:'DATANODE'});
  536. },
  537. createHostComponent: function (hostComponent) {
  538. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  539. var url = '/api/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  540. $.ajax({
  541. type: 'POST',
  542. url: url,
  543. async: false,
  544. dataType: 'text',
  545. timeout: 5000,
  546. success: function (data) {
  547. var jsonData = jQuery.parseJSON(data);
  548. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  549. console.log("TRACE: STep8 -> value of the url is: " + url);
  550. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  551. },
  552. error: function (request, ajaxOptions, error) {
  553. console.log('Step8: In Error ');
  554. console.log('Step8: Error message is: ' + request.responseText);
  555. },
  556. statusCode: require('data/statusCodes')
  557. });
  558. },
  559. createConfigurations: function () {
  560. var selectedServices = this.get('selectedServices');
  561. this.createConfigSite(this.createCoreSiteObj());
  562. this.createConfigSite(this.createHdfsSiteObj('HDFS'));
  563. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  564. this.createConfigSite(this.createMrSiteObj('MAPREDUCE'));
  565. }
  566. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  567. this.createConfigSite(this.createHbaseSiteObj('HBASE'));
  568. }
  569. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  570. this.createConfigSite(this.createHiveSiteObj('HIVE'));
  571. }
  572. },
  573. createConfigSite: function (data) {
  574. console.log("Inside createConfigSite");
  575. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  576. var url = '/api/clusters/' + clusterName + '/configurations';
  577. $.ajax({
  578. type: 'POST',
  579. url: url,
  580. data: JSON.stringify(data),
  581. async: false,
  582. dataType: 'text',
  583. timeout: 5000,
  584. success: function (data) {
  585. var jsonData = jQuery.parseJSON(data);
  586. console.log("TRACE: STep8 -> In success function for the createConfigSite");
  587. console.log("TRACE: STep8 -> value of the url is: " + url);
  588. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  589. },
  590. error: function (request, ajaxOptions, error) {
  591. console.log('Step8: In Error ');
  592. console.log('Step8: Error message is: ' + request.responseText);
  593. console.log("TRACE: STep8 -> value of the url is: " + url);
  594. },
  595. statusCode: require('data/statusCodes')
  596. });
  597. console.log("Exiting createConfigSite");
  598. },
  599. createCoreSiteObj: function () {
  600. return {"type": "core-site", "tag": "version1", "properties": { "fs.default.name": "localhost:8020"}};
  601. },
  602. createHdfsSiteObj: function (serviceName) {
  603. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  604. var hdfsProperties = {};
  605. configs.forEach(function (_configProperty) {
  606. hdfsProperties[_configProperty.name] = _configProperty.value;
  607. }, this);
  608. // TODO: Using hardcoded params until meta data API becomes available
  609. hdfsProperties = {"dfs.datanode.data.dir.perm": "750"};
  610. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  611. },
  612. createMrSiteObj: function (serviceName) {
  613. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  614. var mrProperties = {};
  615. configs.forEach(function (_configProperty) {
  616. mrProperties[_configProperty.name] = _configProperty.value;
  617. }, this);
  618. // TODO: Using hardcoded params until meta data API becomes available
  619. mrProperties = {
  620. "mapred.job.tracker": "localhost:50300",
  621. "mapreduce.history.server.embedded": "false",
  622. "mapreduce.history.server.http.address": "localhost:51111"
  623. };
  624. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  625. },
  626. createHbaseSiteObj: function (serviceName) {
  627. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  628. var hbaseProperties = {};
  629. configs.forEach(function (_configProperty) {
  630. hbaseProperties[_configProperty.name] = _configProperty.value;
  631. }, this);
  632. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  633. },
  634. createHiveSiteObj: function (serviceName) {
  635. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  636. var hiveProperties = {};
  637. configs.forEach(function (_configProperty) {
  638. hiveProperties[_configProperty.name] = _configProperty.value;
  639. }, this);
  640. return {type: 'hbase-site', tag: 'version1', properties: hiveProperties};
  641. },
  642. applyCreatedConfToServices: function () {
  643. var services = this.get('selectedServices').mapProperty('serviceName');
  644. services.forEach(function (_service) {
  645. var data = this.getConfigForService(_service);
  646. this.applyCreatedConfToService(_service, 'PUT', data);
  647. }, this);
  648. },
  649. applyCreatedConfToService: function (service, httpMethod, data) {
  650. console.log("Inside applyCreatedConfToService");
  651. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  652. var url = '/api/clusters/' + clusterName + '/services/' + service;
  653. debugger;
  654. $.ajax({
  655. type: httpMethod,
  656. url: url,
  657. async: false,
  658. dataType: 'text',
  659. data: JSON.stringify(data),
  660. timeout: 5000,
  661. success: function (data) {
  662. var jsonData = jQuery.parseJSON(data);
  663. console.log("TRACE: STep8 -> In success function for the applyCreatedConfToService call");
  664. console.log("TRACE: STep8 -> value of the url is: " + url);
  665. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  666. },
  667. error: function (request, ajaxOptions, error) {
  668. console.log('Step8: In Error ');
  669. console.log('Step8: Error message is: ' + request.responseText);
  670. },
  671. statusCode: require('data/statusCodes')
  672. });
  673. console.log("Exiting applyCreatedConfToService");
  674. },
  675. getConfigForService: function (serviceName) {
  676. switch (serviceName) {
  677. case 'HDFS':
  678. return {config: {'core-site': 'version1', 'hdfs-site': 'version1'}};
  679. case 'MAPREDUCE':
  680. return {config: {'core-site': 'version1', 'mapred-site': 'version1'}};
  681. }
  682. }
  683. })