step8_controller.js 54 KB

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