step8_controller.js 53 KB

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