step8_controller.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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.InstallerStep8Controller = Em.ArrayController.extend({
  20. name: 'installerStep8Controller',
  21. rawContent: require('data/review_configs'),
  22. content: [],
  23. services: [],
  24. clearStep: function () {
  25. this.clear();
  26. this.get('services').clear();
  27. },
  28. loadStep: function () {
  29. console.log("TRACE: Loading step8: Review Page");
  30. this.clearStep();
  31. var configObj = new Ember.Set();
  32. this.loadClusterName();
  33. this.loadHosts();
  34. this.loadRepo();
  35. this.loadServices();
  36. },
  37. loadClusterName: function () {
  38. var obj = {};
  39. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  40. cluster.config_value = App.db.getClusterName();
  41. this.pushObject(Ember.Object.create(cluster));
  42. },
  43. loadHosts: function () {
  44. var masterHosts = App.db.getMasterComponentHosts().mapProperty('hostName').uniq();
  45. var slaveHosts = App.db.getSlaveComponentHosts();
  46. var hostObj = [];
  47. slaveHosts.forEach(function (_hosts) {
  48. hostObj = hostObj.concat(_hosts.hosts);
  49. }, this);
  50. slaveHosts = hostObj.mapProperty('hostname').uniq();
  51. console.log('The value of slaveHosts is: ' + slaveHosts);
  52. var totalHosts = masterHosts.concat(slaveHosts).uniq().length;
  53. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  54. totalHostsObj.config_value = totalHosts;
  55. this.pushObject(Ember.Object.create(totalHostsObj));
  56. },
  57. loadRepo: function () {
  58. var repoOption = App.db.getSoftRepo().repoType;
  59. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  60. if (repoOption === 'local') {
  61. repoObj.config_value = 'Yes';
  62. } else {
  63. repoObj.config_value = 'No';
  64. }
  65. this.pushObject(Ember.Object.create(repoObj));
  66. },
  67. loadServices: function () {
  68. this.set('services', App.db.getSelectedServiceNames());
  69. var services = App.db.getService().filterProperty('isSelected', true);
  70. services.forEach(function (_service) {
  71. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  72. var serviceObj = {};
  73. //var tempObj = {};
  74. var reviewService = this.rawContent.findProperty('config_name', 'services');
  75. serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  76. if (serviceObj !== undefined) {
  77. switch (serviceObj.service_name) {
  78. case 'HDFS':
  79. this.loadHDFS(serviceObj);
  80. break;
  81. case 'MAPREDUCE':
  82. this.loadMapReduce(serviceObj);
  83. break;
  84. case 'HIVE':
  85. this.loadHive(serviceObj);
  86. break;
  87. case 'HBASE':
  88. this.loadHbase(serviceObj);
  89. break;
  90. case 'ZOOKEEPER':
  91. this.loadZk(serviceObj);
  92. break;
  93. case 'OOZIE':
  94. this.loadOozie(serviceObj);
  95. break;
  96. case 'NAGIOS':
  97. this.loadNagios(serviceObj);
  98. break;
  99. case 'GANGLIA':
  100. this.loadGanglia(serviceObj);
  101. case 'HCATALOG':
  102. break;
  103. default:
  104. }
  105. }
  106. //serviceObj.displayName = tempObj.service_name;
  107. //serviceObj.componentNames = tempObj.service_components;
  108. }, this);
  109. },
  110. loadHDFS: function (hdfsObj) {
  111. hdfsObj.get('service_components').forEach(function (_component) {
  112. switch (_component.get('display_name')) {
  113. case 'NameNode':
  114. this.loadNnValue(_component);
  115. break;
  116. case 'SecondaryNameNode':
  117. this.loadSnnValue(_component);
  118. break;
  119. case 'DataNodes':
  120. this.loadDnValue(_component);
  121. break;
  122. default:
  123. }
  124. }, this);
  125. //var
  126. this.services.pushObject(hdfsObj);
  127. },
  128. loadNnValue: function (nnComponent) {
  129. var nnHostName = App.db.getMasterComponentHosts().findProperty('component', nnComponent.display_name);
  130. nnComponent.set('component_value', nnHostName.hostName);
  131. },
  132. loadSnnValue: function (snnComponent) {
  133. var snnHostName = App.db.getMasterComponentHosts().findProperty('component', 'SNameNode');
  134. snnComponent.set('component_value', snnHostName.hostName);
  135. },
  136. loadDnValue: function (dnComponent) {
  137. var dnHosts = App.db.getSlaveComponentHosts().findProperty('displayName', 'DataNode');
  138. var totalDnHosts = dnHosts.hosts.length;
  139. var dnHostGroups = [];
  140. dnHosts.hosts.forEach(function (_dnHost) {
  141. dnHostGroups.push(_dnHost.group);
  142. }, this);
  143. var totalGroups = dnHostGroups.uniq().length;
  144. var groupLabel;
  145. if (totalGroups == 1) {
  146. groupLabel = 'group';
  147. } else {
  148. groupLabel = 'groups';
  149. }
  150. dnComponent.set('component_value', totalDnHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  151. },
  152. loadMapReduce: function (mrObj) {
  153. mrObj.get('service_components').forEach(function (_component) {
  154. switch (_component.get('display_name')) {
  155. case 'JobTracker':
  156. this.loadJtValue(_component);
  157. break;
  158. case 'TaskTrackers':
  159. this.loadTtValue(_component);
  160. break;
  161. default:
  162. }
  163. }, this);
  164. this.get('services').pushObject(mrObj);
  165. },
  166. loadJtValue: function (jtComponent) {
  167. var jtHostName = App.db.getMasterComponentHosts().findProperty('component', jtComponent.display_name);
  168. jtComponent.set('component_value', jtHostName.hostName);
  169. },
  170. loadTtValue: function (ttComponent) {
  171. var ttHosts = App.db.getSlaveComponentHosts().findProperty('displayName', 'TaskTracker');
  172. var totalTtHosts = ttHosts.hosts.length;
  173. var ttHostGroups = [];
  174. ttHosts.hosts.forEach(function (_ttHost) {
  175. ttHostGroups.push(_ttHost.group);
  176. }, this);
  177. var totalGroups = ttHostGroups.uniq().length;
  178. var groupLabel;
  179. if (totalGroups == 1) {
  180. groupLabel = 'group';
  181. } else {
  182. groupLabel = 'groups';
  183. }
  184. ttComponent.set('component_value', totalTtHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  185. },
  186. loadHive: function (hiveObj) {
  187. hiveObj.get('service_components').forEach(function (_component) {
  188. switch (_component.get('display_name')) {
  189. case 'Hive Metastore Server':
  190. this.loadHiveMetaStoreValue(_component);
  191. break;
  192. case 'Database':
  193. this.loadHiveDbValue(_component);
  194. break;
  195. default:
  196. }
  197. }, this);
  198. this.get('services').pushObject(hiveObj);
  199. },
  200. loadHiveMetaStoreValue: function (metaStoreComponent) {
  201. var hiveHostName = App.db.getMasterComponentHosts().findProperty('component', 'Hive Metastore');
  202. metaStoreComponent.set('component_value', hiveHostName.hostName);
  203. },
  204. loadHiveDbValue: function (dbComponent) {
  205. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  206. if (hiveDb.value === 'New PostgreSQL Database') {
  207. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  208. } else {
  209. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  210. dbComponent.set('component_value', db.value +' (' + hiveDb.value + ')');
  211. }
  212. },
  213. loadHbase: function (hbaseObj) {
  214. hbaseObj.service_components.forEach(function (_component) {
  215. switch (_component.display_name) {
  216. case 'Master':
  217. this.loadMasterValue(_component);
  218. break;
  219. case 'Region Servers':
  220. this.loadRegionServerValue(_component);
  221. break;
  222. default:
  223. }
  224. }, this);
  225. this.get('services').pushObject(hbaseObj);
  226. },
  227. loadMasterValue: function (hbaseMaster) {
  228. var hbaseHostName = App.db.getMasterComponentHosts().findProperty('component', 'HBase Master');
  229. hbaseMaster.set('component_value', hbaseHostName.hostName);
  230. },
  231. loadRegionServerValue: function (rsComponent) {
  232. var rsHosts = App.db.getSlaveComponentHosts().findProperty('displayName', 'RegionServer');
  233. var totalRsHosts = rsHosts.hosts.length;
  234. var rsHostGroups = [];
  235. rsHosts.hosts.forEach(function (_ttHost) {
  236. rsHostGroups.push(_ttHost.group);
  237. }, this);
  238. var totalGroups = rsHostGroups.uniq().length;
  239. var groupLabel;
  240. if (totalGroups == 1) {
  241. groupLabel = 'group';
  242. } else {
  243. groupLabel = 'groups';
  244. }
  245. rsComponent.set('component_value', totalRsHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  246. },
  247. loadZk: function (zkObj) {
  248. zkObj.get('service_components').forEach(function (_component) {
  249. switch (_component.get('display_name')) {
  250. case 'Servers':
  251. this.loadZkServerValue(_component);
  252. break;
  253. default:
  254. }
  255. }, this);
  256. this.get('services').pushObject(zkObj);
  257. },
  258. loadZkServerValue: function (serverComponent) {
  259. var zkHostNames = App.db.getMasterComponentHosts().filterProperty('component', 'ZooKeeper').length;
  260. var hostSuffix;
  261. if (zkHostNames === 1) {
  262. hostSuffix = 'host';
  263. } else {
  264. hostSuffix = 'hosts';
  265. }
  266. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  267. },
  268. loadOozie: function (oozieObj) {
  269. oozieObj.get('service_components').forEach(function (_component) {
  270. switch (_component.get('display_name')) {
  271. case 'Server':
  272. this.loadOozieServerValue(_component);
  273. break;
  274. case 'Database':
  275. this.loadOozieDbValue(_component);
  276. break;
  277. default:
  278. }
  279. }, this);
  280. this.get('services').pushObject(oozieObj);
  281. },
  282. loadOozieServerValue: function (oozieServer) {
  283. var oozieServerName = App.db.getMasterComponentHosts().findProperty('component', 'Oozie Server');
  284. oozieServer.set('component_value', oozieServerName.hostName);
  285. },
  286. loadOozieDbValue: function(dbComponent) {
  287. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  288. if (oozieDb.value === 'New PostgreSQL Database') {
  289. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  290. } else {
  291. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  292. dbComponent.set('component_value', db.value +' (' + oozieDb.value + ')');
  293. }
  294. },
  295. loadNagios: function (nagiosObj) {
  296. nagiosObj.service_components.forEach(function (_component) {
  297. switch (_component.display_name) {
  298. case 'Server':
  299. this.loadNagiosServerValue(_component);
  300. break;
  301. case 'Administrator':
  302. this.loadNagiosAdminValue(_component);
  303. break;
  304. default:
  305. }
  306. }, this);
  307. this.get('services').pushObject(nagiosObj);
  308. },
  309. loadNagiosServerValue: function (nagiosServer) {
  310. var nagiosServerName = App.db.getMasterComponentHosts().findProperty('component', 'Nagios Server');
  311. nagiosServer.set('component_value', nagiosServerName.hostName);
  312. },
  313. loadNagiosAdminValue: function (nagiosAdmin) {
  314. var adminLoginName = App.db.getServiceConfigProperties().findProperty('name', 'nagios_web_login');
  315. var adminEmail = App.db.getServiceConfigProperties().findProperty('name', 'nagios_contact');
  316. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value +')');
  317. },
  318. loadGanglia: function (gangliaObj) {
  319. gangliaObj.get('service_components').forEach(function (_component) {
  320. switch (_component.get('display_name')) {
  321. case 'Server':
  322. this.loadGangliaServerValue(_component);
  323. break;
  324. default:
  325. }
  326. }, this);
  327. this.get('services').pushObject(gangliaObj);
  328. },
  329. loadGangliaServerValue: function (gangliaServer) {
  330. var gangliaServerName = App.db.getMasterComponentHosts().findProperty('component', 'Ganglia Collector');
  331. gangliaServer.set('component_value', gangliaServerName.hostName);
  332. },
  333. submit: function () {
  334. this.createCluster();
  335. this.createSelectedServices();
  336. this.createComponents();
  337. this.createHostComponents();
  338. App.router.send('next');
  339. },
  340. /* Following create* functions are called on submitting step8 */
  341. createCluster: function () {
  342. var self = this;
  343. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  344. var url = '/api/clusters/' + clusterName;
  345. $.ajax({
  346. type: 'PUT',
  347. url: url,
  348. async: false,
  349. //accepts: 'text',
  350. dataType: 'text',
  351. timeout: 5000,
  352. success: function (data) {
  353. var jsonData = jQuery.parseJSON(data);
  354. console.log("TRACE: STep8 -> In success function for createCluster call");
  355. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  356. },
  357. error: function (request, ajaxOptions, error) {
  358. console.log('Step8: In Error ');
  359. console.log('Step8: Error message is: ' + request.responseText);
  360. },
  361. statusCode: require('data/statusCodes')
  362. });
  363. },
  364. createSelectedServices: function () {
  365. var services = App.db.getSelectedServiceNames();
  366. services.forEach(function (_service) {
  367. this.createService(_service);
  368. }, this);
  369. },
  370. createService: function (service) {
  371. var self = this;
  372. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  373. var url = '/api/clusters/' + clusterName + '/services/' + service;
  374. $.ajax({
  375. type: 'PUT',
  376. url: url,
  377. async: false,
  378. dataType: 'text',
  379. timeout: 5000,
  380. success: function (data) {
  381. var jsonData = jQuery.parseJSON(data);
  382. console.log("TRACE: STep8 -> In success function for the createService call");
  383. console.log("TRACE: STep8 -> value of the url is: " + url);
  384. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  385. },
  386. error: function (request, ajaxOptions, error) {
  387. console.log('Step8: In Error ');
  388. console.log('Step8: Error message is: ' + request.responseText);
  389. },
  390. statusCode: require('data/statusCodes')
  391. });
  392. },
  393. createComponents: function () {
  394. var serviceComponents = require('data/service_components');
  395. var services = App.db.getSelectedServiceNames();
  396. services.forEach(function (_service) {
  397. var components = serviceComponents.filterProperty('service_name', _service);
  398. components.forEach(function (_component) {
  399. console.log("value of component is: " + _component.component_name);
  400. this.createComponent(_service, _component.component_name);
  401. }, this);
  402. }, this);
  403. },
  404. createComponent: function (service, component) {
  405. var self = this;
  406. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  407. var url = '/api/clusters/' + clusterName + '/services/' + service + '/components/' + component;
  408. $.ajax({
  409. type: 'PUT',
  410. url: url,
  411. async: false,
  412. dataType: 'text',
  413. timeout: 5000,
  414. success: function (data) {
  415. var jsonData = jQuery.parseJSON(data);
  416. console.log("TRACE: STep8 -> value of the url is: " + url);
  417. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  418. },
  419. error: function (request, ajaxOptions, error) {
  420. console.log('Step8: In Error ');
  421. console.log('Step8: Error message is: ' + request.responseText);
  422. },
  423. statusCode: require('data/statusCodes')
  424. });
  425. },
  426. createHostComponents: function () {
  427. var masterHosts = App.db.getMasterComponentHosts();
  428. var slaveHosts = App.db.getSlaveComponentHosts();
  429. masterHosts.forEach(function (_masterHost) {
  430. this.createHostComponent(_masterHost);
  431. }, this);
  432. slaveHosts.forEach(function (_slaveHosts) {
  433. var slaveObj = {};
  434. slaveObj.component = _slaveHosts.componentName;
  435. _slaveHosts.hosts.forEach(function (_slaveHost) {
  436. slaveObj.hostName = _slaveHost.hostname;
  437. this.createHostComponent(slaveObj);
  438. }, this);
  439. }, this);
  440. },
  441. createHostComponent: function (hostComponent) {
  442. var self = this;
  443. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  444. var url = '/api/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  445. $.ajax({
  446. type: 'PUT',
  447. url: url,
  448. async: false,
  449. dataType: 'text',
  450. timeout: 5000,
  451. success: function (data) {
  452. var jsonData = jQuery.parseJSON(data);
  453. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  454. console.log("TRACE: STep8 -> value of the url is: " + url);
  455. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  456. },
  457. error: function (request, ajaxOptions, error) {
  458. console.log('Step8: In Error ');
  459. console.log('Step8: Error message is: ' + request.responseText);
  460. },
  461. statusCode: require('data/statusCodes')
  462. });
  463. }
  464. })