step8_controller.js 35 KB

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