step8_controller.js 36 KB

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