step8_controller.js 52 KB

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