step8_controller.js 56 KB

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