step8_controller.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. break;
  274. case 'HCATALOG':
  275. break;
  276. default:
  277. }
  278. }
  279. }, this);
  280. },
  281. /**
  282. * load all info about HDFS service
  283. * @param hdfsObj
  284. */
  285. loadHDFS: function (hdfsObj) {
  286. hdfsObj.get('service_components').forEach(function (_component) {
  287. switch (_component.get('display_name')) {
  288. case 'NameNode':
  289. this.loadNnValue(_component);
  290. break;
  291. case 'SecondaryNameNode':
  292. this.loadSnnValue(_component);
  293. break;
  294. case 'DataNodes':
  295. this.loadDnValue(_component);
  296. break;
  297. default:
  298. }
  299. }, this);
  300. //var
  301. this.get('services').pushObject(hdfsObj);
  302. },
  303. loadNnValue: function (nnComponent) {
  304. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  305. nnComponent.set('component_value', nnHostName.hostName);
  306. },
  307. loadSnnValue: function (snnComponent) {
  308. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  309. snnComponent.set('component_value', snnHostName.hostName);
  310. },
  311. loadDnValue: function (dnComponent) {
  312. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  313. var totalDnHosts = dnHosts.hosts.length;
  314. var dnHostGroups = [];
  315. dnHosts.hosts.forEach(function (_dnHost) {
  316. dnHostGroups.push(_dnHost.group);
  317. }, this);
  318. var totalGroups = dnHostGroups.uniq().length;
  319. var groupLabel;
  320. if (totalGroups == 1) {
  321. groupLabel = 'group';
  322. } else {
  323. groupLabel = 'groups';
  324. }
  325. dnComponent.set('component_value', totalDnHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  326. },
  327. /**
  328. * Load all info about mapReduce service
  329. * @param mrObj
  330. */
  331. loadMapReduce: function (mrObj) {
  332. mrObj.get('service_components').forEach(function (_component) {
  333. switch (_component.get('display_name')) {
  334. case 'JobTracker':
  335. this.loadJtValue(_component);
  336. break;
  337. case 'TaskTrackers':
  338. this.loadTtValue(_component);
  339. break;
  340. default:
  341. }
  342. }, this);
  343. this.get('services').pushObject(mrObj);
  344. },
  345. loadJtValue: function (jtComponent) {
  346. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  347. jtComponent.set('component_value', jtHostName.hostName);
  348. },
  349. loadTtValue: function (ttComponent) {
  350. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  351. var totalTtHosts = ttHosts.hosts.length;
  352. var ttHostGroups = [];
  353. ttHosts.hosts.forEach(function (_ttHost) {
  354. ttHostGroups.push(_ttHost.group);
  355. }, this);
  356. var totalGroups = ttHostGroups.uniq().length;
  357. var groupLabel;
  358. if (totalGroups == 1) {
  359. groupLabel = 'group';
  360. } else {
  361. groupLabel = 'groups';
  362. }
  363. ttComponent.set('component_value', totalTtHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  364. },
  365. /**
  366. * Load all info about Hive service
  367. * @param hiveObj
  368. */
  369. loadHive: function (hiveObj) {
  370. hiveObj.get('service_components').forEach(function (_component) {
  371. switch (_component.get('display_name')) {
  372. case 'Hive Metastore Server':
  373. this.loadHiveMetaStoreValue(_component);
  374. break;
  375. case 'Database':
  376. this.loadHiveDbValue(_component);
  377. break;
  378. default:
  379. }
  380. }, this);
  381. this.get('services').pushObject(hiveObj);
  382. },
  383. loadHiveMetaStoreValue: function (metaStoreComponent) {
  384. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hive Metastore');
  385. metaStoreComponent.set('component_value', hiveHostName.hostName);
  386. },
  387. loadHiveDbValue: function (dbComponent) {
  388. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  389. if (hiveDb.value === 'New PostgreSQL Database') {
  390. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  391. } else {
  392. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  393. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  394. }
  395. },
  396. /**
  397. * Load all info about Hbase
  398. * @param hbaseObj
  399. */
  400. loadHbase: function (hbaseObj) {
  401. hbaseObj.service_components.forEach(function (_component) {
  402. switch (_component.display_name) {
  403. case 'Master':
  404. this.loadMasterValue(_component);
  405. break;
  406. case 'Region Servers':
  407. this.loadRegionServerValue(_component);
  408. break;
  409. default:
  410. }
  411. }, this);
  412. this.get('services').pushObject(hbaseObj);
  413. },
  414. loadMasterValue: function (hbaseMaster) {
  415. var hbaseHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HBase Master');
  416. hbaseMaster.set('component_value', hbaseHostName.hostName);
  417. },
  418. loadRegionServerValue: function (rsComponent) {
  419. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  420. var totalRsHosts = rsHosts.hosts.length;
  421. var rsHostGroups = [];
  422. rsHosts.hosts.forEach(function (_ttHost) {
  423. rsHostGroups.push(_ttHost.group);
  424. }, this);
  425. var totalGroups = rsHostGroups.uniq().length;
  426. var groupLabel;
  427. if (totalGroups == 1) {
  428. groupLabel = 'group';
  429. } else {
  430. groupLabel = 'groups';
  431. }
  432. rsComponent.set('component_value', totalRsHosts + ' hosts ' + '(' + totalGroups + ' ' + groupLabel + ')');
  433. },
  434. /**
  435. * Load all info about ZooKeeper service
  436. * @param zkObj
  437. */
  438. loadZk: function (zkObj) {
  439. zkObj.get('service_components').forEach(function (_component) {
  440. switch (_component.get('display_name')) {
  441. case 'Servers':
  442. this.loadZkServerValue(_component);
  443. break;
  444. default:
  445. }
  446. }, this);
  447. this.get('services').pushObject(zkObj);
  448. },
  449. loadZkServerValue: function (serverComponent) {
  450. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  451. var hostSuffix;
  452. if (zkHostNames === 1) {
  453. hostSuffix = 'host';
  454. } else {
  455. hostSuffix = 'hosts';
  456. }
  457. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  458. },
  459. /**
  460. * Load all info about Oozie services
  461. * @param oozieObj
  462. */
  463. loadOozie: function (oozieObj) {
  464. oozieObj.get('service_components').forEach(function (_component) {
  465. switch (_component.get('display_name')) {
  466. case 'Server':
  467. this.loadOozieServerValue(_component);
  468. break;
  469. case 'Database':
  470. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  471. // this.loadOozieDbValue(_component);
  472. break;
  473. default:
  474. }
  475. }, this);
  476. this.get('services').pushObject(oozieObj);
  477. },
  478. loadOozieServerValue: function (oozieServer) {
  479. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  480. oozieServer.set('component_value', oozieServerName.hostName);
  481. },
  482. loadOozieDbValue: function (dbComponent) {
  483. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  484. if (oozieDb.value === 'New PostgreSQL Database') {
  485. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  486. } else {
  487. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  488. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  489. }
  490. },
  491. /**
  492. * Load all info about Nagios service
  493. * @param nagiosObj
  494. */
  495. loadNagios: function (nagiosObj) {
  496. nagiosObj.service_components.forEach(function (_component) {
  497. switch (_component.display_name) {
  498. case 'Server':
  499. this.loadNagiosServerValue(_component);
  500. break;
  501. case 'Administrator':
  502. this.loadNagiosAdminValue(_component);
  503. break;
  504. default:
  505. }
  506. }, this);
  507. this.get('services').pushObject(nagiosObj);
  508. },
  509. loadNagiosServerValue: function (nagiosServer) {
  510. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  511. nagiosServer.set('component_value', nagiosServerName.hostName);
  512. },
  513. loadNagiosAdminValue: function (nagiosAdmin) {
  514. var config = this.get('content.serviceConfigProperties');
  515. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  516. var adminEmail = config.findProperty('name', 'nagios_contact');
  517. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  518. },
  519. /**
  520. * Load all info about ganglia
  521. * @param gangliaObj
  522. */
  523. loadGanglia: function (gangliaObj) {
  524. gangliaObj.get('service_components').forEach(function (_component) {
  525. switch (_component.get('display_name')) {
  526. case 'Server':
  527. this.loadGangliaServerValue(_component);
  528. break;
  529. default:
  530. }
  531. }, this);
  532. this.get('services').pushObject(gangliaObj);
  533. },
  534. loadGangliaServerValue: function (gangliaServer) {
  535. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  536. gangliaServer.set('component_value', gangliaServerName.hostName);
  537. },
  538. /**
  539. * Onclick handler for <code>next</code> button
  540. */
  541. submit: function () {
  542. if (App.testMode) {
  543. // App.router.send('next');
  544. //return;
  545. }
  546. if(!this.get('content.cluster.requestId')){
  547. this.createCluster();
  548. this.createSelectedServices();
  549. this.createConfigurations();
  550. this.applyCreatedConfToServices();
  551. this.createComponents();
  552. this.registerHostsToCluster();
  553. this.createHostComponents();
  554. }
  555. App.router.send('next');
  556. },
  557. /* Following create* functions are called on submitting step8 */
  558. createCluster: function () {
  559. if (this.get('content.isWizard')){
  560. return false;
  561. }
  562. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  563. var url = App.apiPrefix + '/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: App.timeout,
  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 = App.apiPrefix + '/clusters/' + clusterName + '/services/' + service;
  594. $.ajax({
  595. type: httpMethod,
  596. url: url,
  597. async: false,
  598. dataType: 'text',
  599. timeout: App.timeout,
  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. var serviceComponents = require('data/service_components');
  615. var services = this.get('selectedServices').mapProperty('serviceName');
  616. services.forEach(function (_service) {
  617. var components = serviceComponents.filterProperty('service_name', _service);
  618. components.forEach(function (_component) {
  619. this.createComponent(_service, _component.component_name);
  620. }, this);
  621. }, this);
  622. },
  623. createComponent: function (service, component) {
  624. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  625. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + service + '/components/' + component;
  626. $.ajax({
  627. type: 'POST',
  628. url: url,
  629. async: false,
  630. dataType: 'text',
  631. timeout: App.timeout,
  632. success: function (data) {
  633. var jsonData = jQuery.parseJSON(data);
  634. console.log("TRACE: STep8 -> In success function for createComponent");
  635. console.log("TRACE: STep8 -> value of the url is: " + url);
  636. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  637. },
  638. error: function (request, ajaxOptions, error) {
  639. console.log('Step8: In Error ');
  640. console.log('Step8: Error message is: ' + request.responseText);
  641. },
  642. statusCode: require('data/statusCodes')
  643. });
  644. },
  645. registerHostsToCluster: function() {
  646. var allHosts = this.get('content.hostsInfo');
  647. for(var hostName in allHosts){
  648. if(!allHosts[hostName].isInstalled){
  649. this.registerHostToCluster(hostName);
  650. }
  651. }
  652. },
  653. registerHostToCluster: function (hostName) {
  654. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  655. var url = App.apiPrefix + '/clusters/' + clusterName + '/hosts/' + hostName;
  656. $.ajax({
  657. type: 'POST',
  658. url: url,
  659. async: false,
  660. dataType: 'text',
  661. timeout: App.timeout,
  662. success: function (data) {
  663. var jsonData = jQuery.parseJSON(data);
  664. console.log("TRACE: STep8 -> In success function for registerHostToCluster");
  665. console.log("TRACE: STep8 -> value of the url is: " + url);
  666. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  667. },
  668. error: function (request, ajaxOptions, error) {
  669. console.log('Step8: In Error ');
  670. console.log('Step8: Error message is: ' + request.responseText);
  671. },
  672. statusCode: require('data/statusCodes')
  673. });
  674. },
  675. createHostComponents: function () {
  676. //TODO: Uncomment following after hooking up with all services.
  677. var masterHosts = this.get('content.masterComponentHosts');
  678. var slaveHosts = this.get('content.slaveComponentHosts');
  679. var clients = this.get('content.clients');
  680. var allHosts = this.get('content.hostsInfo');
  681. masterHosts.forEach(function (_masterHost) {
  682. this.createHostComponent(_masterHost);
  683. }, this);
  684. slaveHosts.forEach(function (_slaveHosts) {
  685. var slaveObj = {};
  686. if (_slaveHosts.componentName !== 'CLIENT') {
  687. slaveObj.component = _slaveHosts.componentName;
  688. _slaveHosts.hosts.forEach(function (_slaveHost) {
  689. slaveObj.hostName = _slaveHost.hostName;
  690. slaveObj.isInstalled = _slaveHost.isInstalled;
  691. this.createHostComponent(slaveObj);
  692. }, this);
  693. } else {
  694. //: todo
  695. this.get('content.clients').forEach(function (_client) {
  696. slaveObj.component = _client.component_name;
  697. _slaveHosts.hosts.forEach(function (_slaveHost) {
  698. slaveObj.hostName = _slaveHost.hostName;
  699. slaveObj.isInstalled = _slaveHost.isInstalled && _client.isInstalled;
  700. this.createHostComponent(slaveObj);
  701. }, this);
  702. }, this);
  703. }
  704. }, this);
  705. // add Ganglia Monitor (Slave) to all hosts
  706. for (var hostName in allHosts) {
  707. // TODO: filter for only confirmed hosts?
  708. this.createHostComponent({ hostName: hostName, component: 'GANGLIA_MONITOR'});
  709. }
  710. },
  711. createHostComponent: function (hostComponent) {
  712. console.log('try to install', hostComponent.component, 'on host', hostComponent.hostName, 'isInstalled', hostComponent.isInstalled);
  713. if (hostComponent.isInstalled) {
  714. return false;
  715. }
  716. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  717. var url = App.apiPrefix + '/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  718. $.ajax({
  719. type: 'POST',
  720. url: url,
  721. async: false,
  722. dataType: 'text',
  723. timeout: App.timeout,
  724. success: function (data) {
  725. var jsonData = jQuery.parseJSON(data);
  726. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  727. console.log("TRACE: STep8 -> value of the url is: " + url);
  728. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  729. },
  730. error: function (request, ajaxOptions, error) {
  731. console.log('Step8: In Error ');
  732. console.log('Step8: Error message is: ' + request.responseText);
  733. },
  734. statusCode: require('data/statusCodes')
  735. });
  736. },
  737. createConfigurations: function () {
  738. var selectedServices = this.get('selectedServices');
  739. if (!this.get('content.isWizard')){
  740. this.createConfigSite(this.createGlobalSiteObj());
  741. this.createConfigSite(this.createCoreSiteObj());
  742. this.createConfigSite(this.createHdfsSiteObj('HDFS'));
  743. }
  744. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  745. this.createConfigSite(this.createMrSiteObj('MAPREDUCE'));
  746. }
  747. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  748. this.createConfigSite(this.createHbaseSiteObj('HBASE'));
  749. }
  750. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  751. this.createConfigSite(this.createOozieSiteObj('OOZIE'));
  752. }
  753. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  754. // TODO
  755. // this.createConfigSite(this.createHiveSiteObj('HIVE'));
  756. }
  757. },
  758. createConfigSite: function (data) {
  759. console.log("Inside createConfigSite");
  760. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  761. var url = App.apiPrefix + '/clusters/' + clusterName + '/configurations';
  762. $.ajax({
  763. type: 'POST',
  764. url: url,
  765. data: JSON.stringify(data),
  766. async: false,
  767. dataType: 'text',
  768. timeout: App.timeout,
  769. success: function (data) {
  770. var jsonData = jQuery.parseJSON(data);
  771. console.log("TRACE: STep8 -> In success function for the createConfigSite");
  772. console.log("TRACE: STep8 -> value of the url is: " + url);
  773. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  774. },
  775. error: function (request, ajaxOptions, error) {
  776. console.log('Step8: In Error ');
  777. console.log('Step8: Error message is: ' + request.responseText);
  778. console.log("TRACE: STep8 -> value of the url is: " + url);
  779. },
  780. statusCode: require('data/statusCodes')
  781. });
  782. console.log("Exiting createConfigSite");
  783. },
  784. createGlobalSiteObj: function () {
  785. var globalSiteProperties = {};
  786. this.get('globals').forEach(function (_globalSiteObj) {
  787. // do not pass any globals whose name ends with _host or _hosts
  788. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  789. // append "m" to JVM memory options
  790. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  791. _globalSiteObj.value += "m";
  792. }
  793. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  794. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  795. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  796. }
  797. }, this);
  798. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  799. },
  800. createCoreSiteObj: function () {
  801. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  802. var coreSiteProperties = {};
  803. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  804. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  805. coreSiteObj.forEach(function (_coreSiteObj) {
  806. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  807. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  808. }
  809. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  810. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  811. }, this);
  812. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  813. },
  814. createHdfsSiteObj: function (serviceName) {
  815. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  816. var hdfsProperties = {};
  817. hdfsSiteObj.forEach(function (_configProperty) {
  818. hdfsProperties[_configProperty.name] = _configProperty.value;
  819. console.log("STEP*: name of the property is: " + _configProperty.name);
  820. console.log("STEP8: value of the property is: " + _configProperty.value);
  821. }, this);
  822. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  823. },
  824. createMrSiteObj: function (serviceName) {
  825. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  826. var mrProperties = {};
  827. configs.forEach(function (_configProperty) {
  828. mrProperties[_configProperty.name] = _configProperty.value;
  829. console.log("STEP*: name of the property is: " + _configProperty.name);
  830. console.log("STEP8: value of the property is: " + _configProperty.value);
  831. }, this);
  832. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  833. },
  834. createHbaseSiteObj: function (serviceName) {
  835. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  836. var hbaseProperties = {};
  837. configs.forEach(function (_configProperty) {
  838. hbaseProperties[_configProperty.name] = _configProperty.value;
  839. }, this);
  840. var masterHosts = App.db.getMasterComponentHosts();
  841. // TODO: should filter on "component" but that gives unexpected results
  842. var zkServers = masterHosts.filterProperty('display_name', 'ZooKeeper').mapProperty('hostName');
  843. hbaseProperties['hbase.zookeeper.quorum'] = zkServers.join(',');
  844. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  845. },
  846. createOozieSiteObj: function (serviceName) {
  847. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  848. var oozieProperties = {};
  849. configs.forEach(function (_configProperty) {
  850. oozieProperties[_configProperty.name] = _configProperty.value;
  851. }, this);
  852. var baseUrl = oozieProperties['oozie.base.url'];
  853. oozieProperties = {
  854. "oozie.service.JPAService.jdbc.password" : " ", "oozie.db.schema.name" : "oozie", "oozie.service.JPAService.jdbc.url" : "jdbc:derby:/var/data/oozie/oozie-db;create=true", "oozie.service.JPAService.jdbc.driver" : "org.apache.derby.jdbc.EmbeddedDriver", "oozie.service.WorkflowAppService.system.libpath" : "/user/oozie/share/lib", "oozie.service.JPAService.jdbc.username" : "sa", "oozie.service.SchemaService.wf.ext.schemas" : "shell-action-0.1.xsd,email-action-0.1.xsd,hive-action-0.2.xsd,sqoop-action-0.2.xsd,ssh-action-0.1.xsd,distcp-action-0.1.xsd", "oozie.service.JPAService.create.db.schema" : "false", "use.system.libpath.for.mapreduce.and.pig.jobs" : "false", "oozie.service.ActionService.executor.ext.classes" : "org.apache.oozie.action.email.EmailActionExecutor,org.apache.oozie.action.hadoop.HiveActionExecutor,org.apache.oozie.action.hadoop.ShellActionExecutor,org.apache.oozie.action.hadoop.SqoopActionExecutor,org.apache.oozie.action.hadoop.DistcpActionExecutor", "oozie.service.HadoopAccessorService.hadoop.configurations" : "*=/etc/hadoop/conf"
  855. };
  856. oozieProperties['oozie.base.url'] = baseUrl;
  857. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  858. },
  859. createHiveSiteObj: function (serviceName) {
  860. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  861. var hiveProperties = {};
  862. configs.forEach(function (_configProperty) {
  863. hiveProperties[_configProperty.name] = _configProperty.value;
  864. }, this);
  865. return {type: 'hbase-site', tag: 'version1', properties: hiveProperties};
  866. },
  867. applyCreatedConfToServices: function () {
  868. var services = this.get('selectedServices').mapProperty('serviceName');
  869. services.forEach(function (_service) {
  870. var data = this.getConfigForService(_service);
  871. this.applyCreatedConfToService(_service, 'PUT', data);
  872. }, this);
  873. },
  874. applyCreatedConfToService: function (service, httpMethod, data) {
  875. console.log("Inside applyCreatedConfToService");
  876. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  877. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + service;
  878. $.ajax({
  879. type: httpMethod,
  880. url: url,
  881. async: false,
  882. dataType: 'text',
  883. data: JSON.stringify(data),
  884. timeout: App.timeout,
  885. success: function (data) {
  886. var jsonData = jQuery.parseJSON(data);
  887. console.log("TRACE: STep8 -> In success function for the applyCreatedConfToService call");
  888. console.log("TRACE: STep8 -> value of the url is: " + url);
  889. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  890. },
  891. error: function (request, ajaxOptions, error) {
  892. console.log('Step8: In Error ');
  893. console.log('Step8: Error message is: ' + request.responseText);
  894. },
  895. statusCode: require('data/statusCodes')
  896. });
  897. console.log("Exiting applyCreatedConfToService");
  898. },
  899. getConfigForService: function (serviceName) {
  900. switch (serviceName) {
  901. case 'HDFS':
  902. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  903. case 'MAPREDUCE':
  904. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  905. case 'HBASE':
  906. return {config: {'global': 'version1', 'core-site': 'version1', 'hbase-site': 'version1'}};
  907. case 'OOZIE':
  908. return {config: {'global': 'version1', 'core-site': 'version1', 'oozie-site': 'version1'}};
  909. }
  910. }
  911. })