step8_controller.js 55 KB

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