step8_controller.js 49 KB

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