step8_controller.js 57 KB

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