step8_controller.js 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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. */
  387. case 'HCATALOG':
  388. break;
  389. default:
  390. }
  391. }
  392. }, this);
  393. },
  394. /**
  395. * load all info about HDFS service
  396. * @param hdfsObj
  397. */
  398. loadHDFS: function (hdfsObj) {
  399. hdfsObj.get('service_components').forEach(function (_component) {
  400. switch (_component.get('display_name')) {
  401. case 'NameNode':
  402. this.loadNnValue(_component);
  403. break;
  404. case 'SecondaryNameNode':
  405. this.loadSnnValue(_component);
  406. break;
  407. case 'DataNodes':
  408. this.loadDnValue(_component);
  409. break;
  410. default:
  411. }
  412. }, this);
  413. //var
  414. this.get('services').pushObject(hdfsObj);
  415. },
  416. loadNnValue: function (nnComponent) {
  417. var nnHostName = this.get('content.masterComponentHosts').findProperty('display_name', nnComponent.display_name);
  418. nnComponent.set('component_value', nnHostName.hostName);
  419. },
  420. loadSnnValue: function (snnComponent) {
  421. var snnHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'SNameNode');
  422. snnComponent.set('component_value', snnHostName.hostName);
  423. },
  424. loadDnValue: function (dnComponent) {
  425. var dnHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'DataNode');
  426. var totalDnHosts = dnHosts.hosts.length;
  427. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'DATANODE').groups.length;
  428. var groupLabel;
  429. if (totalGroups == 1) {
  430. groupLabel = 'group';
  431. } else {
  432. groupLabel = 'groups';
  433. }
  434. */
  435. dnComponent.set('component_value', totalDnHosts + ' hosts');
  436. },
  437. /**
  438. * Load all info about mapReduce service
  439. * @param mrObj
  440. */
  441. loadMapReduce: function (mrObj) {
  442. mrObj.get('service_components').forEach(function (_component) {
  443. switch (_component.get('display_name')) {
  444. case 'JobTracker':
  445. this.loadJtValue(_component);
  446. break;
  447. case 'TaskTrackers':
  448. this.loadTtValue(_component);
  449. break;
  450. default:
  451. }
  452. }, this);
  453. this.get('services').pushObject(mrObj);
  454. },
  455. loadJtValue: function (jtComponent) {
  456. var jtHostName = this.get('content.masterComponentHosts').findProperty('display_name', jtComponent.display_name);
  457. jtComponent.set('component_value', jtHostName.hostName);
  458. },
  459. loadTtValue: function (ttComponent) {
  460. var ttHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'TaskTracker');
  461. var totalTtHosts = ttHosts.hosts.length;
  462. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'TASKTRACKER').groups.length;
  463. var groupLabel;
  464. if (totalGroups == 1) {
  465. groupLabel = 'group';
  466. } else {
  467. groupLabel = 'groups';
  468. }
  469. */
  470. ttComponent.set('component_value', totalTtHosts + ' hosts');
  471. },
  472. /**
  473. * Load all info about Hive service
  474. * @param hiveObj
  475. */
  476. loadHive: function (hiveObj) {
  477. hiveObj.get('service_components').forEach(function (_component) {
  478. switch (_component.get('display_name')) {
  479. case 'Hive Metastore':
  480. this.loadHiveMetaStoreValue(_component);
  481. break;
  482. case 'Database':
  483. this.loadHiveDbValue(_component);
  484. break;
  485. default:
  486. }
  487. }, this);
  488. this.get('services').pushObject(hiveObj);
  489. },
  490. loadHiveMetaStoreValue: function (metaStoreComponent) {
  491. var hiveHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'Hive Server');
  492. metaStoreComponent.set('component_value', hiveHostName.hostName);
  493. },
  494. loadHiveDbValue: function (dbComponent) {
  495. var hiveDb = App.db.getServiceConfigProperties().findProperty('name', 'hive_database');
  496. if (hiveDb.value === 'New MySQL Database') {
  497. dbComponent.set('component_value', 'MySQL (New Database)');
  498. } else {
  499. var db = App.db.getServiceConfigProperties().findProperty('name', 'hive_existing_database');
  500. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  501. }
  502. },
  503. /**
  504. * Load all info about Hbase
  505. * @param hbaseObj
  506. */
  507. loadHbase: function (hbaseObj) {
  508. hbaseObj.service_components.forEach(function (_component) {
  509. switch (_component.display_name) {
  510. case 'Master':
  511. this.loadMasterValue(_component);
  512. break;
  513. case 'Region Servers':
  514. this.loadRegionServerValue(_component);
  515. break;
  516. default:
  517. }
  518. }, this);
  519. this.get('services').pushObject(hbaseObj);
  520. },
  521. loadMasterValue: function (hbaseMaster) {
  522. var hbaseHostName = this.get('content.masterComponentHosts').findProperty('display_name', 'HBase Master');
  523. hbaseMaster.set('component_value', hbaseHostName.hostName);
  524. },
  525. loadRegionServerValue: function (rsComponent) {
  526. var rsHosts = this.get('content.slaveComponentHosts').findProperty('displayName', 'RegionServer');
  527. var totalRsHosts = rsHosts.hosts.length;
  528. /* var totalGroups = this.get('slaveComponentConfig.components').findProperty('componentName', 'HBASE_REGIONSERVER').groups.length;
  529. var groupLabel;
  530. if (totalGroups == 1) {
  531. groupLabel = 'group';
  532. } else {
  533. groupLabel = 'groups';
  534. } */
  535. rsComponent.set('component_value', totalRsHosts + ' hosts');
  536. },
  537. /**
  538. * Load all info about ZooKeeper service
  539. * @param zkObj
  540. */
  541. loadZk: function (zkObj) {
  542. zkObj.get('service_components').forEach(function (_component) {
  543. switch (_component.get('display_name')) {
  544. case 'Servers':
  545. this.loadZkServerValue(_component);
  546. break;
  547. default:
  548. }
  549. }, this);
  550. this.get('services').pushObject(zkObj);
  551. },
  552. loadZkServerValue: function (serverComponent) {
  553. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('display_name', 'ZooKeeper').length;
  554. var hostSuffix;
  555. if (zkHostNames === 1) {
  556. hostSuffix = 'host';
  557. } else {
  558. hostSuffix = 'hosts';
  559. }
  560. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  561. },
  562. /**
  563. * Load all info about Oozie services
  564. * @param oozieObj
  565. */
  566. loadOozie: function (oozieObj) {
  567. oozieObj.get('service_components').forEach(function (_component) {
  568. switch (_component.get('display_name')) {
  569. case 'Server':
  570. this.loadOozieServerValue(_component);
  571. break;
  572. case 'Database':
  573. // TODO: uncomment when ready to integrate with Oozie Database other than Derby
  574. // this.loadOozieDbValue(_component);
  575. break;
  576. default:
  577. }
  578. }, this);
  579. this.get('services').pushObject(oozieObj);
  580. },
  581. loadOozieServerValue: function (oozieServer) {
  582. var oozieServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Oozie Server');
  583. oozieServer.set('component_value', oozieServerName.hostName);
  584. },
  585. loadOozieDbValue: function (dbComponent) {
  586. var oozieDb = App.db.getServiceConfigProperties().findProperty('name', 'oozie_database');
  587. if (oozieDb.value === 'New PostgreSQL Database') {
  588. dbComponent.set('component_value', 'PostgreSQL (New Database)');
  589. } else {
  590. var db = App.db.getServiceConfigProperties().findProperty('name', 'oozie_existing_database');
  591. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  592. }
  593. },
  594. /**
  595. * Load all info about Nagios service
  596. * @param nagiosObj
  597. */
  598. loadNagios: function (nagiosObj) {
  599. nagiosObj.service_components.forEach(function (_component) {
  600. switch (_component.display_name) {
  601. case 'Server':
  602. this.loadNagiosServerValue(_component);
  603. break;
  604. case 'Administrator':
  605. this.loadNagiosAdminValue(_component);
  606. break;
  607. default:
  608. }
  609. }, this);
  610. this.get('services').pushObject(nagiosObj);
  611. },
  612. loadNagiosServerValue: function (nagiosServer) {
  613. var nagiosServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Nagios Server');
  614. nagiosServer.set('component_value', nagiosServerName.hostName);
  615. },
  616. loadNagiosAdminValue: function (nagiosAdmin) {
  617. var config = this.get('content.serviceConfigProperties');
  618. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  619. var adminEmail = config.findProperty('name', 'nagios_contact');
  620. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  621. },
  622. /**
  623. * Load all info about ganglia
  624. * @param gangliaObj
  625. */
  626. loadGanglia: function (gangliaObj) {
  627. gangliaObj.get('service_components').forEach(function (_component) {
  628. switch (_component.get('display_name')) {
  629. case 'Server':
  630. this.loadGangliaServerValue(_component);
  631. break;
  632. default:
  633. }
  634. }, this);
  635. this.get('services').pushObject(gangliaObj);
  636. },
  637. loadGangliaServerValue: function (gangliaServer) {
  638. var gangliaServerName = this.get('content.masterComponentHosts').findProperty('display_name', 'Ganglia Collector');
  639. gangliaServer.set('component_value', gangliaServerName.hostName);
  640. },
  641. loadSqoop: function (sqoopObj) {
  642. this.get('services').pushObject(sqoopObj);
  643. },
  644. loadPig: function (pigObj) {
  645. this.get('services').pushObject(pigObj);
  646. },
  647. /**
  648. * Onclick handler for <code>next</code> button
  649. */
  650. submit: function () {
  651. if (this.get('isSubmitDisabled')) {
  652. return;
  653. }
  654. this.set('isSubmitDisabled', true);
  655. if (App.testMode || !this.get('content.cluster.requestId')) {
  656. this.createCluster();
  657. this.createSelectedServices();
  658. //this.setAmbariUIDb();
  659. this.createConfigurations();
  660. this.applyCreatedConfToServices();
  661. this.createComponents();
  662. this.registerHostsToCluster();
  663. this.createAllHostComponents();
  664. //this.applyCreatedConfToSlaveGroups();
  665. this.ajaxQueueFinished = function(){
  666. console.log('everything is loaded')
  667. App.router.send('next');
  668. };
  669. this.doNextAjaxCall();
  670. } else {
  671. App.router.send('next');
  672. }
  673. },
  674. setAmbariUIDb: function () {
  675. var dbContent = this.get('content.slaveGroupProperties');
  676. var slaveComponentConfig = this.get("slaveComponentConfig");
  677. this.persistKeyValues(slaveComponentConfig.version, dbContent);
  678. this.persistKeyValues('current_version',slaveComponentConfig.version);
  679. },
  680. persistKeyValues: function (key, value) {
  681. var str = "{ '" + key + "' : '" + JSON.stringify(value) + "'}";
  682. var obj = eval("(" + str + ")");
  683. this.ajax({
  684. type: "POST",
  685. url: App.apiPrefix + '/persist',
  686. data: JSON.stringify(obj),
  687. beforeSend: function () {
  688. console.log('BeforeSend: persistKeyValues', obj);
  689. }
  690. });
  691. },
  692. clusterName: function () {
  693. return this.get('content.cluster.name');
  694. }.property('content.cluster.name'),
  695. /**
  696. * The following create* functions are called upon submitting Step 8.
  697. */
  698. createCluster: function () {
  699. if (this.get('content.isWizard')) {
  700. return false;
  701. }
  702. var clusterName = this.get('clusterName');
  703. var url = App.apiPrefix + '/clusters/' + clusterName;
  704. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.defaultLocalStackVersion : App.defaultStackVersion;
  705. this.ajax({
  706. type: 'POST',
  707. url: url,
  708. data: JSON.stringify({ "Clusters": {"version": stackVersion }}),
  709. beforeSend: function () {
  710. console.log("BeforeSend: createCluster for " + clusterName);
  711. }
  712. });
  713. },
  714. createSelectedServices: function () {
  715. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services';
  716. var data = this.createServiceData();
  717. var httpMethod = 'POST';
  718. if(!data.length){
  719. return;
  720. }
  721. this.ajax({
  722. type: httpMethod,
  723. url: url,
  724. data: JSON.stringify(data),
  725. beforeSend: function () {
  726. console.log('BeforeSend: createSelectedServices ', data);
  727. }
  728. });
  729. },
  730. createServiceData: function () {
  731. var services = this.get('selectedServices').mapProperty('serviceName');
  732. var data = [];
  733. services.forEach(function (_service) {
  734. data.pushObject({"ServiceInfo": { "service_name": _service }});
  735. }, this);
  736. return data;
  737. },
  738. createComponents: function () {
  739. var serviceComponents = require('data/service_components');
  740. var services = this.get('selectedServices').mapProperty('serviceName');
  741. services.forEach(function (_service) {
  742. var components = serviceComponents.filterProperty('service_name', _service);
  743. var componentsData = components.map(function (_component) {
  744. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  745. });
  746. // Service must be specified in terms of a query for creating multiple components at the same time.
  747. // See AMBARI-1018.
  748. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + _service;
  749. var data = {
  750. "components": componentsData
  751. }
  752. this.ajax({
  753. type: 'POST',
  754. url: url,
  755. data: JSON.stringify(data),
  756. beforeSend: function () {
  757. console.log('BeforeSend: createComponents for ' + _service, componentsData);
  758. }
  759. });
  760. }, this);
  761. },
  762. registerHostsToCluster: function () {
  763. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts';
  764. var data = this.createRegisterHostData();
  765. if (data.length == 0) {
  766. return;
  767. }
  768. this.ajax({
  769. type: 'POST',
  770. url: url,
  771. data: JSON.stringify(data),
  772. beforeSend: function () {
  773. console.log('BeforeSend: registerHostsToCluster', data);
  774. }
  775. });
  776. },
  777. createRegisterHostData: function () {
  778. var hosts = this.getRegisteredHosts().filterProperty('isInstalled', false);
  779. if(!hosts.length){
  780. return [];
  781. }
  782. return hosts.map(function (host) {
  783. return {"Hosts": { "host_name": host.hostName}};
  784. });
  785. },
  786. // TODO: review the code for add hosts / add services scenarios...
  787. createAllHostComponents: function () {
  788. var masterHosts = this.get('content.masterComponentHosts');
  789. var slaveHosts = this.get('content.slaveComponentHosts');
  790. var clients = this.get('content.clients');
  791. var clientHosts = slaveHosts.filterProperty('componentName', "CLIENT").objectAt(0).hosts;
  792. // note: masterHosts has 'component' vs slaveHosts has 'componentName'
  793. var masterComponents = masterHosts.mapProperty('component').uniq();
  794. masterComponents.forEach(function (component) {
  795. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  796. this.registerHostsToComponent(hostNames, component);
  797. }, this);
  798. slaveHosts.forEach(function (_slave) {
  799. if (_slave.componentName !== 'CLIENT') {
  800. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  801. this.registerHostsToComponent(hostNames, _slave.componentName);
  802. } else {
  803. this.get('content.clients').forEach(function (_client) {
  804. if (!_client.isInstalled) {
  805. var hostNames = clientHosts.mapProperty('hostName').splice(0);
  806. switch (_client.component_name) {
  807. case 'HDFS_CLIENT':
  808. // install HDFS_CLIENT on HBASE_MASTER, HBASE_REGIONSERVER, and WEBHCAT_SERVER hosts
  809. masterHosts.filterProperty('component', 'HBASE_MASTER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  810. hostNames.pushObject(_masterHost.hostName);
  811. }, this);
  812. masterHosts.filterProperty('component', 'HBASE_REGIONSERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  813. hostNames.pushObject(_masterHost.hostName);
  814. }, this);
  815. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  816. hostNames.pushObject(_masterHost.hostName);
  817. }, this);
  818. break;
  819. case 'MAPREDUCE_CLIENT':
  820. // install MAPREDUCE_CLIENT on HIVE_SERVER, OOZIE_SERVER, NAGIOS_SERVER, and WEBHCAT_SERVER hosts
  821. masterHosts.filterProperty('component', 'HIVE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  822. hostNames.pushObject(_masterHost.hostName);
  823. }, this);
  824. masterHosts.filterProperty('component', 'OOZIE_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  825. hostNames.pushObject(_masterHost.hostName);
  826. }, this);
  827. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  828. hostNames.pushObject(_masterHost.hostName);
  829. }, this);
  830. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  831. hostNames.pushObject(_masterHost.hostName);
  832. }, this);
  833. break;
  834. case 'OOZIE_CLIENT':
  835. // install OOZIE_CLIENT on NAGIOS_SERVER host
  836. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  837. hostNames.pushObject(_masterHost.hostName);
  838. }, this);
  839. break;
  840. case 'ZOOKEEPER_CLIENT':
  841. // install ZOOKEEPER_CLIENT on WEBHCAT_SERVER host
  842. masterHosts.filterProperty('component', 'WEBHCAT_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  843. hostNames.pushObject(_masterHost.hostName);
  844. }, this);
  845. break;
  846. case 'HCAT':
  847. // install HCAT (client) on NAGIOS_SERVER host
  848. masterHosts.filterProperty('component', 'NAGIOS_SERVER').filterProperty('isInstalled', false).forEach(function (_masterHost) {
  849. hostNames.pushObject(_masterHost.hostName);
  850. }, this);
  851. break;
  852. }
  853. hostNames = hostNames.uniq();
  854. this.registerHostsToComponent(hostNames, _client.component_name);
  855. }
  856. }, this);
  857. }
  858. }, this);
  859. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  860. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  861. if (gangliaService) {
  862. var hosts = this.getRegisteredHosts();
  863. if (gangliaService.get('isInstalled')) {
  864. hosts = hosts.filterProperty('isInstalled', false);
  865. }
  866. if (hosts.length) {
  867. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  868. }
  869. }
  870. // add MySQL Server if Hive is selected
  871. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  872. if (hiveService) {
  873. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  874. }
  875. },
  876. registerHostsToComponent: function (hostNames, componentName) {
  877. if (hostNames.length == 0) {
  878. return;
  879. }
  880. console.log('registering ' + componentName + ' to ' + JSON.stringify(hostNames));
  881. // currently we are specifying the predicate as a query string.
  882. // this can hit a ~4000-character limit in Jetty server.
  883. // chunk to multiple calls if needed
  884. // var hostsPredicate = hostNames.map(function (hostName) {
  885. // return 'Hosts/host_name=' + hostName;
  886. // }).join('|');
  887. var queryStrArr = [];
  888. var queryStr = '';
  889. hostNames.forEach(function (hostName) {
  890. queryStr += 'Hosts/host_name=' + hostName + '|';
  891. if (queryStr.length > 3500) {
  892. queryStrArr.push(queryStr.slice(0, -1));
  893. queryStr = '';
  894. }
  895. });
  896. if (queryStr.length > 0) {
  897. queryStrArr.push(queryStr.slice(0, -1));
  898. }
  899. queryStrArr.forEach(function (queryStr) {
  900. // console.log('creating host components for ' + queryStr);
  901. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts?' + queryStr;
  902. var data = {
  903. "host_components": [
  904. {
  905. "HostRoles": {
  906. "component_name": componentName
  907. }
  908. }
  909. ]
  910. };
  911. this.ajax({
  912. type: 'POST',
  913. url: url,
  914. data: JSON.stringify(data),
  915. beforeSend: function () {
  916. console.log('BeforeSend: registerHostsToComponent for ' + queryStr + ' and component ' + componentName);
  917. }
  918. });
  919. }, this);
  920. },
  921. createConfigurations: function () {
  922. var selectedServices = this.get('selectedServices');
  923. if (!this.get('content.isWizard')) {
  924. this.createConfigSiteForService(this.createGlobalSiteObj());
  925. // this.createGlobalSitePerSlaveGroup();
  926. this.createConfigSiteForService(this.createCoreSiteObj());
  927. this.createConfigSiteForService(this.createHdfsSiteObj());
  928. //this.createHdfsSitePerSlaveGroup('HDFS');
  929. }
  930. if (selectedServices.someProperty('serviceName', 'MAPREDUCE')) {
  931. this.createConfigSiteForService(this.createMrSiteObj());
  932. //this.createMrSitePerSlaveGroup('MAPREDUCE');
  933. }
  934. if (selectedServices.someProperty('serviceName', 'HBASE')) {
  935. this.createConfigSiteForService(this.createHbaseSiteObj());
  936. //this.createHbaseSitePerSlaveGroup('HBASE');
  937. }
  938. if (selectedServices.someProperty('serviceName', 'OOZIE')) {
  939. this.createConfigSiteForService(this.createOozieSiteObj('OOZIE'));
  940. }
  941. if (selectedServices.someProperty('serviceName', 'HIVE')) {
  942. this.createConfigSiteForService(this.createHiveSiteObj('HIVE'));
  943. }
  944. if (selectedServices.someProperty('serviceName', 'WEBHCAT')) {
  945. this.createConfigSiteForService(this.createWebHCatSiteObj('WEBHCAT'));
  946. }
  947. },
  948. createConfigSiteForService: function (data) {
  949. console.log("Inside createConfigSiteForService");
  950. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/configurations';
  951. this.ajax({
  952. type: 'POST',
  953. url: url,
  954. data: JSON.stringify(data),
  955. beforeSend: function () {
  956. console.log("BeforeSend: createConfigSiteForService for " + data.type);
  957. }
  958. });
  959. },
  960. createGlobalSiteObj: function () {
  961. var globalSiteProperties = {};
  962. //this.get('globals').filterProperty('domain', 'global').forEach(function (_globalSiteObj) {
  963. this.get('globals').forEach(function (_globalSiteObj) {
  964. // do not pass any globals whose name ends with _host or _hosts
  965. if (!/_hosts?$/.test(_globalSiteObj.name)) {
  966. // append "m" to JVM memory options
  967. var value = null;
  968. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name)) {
  969. value = _globalSiteObj.value + "m";
  970. globalSiteProperties[_globalSiteObj.name] = value;
  971. } else {
  972. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value;
  973. }
  974. console.log("STEP8: name of the global property is: " + _globalSiteObj.name);
  975. console.log("STEP8: value of the global property is: " + _globalSiteObj.value);
  976. }
  977. }, this);
  978. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  979. },
  980. createGlobalSitePerSlaveGroup: function () {
  981. this.get('slaveComponentConfig.components').forEach(function (_component) {
  982. _component.groups.forEach(function (_group) {
  983. var globalSiteProperties = {};
  984. var properties = _group.properties;
  985. properties.forEach(function (_property) {
  986. if (!/_hosts?$/.test(_property.name)) {
  987. // append "m" to JVM memory options
  988. var value = null;
  989. if (/_heapsize|_newsize|_maxnewsize$/.test(_property.name)) {
  990. value = _property.value + "m";
  991. globalSiteProperties[_property.name] = value;
  992. } else {
  993. globalSiteProperties[_property.name] = _property.storeValue;
  994. }
  995. console.log("STEP8: name of the global property is: " + _property.name);
  996. console.log("STEP8: value of the global property is: " + _property.storeValue);
  997. }
  998. }, this);
  999. var config = _group.configVersion.config;
  1000. for (var index in config) {
  1001. if (index === 'datanode-global' || index === 'tasktracker-global' || index === 'regionserver-global') {
  1002. var data = {"type": index, "tag": config[index], "properties": globalSiteProperties};
  1003. this.createConfigSiteForService(data);
  1004. }
  1005. }
  1006. }, this);
  1007. }, this);
  1008. },
  1009. createCoreSiteObj: function () {
  1010. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1011. var coreSiteProperties = {};
  1012. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1013. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1014. coreSiteObj.forEach(function (_coreSiteObj) {
  1015. if (isOozieSelected || _coreSiteObj.name != 'hadoop.proxyuser.oozie.hosts') {
  1016. coreSiteProperties[_coreSiteObj.name] = _coreSiteObj.value;
  1017. }
  1018. console.log("STEP*: name of the property is: " + _coreSiteObj.name);
  1019. console.log("STEP8: value of the property is: " + _coreSiteObj.value);
  1020. }, this);
  1021. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1022. },
  1023. createHdfsSiteObj: function () {
  1024. var hdfsSiteObj = this.get('configs').filterProperty('filename', 'hdfs-site.xml');
  1025. var hdfsProperties = {};
  1026. hdfsSiteObj.forEach(function (_configProperty) {
  1027. hdfsProperties[_configProperty.name] = _configProperty.value;
  1028. console.log("STEP*: name of the property is: " + _configProperty.name);
  1029. console.log("STEP8: value of the property is: " + _configProperty.value);
  1030. }, this);
  1031. return {"type": "hdfs-site", "tag": "version1", "properties": hdfsProperties };
  1032. },
  1033. createHdfsSitePerSlaveGroup: function (serviceName) {
  1034. var hdfsSite = this.createHdfsSiteObj();
  1035. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1036. component.groups.forEach(function (_group) {
  1037. var siteProperties = hdfsSite.properties;
  1038. _group.properties.forEach(function (_property) {
  1039. this.get('configMapping').forEach(function (_config) {
  1040. if (_config.templateName.contains(_property.name)) {
  1041. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1042. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1043. if (siteProperties[_config.name]) {
  1044. siteProperties[_config.name] = value;
  1045. }
  1046. }
  1047. }, this);
  1048. }, this);
  1049. var data = {"type": hdfsSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1050. console.log("The value of globalConfig is: " + JSON.stringify(siteProperties));
  1051. this.createConfigSiteForService(data);
  1052. }, this);
  1053. },
  1054. createMrSiteObj: function () {
  1055. var configs = this.get('configs').filterProperty('filename', 'mapred-site.xml');
  1056. var mrProperties = {};
  1057. configs.forEach(function (_configProperty) {
  1058. mrProperties[_configProperty.name] = _configProperty.value;
  1059. console.log("STEP*: name of the property is: " + _configProperty.name);
  1060. console.log("STEP8: value of the property is: " + _configProperty.value);
  1061. }, this);
  1062. return {type: 'mapred-site', tag: 'version1', properties: mrProperties};
  1063. },
  1064. createMrSitePerSlaveGroup: function (serviceName) {
  1065. var mrSite = this.createMrSiteObj();
  1066. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1067. component.groups.forEach(function (_group) {
  1068. var siteProperties = mrSite.properties;
  1069. _group.properties.forEach(function (_property) {
  1070. this.get('configMapping').forEach(function (_config) {
  1071. if (_config.templateName.contains(_property.name)) {
  1072. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1073. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1074. if (siteProperties[_config.name]) {
  1075. siteProperties[_config.name] = value;
  1076. }
  1077. }
  1078. }, this);
  1079. }, this);
  1080. var data = {"type": mrSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1081. this.createConfigSiteForService(data);
  1082. }, this);
  1083. },
  1084. createHbaseSiteObj: function () {
  1085. var configs = this.get('configs').filterProperty('filename', 'hbase-site.xml');
  1086. var hbaseProperties = {};
  1087. configs.forEach(function (_configProperty) {
  1088. hbaseProperties[_configProperty.name] = _configProperty.value;
  1089. }, this);
  1090. var masterHosts = App.db.getMasterComponentHosts();
  1091. // TODO: should filter on "component" but that gives unexpected results
  1092. var zkServers = masterHosts.filterProperty('display_name', 'ZooKeeper').mapProperty('hostName');
  1093. hbaseProperties['hbase.zookeeper.quorum'] = zkServers.join(',');
  1094. return {type: 'hbase-site', tag: 'version1', properties: hbaseProperties};
  1095. },
  1096. createHbaseSitePerSlaveGroup: function (serviceName) {
  1097. var hbaseSite = this.createHbaseSiteObj();
  1098. var component = this.get('slaveComponentConfig.components').findProperty('serviceName', serviceName);
  1099. component.groups.forEach(function (_group) {
  1100. var siteProperties = hbaseSite.properties;
  1101. _group.properties.forEach(function (_property) {
  1102. this.get('configMapping').forEach(function (_config) {
  1103. if (_config.templateName.contains(_property.name)) {
  1104. this.get('globals').findProperty('name', _property.name).value = _property.storeValue;
  1105. var value = this.getGlobConfigValue(_config.templateName, _config.value);
  1106. if (siteProperties[_config.name]) {
  1107. siteProperties[_config.name] = value;
  1108. }
  1109. }
  1110. }, this);
  1111. }, this);
  1112. var data = {"type": hbaseSite.type, "tag": _group.siteVersion, "properties": siteProperties};
  1113. this.createConfigSiteForService(data);
  1114. }, this);
  1115. },
  1116. createOozieSiteObj: function (serviceName) {
  1117. var configs = this.get('configs').filterProperty('filename', 'oozie-site.xml');
  1118. var oozieProperties = {};
  1119. configs.forEach(function (_configProperty) {
  1120. oozieProperties[_configProperty.name] = _configProperty.value;
  1121. }, this);
  1122. return {type: 'oozie-site', tag: 'version1', properties: oozieProperties};
  1123. },
  1124. createHiveSiteObj: function (serviceName) {
  1125. var configs = this.get('configs').filterProperty('filename', 'hive-site.xml');
  1126. var hiveProperties = {};
  1127. configs.forEach(function (_configProperty) {
  1128. hiveProperties[_configProperty.name] = _configProperty.value;
  1129. }, this);
  1130. hiveProperties['hive.metastore.uris'] = 'thrift://' + this.get('globals').findProperty('name', 'hivemetastore_host').value + ':9083';
  1131. hiveProperties['javax.jdo.option.ConnectionURL'] =
  1132. 'jdbc:mysql://' + this.get('globals').findProperty('name', 'hive_mysql_host').value +
  1133. '/' + this.get('globals').findProperty('name', 'hive_database_name').value + '?createDatabaseIfNotExist=true';
  1134. return {type: 'hive-site', tag: 'version1', properties: hiveProperties};
  1135. },
  1136. createWebHCatSiteObj: function (serviceName) {
  1137. var configs = this.get('configs').filterProperty('filename', 'webhcat-site.xml');
  1138. var webHCatProperties = {};
  1139. configs.forEach(function (_configProperty) {
  1140. webHCatProperties[_configProperty.name] = _configProperty.value;
  1141. }, this);
  1142. return {type: 'webhcat-site', tag: 'version1', properties: webHCatProperties};
  1143. },
  1144. applyCreatedConfToServices: function () {
  1145. var services = this.get('selectedServices').mapProperty('serviceName');
  1146. services.forEach(function (_service) {
  1147. var data = this.getConfigForService(_service);
  1148. this.applyCreatedConfToService(_service, 'PUT', data);
  1149. }, this);
  1150. },
  1151. applyCreatedConfToService: function (service, httpMethod, data) {
  1152. console.log("Inside applyCreatedConfToService");
  1153. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services/' + service;
  1154. this.ajax({
  1155. type: httpMethod,
  1156. url: url,
  1157. data: JSON.stringify(data),
  1158. beforeSend: function () {
  1159. console.log("BeforeSend: applyCreatedConfToService for " + service);
  1160. }
  1161. });
  1162. },
  1163. applyCreatedConfToSlaveGroups: function () {
  1164. this.get('slaveComponentConfig.components').forEach(function (_component) {
  1165. _component.groups.forEach(function (_group) {
  1166. var aggregatedHostNames = '';
  1167. _group.hostNames.forEach(function (_hostName, index) {
  1168. aggregatedHostNames += 'HostRoles/host_name=' + _hostName;
  1169. if (index !== _group.hostNames.length-1) {
  1170. aggregatedHostNames += '|';
  1171. }
  1172. }, this);
  1173. console.log("The aggregated hostNames value is: " + aggregatedHostNames);
  1174. this.applyCreatedConfToSlaveGroup(aggregatedHostNames, 'PUT', _group.configVersion,_group.groupName);
  1175. }, this);
  1176. }, this);
  1177. },
  1178. applyCreatedConfToSlaveGroup: function (aggregatedHostNames, httpMethod, data, groupName) {
  1179. console.log("Inside applyCreatedConfToHost");
  1180. var url = App.apiPrefix + '/clusters/' + this.get('clusterName') + '/host_components?' + aggregatedHostNames;
  1181. this.ajax({
  1182. type: httpMethod,
  1183. url: url,
  1184. data: JSON.stringify(data),
  1185. beforeSend: function () {
  1186. console.log("BeforeSend: applyCreatedConfToSlaveGroup for group: " + groupName);
  1187. }
  1188. });
  1189. },
  1190. getConfigForService: function (serviceName) {
  1191. switch (serviceName) {
  1192. case 'HDFS':
  1193. return {config: {'global': 'version1', 'core-site': 'version1', 'hdfs-site': 'version1'}};
  1194. case 'MAPREDUCE':
  1195. return {config: {'global': 'version1', 'core-site': 'version1', 'mapred-site': 'version1'}};
  1196. case 'HBASE':
  1197. return {config: {'global': 'version1', 'core-site': 'version1', 'hbase-site': 'version1'}};
  1198. case 'OOZIE':
  1199. return {config: {'global': 'version1', 'core-site': 'version1', 'oozie-site': 'version1'}};
  1200. case 'HIVE':
  1201. return {config: {'global': 'version1', 'core-site': 'version1', 'hive-site': 'version1'}};
  1202. case 'WEBHCAT':
  1203. return {config: {'global': 'version1', 'core-site': 'version1', 'webhcat-site': 'version1'}};
  1204. default:
  1205. return {config: {'global': 'version1'}};
  1206. }
  1207. },
  1208. ajaxQueue: [],
  1209. ajaxQueueFinished: function () {
  1210. //do something
  1211. },
  1212. doNextAjaxCall: function () {
  1213. if (this.get('ajaxBusy')) {
  1214. return;
  1215. }
  1216. var queue = this.get('ajaxQueue');
  1217. if (!queue.length) {
  1218. this.ajaxQueueFinished();
  1219. return;
  1220. }
  1221. var first = queue[0];
  1222. this.set('ajaxQueue', queue.slice(1));
  1223. this.set('ajaxBusy', true);
  1224. console.log('AJAX send ' + first.url);
  1225. $.ajax(first);
  1226. },
  1227. /**
  1228. * We need to do a lot of ajax calls(about 10 or more) async in special order.
  1229. * To do this i generate array of ajax objects and then send requests step by step.
  1230. * All ajax objects are stored in <code>ajaxQueue</code>
  1231. * @param params
  1232. */
  1233. ajax: function(params){
  1234. if(App.testMode) return;
  1235. var self = this;
  1236. params = jQuery.extend({
  1237. async: true,
  1238. dataType: 'text',
  1239. statusCode: require('data/statusCodes'),
  1240. timeout: App.timeout,
  1241. error: function (request, ajaxOptions, error) {
  1242. console.log('Step8: In Error ');
  1243. console.log('Step8: Error message is: ' + request.responseText);
  1244. },
  1245. success: function (data) {
  1246. var jsonData = jQuery.parseJSON(data);
  1247. console.log("TRACE: STep8 -> In success function");
  1248. console.log("TRACE: STep8 -> value of the url is: " + params.url);
  1249. console.log("TRACE: STep8 -> value of the received data is: " + jsonData);
  1250. }
  1251. }, params);
  1252. var success = params.success;
  1253. var error = params.error;
  1254. params.success = function () {
  1255. if (success) {
  1256. success();
  1257. }
  1258. ;
  1259. self.set('ajaxBusy', false);
  1260. self.doNextAjaxCall();
  1261. }
  1262. params.error = function () {
  1263. if (error) {
  1264. error();
  1265. }
  1266. ;
  1267. self.set('ajaxBusy', false);
  1268. self.doNextAjaxCall();
  1269. }
  1270. this.get('ajaxQueue').pushObject(params);
  1271. }
  1272. })