step8_controller.js 36 KB

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