step8_controller.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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. this.createComponent(_service, _component.component_name);
  449. }, this);
  450. }, this);
  451. //TODO: Remove below code after hooking up with all services.
  452. /* this.createComponent('HDFS','NAMENODE');
  453. this.createComponent('HDFS','DATANODE'); */
  454. },
  455. createComponent: function (service, component) {
  456. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  457. var url = '/api/clusters/' + clusterName + '/services/' + service + '/components/' + component;
  458. $.ajax({
  459. type: 'POST',
  460. url: url,
  461. async: false,
  462. dataType: 'text',
  463. timeout: 5000,
  464. success: function (data) {
  465. var jsonData = jQuery.parseJSON(data);
  466. console.log("TRACE: STep8 -> In success function for createComponent");
  467. console.log("TRACE: STep8 -> value of the url is: " + url);
  468. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  469. },
  470. error: function (request, ajaxOptions, error) {
  471. console.log('Step8: In Error ');
  472. console.log('Step8: Error message is: ' + request.responseText);
  473. },
  474. statusCode: require('data/statusCodes')
  475. });
  476. },
  477. registerHostsToCluster: function() {
  478. this.get('totalHosts').forEach(function(_hostname){
  479. this.registerHostToCluster(_hostname);
  480. },this);
  481. },
  482. registerHostToCluster: function(hostname) {
  483. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  484. var url = '/api/clusters/' + clusterName + '/hosts/' + hostname;
  485. $.ajax({
  486. type: 'POST',
  487. url: url,
  488. async: false,
  489. dataType: 'text',
  490. timeout: 5000,
  491. success: function (data) {
  492. var jsonData = jQuery.parseJSON(data);
  493. console.log("TRACE: STep8 -> In success function for registerHostToCluster");
  494. console.log("TRACE: STep8 -> value of the url is: " + url);
  495. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  496. },
  497. error: function (request, ajaxOptions, error) {
  498. console.log('Step8: In Error ');
  499. console.log('Step8: Error message is: ' + request.responseText);
  500. },
  501. statusCode: require('data/statusCodes')
  502. });
  503. },
  504. createHostComponents: function () {
  505. //TODO: Uncomment following after hooking up with all services.
  506. var masterHosts = this.get('content.masterComponentHosts');
  507. var slaveHosts = this.get('content.slaveComponentHosts');
  508. masterHosts.forEach(function (_masterHost) {
  509. this.createHostComponent(_masterHost);
  510. }, this);
  511. slaveHosts.forEach(function (_slaveHosts) {
  512. var slaveObj = {};
  513. if (_slaveHosts.componentName !== 'CLIENT') {
  514. slaveObj.component = _slaveHosts.componentName;
  515. _slaveHosts.hosts.forEach(function (_slaveHost) {
  516. slaveObj.hostName = _slaveHost.hostname;
  517. this.createHostComponent(slaveObj);
  518. }, this);
  519. } else {
  520. this.get('content.clients').forEach(function (_client) {
  521. slaveObj.component = _client.component_name;
  522. _slaveHosts.hosts.forEach(function (_slaveHost) {
  523. slaveObj.hostName = _slaveHost.hostname;
  524. this.createHostComponent(slaveObj);
  525. }, this);
  526. }, this);
  527. }
  528. }, this);
  529. //TODO: Remove following code after hooking up with all services
  530. //this.createHostComponent({hostName:'localhost.localdomain',component:'NAMENODE'});
  531. //this.createHostComponent({hostName:'localhost.localdomain',component:'DATANODE'});
  532. },
  533. createHostComponent: function (hostComponent) {
  534. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  535. var url = '/api/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  536. $.ajax({
  537. type: 'POST',
  538. url: url,
  539. async: false,
  540. dataType: 'text',
  541. timeout: 5000,
  542. success: function (data) {
  543. var jsonData = jQuery.parseJSON(data);
  544. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  545. console.log("TRACE: STep8 -> value of the url is: " + url);
  546. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  547. },
  548. error: function (request, ajaxOptions, error) {
  549. console.log('Step8: In Error ');
  550. console.log('Step8: Error message is: ' + request.responseText);
  551. },
  552. statusCode: require('data/statusCodes')
  553. });
  554. },
  555. createConfigurations: function () {
  556. var selectedServices = this.get('selectedServices');
  557. this.createConfigSite(this.createCoreSiteObj());
  558. this.createConfigSite(this.createHdfsSiteObj('HDFS'));
  559. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  560. this.createConfigSite(this.createMrSiteObj('MAPREDUCE'));
  561. }
  562. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  563. this.createConfigSite(this.createHbaseSiteObj('HBASE'));
  564. }
  565. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  566. this.createConfigSite(this.createHiveSiteObj('HIVE'));
  567. }
  568. },
  569. createConfigSite: function (data) {
  570. console.log("Inside createConfigSite");
  571. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  572. var url = '/api/clusters/' + clusterName + '/configurations';
  573. $.ajax({
  574. type: 'POST',
  575. url: url,
  576. data: data,
  577. async: false,
  578. dataType: 'text',
  579. timeout: 5000,
  580. success: function (data) {
  581. var jsonData = jQuery.parseJSON(data);
  582. console.log("TRACE: STep8 -> In success function for the createConfigSite");
  583. console.log("TRACE: STep8 -> value of the url is: " + url);
  584. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  585. },
  586. error: function (request, ajaxOptions, error) {
  587. console.log('Step8: In Error ');
  588. console.log('Step8: Error message is: ' + request.responseText);
  589. console.log("TRACE: STep8 -> value of the url is: " + url);
  590. },
  591. statusCode: require('data/statusCodes')
  592. });
  593. console.log("Exiting createConfigSite");
  594. },
  595. createCoreSiteObj: function () {
  596. return '{"type": "core-site", "tag": "version1", "properties": { "fs.default.name": "localhost:8020"}}';
  597. },
  598. createHdfsSiteObj: function (serviceName) {
  599. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  600. var hdfsProperties = {};
  601. configs.forEach(function (_configProperty) {
  602. hdfsProperties[_configProperty.name] = _configProperty.value;
  603. }, this);
  604. hdfsProperties = {"dfs.datanode.data.dir.perm": "750"};
  605. return '{"type": "hdfs-site", "tag": "version1", "properties":' + JSON.stringify(hdfsProperties) + '}';
  606. },
  607. createMrSiteObj: function (serviceName) {
  608. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  609. var mrProperties = {};
  610. configs.forEach(function (_configProperty) {
  611. mrProperties[_configProperty.name] = _configProperty.value;
  612. }, this);
  613. return{type: 'mapred-site', tag: 'version1', properties: mrProperties};
  614. },
  615. createHbaseSiteObj: function (serviceName) {
  616. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  617. var hbaseProperties = {};
  618. configs.forEach(function (_configProperty) {
  619. hbaseProperties[_configProperty.name] = _configProperty.value;
  620. }, this);
  621. return{type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  622. },
  623. createHiveSiteObj: function (serviceName) {
  624. var configs = App.db.getServiceConfigProperties().filterProperty('serviceName', serviceName);
  625. var hiveProperties = {};
  626. configs.forEach(function (_configProperty) {
  627. hiveProperties[_configProperty.name] = _configProperty.value;
  628. }, this);
  629. return{type: 'hbase-site', tag: 'version1', properties: hiveProperties};
  630. },
  631. applyCreatedConfToServices: function () {
  632. var services = this.get('selectedServices').mapProperty('serviceName');
  633. services.forEach(function (_service) {
  634. var data = this.getConfigForService(_service);
  635. this.applyCreatedConfToService(_service, 'PUT', data);
  636. }, this);
  637. },
  638. applyCreatedConfToService: function (service, httpMethod, data) {
  639. console.log("Inside applyCreatedConfToService");
  640. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  641. var url = '/api/clusters/' + clusterName + '/services/' + service;
  642. debugger;
  643. $.ajax({
  644. type: httpMethod,
  645. url: url,
  646. async: false,
  647. dataType: 'text',
  648. data: JSON.stringify(data),
  649. timeout: 5000,
  650. success: function (data) {
  651. var jsonData = jQuery.parseJSON(data);
  652. console.log("TRACE: STep8 -> In success function for the applyCreatedConfToService call");
  653. console.log("TRACE: STep8 -> value of the url is: " + url);
  654. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  655. },
  656. error: function (request, ajaxOptions, error) {
  657. console.log('Step8: In Error ');
  658. console.log('Step8: Error message is: ' + request.responseText);
  659. },
  660. statusCode: require('data/statusCodes')
  661. });
  662. console.log("Exiting applyCreatedConfToService");
  663. },
  664. getConfigForService: function (serviceName) {
  665. switch (serviceName) {
  666. case 'HDFS':
  667. return {config: {'core-site': 'version1', 'hdfs-site': 'version1'}};
  668. case 'MAPREDUCE':
  669. return {config: {'core-site': 'version1', 'mapred-site': 'version1'}};
  670. }
  671. }
  672. })