step8_controller.js 58 KB

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