step8_controller.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564
  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. servicesInstalled: false,
  32. selectedServices: function () {
  33. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  34. }.property('content.services').cacheable(),
  35. clearStep: function () {
  36. this.get('services').clear();
  37. this.get('configs').clear();
  38. this.get('globals').clear();
  39. this.get('clusterInfo').clear();
  40. this.set('servicesInstalled', false);
  41. },
  42. loadStep: function () {
  43. console.log("TRACE: Loading step8: Review Page");
  44. this.clearStep();
  45. this.loadGlobals();
  46. this.loadConfigs();
  47. this.setCustomConfigs();
  48. //this.loadSlaveConfiguration();
  49. this.loadClusterInfo();
  50. this.loadServices();
  51. this.set('isSubmitDisabled', false);
  52. },
  53. loadGlobals: function () {
  54. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  55. if (globals.someProperty('name', 'hive_database')) {
  56. //TODO: Hive host depends on the type of db selected. Change puppet variable name if postgres is not the default db
  57. var hiveDb = globals.findProperty('name', 'hive_database');
  58. if (hiveDb.value === 'New MySQL Database') {
  59. if (globals.someProperty('name', 'hive_ambari_host')) {
  60. globals.findProperty('name', 'hive_ambari_host').name = 'hive_mysql_hostname';
  61. }
  62. globals = globals.without(globals.findProperty('name', 'hive_existing_host'));
  63. globals = globals.without(globals.findProperty('name', 'hive_existing_database'));
  64. } else {
  65. globals.findProperty('name', 'hive_existing_host').name = 'hive_mysql_hostname';
  66. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  67. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  68. }
  69. }
  70. this.set('globals', globals);
  71. },
  72. loadConfigs: function () {
  73. var storedConfigs = this.get('content.serviceConfigProperties').filterProperty('id', 'site property').filterProperty('value');
  74. var uiConfigs = this.loadUiSideConfigs();
  75. this.set('configs', storedConfigs.concat(uiConfigs));
  76. },
  77. loadUiSideConfigs: function () {
  78. var uiConfig = [];
  79. var configs = this.get('configMapping').filterProperty('foreignKey', null);
  80. configs.forEach(function (_config) {
  81. var value = this.getGlobConfigValue(_config.templateName, _config.value, _config.name);
  82. uiConfig.pushObject({
  83. "id": "site property",
  84. "name": _config.name,
  85. "value": value,
  86. "filename": _config.filename
  87. });
  88. }, this);
  89. var dependentConfig = this.get('configMapping').filterProperty('foreignKey');
  90. dependentConfig.forEach(function (_config) {
  91. this.setConfigValue(uiConfig, _config);
  92. uiConfig.pushObject({
  93. "id": "site property",
  94. "name": _config.name,
  95. "value": _config.value,
  96. "filename": _config.filename
  97. });
  98. }, this);
  99. return uiConfig;
  100. },
  101. getRegisteredHosts: function () {
  102. var allHosts = this.get('content.hosts');
  103. var hosts = [];
  104. for (var hostName in allHosts) {
  105. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  106. allHosts[hostName].hostName = allHosts[hostName].name;
  107. hosts.pushObject(allHosts[hostName]);
  108. }
  109. }
  110. return hosts;
  111. },
  112. /**
  113. * Set all site property that are derived from other puppet-variable
  114. */
  115. getGlobConfigValue: function (templateName, expression, name) {
  116. var express = expression.match(/<(.*?)>/g);
  117. var value = expression;
  118. if (express == null) {
  119. return expression;
  120. }
  121. express.forEach(function (_express) {
  122. //console.log("The value of template is: " + _express);
  123. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  124. if (this.get('globals').someProperty('name', templateName[index])) {
  125. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  126. var globValue = this.get('globals').findProperty('name', templateName[index]).value;
  127. // Hack for templeton.zookeeper.hosts
  128. 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
  129. if (name === "templeton.zookeeper.hosts" || name === 'hbase.zookeeper.quorum') {
  130. // globValue is an array of ZooKeeper Server hosts
  131. var zooKeeperPort = '2181';
  132. if (name === "templeton.zookeeper.hosts") {
  133. var zooKeeperServers = globValue.map(function (item) {
  134. return item + ':' + zooKeeperPort;
  135. }).join(',');
  136. value = value.replace(_express, zooKeeperServers);
  137. } else {
  138. value = value.replace(_express, globValue.join(','));
  139. }
  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. _keyValue = _keyValue.trim();
  222. console.log("The value of the keyValue is: " + _keyValue);
  223. // split on the first = encountered (the value may contain ='s)
  224. var matches = _keyValue.match(/^([^=]+)=(.*)$/);
  225. if (matches) {
  226. var key = matches[1];
  227. var value = matches[2];
  228. if (key) {
  229. this.setSiteProperty(key, value, _site.name + '.xml');
  230. }
  231. }
  232. }, this);
  233. }
  234. }, this);
  235. },
  236. /**
  237. * Set property of the site variable
  238. */
  239. setSiteProperty: function (key, value, filename) {
  240. this.get('configs').pushObject({
  241. "id": "site property",
  242. "name": key,
  243. "value": value,
  244. "filename": filename
  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 + Em.I18n.t('installer.step8.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 + Em.I18n.t('installer.step8.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', 'HiveServer2');
  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').filterProperty('display_name', 'HBase Master');
  556. if(hbaseHostName.length == 1){
  557. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  558. } else {
  559. hbaseMaster.set('component_value', hbaseHostName[0].hostName + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  560. }
  561. },
  562. loadRegionServerValue: function (rsComponent) {
  563. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  564. var totalRsHosts = rsHosts.hosts.length;
  565. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'HBASE_REGIONSERVER').groups.length;
  566. var groupLabel;
  567. if (totalGroups == 1) {
  568. groupLabel = 'group';
  569. } else {
  570. groupLabel = 'groups';
  571. } */
  572. rsComponent.set('component_value', totalRsHosts + Em.I18n.t('installer.step8.hosts'));
  573. },
  574. /**
  575. * Load all info about ZooKeeper service
  576. * @param zkObj
  577. */
  578. loadZk: function (zkObj) {
  579. zkObj.get('service_components').forEach(function (_component) {
  580. switch (_component.get('display_name')) {
  581. case 'Servers':
  582. this.loadZkServerValue(_component);
  583. break;
  584. default:
  585. }
  586. }, this);
  587. this.get('services').pushObject(zkObj);
  588. },
  589. loadZkServerValue: function (serverComponent) {
  590. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  591. var hostSuffix;
  592. if (zkHostNames === 1) {
  593. hostSuffix = Em.I18n.t('installer.step8.host');
  594. } else {
  595. hostSuffix = Em.I18n.t('installer.step8.hosts');
  596. }
  597. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  598. },
  599. /**
  600. * Load all info about Oozie services
  601. * @param oozieObj
  602. */
  603. loadOozie: function (oozieObj) {
  604. oozieObj.get('service_components').forEach(function (_component) {
  605. switch (_component.get('display_name')) {
  606. case 'Server':
  607. this.loadOozieServerValue(_component);
  608. break;
  609. case 'Database':
  610. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  611. // this.loadOozieDbValue(_component);
  612. break;
  613. default:
  614. }
  615. }, this);
  616. this.get('services').pushObject(oozieObj);
  617. },
  618. loadOozieServerValue: function (oozieServer) {
  619. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  620. oozieServer.set('component_value', oozieServerName.hostName);
  621. },
  622. loadOozieDbValue: function (dbComponent) {
  623. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  624. if (oozieDb.value === 'New PostgreSQL Database') {
  625. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  626. } else {
  627. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  628. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  629. }
  630. },
  631. /**
  632. * Load all info about Nagios service
  633. * @param nagiosObj
  634. */
  635. loadNagios: function (nagiosObj) {
  636. nagiosObj.service_components.forEach(function (_component) {
  637. switch (_component.display_name) {
  638. case 'Server':
  639. this.loadNagiosServerValue(_component);
  640. break;
  641. case 'Administrator':
  642. this.loadNagiosAdminValue(_component);
  643. break;
  644. default:
  645. }
  646. }, this);
  647. this.get('services').pushObject(nagiosObj);
  648. },
  649. loadNagiosServerValue: function (nagiosServer) {
  650. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  651. nagiosServer.set('component_value', nagiosServerName.hostName);
  652. },
  653. loadNagiosAdminValue: function (nagiosAdmin) {
  654. var config = this.get('content.serviceConfigProperties');
  655. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  656. var adminEmail = config.findProperty('name', 'nagios_contact');
  657. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  658. },
  659. /**
  660. * Load all info about ganglia
  661. * @param gangliaObj
  662. */
  663. loadGanglia: function (gangliaObj) {
  664. gangliaObj.get('service_components').forEach(function (_component) {
  665. switch (_component.get('display_name')) {
  666. case 'Server':
  667. this.loadGangliaServerValue(_component);
  668. break;
  669. default:
  670. }
  671. }, this);
  672. this.get('services').pushObject(gangliaObj);
  673. },
  674. loadGangliaServerValue: function (gangliaServer) {
  675. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  676. gangliaServer.set('component_value', gangliaServerName.hostName);
  677. },
  678. loadSqoop: function (sqoopObj) {
  679. this.get('services').pushObject(sqoopObj);
  680. },
  681. loadPig: function (pigObj) {
  682. this.get('services').pushObject(pigObj);
  683. },
  684. /**
  685. * Onclick handler for <code>next</code> button
  686. */
  687. submit: function () {
  688. if (this.get('isSubmitDisabled')) {
  689. return;
  690. }
  691. this.set('isSubmitDisabled', true);
  692. // checkpoint the cluster status on the server so that the user can resume from where they left off
  693. switch (this.get('content.controllerName')) {
  694. case 'installerController':
  695. App.clusterStatus.setClusterStatus({
  696. clusterName: this.get('clusterName'),
  697. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  698. wizardControllerName: this.get('content.controllerName'),
  699. localdb: App.db.data
  700. });
  701. break;
  702. case 'addHostController':
  703. App.clusterStatus.setClusterStatus({
  704. clusterName: this.get('clusterName'),
  705. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  706. wizardControllerName: this.get('content.controllerName'),
  707. localdb: App.db.data
  708. });
  709. break;
  710. default:
  711. break;
  712. }
  713. // delete any existing clusters to start from a clean slate
  714. // before creating a new cluster in install wizard
  715. // TODO: modify for multi-cluster support
  716. if (this.get('content.controllerName') == 'installerController') {
  717. var clusterNames = this.getExistingClusterNames();
  718. this.deleteClusters(clusterNames);
  719. }
  720. this.createCluster();
  721. this.createSelectedServices();
  722. this.createConfigurations();
  723. this.applyCreatedConfToServices();
  724. this.createComponents();
  725. this.registerHostsToCluster();
  726. this.createAllHostComponents();
  727. this.ajaxQueueFinished = function () {
  728. console.log('everything is loaded')
  729. App.router.send('next');
  730. };
  731. this.doNextAjaxCall();
  732. },
  733. /**
  734. * Used in progress bar
  735. */
  736. ajaxQueueLength: function() {
  737. return this.get('ajaxQueue').length;
  738. }.property('ajaxQueue.length'),
  739. /**
  740. * Used in progress bar
  741. */
  742. ajaxQueueLeft: 0,
  743. setAmbariUIDb: function () {
  744. var dbContent = this.get('content.slaveGroupProperties');
  745. var slaveComponentConfig = this.get("slaveComponentConfig");
  746. this.persistKeyValues(slaveComponentConfig.version, dbContent);
  747. this.persistKeyValues('current_version', slaveComponentConfig.version);
  748. },
  749. persistKeyValues: function (key, value) {
  750. var str = "{ '" + key + "' : '" + JSON.stringify(value) + "'}";
  751. var obj = eval("(" + str + ")");
  752. this.ajax({
  753. type: "POST",
  754. url: App.apiPrefix + '/persist',
  755. data: JSON.stringify(obj),
  756. beforeSend: function () {
  757. console.log('BeforeSend: persistKeyValues', obj);
  758. }
  759. });
  760. },
  761. clusterName: function () {
  762. return this.get('content.cluster.name');
  763. }.property('content.cluster.name'),
  764. // returns an array of existing cluster names.
  765. // returns an empty array if there are no existing clusters.
  766. getExistingClusterNames: function () {
  767. var url = App.apiPrefix + '/clusters';
  768. var clusterNames = [];
  769. $.ajax({
  770. type: 'GET',
  771. url: url,
  772. async: false,
  773. success: function(data) {
  774. var jsonData = jQuery.parseJSON(data);
  775. clusterNames = jsonData.items.mapProperty('Clusters.cluster_name');
  776. console.log("Got existing cluster names: " + clusterNames);
  777. },
  778. error: function () {
  779. console.log("Failed to get existing cluster names");
  780. }
  781. });
  782. return clusterNames;
  783. },
  784. deleteClusters: function (clusterNames) {
  785. clusterNames.forEach(function(clusterName) {
  786. var url = App.apiPrefix + '/clusters/' + clusterName;
  787. $.ajax({
  788. type: 'DELETE',
  789. url: url,
  790. async: false,
  791. success: function () {
  792. console.log('DELETE cluster ' + clusterName + ' succeeded');
  793. },
  794. error: function () {
  795. console.log('DELETE cluster ' + clusterName + ' failed');
  796. }
  797. });
  798. });
  799. },
  800. /**
  801. * The following create* functions are called upon submitting Step 8.
  802. */
  803. createCluster: function () {
  804. if (this.get('content.isWizard')) {
  805. return false;
  806. }
  807. var clusterName = this.get('clusterName');
  808. var url = App.apiPrefix + '/clusters/' + clusterName;
  809. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.defaultLocalStackVersion : App.defaultStackVersion;
  810. this.ajax({
  811. type: 'POST',
  812. url: url,
  813. data: JSON.stringify({ "Clusters": {"version": stackVersion }}),
  814. beforeSend: function () {
  815. console.log("BeforeSend: createCluster for " + clusterName);
  816. }
  817. });
  818. },
  819. createSelectedServices: function () {
  820. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  821. var data = this.createServiceData();
  822. var httpMethod = 'POST';
  823. if (!data.length) {
  824. return;
  825. }
  826. this.ajax({
  827. type: httpMethod,
  828. url: url,
  829. data: JSON.stringify(data),
  830. beforeSend: function () {
  831. console.log('BeforeSend: createSelectedServices ', data);
  832. }
  833. });
  834. },
  835. createServiceData: function () {
  836. var services = this.get('selectedServices').mapProperty('serviceName');
  837. var data = [];
  838. services.forEach(function (_service) {
  839. data.pushObject({"ServiceInfo": { "service_name": _service }});
  840. }, this);
  841. return data;
  842. },
  843. createComponents: function () {
  844. var serviceComponents = require('data/service_components');
  845. var services = this.get('selectedServices').mapProperty('serviceName');
  846. services.forEach(function (_service) {
  847. var components = serviceComponents.filterProperty('service_name', _service);
  848. var componentsData = components.map(function (_component) {
  849. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  850. });
  851. // Service must be specified in terms of a query for creating multiple components at the same time.
  852. // See AMBARI-1018.
  853. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  854. var data = {
  855. "components": componentsData
  856. }
  857. this.ajax({
  858. type: 'POST',
  859. url: url,
  860. data: JSON.stringify(data),
  861. beforeSend: function () {
  862. console.log('BeforeSend: createComponents for ' + _service, componentsData);
  863. }
  864. });
  865. }, this);
  866. },
  867. registerHostsToCluster: function () {
  868. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  869. var data = this.createRegisterHostData();
  870. if (data.length == 0) {
  871. return;
  872. }
  873. this.ajax({
  874. type: 'POST',
  875. url: url,
  876. data: JSON.stringify(data),
  877. beforeSend: function () {
  878. console.log('BeforeSend: registerHostsToCluster', data);
  879. }
  880. });
  881. },
  882. createRegisterHostData: function () {
  883. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  884. if (!hosts.length) {
  885. return [];
  886. }
  887. return hosts.map(function (host) {
  888. return {"Hosts": { "host_name": host.hostName}};
  889. });
  890. },
  891. // TODO: review the code for add hosts / add services scenarios...
  892. createAllHostComponents: function () {
  893. var masterHosts = this.get('content.masterComponentHosts');
  894. var slaveHosts = this.get('content.slaveComponentHosts');
  895. var clients = this.get('content.clients');
  896. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  897. var masterComponents = masterHosts.mapProperty('component').uniq();
  898. masterComponents.forEach(function (component) {
  899. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  900. this.registerHostsToComponent(hostNames, component);
  901. }, this);
  902. slaveHosts.forEach(function (_slave) {
  903. if (_slave.componentName !== 'CLIENT') {
  904. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  905. this.registerHostsToComponent(hostNames, _slave.componentName);
  906. } else {
  907. clients.forEach(function (_client) {
  908. var hostNames = _slave.hosts.mapProperty('hostName');
  909. switch (_client.component_name) {
  910. case 'HDFS_CLIENT':
  911. // install HDFS_CLIENT on HBASE_MASTER, HBASE_REGIONSERVER, and WEBHCAT_SERVER hosts
  912. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  913. hostNames.pushObject(_masterHost.hostName);
  914. }, this);
  915. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  916. hostNames.pushObject(_masterHost.hostName);
  917. }, this);
  918. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  919. hostNames.pushObject(_masterHost.hostName);
  920. }, this);
  921. break;
  922. case 'MAPREDUCE_CLIENT':
  923. // install MAPREDUCE_CLIENT on HIVE_SERVER, OOZIE_SERVER, NAGIOS_SERVER, and WEBHCAT_SERVER hosts
  924. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  925. hostNames.pushObject(_masterHost.hostName);
  926. }, this);
  927. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  928. hostNames.pushObject(_masterHost.hostName);
  929. }, this);
  930. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  931. hostNames.pushObject(_masterHost.hostName);
  932. }, this);
  933. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  934. hostNames.pushObject(_masterHost.hostName);
  935. }, this);
  936. break;
  937. case 'OOZIE_CLIENT':
  938. // install OOZIE_CLIENT on NAGIOS_SERVER host
  939. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  940. hostNames.pushObject(_masterHost.hostName);
  941. }, this);
  942. break;
  943. case 'ZOOKEEPER_CLIENT':
  944. // install ZOOKEEPER_CLIENT on WEBHCAT_SERVER host
  945. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  946. hostNames.pushObject(_masterHost.hostName);
  947. }, this);
  948. break;
  949. case 'HIVE_CLIENT':
  950. //install HIVE client on NAGIOS_SERVER host
  951. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  952. hostNames.pushObject(_masterHost.hostName);
  953. }, this);
  954. break;
  955. case 'HCAT':
  956. // install HCAT (client) on NAGIOS_SERVER host
  957. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  958. hostNames.pushObject(_masterHost.hostName);
  959. }, this);
  960. break;
  961. }
  962. hostNames = hostNames.uniq();
  963. if(_client.isInstalled){
  964. //check whether clients are already installed on selected master hosts!!!
  965. var installedHosts = _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName');
  966. installedHosts.forEach(function(host){
  967. if(hostNames.contains(host)){
  968. hostNames.splice(hostNames.indexOf(host), 1);
  969. }
  970. }, this);
  971. }
  972. this.registerHostsToComponent(hostNames, _client.component_name);
  973. }, this);
  974. }
  975. }, this);
  976. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  977. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  978. if (gangliaService) {
  979. var hosts = this.getRegisteredHosts();
  980. if (gangliaService.get('isInstalled')) {
  981. hosts = hosts.filterProperty('isInstalled', false);
  982. }
  983. if (hosts.length) {
  984. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  985. }
  986. }
  987. // add MySQL Server if Hive is selected
  988. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  989. if (hiveService) {
  990. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  991. }
  992. },
  993. registerHostsToComponent: function (hostNames, componentName) {
  994. if (hostNames.length == 0) {
  995. return;
  996. }
  997. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  998. // currently we are specifying the predicate as a query string.
  999. // this can hit a ~4000-character limit in Jetty server.
  1000. // chunk to multiple calls if needed
  1001. // var hostsPredicate = hostNames.map(function (hostName) {
  1002. // return 'Hosts/host_name=' + hostName;
  1003. // }).join('|');
  1004. var queryStrArr = [];
  1005. var queryStr = '';
  1006. hostNames.forEach(function (hostName) {
  1007. queryStr += 'Hosts/host_name=' + hostName + '|';
  1008. if (queryStr.length > 3500) {
  1009. queryStrArr.push(queryStr.slice(0, -1));
  1010. queryStr = '';
  1011. }
  1012. });
  1013. if (queryStr.length > 0) {
  1014. queryStrArr.push(queryStr.slice(0, -1));
  1015. }
  1016. queryStrArr.forEach(function (queryStr) {
  1017. // console.log('creating host components for ' + queryStr);
  1018. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + queryStr;
  1019. var data = {
  1020. "host_components": [
  1021. {
  1022. "HostRoles": {
  1023. "component_name": componentName
  1024. }
  1025. }
  1026. ]
  1027. };
  1028. this.ajax({
  1029. type: 'POST',
  1030. url: url,
  1031. data: JSON.stringify(data),
  1032. beforeSend: function () {
  1033. console.log('BeforeSend: registerHostsToComponent for ' + queryStr + ' and component ' + componentName);
  1034. }
  1035. });
  1036. }, this);
  1037. },
  1038. createConfigurations: function () {
  1039. var selectedServices = this.get('selectedServices');
  1040. if (!this.get('content.isWizard')) {
  1041. this.createConfigSiteForService(this.createGlobalSiteObj());
  1042. // this.createGlobalSitePerSlaveGroup();
  1043. this.createConfigSiteForService(this.createCoreSiteObj());
  1044. this.createConfigSiteForService(this.createHdfsSiteObj());
  1045. //this.createHdfsSitePerSlaveGroup('HDFS');
  1046. }
  1047. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  1048. this.createConfigSiteForService(this.createMrSiteObj());
  1049. //this.createMrSitePerSlaveGroup('MAPREDUCE');
  1050. }
  1051. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  1052. this.createConfigSiteForService(this.createHbaseSiteObj());
  1053. //this.createHbaseSitePerSlaveGroup('HBASE');
  1054. }
  1055. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  1056. this.createConfigSiteForService(this.createOozieSiteObj('OOZIE'));
  1057. }
  1058. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  1059. this.createConfigSiteForService(this.createHiveSiteObj('HIVE'));
  1060. }
  1061. if (selectedServices.someProperty('serviceName', 'WEBHCAT')) {
  1062. this.createConfigSiteForService(this.createWebHCatSiteObj('WEBHCAT'));
  1063. }
  1064. },
  1065. createConfigSiteForService: function (data) {
  1066. console.log("Inside createConfigSiteForService");
  1067. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/configurations';
  1068. this.ajax({
  1069. type: 'POST',
  1070. url: url,
  1071. data: JSON.stringify(data),
  1072. beforeSend: function () {
  1073. console.log("BeforeSend: createConfigSiteForService for " + data.type);
  1074. }
  1075. });
  1076. },
  1077. createGlobalSiteObj: function () {
  1078. var globalSiteProperties = {};
  1079. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  1080. this.get('globals').forEach(function (_globalSiteObj) {
  1081. // do not pass any globals whose name ends with _host or _hosts
  1082. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  1083. // append "m" to JVM memory options except for hadoop_heapsize
  1084. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && _globalSiteObj.name !== 'hadoop_heapsize') {
  1085. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1086. } else {
  1087. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  1088. }
  1089. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  1090. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  1091. }
  1092. if (_globalSiteObj.name == 'java64_home') {
  1093. globalSiteProperties['java64_home'] = this.get('content.installOptions.javaHome');
  1094. }
  1095. }, this);
  1096. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1097. },
  1098. createGlobalSitePerSlaveGroup: function () {
  1099. this.get('slaveComponentConfig.components').forEach(function (_component) {
  1100. _component.groups.forEach(function (_group) {
  1101. var globalSiteProperties = {};
  1102. var properties = _group.properties;
  1103. properties.forEach(function (_property) {
  1104. if (!/_hosts?$/.test(_property.name)) {
  1105. // append "m" to JVM memory options except for hadoop_heapsize
  1106. if (/_heapsize|_newsize|_maxnewsize$/.test(_property.name) && _property.name !== 'hadoop_heapsize') {
  1107. globalSiteProperties[_property.name] = _property.value + "m";
  1108. } else {
  1109. globalSiteProperties[_property.name] = _property.storeValue;
  1110. }
  1111. console.log("STEP8: name of the global property is: " + _property.name);
  1112. console.log("STEP8: value of the global property is: " + _property.storeValue);
  1113. }
  1114. }, this);
  1115. var config = _group.configVersion.config;
  1116. for (var index in config) {
  1117. if (index === 'datanode-global' || index === 'tasktracker-global' || index === 'regionserver-global') {
  1118. var data = {"type": index, "tag": config[index], "properties": globalSiteProperties};
  1119. this.createConfigSiteForService(data);
  1120. }
  1121. }
  1122. }, this);
  1123. }, this);
  1124. },
  1125. createCoreSiteObj: function () {
  1126. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1127. var coreSiteProperties = {};
  1128. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1129. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1130. var oozieUser = this.get('globals').someProperty('name','oozie_user') ? this.get('globals').findProperty('name','oozie_user').value : null;
  1131. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1132. var hiveUser = this.get('globals').someProperty('name','hive_user') ? this.get('globals').findProperty('name','hive_user').value : null;
  1133. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1134. var hcatUser = this.get('globals').someProperty('name','hcat_user') ? this.get('globals').findProperty('name','hcat_user').value : null;
  1135. coreSiteObj.forEach(function (_coreSiteObj) {
  1136. if ((isOozieSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser +'.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser +'.groups')) && (isHiveSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser +'.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.groups')) && (isHcatSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser +'.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.groups'))) {
  1137. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1138. }
  1139. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  1140. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  1141. }, this);
  1142. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1143. },
  1144. createHdfsSiteObj: function () {
  1145. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  1146. var hdfsProperties = {};
  1147. hdfsSiteObj.forEach(function (_configProperty) {
  1148. hdfsProperties[_configProperty.name] = _configProperty.value;
  1149. console.log("STEP*: name of the property is: " + _configProperty.name);
  1150. console.log("STEP8: value of the property is: " + _configProperty.value);
  1151. }, this);
  1152. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  1153. },
  1154. createHdfsSitePerSlaveGroup: function (serviceName) {
  1155. var hdfsSite = this.createHdfsSiteObj();
  1156. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1157. component.groups.forEach(function (_group) {
  1158. var siteProperties = hdfsSite.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": hdfsSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1171. console.log("The value of globalConfig is: " + JSON.stringify(siteProperties));
  1172. this.createConfigSiteForService(data);
  1173. }, this);
  1174. },
  1175. createMrSiteObj: function () {
  1176. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  1177. var mrProperties = {};
  1178. configs.forEach(function (_configProperty) {
  1179. mrProperties[_configProperty.name] = _configProperty.value;
  1180. console.log("STEP*: name of the property is: " + _configProperty.name);
  1181. console.log("STEP8: value of the property is: " + _configProperty.value);
  1182. }, this);
  1183. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  1184. },
  1185. createMrSitePerSlaveGroup: function (serviceName) {
  1186. var mrSite = this.createMrSiteObj();
  1187. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1188. component.groups.forEach(function (_group) {
  1189. var siteProperties = mrSite.properties;
  1190. _group.properties.forEach(function (_property) {
  1191. this.get('configMapping').forEach(function (_config) {
  1192. if (_config.templateName.contains(_property.name)) {
  1193. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1194. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1195. if (siteProperties[_config.name]) {
  1196. siteProperties[_config.name] = value;
  1197. }
  1198. }
  1199. }, this);
  1200. }, this);
  1201. var data = {"type": mrSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1202. this.createConfigSiteForService(data);
  1203. }, this);
  1204. },
  1205. createHbaseSiteObj: function () {
  1206. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  1207. var hbaseProperties = {};
  1208. configs.forEach(function (_configProperty) {
  1209. hbaseProperties[_configProperty.name] = _configProperty.value;
  1210. }, this);
  1211. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  1212. },
  1213. createHbaseSitePerSlaveGroup: function (serviceName) {
  1214. var hbaseSite = this.createHbaseSiteObj();
  1215. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1216. component.groups.forEach(function (_group) {
  1217. var siteProperties = hbaseSite.properties;
  1218. _group.properties.forEach(function (_property) {
  1219. this.get('configMapping').forEach(function (_config) {
  1220. if (_config.templateName.contains(_property.name)) {
  1221. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1222. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1223. if (siteProperties[_config.name]) {
  1224. siteProperties[_config.name] = value;
  1225. }
  1226. }
  1227. }, this);
  1228. }, this);
  1229. var data = {"type": hbaseSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1230. this.createConfigSiteForService(data);
  1231. }, this);
  1232. },
  1233. createOozieSiteObj: function (serviceName) {
  1234. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  1235. var oozieProperties = {};
  1236. configs.forEach(function (_configProperty) {
  1237. oozieProperties[_configProperty.name] = _configProperty.value;
  1238. }, this);
  1239. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  1240. },
  1241. createHiveSiteObj: function (serviceName) {
  1242. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  1243. var hiveProperties = {};
  1244. configs.forEach(function (_configProperty) {
  1245. hiveProperties[_configProperty.name] = _configProperty.value;
  1246. }, this);
  1247. return {type: 'hive-site', tag: 'version1', properties: hiveProperties};
  1248. },
  1249. createWebHCatSiteObj: function (serviceName) {
  1250. var configs = this.get('configs').filterProperty('filename', 'webhcat-site.xml');
  1251. var webHCatProperties = {};
  1252. configs.forEach(function (_configProperty) {
  1253. webHCatProperties[_configProperty.name] = _configProperty.value;
  1254. }, this);
  1255. return {type: 'webhcat-site', tag: 'version1', properties: webHCatProperties};
  1256. },
  1257. applyCreatedConfToServices: function () {
  1258. var services = this.get('selectedServices').mapProperty('serviceName');
  1259. services.forEach(function (_service) {
  1260. var data = this.getConfigForService(_service);
  1261. this.applyCreatedConfToService(_service, 'PUT', data);
  1262. }, this);
  1263. },
  1264. applyCreatedConfToService: function (service, httpMethod, data) {
  1265. console.log("Inside applyCreatedConfToService");
  1266. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services/' + service;
  1267. this.ajax({
  1268. type: httpMethod,
  1269. url: url,
  1270. data: JSON.stringify(data),
  1271. beforeSend: function () {
  1272. console.log("BeforeSend: applyCreatedConfToService for " + service);
  1273. }
  1274. });
  1275. },
  1276. applyCreatedConfToSlaveGroups: function () {
  1277. this.get('slaveComponentConfig.components').forEach(function (_component) {
  1278. _component.groups.forEach(function (_group) {
  1279. var aggregatedHostNames = '';
  1280. _group.hostNames.forEach(function (_hostName, index) {
  1281. aggregatedHostNames += 'HostRoles/host_name=' + _hostName;
  1282. if (index !== _group.hostNames.length - 1) {
  1283. aggregatedHostNames += '|';
  1284. }
  1285. }, this);
  1286. console.log("The aggregated hostNames value is: " + aggregatedHostNames);
  1287. this.applyCreatedConfToSlaveGroup(aggregatedHostNames, 'PUT', _group.configVersion, _group.groupName);
  1288. }, this);
  1289. }, this);
  1290. },
  1291. applyCreatedConfToSlaveGroup: function (aggregatedHostNames, httpMethod, data, groupName) {
  1292. console.log("Inside applyCreatedConfToHost");
  1293. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/host_components?' + aggregatedHostNames;
  1294. this.ajax({
  1295. type: httpMethod,
  1296. url: url,
  1297. data: JSON.stringify(data),
  1298. beforeSend: function () {
  1299. console.log("BeforeSend: applyCreatedConfToSlaveGroup for group: " + groupName);
  1300. }
  1301. });
  1302. },
  1303. getConfigForService: function (serviceName) {
  1304. switch (serviceName) {
  1305. case 'HDFS':
  1306. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  1307. case 'MAPREDUCE':
  1308. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  1309. case 'HBASE':
  1310. return {config: {'global': 'version1', 'hbase-site': 'version1'}};
  1311. case 'OOZIE':
  1312. return {config: {'global': 'version1', 'oozie-site': 'version1'}};
  1313. case 'HIVE':
  1314. return {config: {'global': 'version1', 'hive-site': 'version1'}};
  1315. case 'WEBHCAT':
  1316. return {config: {'global': 'version1', 'webhcat-site': 'version1'}};
  1317. default:
  1318. return {config: {'global': 'version1'}};
  1319. }
  1320. },
  1321. ajaxQueue: [],
  1322. ajaxQueueFinished: function () {
  1323. //do something
  1324. },
  1325. doNextAjaxCall: function () {
  1326. if (this.get('ajaxBusy')) {
  1327. return;
  1328. }
  1329. var queue = this.get('ajaxQueue');
  1330. if (!queue.length) {
  1331. this.ajaxQueueFinished();
  1332. return;
  1333. }
  1334. var first = queue[0];
  1335. this.set('ajaxQueue', queue.slice(1));
  1336. this.set('ajaxQueueLeft', this.get('ajaxQueue').length);
  1337. this.set('ajaxBusy', true);
  1338. console.log('AJAX send ' + first.url);
  1339. $.ajax(first);
  1340. },
  1341. /**
  1342. * We need to do a lot of ajax calls async in special order.
  1343. * To do this, generate array of ajax objects and then send requests step by step.
  1344. * All ajax objects are stored in <code>ajaxQueue</code>
  1345. * @param params
  1346. */
  1347. ajax: function (params) {
  1348. if (App.testMode) return;
  1349. var self = this;
  1350. params = jQuery.extend({
  1351. async: true,
  1352. dataType: 'text',
  1353. statusCode: require('data/statusCodes'),
  1354. timeout: App.timeout,
  1355. error: function (request, ajaxOptions, error) {
  1356. console.log('Step8: In Error ');
  1357. // console.log('Step8: Error message is: ' + request.responseText);
  1358. },
  1359. success: function (data) {
  1360. var jsonData = jQuery.parseJSON(data);
  1361. console.log("TRACE: STep8 -> In success function");
  1362. console.log("TRACE: STep8 -> value of the url is: " + params.url);
  1363. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  1364. }
  1365. }, params);
  1366. var success = params.success;
  1367. var error = params.error;
  1368. params.success = function () {
  1369. if (success) {
  1370. success();
  1371. }
  1372. self.set('ajaxBusy', false);
  1373. self.doNextAjaxCall();
  1374. }
  1375. params.error = function (xhr, status, error) {
  1376. var responseText = JSON.parse(xhr.responseText);
  1377. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1378. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1379. self.set('hasErrorOccurred', true);
  1380. // an error will break the ajax call chain and allow submission again
  1381. self.set('isSubmitDisabled', false);
  1382. self.get('ajaxQueue').clear();
  1383. self.set('ajaxBusy', false);
  1384. }
  1385. this.get('ajaxQueue').pushObject(params);
  1386. }
  1387. })