step8_controller.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. dbComponent.set('component_value', 'MySQL');
  206. },
  207. loadHbase: function (hbaseObj) {
  208. hbaseObj.service_components.forEach(function (_component) {
  209. switch (_component.display_name) {
  210. case 'Master':
  211. this.loadMasterValue(_component);
  212. break;
  213. case 'Region Servers':
  214. this.loadRegionServerValue(_component);
  215. break;
  216. default:
  217. }
  218. }, this);
  219. this.get('services').pushObject(hbaseObj);
  220. },
  221. loadMasterValue: function (hbaseMaster) {
  222. var hbaseHostName = App.db.getMasterComponentHosts().findProperty('component', 'HBase Master');
  223. hbaseMaster.set('component_value', hbaseHostName.hostName);
  224. },
  225. loadRegionServerValue: function (rsComponent) {
  226. var rsHosts = App.db.getSlaveComponentHosts().findProperty('displayName', 'RegionServer');
  227. var totalRsHosts = rsHosts.hosts.length;
  228. var rsHostGroups = [];
  229. rsHosts.hosts.forEach(function (_ttHost) {
  230. rsHostGroups.push(_ttHost.group);
  231. }, this);
  232. var totalGroups = rsHostGroups.uniq().length;
  233. var groupLabel;
  234. if (totalGroups == 1) {
  235. groupLabel = 'group';
  236. } else {
  237. groupLabel = 'groups';
  238. }
  239. rsComponent.set('component_value', totalRsHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  240. },
  241. loadZk: function (zkObj) {
  242. zkObj.get('service_components').forEach(function (_component) {
  243. switch (_component.get('display_name')) {
  244. case 'Servers':
  245. this.loadZkServerValue(_component);
  246. break;
  247. default:
  248. }
  249. }, this);
  250. this.get('services').pushObject(zkObj);
  251. },
  252. loadZkServerValue: function (serverComponent) {
  253. var zkHostNames = App.db.getMasterComponentHosts().filterProperty('component', 'ZooKeeper').length;
  254. var hostSuffix;
  255. if (zkHostNames === 1) {
  256. hostSuffix = 'host';
  257. } else {
  258. hostSuffix = 'hosts';
  259. }
  260. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  261. },
  262. loadOozie: function (oozieObj) {
  263. oozieObj.get('service_components').forEach(function (_component) {
  264. switch (_component.get('display_name')) {
  265. case 'Server':
  266. this.loadOozieServerValue(_component);
  267. break;
  268. default:
  269. }
  270. }, this);
  271. this.get('services').pushObject(oozieObj);
  272. },
  273. loadOozieServerValue: function (oozieServer) {
  274. var oozieServerName = App.db.getMasterComponentHosts().findProperty('component', 'Oozie Server');
  275. oozieServer.set('component_value', oozieServerName.hostName);
  276. },
  277. loadNagios: function (nagiosObj) {
  278. nagiosObj.service_components.forEach(function (_component) {
  279. switch (_component.display_name) {
  280. case 'Server':
  281. this.loadNagiosServerValue(_component);
  282. break;
  283. case 'Administrator':
  284. this.loadNagiosAdminValue(_component);
  285. break;
  286. default:
  287. }
  288. }, this);
  289. this.get('services').pushObject(nagiosObj);
  290. },
  291. loadNagiosServerValue: function (nagiosServer) {
  292. var nagiosServerName = App.db.getMasterComponentHosts().findProperty('component', 'Nagios Server');
  293. nagiosServer.set('component_value', nagiosServerName.hostName);
  294. },
  295. loadNagiosAdminValue: function (nagiosAdmin) {
  296. var adminLoginName = App.db.getServiceConfigProperties().findProperty('name', 'nagios_web_login');
  297. var adminEmail = App.db.getServiceConfigProperties().findProperty('name', 'nagios_contact');
  298. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value +')');
  299. },
  300. loadGanglia: function (gangliaObj) {
  301. gangliaObj.get('service_components').forEach(function (_component) {
  302. switch (_component.get('display_name')) {
  303. case 'Server':
  304. this.loadGangliaServerValue(_component);
  305. break;
  306. default:
  307. }
  308. }, this);
  309. this.get('services').pushObject(gangliaObj);
  310. },
  311. loadGangliaServerValue: function (gangliaServer) {
  312. var gangliaServerName = App.db.getMasterComponentHosts().findProperty('component', 'Ganglia Collector');
  313. gangliaServer.set('component_value', gangliaServerName.hostName);
  314. },
  315. submit: function () {
  316. this.createCluster();
  317. this.createSelectedServices();
  318. this.createComponents();
  319. this.createHostComponents();
  320. App.router.send('next');
  321. },
  322. /* Following create* functions are called on submitting step8 */
  323. createCluster: function () {
  324. var self = this;
  325. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  326. var url = '/api/clusters/' + clusterName;
  327. $.ajax({
  328. type: 'PUT',
  329. url: url,
  330. async: false,
  331. //accepts: 'text',
  332. dataType: 'text',
  333. timeout: 5000,
  334. success: function (data) {
  335. var jsonData = jQuery.parseJSON(data);
  336. console.log("TRACE: STep8 -> In success function for createCluster call");
  337. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  338. },
  339. error: function (request, ajaxOptions, error) {
  340. console.log('Step8: In Error ');
  341. console.log('Step8: Error message is: ' + request.responseText);
  342. },
  343. statusCode: require('data/statusCodes')
  344. });
  345. },
  346. createSelectedServices: function () {
  347. var services = App.db.getSelectedServiceNames();
  348. services.forEach(function (_service) {
  349. this.createService(_service);
  350. }, this);
  351. },
  352. createService: function (service) {
  353. var self = this;
  354. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  355. var url = '/api/clusters/' + clusterName + '/services/' + service;
  356. $.ajax({
  357. type: 'PUT',
  358. url: url,
  359. async: false,
  360. dataType: 'text',
  361. timeout: 5000,
  362. success: function (data) {
  363. var jsonData = jQuery.parseJSON(data);
  364. console.log("TRACE: STep8 -> In success function for the createService call");
  365. console.log("TRACE: STep8 -> value of the url is: " + url);
  366. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  367. },
  368. error: function (request, ajaxOptions, error) {
  369. console.log('Step8: In Error ');
  370. console.log('Step8: Error message is: ' + request.responseText);
  371. },
  372. statusCode: require('data/statusCodes')
  373. });
  374. },
  375. createComponents: function () {
  376. var serviceComponents = require('data/service_components');
  377. var services = App.db.getSelectedServiceNames();
  378. services.forEach(function (_service) {
  379. var components = serviceComponents.filterProperty('service_name', _service);
  380. components.forEach(function (_component) {
  381. console.log("value of component is: " + _component.component_name);
  382. this.createComponent(_service, _component.component_name);
  383. }, this);
  384. }, this);
  385. },
  386. createComponent: function (service, component) {
  387. var self = this;
  388. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  389. var url = '/api/clusters/' + clusterName + '/services/' + service + '/components/' + component;
  390. $.ajax({
  391. type: 'PUT',
  392. url: url,
  393. async: false,
  394. dataType: 'text',
  395. timeout: 5000,
  396. success: function (data) {
  397. var jsonData = jQuery.parseJSON(data);
  398. console.log("TRACE: STep8 -> value of the url is: " + url);
  399. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  400. },
  401. error: function (request, ajaxOptions, error) {
  402. console.log('Step8: In Error ');
  403. console.log('Step8: Error message is: ' + request.responseText);
  404. },
  405. statusCode: require('data/statusCodes')
  406. });
  407. },
  408. createHostComponents: function () {
  409. var masterHosts = App.db.getMasterComponentHosts();
  410. var slaveHosts = App.db.getSlaveComponentHosts();
  411. masterHosts.forEach(function (_masterHost) {
  412. this.createHostComponent(_masterHost);
  413. }, this);
  414. slaveHosts.forEach(function (_slaveHosts) {
  415. var slaveObj = {};
  416. slaveObj.component = _slaveHosts.componentName;
  417. _slaveHosts.hosts.forEach(function (_slaveHost) {
  418. slaveObj.hostName = _slaveHost.hostname;
  419. this.createHostComponent(slaveObj);
  420. }, this);
  421. }, this);
  422. },
  423. createHostComponent: function (hostComponent) {
  424. var self = this;
  425. var clusterName = this.findProperty('config_name', 'cluster').config_value;
  426. var url = '/api/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  427. $.ajax({
  428. type: 'PUT',
  429. url: url,
  430. async: false,
  431. dataType: 'text',
  432. timeout: 5000,
  433. success: function (data) {
  434. var jsonData = jQuery.parseJSON(data);
  435. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  436. console.log("TRACE: STep8 -> value of the url is: " + url);
  437. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  438. },
  439. error: function (request, ajaxOptions, error) {
  440. console.log('Step8: In Error ');
  441. console.log('Step8: Error message is: ' + request.responseText);
  442. },
  443. statusCode: require('data/statusCodes')
  444. });
  445. }
  446. })