step8_controller.js 56 KB

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