step8_controller.js 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  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. // TODO: aggregate create calls. doesn't seem like backend supports creating multiple services at the same time yet.
  586. createSelectedServices: function () {
  587. var services = this.get('selectedServices').mapProperty('serviceName');
  588. services.forEach(function (_service) {
  589. this.createService(_service, 'POST');
  590. }, this);
  591. },
  592. createService: function (service, httpMethod) {
  593. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  594. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + service;
  595. $.ajax({
  596. type: httpMethod,
  597. url: url,
  598. async: false,
  599. dataType: 'text',
  600. timeout: App.timeout,
  601. success: function (data) {
  602. var jsonData = jQuery.parseJSON(data);
  603. console.log("TRACE: STep8 -> In success function for the createService call");
  604. console.log("TRACE: STep8 -> value of the url is: " + url);
  605. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  606. },
  607. error: function (request, ajaxOptions, error) {
  608. console.log('Step8: In Error ');
  609. console.log('Step8: Error message is: ' + request.responseText);
  610. },
  611. statusCode: require('data/statusCodes')
  612. });
  613. },
  614. createComponents: function () {
  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. var componentsData = components.map(function(_component) {
  620. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  621. });
  622. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  623. // Service must be specified in terms of a query for creating multiple components at the same time.
  624. // See AMBARI-1018.
  625. var url = App.apiPrefix + '/clusters/' + clusterName + '/services?ServiceInfo/service_name=' + _service;
  626. var data = {
  627. "components": componentsData
  628. }
  629. $.ajax({
  630. type: 'POST',
  631. url: url,
  632. async: false,
  633. dataType: 'text',
  634. data: JSON.stringify(data),
  635. timeout: App.timeout,
  636. success: function (data) {
  637. var jsonData = jQuery.parseJSON(data);
  638. console.log("TRACE: STep8 -> In success function for createComponent");
  639. console.log("TRACE: STep8 -> value of the url is: " + url);
  640. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  641. },
  642. error: function (request, ajaxOptions, error) {
  643. console.log('Step8: In Error ');
  644. console.log('Step8: Error message is: ' + request.responseText);
  645. },
  646. statusCode: require('data/statusCodes')
  647. });
  648. }, this);
  649. },
  650. registerHostsToCluster: function() {
  651. var allHosts = this.get('content.hostsInfo');
  652. for(var hostName in allHosts){
  653. if(!allHosts[hostName].isInstalled){
  654. this.registerHostToCluster(hostName);
  655. }
  656. }
  657. },
  658. registerHostToCluster: function (hostName) {
  659. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  660. var url = App.apiPrefix + '/clusters/' + clusterName + '/hosts/' + hostName;
  661. $.ajax({
  662. type: 'POST',
  663. url: url,
  664. async: false,
  665. dataType: 'text',
  666. timeout: App.timeout,
  667. success: function (data) {
  668. var jsonData = jQuery.parseJSON(data);
  669. console.log("TRACE: STep8 -> In success function for registerHostToCluster");
  670. console.log("TRACE: STep8 -> value of the url is: " + url);
  671. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  672. },
  673. error: function (request, ajaxOptions, error) {
  674. console.log('Step8: In Error ');
  675. console.log('Step8: Error message is: ' + request.responseText);
  676. },
  677. statusCode: require('data/statusCodes')
  678. });
  679. },
  680. createHostComponents: function () {
  681. //TODO: Uncomment following after hooking up with all services.
  682. var masterHosts = this.get('content.masterComponentHosts');
  683. var slaveHosts = this.get('content.slaveComponentHosts');
  684. var clients = this.get('content.clients');
  685. var allHosts = this.get('content.hostsInfo');
  686. var slaveClient = slaveHosts.filterProperty('componentName', "CLIENT").objectAt(0);
  687. masterHosts.forEach(function (_masterHost) {
  688. this.createHostComponent(_masterHost);
  689. }, this);
  690. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  691. var hosts = slaveClient.hosts.filterProperty("hostName", _masterHost.hostName);
  692. if (!hosts.length) {
  693. var slaveObj = {};
  694. slaveObj.component = "HDFS_CLIENT";
  695. slaveObj.hostName = _masterHost.hostName;
  696. slaveObj.isInstalled = false;
  697. this.createHostComponent(slaveObj);
  698. }
  699. }, this);
  700. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  701. var hosts = slaveClient.hosts.filterProperty("hostName", _masterHost.hostName);
  702. if (!hosts.length) {
  703. var slaveObj = {};
  704. slaveObj.component = "MAPREDUCE_CLIENT";
  705. slaveObj.hostName = _masterHost.hostName;
  706. slaveObj.isInstalled = false;
  707. this.createHostComponent(slaveObj);
  708. }
  709. }, this);
  710. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  711. var hosts = slaveClient.hosts.filterProperty("hostName", _masterHost.hostName);
  712. if (!hosts.length) {
  713. var slaveObj = {};
  714. slaveObj.component = "MAPREDUCE_CLIENT";
  715. slaveObj.hostName = _masterHost.hostName;
  716. slaveObj.isInstalled = false;
  717. this.createHostComponent(slaveObj);
  718. }
  719. }, this);
  720. slaveHosts.filterProperty('componentName', "HBASE_REGIONSERVER").forEach(function (slave) {
  721. slave.hosts.forEach(function(_slaveHost){
  722. var hosts = slaveClient.hosts.filterProperty('hostName', _slaveHost.hostName);
  723. if (!hosts.length) {
  724. var slaveObj = {};
  725. slaveObj.component = "HDFS_CLIENT";
  726. slaveObj.hostName = _slaveHost.hostName;
  727. slaveObj.isInstalled = false;
  728. this.createHostComponent(slaveObj);
  729. }
  730. }, this)
  731. }, this);
  732. slaveHosts.forEach(function (_slaveHosts) {
  733. var slaveObj = {};
  734. if (_slaveHosts.componentName !== 'CLIENT') {
  735. slaveObj.component = _slaveHosts.componentName;
  736. _slaveHosts.hosts.forEach(function (_slaveHost) {
  737. slaveObj.hostName = _slaveHost.hostName;
  738. slaveObj.isInstalled = _slaveHost.isInstalled;
  739. this.createHostComponent(slaveObj);
  740. }, this);
  741. } else {
  742. //: todo
  743. this.get('content.clients').forEach(function (_client) {
  744. slaveObj.component = _client.component_name;
  745. _slaveHosts.hosts.forEach(function (_slaveHost) {
  746. slaveObj.hostName = _slaveHost.hostName;
  747. slaveObj.isInstalled = _slaveHost.isInstalled && _client.isInstalled;
  748. this.createHostComponent(slaveObj);
  749. }, this);
  750. }, this);
  751. }
  752. }, this);
  753. // add Ganglia Monitor (Slave) to all hosts if Ganglia is selected
  754. if (this.get('selectedServices').someProperty('serviceName', 'GANGLIA')) {
  755. for (var hostName in allHosts) {
  756. // TODO: filter for only confirmed hosts?
  757. this.createHostComponent({ hostName: hostName, component: 'GANGLIA_MONITOR'});
  758. }
  759. }
  760. },
  761. createHostComponent: function (hostComponent) {
  762. console.log('try to install', hostComponent.component, 'on host', hostComponent.hostName, 'isInstalled', hostComponent.isInstalled);
  763. if (hostComponent.isInstalled) {
  764. return false;
  765. }
  766. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  767. var url = App.apiPrefix + '/clusters/' + clusterName + '/hosts/' + hostComponent.hostName + '/host_components/' + hostComponent.component;
  768. $.ajax({
  769. type: 'POST',
  770. url: url,
  771. async: false,
  772. dataType: 'text',
  773. timeout: App.timeout,
  774. success: function (data) {
  775. var jsonData = jQuery.parseJSON(data);
  776. console.log("TRACE: STep8 -> In success function for the createComponent with new host call");
  777. console.log("TRACE: STep8 -> value of the url is: " + url);
  778. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  779. },
  780. error: function (request, ajaxOptions, error) {
  781. console.log('Step8: In Error ');
  782. console.log('Step8: Error message is: ' + request.responseText);
  783. },
  784. statusCode: require('data/statusCodes')
  785. });
  786. },
  787. createConfigurations: function () {
  788. var selectedServices = this.get('selectedServices');
  789. if (!this.get('content.isWizard')){
  790. this.createConfigSite(this.createGlobalSiteObj());
  791. this.createConfigSite(this.createCoreSiteObj());
  792. this.createConfigSite(this.createHdfsSiteObj('HDFS'));
  793. }
  794. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  795. this.createConfigSite(this.createMrSiteObj('MAPREDUCE'));
  796. }
  797. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  798. this.createConfigSite(this.createHbaseSiteObj('HBASE'));
  799. }
  800. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  801. this.createConfigSite(this.createOozieSiteObj('OOZIE'));
  802. }
  803. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  804. // TODO
  805. // this.createConfigSite(this.createHiveSiteObj('HIVE'));
  806. }
  807. },
  808. createConfigSite: function (data) {
  809. console.log("Inside createConfigSite");
  810. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  811. var url = App.apiPrefix + '/clusters/' + clusterName + '/configurations';
  812. $.ajax({
  813. type: 'POST',
  814. url: url,
  815. data: JSON.stringify(data),
  816. async: false,
  817. dataType: 'text',
  818. timeout: App.timeout,
  819. success: function (data) {
  820. var jsonData = jQuery.parseJSON(data);
  821. console.log("TRACE: STep8 -> In success function for the createConfigSite");
  822. console.log("TRACE: STep8 -> value of the url is: " + url);
  823. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  824. },
  825. error: function (request, ajaxOptions, error) {
  826. console.log('Step8: In Error ');
  827. console.log('Step8: Error message is: ' + request.responseText);
  828. console.log("TRACE: STep8 -> value of the url is: " + url);
  829. },
  830. statusCode: require('data/statusCodes')
  831. });
  832. console.log("Exiting createConfigSite");
  833. },
  834. createGlobalSiteObj: function () {
  835. var globalSiteProperties = {};
  836. this.get('globals').forEach(function (_globalSiteObj) {
  837. // do not pass any globals whose name ends with _host or _hosts
  838. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  839. // append "m" to JVM memory options
  840. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  841. _globalSiteObj.value += "m";
  842. }
  843. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  844. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  845. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  846. }
  847. }, this);
  848. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  849. },
  850. createCoreSiteObj: function () {
  851. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  852. var coreSiteProperties = {};
  853. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  854. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  855. coreSiteObj.forEach(function (_coreSiteObj) {
  856. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  857. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  858. }
  859. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  860. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  861. }, this);
  862. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  863. },
  864. createHdfsSiteObj: function (serviceName) {
  865. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  866. var hdfsProperties = {};
  867. hdfsSiteObj.forEach(function (_configProperty) {
  868. hdfsProperties[_configProperty.name] = _configProperty.value;
  869. console.log("STEP*: name of the property is: " + _configProperty.name);
  870. console.log("STEP8: value of the property is: " + _configProperty.value);
  871. }, this);
  872. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  873. },
  874. createMrSiteObj: function (serviceName) {
  875. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  876. var mrProperties = {};
  877. configs.forEach(function (_configProperty) {
  878. mrProperties[_configProperty.name] = _configProperty.value;
  879. console.log("STEP*: name of the property is: " + _configProperty.name);
  880. console.log("STEP8: value of the property is: " + _configProperty.value);
  881. }, this);
  882. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  883. },
  884. createHbaseSiteObj: function (serviceName) {
  885. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  886. var hbaseProperties = {};
  887. configs.forEach(function (_configProperty) {
  888. hbaseProperties[_configProperty.name] = _configProperty.value;
  889. }, this);
  890. var masterHosts = App.db.getMasterComponentHosts();
  891. // TODO: should filter on "component" but that gives unexpected results
  892. var zkServers = masterHosts.filterProperty('display_name', 'ZooKeeper').mapProperty('hostName');
  893. hbaseProperties['hbase.zookeeper.quorum'] = zkServers.join(',');
  894. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  895. },
  896. createOozieSiteObj: function (serviceName) {
  897. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  898. var oozieProperties = {};
  899. configs.forEach(function (_configProperty) {
  900. oozieProperties[_configProperty.name] = _configProperty.value;
  901. }, this);
  902. var baseUrl = oozieProperties['oozie.base.url'];
  903. oozieProperties = {
  904. "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"
  905. };
  906. oozieProperties['oozie.base.url'] = baseUrl;
  907. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  908. },
  909. createHiveSiteObj: function (serviceName) {
  910. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  911. var hiveProperties = {};
  912. configs.forEach(function (_configProperty) {
  913. hiveProperties[_configProperty.name] = _configProperty.value;
  914. }, this);
  915. return {type: 'hbase-site', tag: 'version1', properties: hiveProperties};
  916. },
  917. applyCreatedConfToServices: function () {
  918. var services = this.get('selectedServices').mapProperty('serviceName');
  919. services.forEach(function (_service) {
  920. var data = this.getConfigForService(_service);
  921. this.applyCreatedConfToService(_service, 'PUT', data);
  922. }, this);
  923. },
  924. applyCreatedConfToService: function (service, httpMethod, data) {
  925. console.log("Inside applyCreatedConfToService");
  926. var clusterName = this.get('clusterInfo').findProperty('config_name', 'cluster').config_value;
  927. var url = App.apiPrefix + '/clusters/' + clusterName + '/services/' + service;
  928. $.ajax({
  929. type: httpMethod,
  930. url: url,
  931. async: false,
  932. dataType: 'text',
  933. data: JSON.stringify(data),
  934. timeout: App.timeout,
  935. success: function (data) {
  936. var jsonData = jQuery.parseJSON(data);
  937. console.log("TRACE: STep8 -> In success function for the applyCreatedConfToService call");
  938. console.log("TRACE: STep8 -> value of the url is: " + url);
  939. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  940. },
  941. error: function (request, ajaxOptions, error) {
  942. console.log('Step8: In Error ');
  943. console.log('Step8: Error message is: ' + request.responseText);
  944. },
  945. statusCode: require('data/statusCodes')
  946. });
  947. console.log("Exiting applyCreatedConfToService");
  948. },
  949. getConfigForService: function (serviceName) {
  950. switch (serviceName) {
  951. case 'HDFS':
  952. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  953. case 'MAPREDUCE':
  954. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  955. case 'HBASE':
  956. return {config: {'global': 'version1', 'core-site': 'version1', 'hbase-site': 'version1'}};
  957. case 'OOZIE':
  958. return {config: {'global': 'version1', 'core-site': 'version1', 'oozie-site': 'version1'}};
  959. }
  960. }
  961. })