step8_controller.js 54 KB

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