step8_controller.js 52 KB

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