step8_controller.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426
  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. slaveComponentConfig: null,
  29. isSubmitDisabled: false,
  30. selectedServices: function () {
  31. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  32. }.property('content.services').cacheable(),
  33. clearStep: function () {
  34. this.get('services').clear();
  35. this.get('configs').clear();
  36. this.get('globals').clear();
  37. this.get('clusterInfo').clear();
  38. },
  39. loadStep: function () {
  40. console.log("TRACE: Loading step8: Review Page");
  41. this.clearStep();
  42. this.loadGlobals();
  43. this.loadConfigs();
  44. this.setCustomConfigs();
  45. //this.loadSlaveConfiguration();
  46. this.loadClusterInfo();
  47. this.loadServices();
  48. this.set('isSubmitDisabled', false);
  49. },
  50. loadGlobals: function () {
  51. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  52. if (globals.someProperty('name', 'hive_database')) {
  53. //TODO: Hive host depends on the type of db selected. Change puppet variable name if postgres is not the default db
  54. var hiveDb = globals.findProperty('name', 'hive_database');
  55. if (hiveDb.value === 'New MySQL Database') {
  56. globals.findProperty('name', 'hive_ambari_host').name = 'hive_mysql_host';
  57. globals = globals.without(globals.findProperty('name', 'hive_existing_host'));
  58. globals = globals.without(globals.findProperty('name', 'hive_existing_database'));
  59. } else {
  60. globals.findProperty('name', 'hive_existing_host').name = 'hive_mysql_host';
  61. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  62. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  63. }
  64. }
  65. this.set('globals', globals);
  66. },
  67. loadConfigs: function () {
  68. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property').filterProperty('value');
  69. var uiConfigs = this.loadUiSideConfigs();
  70. this.set('configs', storedConfigs.concat(uiConfigs));
  71. },
  72. loadUiSideConfigs: function () {
  73. var uiConfig = [];
  74. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  75. configs.forEach(function (_config) {
  76. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  77. uiConfig.pushObject({
  78. "id": "site property",
  79. "name": _config.name,
  80. "value": value,
  81. "filename": _config.filename
  82. });
  83. }, this);
  84. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  85. dependentConfig.forEach(function (_config) {
  86. this.setConfigValue(uiConfig, _config);
  87. uiConfig.pushObject({
  88. "id": "site property",
  89. "name": _config.name,
  90. "value": _config.value,
  91. "filename": _config.filename
  92. });
  93. }, this);
  94. return uiConfig;
  95. },
  96. getRegisteredHosts: function () {
  97. var allHosts = this.get('content.hosts');
  98. var hosts = [];
  99. for (var hostName in allHosts) {
  100. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  101. allHosts[hostName].hostName = allHosts[hostName].name;
  102. hosts.pushObject(allHosts[hostName]);
  103. }
  104. }
  105. return hosts;
  106. },
  107. /**
  108. * Set all site property that are derived from other puppet-variable
  109. */
  110. getGlobConfigValue: function (templateName, expression) {
  111. var express = expression.match(/<(.*?)>/g);
  112. var value = expression;
  113. if (express == null) {
  114. return expression;
  115. }
  116. express.forEach(function (_express) {
  117. //console.log("The value of template is: " + _express);
  118. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  119. if (this.get('globals').someProperty('name', templateName[index])) {
  120. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  121. var globValue = this.get('globals').findProperty('name', templateName[index]).value;
  122. value = value.replace(_express, globValue);
  123. } else {
  124. /*
  125. console.log("ERROR: The variable name is: " + templateName[index]);
  126. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  127. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  128. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  129. */
  130. value = null;
  131. }
  132. }, this);
  133. return value;
  134. },
  135. /**
  136. * Set all site property that are derived from other site-properties
  137. */
  138. setConfigValue: function (uiConfig, config) {
  139. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  140. if (fkValue) {
  141. fkValue.forEach(function (_fkValue) {
  142. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  143. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  144. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  145. config.value = config.value.replace(_fkValue, globalValue);
  146. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  147. var globalValue;
  148. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  149. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  150. } else {
  151. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  152. }
  153. config.value = config.value.replace(_fkValue, globalValue);
  154. }
  155. }, this);
  156. }
  157. if (fkValue = config.name.match(/<(foreignKey.*?)>/g)) {
  158. fkValue.forEach(function (_fkValue) {
  159. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  160. if (uiConfig.someProperty('name', config.foreignKey[index])) {
  161. var globalValue = uiConfig.findProperty('name', config.foreignKey[index]).value;
  162. config.name = config.name.replace(_fkValue, globalValue);
  163. } else if (this.get('content.serviceConfigProperties').someProperty('name', config.foreignKey[index])) {
  164. var globalValue;
  165. if (this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value === '') {
  166. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).defaultValue;
  167. } else {
  168. globalValue = this.get('content.serviceConfigProperties').findProperty('name', config.foreignKey[index]).value;
  169. }
  170. config.name = config.name.replace(_fkValue, globalValue);
  171. }
  172. }, this);
  173. }
  174. //For properties in the configMapping file having foreignKey and templateName properties.
  175. var templateValue = config.value.match(/<(templateName.*?)>/g);
  176. if (templateValue) {
  177. templateValue.forEach(function (_value) {
  178. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  179. if (this.get('globals').someProperty('name', config.templateName[index])) {
  180. var globalValue = this.get('globals').findProperty('name', config.templateName[index]).value;
  181. config.value = config.value.replace(_value, globalValue);
  182. }
  183. }, this);
  184. }
  185. },
  186. /**
  187. * override site properties with the entered key-value pair in *-site.xml
  188. */
  189. setCustomConfigs: function () {
  190. var site = this.get('content.serviceConfigProperties').filterProperty('id', 'conf-site');
  191. site.forEach(function (_site) {
  192. var keyValue = _site.value.split(/\n+/);
  193. if (keyValue) {
  194. keyValue.forEach(function (_keyValue) {
  195. console.log("The value of the keyValue is: " + _keyValue.trim());
  196. _keyValue = _keyValue.trim();
  197. var key = _keyValue.match(/(.+)=/);
  198. var value = _keyValue.match(/=(.*)/);
  199. if (key) {
  200. this.setSiteProperty(key[1], value[1], _site.filename);
  201. }
  202. }, this);
  203. }
  204. }, this);
  205. },
  206. /**
  207. * Set property of the site variable
  208. */
  209. setSiteProperty: function (key, value, filename) {
  210. if (this.get('configs').someProperty('name', key)) {
  211. this.get('configs').findProperty('name', key).value = value;
  212. } else {
  213. this.get('configs').pushObject({
  214. "id": "site property",
  215. "name": key,
  216. "value": value,
  217. "filename": filename
  218. });
  219. }
  220. },
  221. loadSlaveConfiguration: function () {
  222. var slaveComponentConfig = this.convertSlaveConfig(this.get('content.slaveGroupProperties'));
  223. this.set("slaveComponentConfig", slaveComponentConfig);
  224. },
  225. convertSlaveConfig: function (slaveContent) {
  226. var dest = {
  227. "version": "1.0",
  228. "components": [
  229. ],
  230. "slaveHostComponents": []
  231. };
  232. slaveContent.forEach(function (_slaveContent) {
  233. var newComponent = {};
  234. newComponent.componentName = _slaveContent.componentName;
  235. newComponent.serviceName = this.getServiceInfo(newComponent.componentName).name;
  236. newComponent.groups = [];
  237. var index = 2;
  238. if(_slaveContent.groups){
  239. _slaveContent.groups.forEach(function (_group) {
  240. var newGroup = {};
  241. newGroup.groupName = _group.name;
  242. newGroup.configVersion = {config: {'global': 'version1', 'core-site': 'version1'}}; // TODO : every time a new version should be generated
  243. if (this.getServiceInfo(_slaveContent.componentName)) {
  244. newGroup.configVersion.config[this.getServiceInfo(_slaveContent.componentName).domain] = 'version' + index;
  245. newGroup.configVersion.config[this.getServiceInfo(_slaveContent.componentName).siteName] = 'version' + index;
  246. }
  247. newGroup.siteVersion = 'version' + index;
  248. newGroup.hostNames = _slaveContent.hosts.filterProperty("group", newGroup.groupName).mapProperty('hostName');
  249. newGroup.properties = _group.properties;
  250. if (!Ember.empty(newGroup.hostNames)) {
  251. newComponent.groups.push(newGroup);
  252. }
  253. index++;
  254. }, this);
  255. }
  256. dest.components.push(newComponent);
  257. }, this);
  258. var hostsInfo = this.get('content.hosts');
  259. for (var index in hostsInfo) {
  260. var hostIndex = 2;
  261. var slaveHost = {name: null, configVersion: null, slaveComponents: []};
  262. dest.components.forEach(function (_component) {
  263. _component.groups.forEach(function (_group) {
  264. if (_group.hostNames.contains(hostsInfo[index].name)) {
  265. var slaveComponent = {};
  266. slaveHost.name = hostsInfo[index].name;
  267. slaveComponent.componentName = _component.componentName;
  268. slaveComponent.groupName = _group.groupName;
  269. slaveComponent.properties = _group.properties;
  270. slaveHost.slaveComponents.pushObject(slaveComponent);
  271. }
  272. }, this);
  273. }, this);
  274. hostIndex++;
  275. if (!Ember.none(slaveHost.name)) {
  276. dest.slaveHostComponents.pushObject(slaveHost);
  277. }
  278. }
  279. return dest;
  280. },
  281. getServiceInfo: function (componentName) {
  282. var serviceConfig;
  283. switch (componentName) {
  284. case 'DATANODE':
  285. serviceConfig = {
  286. name: 'HDFS',
  287. siteName: 'hdfs-site',
  288. domain: 'datanode-global'
  289. };
  290. break;
  291. case 'TASKTRACKER':
  292. serviceConfig = {
  293. name: 'MAPREDUCE',
  294. siteName: 'mapred-site',
  295. domain: 'tasktracker-global'
  296. };
  297. break;
  298. case 'HBASE_REGIONSERVER':
  299. serviceConfig = {
  300. name: 'HBASE',
  301. siteName: 'hbase-site',
  302. domain: 'regionserver-global'
  303. };
  304. break;
  305. default:
  306. serviceConfig = {};
  307. }
  308. return serviceConfig;
  309. },
  310. /**
  311. * Load all info about cluster to <code>clusterInfo</code> variable
  312. */
  313. loadClusterInfo: function () {
  314. // cluster name
  315. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  316. cluster.config_value = this.get('content.cluster.name');
  317. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  318. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  319. //hosts
  320. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  321. var slaveHosts = this.get('content.slaveComponentHosts');
  322. var hostObj = [];
  323. slaveHosts.forEach(function (_hosts) {
  324. hostObj = hostObj.concat(_hosts.hosts);
  325. }, this);
  326. slaveHosts = hostObj.mapProperty('hostName').uniq();
  327. var componentHosts = masterHosts.concat(slaveHosts).uniq();
  328. var totalHosts = App.Host.find().mapProperty('hostName').concat(componentHosts).uniq();
  329. var newHostsCount = totalHosts.length - App.Host.find().content.length;
  330. this.set('totalHosts', totalHosts);
  331. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  332. totalHostsObj.config_value = totalHosts.length + ' (' + newHostsCount + ' new)';
  333. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  334. //repo
  335. var repoOption = this.get('content.installOption.localRepo');
  336. var repoObj = this.rawContent.findProperty('config_name', 'Repo');
  337. if (repoOption) {
  338. repoObj.config_value = 'Yes';
  339. } else {
  340. repoObj.config_value = 'No';
  341. }
  342. this.get('clusterInfo').pushObject(Ember.Object.create(repoObj));
  343. },
  344. /**
  345. * Load all info about services to <code>services</code> variable
  346. */
  347. loadServices: function () {
  348. var selectedServices = this.get('selectedServices');
  349. this.set('services', selectedServices.mapProperty('serviceName'));
  350. selectedServices.forEach(function (_service) {
  351. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  352. var reviewService = this.rawContent.findProperty('config_name', 'services');
  353. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  354. if (serviceObj) {
  355. switch (serviceObj.service_name) {
  356. case 'HDFS':
  357. this.loadHDFS(serviceObj);
  358. break;
  359. case 'MAPREDUCE':
  360. this.loadMapReduce(serviceObj);
  361. break;
  362. case 'HIVE':
  363. this.loadHive(serviceObj);
  364. break;
  365. case 'HBASE':
  366. this.loadHbase(serviceObj);
  367. break;
  368. case 'ZOOKEEPER':
  369. this.loadZk(serviceObj);
  370. break;
  371. case 'OOZIE':
  372. this.loadOozie(serviceObj);
  373. break;
  374. case 'NAGIOS':
  375. this.loadNagios(serviceObj);
  376. break;
  377. case 'GANGLIA':
  378. this.loadGanglia(serviceObj);
  379. break;
  380. case 'PIG':
  381. this.loadPig(serviceObj);
  382. break;
  383. case 'SQOOP':
  384. this.loadSqoop(serviceObj);
  385. break;
  386. case 'HCATALOG':
  387. break;
  388. default:
  389. }
  390. }
  391. }, this);
  392. },
  393. /**
  394. * load all info about HDFS service
  395. * @param hdfsObj
  396. */
  397. loadHDFS: function (hdfsObj) {
  398. hdfsObj.get('service_components').forEach(function (_component) {
  399. switch (_component.get('display_name')) {
  400. case 'NameNode':
  401. this.loadNnValue(_component);
  402. break;
  403. case 'SecondaryNameNode':
  404. this.loadSnnValue(_component);
  405. break;
  406. case 'DataNodes':
  407. this.loadDnValue(_component);
  408. break;
  409. default:
  410. }
  411. }, this);
  412. //var
  413. this.get('services').pushObject(hdfsObj);
  414. },
  415. loadNnValue: function (nnComponent) {
  416. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  417. nnComponent.set('component_value', nnHostName.hostName);
  418. },
  419. loadSnnValue: function (snnComponent) {
  420. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  421. snnComponent.set('component_value', snnHostName.hostName);
  422. },
  423. loadDnValue: function (dnComponent) {
  424. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  425. var totalDnHosts = dnHosts.hosts.length;
  426. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'DATANODE').groups.length;
  427. var groupLabel;
  428. if (totalGroups == 1) {
  429. groupLabel = 'group';
  430. } else {
  431. groupLabel = 'groups';
  432. }
  433. */
  434. dnComponent.set('component_value', totalDnHosts + ' hosts');
  435. },
  436. /**
  437. * Load all info about mapReduce service
  438. * @param mrObj
  439. */
  440. loadMapReduce: function (mrObj) {
  441. mrObj.get('service_components').forEach(function (_component) {
  442. switch (_component.get('display_name')) {
  443. case 'JobTracker':
  444. this.loadJtValue(_component);
  445. break;
  446. case 'TaskTrackers':
  447. this.loadTtValue(_component);
  448. break;
  449. default:
  450. }
  451. }, this);
  452. this.get('services').pushObject(mrObj);
  453. },
  454. loadJtValue: function (jtComponent) {
  455. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  456. jtComponent.set('component_value', jtHostName.hostName);
  457. },
  458. loadTtValue: function (ttComponent) {
  459. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  460. var totalTtHosts = ttHosts.hosts.length;
  461. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'TASKTRACKER').groups.length;
  462. var groupLabel;
  463. if (totalGroups == 1) {
  464. groupLabel = 'group';
  465. } else {
  466. groupLabel = 'groups';
  467. }
  468. */
  469. ttComponent.set('component_value', totalTtHosts + ' hosts');
  470. },
  471. /**
  472. * Load all info about Hive service
  473. * @param hiveObj
  474. */
  475. loadHive: function (hiveObj) {
  476. hiveObj.get('service_components').forEach(function (_component) {
  477. switch (_component.get('display_name')) {
  478. case 'Hive Metastore':
  479. this.loadHiveMetaStoreValue(_component);
  480. break;
  481. case 'Database':
  482. this.loadHiveDbValue(_component);
  483. break;
  484. default:
  485. }
  486. }, this);
  487. this.get('services').pushObject(hiveObj);
  488. },
  489. loadHiveMetaStoreValue: function (metaStoreComponent) {
  490. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hive Server');
  491. metaStoreComponent.set('component_value', hiveHostName.hostName);
  492. },
  493. loadHiveDbValue: function (dbComponent) {
  494. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  495. if (hiveDb.value === 'New MySQL Database') {
  496. dbComponent.set('component_value', 'MySQL (New Database)');
  497. } else {
  498. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  499. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  500. }
  501. },
  502. /**
  503. * Load all info about Hbase
  504. * @param hbaseObj
  505. */
  506. loadHbase: function (hbaseObj) {
  507. hbaseObj.service_components.forEach(function (_component) {
  508. switch (_component.display_name) {
  509. case 'Master':
  510. this.loadMasterValue(_component);
  511. break;
  512. case 'Region Servers':
  513. this.loadRegionServerValue(_component);
  514. break;
  515. default:
  516. }
  517. }, this);
  518. this.get('services').pushObject(hbaseObj);
  519. },
  520. loadMasterValue: function (hbaseMaster) {
  521. var hbaseHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HBase Master');
  522. hbaseMaster.set('component_value', hbaseHostName.hostName);
  523. },
  524. loadRegionServerValue: function (rsComponent) {
  525. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  526. var totalRsHosts = rsHosts.hosts.length;
  527. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'HBASE_REGIONSERVER').groups.length;
  528. var groupLabel;
  529. if (totalGroups == 1) {
  530. groupLabel = 'group';
  531. } else {
  532. groupLabel = 'groups';
  533. } */
  534. rsComponent.set('component_value', totalRsHosts + ' hosts');
  535. },
  536. /**
  537. * Load all info about ZooKeeper service
  538. * @param zkObj
  539. */
  540. loadZk: function (zkObj) {
  541. zkObj.get('service_components').forEach(function (_component) {
  542. switch (_component.get('display_name')) {
  543. case 'Servers':
  544. this.loadZkServerValue(_component);
  545. break;
  546. default:
  547. }
  548. }, this);
  549. this.get('services').pushObject(zkObj);
  550. },
  551. loadZkServerValue: function (serverComponent) {
  552. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  553. var hostSuffix;
  554. if (zkHostNames === 1) {
  555. hostSuffix = 'host';
  556. } else {
  557. hostSuffix = 'hosts';
  558. }
  559. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  560. },
  561. /**
  562. * Load all info about Oozie services
  563. * @param oozieObj
  564. */
  565. loadOozie: function (oozieObj) {
  566. oozieObj.get('service_components').forEach(function (_component) {
  567. switch (_component.get('display_name')) {
  568. case 'Server':
  569. this.loadOozieServerValue(_component);
  570. break;
  571. case 'Database':
  572. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  573. // this.loadOozieDbValue(_component);
  574. break;
  575. default:
  576. }
  577. }, this);
  578. this.get('services').pushObject(oozieObj);
  579. },
  580. loadOozieServerValue: function (oozieServer) {
  581. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  582. oozieServer.set('component_value', oozieServerName.hostName);
  583. },
  584. loadOozieDbValue: function (dbComponent) {
  585. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  586. if (oozieDb.value === 'New PostgreSQL Database') {
  587. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  588. } else {
  589. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  590. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  591. }
  592. },
  593. /**
  594. * Load all info about Nagios service
  595. * @param nagiosObj
  596. */
  597. loadNagios: function (nagiosObj) {
  598. nagiosObj.service_components.forEach(function (_component) {
  599. switch (_component.display_name) {
  600. case 'Server':
  601. this.loadNagiosServerValue(_component);
  602. break;
  603. case 'Administrator':
  604. this.loadNagiosAdminValue(_component);
  605. break;
  606. default:
  607. }
  608. }, this);
  609. this.get('services').pushObject(nagiosObj);
  610. },
  611. loadNagiosServerValue: function (nagiosServer) {
  612. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  613. nagiosServer.set('component_value', nagiosServerName.hostName);
  614. },
  615. loadNagiosAdminValue: function (nagiosAdmin) {
  616. var config = this.get('content.serviceConfigProperties');
  617. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  618. var adminEmail = config.findProperty('name', 'nagios_contact');
  619. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  620. },
  621. /**
  622. * Load all info about ganglia
  623. * @param gangliaObj
  624. */
  625. loadGanglia: function (gangliaObj) {
  626. gangliaObj.get('service_components').forEach(function (_component) {
  627. switch (_component.get('display_name')) {
  628. case 'Server':
  629. this.loadGangliaServerValue(_component);
  630. break;
  631. default:
  632. }
  633. }, this);
  634. this.get('services').pushObject(gangliaObj);
  635. },
  636. loadGangliaServerValue: function (gangliaServer) {
  637. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  638. gangliaServer.set('component_value', gangliaServerName.hostName);
  639. },
  640. loadSqoop: function (sqoopObj) {
  641. this.get('services').pushObject(sqoopObj);
  642. },
  643. loadPig: function (pigObj) {
  644. this.get('services').pushObject(pigObj);
  645. },
  646. /**
  647. * Onclick handler for <code>next</code> button
  648. */
  649. submit: function () {
  650. if (this.get('isSubmitDisabled')) {
  651. return;
  652. }
  653. this.set('isSubmitDisabled', true);
  654. if (App.testMode || !this.get('content.cluster.requestId')) {
  655. this.createCluster();
  656. this.createSelectedServices();
  657. //this.setAmbariUIDb();
  658. this.createConfigurations();
  659. this.applyCreatedConfToServices();
  660. this.createComponents();
  661. this.registerHostsToCluster();
  662. this.createAllHostComponents();
  663. //this.applyCreatedConfToSlaveGroups();
  664. this.ajaxQueueFinished = function(){
  665. console.log('everything is loaded')
  666. App.router.send('next');
  667. };
  668. this.doNextAjaxCall();
  669. } else {
  670. App.router.send('next');
  671. }
  672. },
  673. setAmbariUIDb: function () {
  674. var dbContent = this.get('content.slaveGroupProperties');
  675. var slaveComponentConfig = this.get("slaveComponentConfig");
  676. this.persistKeyValues(slaveComponentConfig.version, dbContent);
  677. this.persistKeyValues('current_version',slaveComponentConfig.version);
  678. },
  679. persistKeyValues: function (key, value) {
  680. var str = "{ '" + key + "' : '" + JSON.stringify(value) + "'}";
  681. var obj = eval("(" + str + ")");
  682. this.ajax({
  683. type: "POST",
  684. url: App.apiPrefix + '/persist',
  685. data: JSON.stringify(obj),
  686. beforeSend: function () {
  687. console.log('BeforeSend: persistKeyValues', obj);
  688. }
  689. });
  690. },
  691. clusterName: function () {
  692. return this.get('content.cluster.name');
  693. }.property('content.cluster.name'),
  694. /**
  695. * The following create* functions are called upon submitting Step 8.
  696. */
  697. createCluster: function () {
  698. if (this.get('content.isWizard')) {
  699. return false;
  700. }
  701. var clusterName = this.get('clusterName');
  702. var url = App.apiPrefix + '/clusters/' + clusterName;
  703. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.defaultLocalStackVersion : App.defaultStackVersion;
  704. this.ajax({
  705. type: 'POST',
  706. url: url,
  707. data: JSON.stringify({ "Clusters": {"version": stackVersion }}),
  708. beforeSend: function () {
  709. console.log("BeforeSend: createCluster for " + clusterName);
  710. }
  711. });
  712. },
  713. createSelectedServices: function () {
  714. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  715. var data = this.createServiceData();
  716. var httpMethod = 'POST';
  717. if(!data.length){
  718. return;
  719. }
  720. this.ajax({
  721. type: httpMethod,
  722. url: url,
  723. data: JSON.stringify(data),
  724. beforeSend: function () {
  725. console.log('BeforeSend: createSelectedServices ', data);
  726. }
  727. });
  728. },
  729. createServiceData: function () {
  730. var services = this.get('selectedServices').mapProperty('serviceName');
  731. var data = [];
  732. services.forEach(function (_service) {
  733. data.pushObject({"ServiceInfo": { "service_name": _service }});
  734. }, this);
  735. return data;
  736. },
  737. createComponents: function () {
  738. var serviceComponents = require('data/service_components');
  739. var services = this.get('selectedServices').mapProperty('serviceName');
  740. services.forEach(function (_service) {
  741. var components = serviceComponents.filterProperty('service_name', _service);
  742. var componentsData = components.map(function (_component) {
  743. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  744. });
  745. debugger;
  746. // Service must be specified in terms of a query for creating multiple components at the same time.
  747. // See AMBARI-1018.
  748. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  749. var data = {
  750. "components": componentsData
  751. }
  752. this.ajax({
  753. type: 'POST',
  754. url: url,
  755. data: JSON.stringify(data),
  756. beforeSend: function () {
  757. console.log('BeforeSend: createComponents for ' + _service, componentsData);
  758. }
  759. });
  760. }, this);
  761. },
  762. registerHostsToCluster: function () {
  763. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  764. var data = this.createRegisterHostData();
  765. if (data.length == 0) {
  766. return;
  767. }
  768. this.ajax({
  769. type: 'POST',
  770. url: url,
  771. data: JSON.stringify(data),
  772. beforeSend: function () {
  773. console.log('BeforeSend: registerHostsToCluster', data);
  774. }
  775. });
  776. },
  777. createRegisterHostData: function () {
  778. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  779. if(!hosts.length){
  780. return [];
  781. }
  782. return hosts.map(function (host) {
  783. return {"Hosts": { "host_name": host.hostName}};
  784. });
  785. },
  786. // TODO: review the code for add hosts / add services scenarios...
  787. createAllHostComponents: function () {
  788. var masterHosts = this.get('content.masterComponentHosts');
  789. var slaveHosts = this.get('content.slaveComponentHosts');
  790. var clients = this.get('content.clients');
  791. var clientHosts = slaveHosts.filterProperty('componentName', "CLIENT").objectAt(0).hosts;
  792. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  793. var masterComponents = masterHosts.mapProperty('component').uniq();
  794. masterComponents.forEach(function (component) {
  795. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  796. this.registerHostsToComponent(hostNames, component);
  797. }, this);
  798. slaveHosts.forEach(function (_slave) {
  799. if (_slave.componentName !== 'CLIENT') {
  800. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  801. this.registerHostsToComponent(hostNames, _slave.componentName);
  802. } else {
  803. this.get('content.clients').forEach(function (_client) {
  804. if (!_client.isInstalled) {
  805. var hostNames = clientHosts.mapProperty('hostName').splice(0);
  806. switch (_client.component_name) {
  807. case 'HDFS_CLIENT':
  808. // install HDFS_CLIENT on HBASE_MASTER, HBASE_REGIONSERVER, and WEBHCAT_SERVER hosts
  809. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  810. hostNames.pushObject(_masterHost.hostName);
  811. }, this);
  812. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  813. hostNames.pushObject(_masterHost.hostName);
  814. }, this);
  815. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  816. hostNames.pushObject(_masterHost.hostName);
  817. }, this);
  818. break;
  819. case 'MAPREDUCE_CLIENT':
  820. // install MAPREDUCE_CLIENT on HIVE_SERVER, OOZIE_SERVER, NAGIOS_SERVER, and WEBHCAT_SERVER hosts
  821. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  822. hostNames.pushObject(_masterHost.hostName);
  823. }, this);
  824. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  825. hostNames.pushObject(_masterHost.hostName);
  826. }, this);
  827. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  828. hostNames.pushObject(_masterHost.hostName);
  829. }, this);
  830. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  831. hostNames.pushObject(_masterHost.hostName);
  832. }, this);
  833. break;
  834. case 'OOZIE_CLIENT':
  835. // install OOZIE_CLIENT on NAGIOS_SERVER host
  836. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  837. hostNames.pushObject(_masterHost.hostName);
  838. }, this);
  839. break;
  840. case 'ZOOKEEPER_CLIENT':
  841. // install ZOOKEEPER_CLIENT on WEBHCAT_SERVER host
  842. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  843. hostNames.pushObject(_masterHost.hostName);
  844. }, this);
  845. break;
  846. }
  847. hostNames = hostNames.uniq();
  848. this.registerHostsToComponent(hostNames, _client.component_name);
  849. }
  850. }, this);
  851. }
  852. }, this);
  853. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  854. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  855. if (gangliaService) {
  856. var hosts = this.getRegisteredHosts();
  857. if (gangliaService.get('isInstalled')) {
  858. hosts = hosts.filterProperty('isInstalled', false);
  859. }
  860. if (hosts.length) {
  861. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  862. }
  863. }
  864. // add MySQL Server if Hive is selected
  865. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  866. if (hiveService) {
  867. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  868. }
  869. },
  870. registerHostsToComponent: function (hostNames, componentName) {
  871. if (hostNames.length == 0) {
  872. return;
  873. }
  874. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  875. // currently we are specifying the predicate as a query string.
  876. // this can hit a ~4000-character limit in Jetty server.
  877. // chunk to multiple calls if needed
  878. // var hostsPredicate = hostNames.map(function (hostName) {
  879. // return 'Hosts/host_name=' + hostName;
  880. // }).join('|');
  881. var queryStrArr = [];
  882. var queryStr = '';
  883. hostNames.forEach(function (hostName) {
  884. queryStr += 'Hosts/host_name=' + hostName + '|';
  885. if (queryStr.length > 3500) {
  886. queryStrArr.push(queryStr.slice(0, -1));
  887. queryStr = '';
  888. }
  889. });
  890. if (queryStr.length > 0) {
  891. queryStrArr.push(queryStr.slice(0, -1));
  892. }
  893. queryStrArr.forEach(function (queryStr) {
  894. // console.log('creating host components for ' + queryStr);
  895. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + queryStr;
  896. var data = {
  897. "host_components": [
  898. {
  899. "HostRoles": {
  900. "component_name": componentName
  901. }
  902. }
  903. ]
  904. };
  905. this.ajax({
  906. type: 'POST',
  907. url: url,
  908. data: JSON.stringify(data),
  909. beforeSend: function () {
  910. console.log('BeforeSend: registerHostsToComponent for ' + queryStr + ' and component ' + componentName);
  911. }
  912. });
  913. }, this);
  914. },
  915. createConfigurations: function () {
  916. var selectedServices = this.get('selectedServices');
  917. if (!this.get('content.isWizard')) {
  918. this.createConfigSiteForService(this.createGlobalSiteObj());
  919. // this.createGlobalSitePerSlaveGroup();
  920. this.createConfigSiteForService(this.createCoreSiteObj());
  921. this.createConfigSiteForService(this.createHdfsSiteObj());
  922. //this.createHdfsSitePerSlaveGroup('HDFS');
  923. }
  924. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  925. this.createConfigSiteForService(this.createMrSiteObj());
  926. //this.createMrSitePerSlaveGroup('MAPREDUCE');
  927. }
  928. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  929. this.createConfigSiteForService(this.createHbaseSiteObj());
  930. //this.createHbaseSitePerSlaveGroup('HBASE');
  931. }
  932. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  933. this.createConfigSiteForService(this.createOozieSiteObj('OOZIE'));
  934. }
  935. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  936. this.createConfigSiteForService(this.createHiveSiteObj('HIVE'));
  937. }
  938. if (selectedServices.someProperty('serviceName', 'WEBHCAT')) {
  939. this.createConfigSiteForService(this.createWebHCatSiteObj('WEBHCAT'));
  940. }
  941. },
  942. createConfigSiteForService: function (data) {
  943. console.log("Inside createConfigSiteForService");
  944. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/configurations';
  945. this.ajax({
  946. type: 'POST',
  947. url: url,
  948. data: JSON.stringify(data),
  949. beforeSend: function () {
  950. console.log("BeforeSend: createConfigSiteForService for " + data.type);
  951. }
  952. });
  953. },
  954. createGlobalSiteObj: function () {
  955. var globalSiteProperties = {};
  956. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  957. this.get('globals').forEach(function (_globalSiteObj) {
  958. // do not pass any globals whose name ends with _host or _hosts
  959. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  960. // append "m" to JVM memory options
  961. var value = null;
  962. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  963. value = _globalSiteObj.value + "m";
  964. globalSiteProperties[_globalSiteObj.name] = value;
  965. } else {
  966. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  967. }
  968. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  969. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  970. }
  971. }, this);
  972. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  973. },
  974. createGlobalSitePerSlaveGroup: function () {
  975. this.get('slaveComponentConfig.components').forEach(function (_component) {
  976. _component.groups.forEach(function (_group) {
  977. var globalSiteProperties = {};
  978. var properties = _group.properties;
  979. properties.forEach(function (_property) {
  980. if (!/_hosts?$/.test(_property.name)) {
  981. // append "m" to JVM memory options
  982. var value = null;
  983. if (/_heapsize|_newsize|_maxnewsize$/.test(_property.name)) {
  984. value = _property.value + "m";
  985. globalSiteProperties[_property.name] = value;
  986. } else {
  987. globalSiteProperties[_property.name] = _property.storeValue;
  988. }
  989. console.log("STEP8: name of the global property is: " + _property.name);
  990. console.log("STEP8: value of the global property is: " + _property.storeValue);
  991. }
  992. }, this);
  993. var config = _group.configVersion.config;
  994. for (var index in config) {
  995. if (index === 'datanode-global' || index === 'tasktracker-global' || index === 'regionserver-global') {
  996. var data = {"type": index, "tag": config[index], "properties": globalSiteProperties};
  997. this.createConfigSiteForService(data);
  998. }
  999. }
  1000. }, this);
  1001. }, this);
  1002. },
  1003. createCoreSiteObj: function () {
  1004. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1005. var coreSiteProperties = {};
  1006. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1007. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1008. coreSiteObj.forEach(function (_coreSiteObj) {
  1009. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  1010. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1011. }
  1012. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  1013. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  1014. }, this);
  1015. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1016. },
  1017. createHdfsSiteObj: function () {
  1018. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  1019. var hdfsProperties = {};
  1020. hdfsSiteObj.forEach(function (_configProperty) {
  1021. hdfsProperties[_configProperty.name] = _configProperty.value;
  1022. console.log("STEP*: name of the property is: " + _configProperty.name);
  1023. console.log("STEP8: value of the property is: " + _configProperty.value);
  1024. }, this);
  1025. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  1026. },
  1027. createHdfsSitePerSlaveGroup: function (serviceName) {
  1028. var hdfsSite = this.createHdfsSiteObj();
  1029. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1030. component.groups.forEach(function (_group) {
  1031. var siteProperties = hdfsSite.properties;
  1032. _group.properties.forEach(function (_property) {
  1033. this.get('configMapping').forEach(function (_config) {
  1034. if (_config.templateName.contains(_property.name)) {
  1035. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1036. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1037. if (siteProperties[_config.name]) {
  1038. siteProperties[_config.name] = value;
  1039. }
  1040. }
  1041. }, this);
  1042. }, this);
  1043. var data = {"type": hdfsSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1044. console.log("The value of globalConfig is: " + JSON.stringify(siteProperties));
  1045. this.createConfigSiteForService(data);
  1046. }, this);
  1047. },
  1048. createMrSiteObj: function () {
  1049. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  1050. var mrProperties = {};
  1051. configs.forEach(function (_configProperty) {
  1052. mrProperties[_configProperty.name] = _configProperty.value;
  1053. console.log("STEP*: name of the property is: " + _configProperty.name);
  1054. console.log("STEP8: value of the property is: " + _configProperty.value);
  1055. }, this);
  1056. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  1057. },
  1058. createMrSitePerSlaveGroup: function (serviceName) {
  1059. var mrSite = this.createMrSiteObj();
  1060. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1061. component.groups.forEach(function (_group) {
  1062. var siteProperties = mrSite.properties;
  1063. _group.properties.forEach(function (_property) {
  1064. this.get('configMapping').forEach(function (_config) {
  1065. if (_config.templateName.contains(_property.name)) {
  1066. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1067. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1068. if (siteProperties[_config.name]) {
  1069. siteProperties[_config.name] = value;
  1070. }
  1071. }
  1072. }, this);
  1073. }, this);
  1074. var data = {"type": mrSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1075. this.createConfigSiteForService(data);
  1076. }, this);
  1077. },
  1078. createHbaseSiteObj: function () {
  1079. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  1080. var hbaseProperties = {};
  1081. configs.forEach(function (_configProperty) {
  1082. hbaseProperties[_configProperty.name] = _configProperty.value;
  1083. }, this);
  1084. var masterHosts = App.db.getMasterComponentHosts();
  1085. // TODO: should filter on "component" but that gives unexpected results
  1086. var zkServers = masterHosts.filterProperty('display_name', 'ZooKeeper').mapProperty('hostName');
  1087. hbaseProperties['hbase.zookeeper.quorum'] = zkServers.join(',');
  1088. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  1089. },
  1090. createHbaseSitePerSlaveGroup: function (serviceName) {
  1091. var hbaseSite = this.createHbaseSiteObj();
  1092. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1093. component.groups.forEach(function (_group) {
  1094. var siteProperties = hbaseSite.properties;
  1095. _group.properties.forEach(function (_property) {
  1096. this.get('configMapping').forEach(function (_config) {
  1097. if (_config.templateName.contains(_property.name)) {
  1098. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1099. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1100. if (siteProperties[_config.name]) {
  1101. siteProperties[_config.name] = value;
  1102. }
  1103. }
  1104. }, this);
  1105. }, this);
  1106. var data = {"type": hbaseSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1107. this.createConfigSiteForService(data);
  1108. }, this);
  1109. },
  1110. createOozieSiteObj: function (serviceName) {
  1111. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  1112. var oozieProperties = {};
  1113. configs.forEach(function (_configProperty) {
  1114. oozieProperties[_configProperty.name] = _configProperty.value;
  1115. }, this);
  1116. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  1117. },
  1118. createHiveSiteObj: function (serviceName) {
  1119. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  1120. var hiveProperties = {};
  1121. configs.forEach(function (_configProperty) {
  1122. hiveProperties[_configProperty.name] = _configProperty.value;
  1123. }, this);
  1124. hiveProperties['hive.metastore.uris'] = 'thrift://' + this.get('globals').findProperty('hivemetastore_host').value + ':9083';
  1125. hiveProperties['javax.jdo.option.ConnectionURL'] =
  1126. 'jdbc:mysql://' + this.get('globals').findProperty('name', 'hive_mysql_host').value +
  1127. '/' + this.get('globals').findProperty('name', 'hive_database_name').value + '?createDatabaseIfNotExist=true';
  1128. return {type: 'hive-site', tag: 'version1', properties: hiveProperties};
  1129. },
  1130. createWebHCatSiteObj: function (serviceName) {
  1131. var configs = this.get('configs').filterProperty('filename', 'webhcat-site.xml');
  1132. var webHCatProperties = {};
  1133. configs.forEach(function (_configProperty) {
  1134. webHCatProperties[_configProperty.name] = _configProperty.value;
  1135. }, this);
  1136. return {type: 'webhcat-site', tag: 'version1', properties: webHCatProperties};
  1137. },
  1138. applyCreatedConfToServices: function () {
  1139. var services = this.get('selectedServices').mapProperty('serviceName');
  1140. services.forEach(function (_service) {
  1141. var data = this.getConfigForService(_service);
  1142. this.applyCreatedConfToService(_service, 'PUT', data);
  1143. }, this);
  1144. },
  1145. applyCreatedConfToService: function (service, httpMethod, data) {
  1146. console.log("Inside applyCreatedConfToService");
  1147. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services/' + service;
  1148. this.ajax({
  1149. type: httpMethod,
  1150. url: url,
  1151. data: JSON.stringify(data),
  1152. beforeSend: function () {
  1153. console.log("BeforeSend: applyCreatedConfToService for " + service);
  1154. }
  1155. });
  1156. },
  1157. applyCreatedConfToSlaveGroups: function () {
  1158. this.get('slaveComponentConfig.components').forEach(function (_component) {
  1159. _component.groups.forEach(function (_group) {
  1160. var aggregatedHostNames = '';
  1161. _group.hostNames.forEach(function (_hostName, index) {
  1162. aggregatedHostNames += 'HostRoles/host_name=' + _hostName;
  1163. if (index !== _group.hostNames.length-1) {
  1164. aggregatedHostNames += '|';
  1165. }
  1166. }, this);
  1167. console.log("The aggregated hostNames value is: " + aggregatedHostNames);
  1168. this.applyCreatedConfToSlaveGroup(aggregatedHostNames, 'PUT', _group.configVersion,_group.groupName);
  1169. }, this);
  1170. }, this);
  1171. },
  1172. applyCreatedConfToSlaveGroup: function (aggregatedHostNames, httpMethod, data, groupName) {
  1173. console.log("Inside applyCreatedConfToHost");
  1174. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/host_components?' + aggregatedHostNames;
  1175. this.ajax({
  1176. type: httpMethod,
  1177. url: url,
  1178. data: JSON.stringify(data),
  1179. beforeSend: function () {
  1180. console.log("BeforeSend: applyCreatedConfToSlaveGroup for group: " + groupName);
  1181. }
  1182. });
  1183. },
  1184. getConfigForService: function (serviceName) {
  1185. switch (serviceName) {
  1186. case 'HDFS':
  1187. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  1188. case 'MAPREDUCE':
  1189. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  1190. case 'HBASE':
  1191. return {config: {'global': 'version1', 'core-site': 'version1', 'hbase-site': 'version1'}};
  1192. case 'OOZIE':
  1193. return {config: {'global': 'version1', 'core-site': 'version1', 'oozie-site': 'version1'}};
  1194. case 'HIVE':
  1195. return {config: {'global': 'version1', 'core-site': 'version1', 'hive-site': 'version1'}};
  1196. case 'WEBHCAT':
  1197. return {config: {'global': 'version1', 'core-site': 'version1', 'webhcat-site': 'version1'}};
  1198. default:
  1199. return {config: {'global': 'version1'}};
  1200. }
  1201. },
  1202. ajaxQueue: [],
  1203. ajaxQueueFinished: function () {
  1204. //do something
  1205. },
  1206. doNextAjaxCall: function () {
  1207. if (this.get('ajaxBusy')) {
  1208. return;
  1209. }
  1210. var queue = this.get('ajaxQueue');
  1211. if (!queue.length) {
  1212. this.ajaxQueueFinished();
  1213. return;
  1214. }
  1215. var first = queue[0];
  1216. this.set('ajaxQueue', queue.slice(1));
  1217. this.set('ajaxBusy', true);
  1218. console.log('AJAX send ' + first.url);
  1219. $.ajax(first);
  1220. },
  1221. /**
  1222. * We need to do a lot of ajax calls(about 10 or more) async in special order.
  1223. * To do this i generate array of ajax objects and then send requests step by step.
  1224. * All ajax objects are stored in <code>ajaxQueue</code>
  1225. * @param params
  1226. */
  1227. ajax: function(params){
  1228. if(App.testMode) return;
  1229. var self = this;
  1230. params = jQuery.extend({
  1231. async: true,
  1232. dataType: 'text',
  1233. statusCode: require('data/statusCodes'),
  1234. timeout: App.timeout,
  1235. error: function (request, ajaxOptions, error) {
  1236. console.log('Step8: In Error ');
  1237. console.log('Step8: Error message is: ' + request.responseText);
  1238. },
  1239. success: function (data) {
  1240. var jsonData = jQuery.parseJSON(data);
  1241. console.log("TRACE: STep8 -> In success function");
  1242. console.log("TRACE: STep8 -> value of the url is: " + params.url);
  1243. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  1244. }
  1245. }, params);
  1246. var success = params.success;
  1247. var error = params.error;
  1248. params.success = function () {
  1249. if (success) {
  1250. success();
  1251. }
  1252. ;
  1253. self.set('ajaxBusy', false);
  1254. self.doNextAjaxCall();
  1255. }
  1256. params.error = function () {
  1257. if (error) {
  1258. error();
  1259. }
  1260. ;
  1261. self.set('ajaxBusy', false);
  1262. self.doNextAjaxCall();
  1263. }
  1264. this.get('ajaxQueue').pushObject(params);
  1265. }
  1266. })