step8_controller.js 54 KB

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