step8_controller.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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. var stringUtils = require('utils/string_utils');
  20. App.WizardStep8Controller = Em.Controller.extend({
  21. name: 'wizardStep8Controller',
  22. /**
  23. * List of raw data about cluster that should be displayed
  24. * @type {Array}
  25. */
  26. rawContent: require('data/review_configs'),
  27. /**
  28. * @type {Object[]}
  29. */
  30. totalHosts: [],
  31. /**
  32. * List of data about cluster (based on formatted <code>rawContent</code>)
  33. * @type {Object[]}
  34. */
  35. clusterInfo: [],
  36. /**
  37. * List of services with components assigned to hosts
  38. * @type {Object[]}
  39. */
  40. services: [],
  41. /**
  42. * @type {Object[]}
  43. */
  44. configs: [],
  45. /**
  46. * @type {Object[]}
  47. */
  48. globals: [],
  49. /**
  50. * List of ajax-request to be executed
  51. * @type {Array}
  52. */
  53. ajaxQueue: [],
  54. /**
  55. * All configs
  56. * @type {Array}
  57. */
  58. configMapping: function(){
  59. return App.config.get('configMapping').all(true);
  60. }.property('App.config.configMapping'),
  61. /**
  62. *
  63. */
  64. slaveComponentConfig: null,
  65. /**
  66. * Should Submit button be disabled
  67. * @type {bool}
  68. */
  69. isSubmitDisabled: false,
  70. /**
  71. * Should Back button be disabled
  72. * @type {bool}
  73. */
  74. isBackBtnDisabled: false,
  75. /**
  76. * Is error appears while <code>ajaxQueue</code> executes
  77. * @type {bool}
  78. */
  79. hasErrorOccurred: false,
  80. /**
  81. * Are services installed
  82. * Used to hide Deploy Progress Bar
  83. * @type {bool}
  84. */
  85. servicesInstalled: false,
  86. /**
  87. * List of service config tags
  88. * @type {Object[]}
  89. */
  90. serviceConfigTags: [],
  91. /**
  92. * Is cluster security enabled
  93. * @type {bool}
  94. */
  95. securityEnabled: function() {
  96. return App.router.get('mainAdminSecurityController.securityEnabled');
  97. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  98. /**
  99. * During page save time, we set the host overrides to the server.
  100. * The new host -> site:tag map is stored below. This will be
  101. * useful during save, to update the host's host components. Also,
  102. * it will be useful in deletion of overrides.
  103. *
  104. * Example:
  105. * {
  106. * 'hostname1': {
  107. * 'global': {
  108. * 'tagName': 'tag3187261938_hostname1',
  109. * 'map': {
  110. * 'hadoop_heapsize': '2048m'
  111. * }
  112. * }
  113. * }
  114. * }
  115. *
  116. * @see loadedHostToOverrideSiteToTagMap
  117. */
  118. savedHostToOverrideSiteToTagMap: {},
  119. /**
  120. * Selected config group
  121. * @type {Object}
  122. */
  123. selectedConfigGroup: null,
  124. /**
  125. * List of config groups
  126. * @type {Object[]}
  127. */
  128. configGroups: [],
  129. /**
  130. * List of selected but not installed services
  131. * @type {Object[]}
  132. */
  133. selectedServices: function () {
  134. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  135. }.property('content.services').cacheable(),
  136. /**
  137. * Clear current step data
  138. */
  139. clearStep: function () {
  140. this.get('services').clear();
  141. this.get('configs').clear();
  142. this.get('globals').clear();
  143. this.get('clusterInfo').clear();
  144. this.get('serviceConfigTags').clear();
  145. this.set('servicesInstalled', false);
  146. },
  147. /**
  148. * Load current step data
  149. */
  150. loadStep: function () {
  151. console.log("TRACE: Loading step8: Review Page");
  152. if (this.get('content.controllerName') != 'installerController') {
  153. App.router.get('mainAdminSecurityController').setSecurityStatus();
  154. }
  155. this.clearStep();
  156. if (this.get('content.serviceConfigProperties')) {
  157. this.formatProperties();
  158. this.loadGlobals();
  159. this.loadConfigs();
  160. }
  161. this.loadClusterInfo();
  162. this.loadServices();
  163. this.set('isSubmitDisabled', false);
  164. this.set('isBackBtnDisabled', false);
  165. },
  166. /**
  167. * replace whitespace character with coma between directories
  168. */
  169. formatProperties: function(){
  170. this.get('content.serviceConfigProperties').forEach(function(_configProperty){
  171. _configProperty.value = App.config.trimProperty(_configProperty,false);
  172. });
  173. },
  174. /**
  175. * Load global configs and remove some of them:
  176. * <ul>
  177. * <li>Unused DB properties for Hive</li>
  178. * <li>Unused DB properties for Oozie</li>
  179. * <ul>
  180. */
  181. loadGlobals: function () {
  182. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  183. if (globals.someProperty('name', 'hive_database')) {
  184. var hiveDb = globals.findProperty('name', 'hive_database');
  185. var hiveDbType = {name: 'hive_database_type', value: 'mysql'};
  186. if (hiveDb.value === 'New MySQL Database') {
  187. if (globals.someProperty('name', 'hive_ambari_host')) {
  188. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_ambari_host').value;
  189. hiveDbType.value = 'mysql';
  190. }
  191. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
  192. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
  193. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
  194. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
  195. } else if (hiveDb.value === 'Existing MySQL Database'){
  196. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_existing_mysql_host').value;
  197. hiveDbType.value = 'mysql';
  198. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  199. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  200. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_host'));
  201. globals = globals.without(globals.findProperty('name', 'hive_existing_oracle_database'));
  202. } else { //existing oracle database
  203. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_existing_oracle_host').value;
  204. hiveDbType.value = 'oracle';
  205. globals = globals.without(globals.findProperty('name', 'hive_ambari_host'));
  206. globals = globals.without(globals.findProperty('name', 'hive_ambari_database'));
  207. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_host'));
  208. globals = globals.without(globals.findProperty('name', 'hive_existing_mysql_database'));
  209. }
  210. globals.push(hiveDbType);
  211. }
  212. if (globals.someProperty('name', 'oozie_database')) {
  213. var oozieDb = globals.findProperty('name', 'oozie_database');
  214. var oozieDbType = {name:'oozie_database_type'};
  215. if (oozieDb.value === 'New Derby Database') {
  216. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_ambari_host').value;
  217. oozieDbType.value = 'derby';
  218. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  219. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  220. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  221. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  222. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  223. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  224. } else if (oozieDb.value === 'Existing MySQL Database') {
  225. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_existing_mysql_host').value;
  226. oozieDbType.value = 'mysql';
  227. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  228. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  229. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_host'));
  230. globals = globals.without(globals.findProperty('name', 'oozie_existing_oracle_database'));
  231. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  232. } else { // existing oracle database
  233. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_existing_oracle_host').value;
  234. oozieDbType.value = 'oracle';
  235. globals = globals.without(globals.findProperty('name', 'oozie_ambari_host'));
  236. globals = globals.without(globals.findProperty('name', 'oozie_ambari_database'));
  237. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_host'));
  238. globals = globals.without(globals.findProperty('name', 'oozie_existing_mysql_database'));
  239. globals = globals.without(globals.findProperty('name', 'oozie_derby_database'));
  240. }
  241. globals.push(oozieDbType);
  242. }
  243. this.set('globals', globals);
  244. },
  245. /**
  246. * Load all site properties
  247. */
  248. loadConfigs: function () {
  249. //storedConfigs contains custom configs as well
  250. var serviceConfigProperties = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  251. serviceConfigProperties.forEach(function(_config){
  252. _config.value = (typeof _config.value === "boolean") ? _config.value.toString() : _config.value;
  253. });
  254. var storedConfigs = serviceConfigProperties.filterProperty('value');
  255. var mappedConfigs = App.config.excludeUnsupportedConfigs(this.get('configMapping'), this.get('selectedServices').mapProperty('serviceName'));
  256. var uiConfigs = this.loadUiSideConfigs(mappedConfigs);
  257. this.set('configs', storedConfigs.concat(uiConfigs));
  258. },
  259. /**
  260. * Load UI configs
  261. * @param {Array} configMapping
  262. * @return {Array}
  263. */
  264. loadUiSideConfigs: function (configMapping) {
  265. var uiConfig = [];
  266. var configs = configMapping.filterProperty('foreignKey', null);
  267. this.addDynamicProperties(configs);
  268. configs.forEach(function (_config) {
  269. var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value, _config.name);
  270. uiConfig.pushObject({
  271. "id": "site property",
  272. "name": _config.name,
  273. "value": valueWithOverrides.value,
  274. "filename": _config.filename,
  275. "overrides": valueWithOverrides.overrides
  276. });
  277. }, this);
  278. var dependentConfig = $.extend(true, [], configMapping.filterProperty('foreignKey'));
  279. dependentConfig.forEach(function (_config) {
  280. App.config.setConfigValue(uiConfig, this.get('content.serviceConfigProperties'), _config, this.get('globals'));
  281. uiConfig.pushObject({
  282. "id": "site property",
  283. "name": _config._name || _config.name,
  284. "value": _config.value,
  285. "filename": _config.filename
  286. });
  287. }, this);
  288. return uiConfig;
  289. },
  290. /**
  291. * Add dynamic properties to configs
  292. * @param {Array} configs
  293. */
  294. addDynamicProperties: function(configs) {
  295. var templetonHiveProperty = this.get('content.serviceConfigProperties').someProperty('name', 'templeton.hive.properties');
  296. if (!templetonHiveProperty) {
  297. configs.pushObject({
  298. "name": "templeton.hive.properties",
  299. "templateName": ["hivemetastore_host"],
  300. "foreignKey": null,
  301. "value": "hive.metastore.local=false,hive.metastore.uris=thrift://<templateName[0]>:9083,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse",
  302. "filename": "webhcat-site.xml"
  303. });
  304. }
  305. },
  306. /**
  307. * Format <code>content.hosts</code> from Object to Array
  308. * @returns {Array}
  309. */
  310. getRegisteredHosts: function () {
  311. var allHosts = this.get('content.hosts');
  312. var hosts = [];
  313. for (var hostName in allHosts) {
  314. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  315. allHosts[hostName].hostName = allHosts[hostName].name;
  316. hosts.pushObject(allHosts[hostName]);
  317. }
  318. }
  319. return hosts;
  320. },
  321. /**
  322. * Set all site property that are derived from other puppet-variable
  323. * @param {String} templateName
  324. * @param {String} expression
  325. * @param {String} name
  326. * @return {Object}
  327. * example: <code>{
  328. * value: '...',
  329. * overrides: {
  330. * 'value1': [h1, h2],
  331. * 'value2': [h3]
  332. * }
  333. * }</code>
  334. */
  335. getGlobConfigValueWithOverrides: function (templateName, expression, name) {
  336. var express = expression.match(/<(.*?)>/g);
  337. var value = expression;
  338. if (express == null) {
  339. return { value : expression, overrides: []}; // if site property do not map any global property then return the value
  340. }
  341. var overrideHostToValue = {};
  342. express.forEach(function (_express) {
  343. //console.log("The value of template is: " + _express);
  344. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  345. if (this.get('globals').someProperty('name', templateName[index])) {
  346. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  347. var globalObj = this.get('globals').findProperty('name', templateName[index]);
  348. var globValue = globalObj.value;
  349. // Hack for templeton.zookeeper.hosts
  350. var preReplaceValue = null;
  351. 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
  352. preReplaceValue = value;
  353. value = this._replaceConfigValues(name, _express, value, globValue);
  354. }
  355. if(globalObj.overrides!=null){
  356. globalObj.overrides.forEach(function(override){
  357. var ov = override.value;
  358. var hostsArray = override.hosts;
  359. hostsArray.forEach(function(host){
  360. if(!(host in overrideHostToValue)){
  361. overrideHostToValue[host] = this._replaceConfigValues(name, _express, preReplaceValue, ov);
  362. }else{
  363. overrideHostToValue[host] = this._replaceConfigValues(name, _express, overrideHostToValue[host], ov);
  364. }
  365. }, this);
  366. }, this);
  367. }
  368. } else {
  369. /*
  370. console.log("ERROR: The variable name is: " + templateName[index]);
  371. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  372. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  373. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  374. */
  375. value = null;
  376. }
  377. }, this);
  378. var valueWithOverrides = {
  379. value: value,
  380. overrides: []
  381. };
  382. var overrideValueToHostMap = {};
  383. if(!jQuery.isEmptyObject(overrideHostToValue)){
  384. for(var host in overrideHostToValue){
  385. var hostVal = overrideHostToValue[host];
  386. if(!(hostVal in overrideValueToHostMap)){
  387. overrideValueToHostMap[hostVal] = [];
  388. }
  389. overrideValueToHostMap[hostVal].push(host);
  390. }
  391. }
  392. for(var val in overrideValueToHostMap){
  393. valueWithOverrides.overrides.push({
  394. value: val,
  395. hosts: overrideValueToHostMap[val]
  396. });
  397. }
  398. return valueWithOverrides;
  399. },
  400. /**
  401. * replace some values in config property
  402. * @param {string} name
  403. * @param {string} express
  404. * @param {string} value
  405. * @param {string} globValue
  406. * @return {string}
  407. * @private
  408. */
  409. _replaceConfigValues: function (name, express, value, globValue) {
  410. return value.replace(express, globValue);
  411. },
  412. /**
  413. * Load all info about cluster to <code>clusterInfo</code> variable
  414. */
  415. loadClusterInfo: function () {
  416. //Admin name
  417. var admin = this.rawContent.findProperty('config_name', 'Admin');
  418. admin.config_value = App.db.getLoginName();
  419. console.log("STEP8: the value of content cluster name: " + App.db.getLoginName());
  420. if (admin.config_value) {
  421. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  422. }
  423. // cluster name
  424. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  425. cluster.config_value = this.get('content.cluster.name');
  426. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  427. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  428. //hosts
  429. var masterHosts = this.get('content.masterComponentHosts').mapProperty('hostName').uniq();
  430. var slaveHosts = this.get('content.slaveComponentHosts');
  431. var hostObj = [];
  432. slaveHosts.forEach(function (_hosts) {
  433. hostObj = hostObj.concat(_hosts.hosts);
  434. }, this);
  435. slaveHosts = hostObj.mapProperty('hostName').uniq();
  436. var componentHosts = masterHosts.concat(slaveHosts).uniq();
  437. var totalHosts = App.Host.find().mapProperty('hostName').concat(componentHosts).uniq();
  438. var newHostsCount = totalHosts.length - App.Host.find().content.length;
  439. this.set('totalHosts', totalHosts);
  440. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  441. totalHostsObj.config_value = totalHosts.length + ' (' + newHostsCount + ' new)';
  442. this.get('clusterInfo').pushObject(Ember.Object.create(totalHostsObj));
  443. //repo
  444. if (['addHostController', 'addServiceController'].contains(this.get('content.controllerName'))) {
  445. this.loadRepoInfo();
  446. } else { // from install wizard
  447. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  448. var allRepos = [];
  449. var supportedOs = ['redhat5', 'redhat6', 'sles11'];
  450. if (selectedStack && selectedStack.operatingSystems) {
  451. selectedStack.operatingSystems.forEach(function (os) {
  452. if (os.selected && supportedOs.contains(os.osType)) {
  453. allRepos.push(Em.Object.create({
  454. base_url: os.baseUrl,
  455. os_type: Em.I18n.t("installer.step8.repoInfo.osType." + os.osType)
  456. }));
  457. }
  458. }, this);
  459. }
  460. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  461. this.get('clusterInfo').set('repoInfo', allRepos);
  462. }
  463. },
  464. /**
  465. * get the repositories info of HDP from server. Used only in addHost controller.
  466. */
  467. loadRepoInfo: function(){
  468. var nameVersionCombo = App.get('currentStackVersion');
  469. var stackName = nameVersionCombo.split('-')[0];
  470. var stackVersion = nameVersionCombo.split('-')[1];
  471. App.ajax.send({
  472. name: 'cluster.load_repositories',
  473. sender: this,
  474. data: {
  475. stackName: stackName,
  476. stackVersion: stackVersion
  477. },
  478. success: 'loadRepoInfoSuccessCallback',
  479. error: 'loadRepositoriesErrorCallback'
  480. });
  481. },
  482. loadRepoInfoSuccessCallback: function (data) {
  483. var allRepos = [];
  484. var supportedOs = ['redhat5', 'redhat6', 'sles11'];
  485. data.items.forEach(function (item) {
  486. var os = item.repositories[0].Repositories;
  487. if (supportedOs.contains(os.os_type)) {
  488. allRepos.push(Em.Object.create({
  489. base_url: os.base_url,
  490. os_type: Em.I18n.t("installer.step8.repoInfo.osType." + os.os_type)
  491. }));
  492. }
  493. }, this);
  494. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  495. this.get('clusterInfo').set('repoInfo', allRepos);
  496. },
  497. loadRepoInfoErrorCallback: function(request) {
  498. console.log('Error message is: ' + request.responseText);
  499. var allRepos = [];
  500. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  501. this.get('clusterInfo').set('repoInfo', allRepos);
  502. },
  503. /**
  504. * Load all info about services to <code>services</code> variable
  505. */
  506. loadServices: function () {
  507. var reviewService = this.rawContent.findProperty('config_name', 'services');
  508. this.get('selectedServices').forEach(function (_service) {
  509. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  510. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  511. if (serviceObj) {
  512. serviceObj.get('service_components').forEach(function (_component) {
  513. this.assignComponentHosts(_component);
  514. }, this);
  515. this.get('services').pushObject(serviceObj);
  516. }
  517. }, this);
  518. },
  519. /**
  520. *
  521. * @param {Em.Object} component
  522. */
  523. assignComponentHosts: function (component) {
  524. var componentValue;
  525. if (component.get('customHandler')) {
  526. this[component.get('customHandler')].call(this, component);
  527. } else {
  528. if (component.get('isMaster')) {
  529. componentValue = this.get('content.masterComponentHosts')
  530. .findProperty('component', component.component_name).hostName;
  531. } else {
  532. var hostsLength = this.get('content.slaveComponentHosts')
  533. .findProperty('componentName', component.component_name)
  534. .hosts.length;
  535. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  536. }
  537. component.set('component_value', componentValue);
  538. }
  539. },
  540. /**
  541. * Set dispalyed Hive DB value based on DB type
  542. * @param dbComponent
  543. */
  544. loadHiveDbValue: function (dbComponent) {
  545. var hiveDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_database');
  546. if (hiveDb.value === 'New MySQL Database') {
  547. dbComponent.set('component_value', 'MySQL (New Database)');
  548. } else if(hiveDb.value === 'Existing MySQL Database'){
  549. var db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_existing_mysql_database');
  550. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  551. } else { // existing oracle database
  552. var db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_existing_oracle_database');
  553. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  554. }
  555. },
  556. /**
  557. * Set displayed HBase master value
  558. * @param {Object} hbaseMaster
  559. */
  560. loadHbaseMasterValue: function (hbaseMaster) {
  561. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  562. if (hbaseHostName.length == 1) {
  563. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  564. } else {
  565. hbaseMaster.set('component_value', hbaseHostName[0].hostName + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  566. }
  567. },
  568. /**
  569. * Set displayed ZooKeeper Server value
  570. * @param {Object} serverComponent
  571. */
  572. loadZkServerValue: function (serverComponent) {
  573. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  574. var hostSuffix;
  575. if (zkHostNames === 1) {
  576. hostSuffix = Em.I18n.t('installer.step8.host');
  577. } else {
  578. hostSuffix = Em.I18n.t('installer.step8.hosts');
  579. }
  580. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  581. },
  582. /**
  583. * Set displayed Oozie DB value based on DB type
  584. * @param {Object} dbComponent
  585. */
  586. loadOozieDbValue: function (dbComponent) {
  587. var oozieDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_database');
  588. if (oozieDb.value === 'New Derby Database'){
  589. var db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_derby_database');
  590. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  591. }/* else if (oozieDb.value === 'New MySQL Database') {
  592. dbComponent.set('component_value', 'MySQL (New Database)');
  593. } */else if(oozieDb.value === 'Existing MySQL Database'){
  594. var db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mysql_database');
  595. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  596. } else { // existing oracle database
  597. var db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_oracle_database');
  598. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  599. }
  600. },
  601. /**
  602. * Set displayed Nagion Admin value
  603. * @param {Object} nagiosAdmin
  604. */
  605. loadNagiosAdminValue: function (nagiosAdmin) {
  606. var config = this.get('content.serviceConfigProperties');
  607. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  608. var adminEmail = config.findProperty('name', 'nagios_contact');
  609. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  610. },
  611. /**
  612. * Onclick handler for <code>next</code> button
  613. */
  614. submit: function () {
  615. if (this.get('isSubmitDisabled')) return;
  616. if ((this.get('content.controllerName') == 'addHostController') && this.get('securityEnabled')) {
  617. var self = this;
  618. App.showConfirmationPopup(function() {
  619. self.submitProceed();
  620. }, Em.I18n.t('installer.step8.securityConfirmationPopupBody'));
  621. }
  622. else {
  623. this.submitProceed();
  624. }
  625. },
  626. /**
  627. * Update configurations for installed services.
  628. *
  629. * @param {Array} configsToUpdate - configs need to update
  630. * @return {*}
  631. */
  632. updateConfigurations: function (configsToUpdate) {
  633. var configurationController = App.router.get('mainServiceInfoConfigsController');
  634. var serviceNames = configsToUpdate.mapProperty('serviceName').uniq();
  635. serviceNames.forEach(function(serviceName) {
  636. var configs = configsToUpdate.filterProperty('serviceName', serviceName);
  637. configurationController.setNewTagNames(configs);
  638. var tagName = configs.objectAt(0).newTagName;
  639. var siteConfigs = configs.filterProperty('id', 'site property');
  640. siteConfigs.mapProperty('filename').uniq().forEach(function(siteName) {
  641. var formattedConfigs = configurationController.createSiteObj(siteName.replace(".xml", ""), tagName, configs.filterProperty('filename', siteName));
  642. configurationController.doPUTClusterConfigurationSite(formattedConfigs);
  643. });
  644. });
  645. },
  646. /**
  647. * Prepare <code>ajaxQueue</code> and start to execute it
  648. */
  649. submitProceed: function() {
  650. this.set('isSubmitDisabled', true);
  651. this.set('isBackBtnDisabled', true);
  652. if (this.get('content.controllerName') == 'addHostController') {
  653. App.router.get('addHostController').setLowerStepsDisable(4);
  654. }
  655. // checkpoint the cluster status on the server so that the user can resume from where they left off
  656. switch (this.get('content.controllerName')) {
  657. case 'installerController':
  658. App.clusterStatus.setClusterStatus({
  659. clusterName: this.get('clusterName'),
  660. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  661. wizardControllerName: this.get('content.controllerName'),
  662. localdb: App.db.data
  663. });
  664. break;
  665. case 'addHostController':
  666. App.clusterStatus.setClusterStatus({
  667. clusterName: this.get('clusterName'),
  668. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  669. wizardControllerName: this.get('content.controllerName'),
  670. localdb: App.db.data
  671. });
  672. break;
  673. case 'addServiceController':
  674. App.clusterStatus.setClusterStatus({
  675. clusterName: this.get('clusterName'),
  676. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  677. wizardControllerName: this.get('content.controllerName'),
  678. localdb: App.db.data
  679. });
  680. break;
  681. default:
  682. break;
  683. }
  684. // delete any existing clusters to start from a clean slate
  685. // before creating a new cluster in install wizard
  686. // TODO: modify for multi-cluster support
  687. if (this.get('content.controllerName') == 'installerController' && (!App.testMode)) {
  688. this.deleteClusters(this.getExistingClusterNames());
  689. }
  690. if (this.get('wizardController').getDBProperty('configsToUpdate')) {
  691. this.updateConfigurations(this.get('wizardController').getDBProperty('configsToUpdate'));
  692. }
  693. this.setLocalRepositories();
  694. this.createCluster();
  695. this.createSelectedServices();
  696. if (this.get('content.controllerName') !== 'addHostController') {
  697. this.createConfigurations();
  698. this.applyConfigurationsToCluster();
  699. }
  700. this.createComponents();
  701. this.registerHostsToCluster();
  702. if (App.supports.hostOverridesInstaller) {
  703. this.createConfigurationGroups();
  704. }
  705. this.createMasterHostComponents();
  706. this.createSlaveAndClientsHostComponents();
  707. this.createAdditionalHostComponents();
  708. this.doNextAjaxCall();
  709. },
  710. /**
  711. * Used in progress bar
  712. */
  713. ajaxQueueLength: function () {
  714. return this.get('ajaxQueue').length;
  715. }.property('ajaxQueue.length'),
  716. /**
  717. * Used in progress bar
  718. */
  719. ajaxQueueLeft: 0,
  720. clusterName: function () {
  721. return this.get('content.cluster.name');
  722. }.property('content.cluster.name'),
  723. clusterNames: [],
  724. /**
  725. * Get list of existing cluster names
  726. * @returns {string[]}
  727. * returns an array of existing cluster names.
  728. * returns an empty array if there are no existing clusters.
  729. */
  730. getExistingClusterNames: function () {
  731. App.ajax.send({
  732. name: 'wizard.step8.existing_cluster_names',
  733. sender: this,
  734. success: 'getExistingClusterNamesSuccessCallBack',
  735. error: 'getExistingClusterNamesErrorCallback'
  736. });
  737. return this.get('clusterNames');
  738. },
  739. /**
  740. * Save received list to <code>clusterNames</code>
  741. * @param {Object} data
  742. */
  743. getExistingClusterNamesSuccessCallBack: function (data) {
  744. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  745. console.log("Got existing cluster names: " + clusterNames);
  746. this.set('clusterNames', clusterNames);
  747. },
  748. /**
  749. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  750. */
  751. getExistingClusterNamesErrorCallback: function () {
  752. console.log("Failed to get existing cluster names");
  753. this.set('clusterNames', []);
  754. },
  755. /**
  756. * Delete cluster by name
  757. * One request for one cluster!
  758. * @param {string[]} clusterNames
  759. */
  760. deleteClusters: function (clusterNames) {
  761. clusterNames.forEach(function (clusterName) {
  762. App.ajax.send({
  763. name: 'wizard.step8.delete_cluster',
  764. sender: this,
  765. data: {
  766. name: clusterName
  767. }
  768. });
  769. }, this);
  770. },
  771. /**
  772. * Updates local repositories for the Ambari server.
  773. */
  774. setLocalRepositories: function () {
  775. if (this.get('content.controllerName') !== 'installerController' || !App.supports.localRepositories) return;
  776. var self = this;
  777. var stack = this.get('content.stacks').findProperty('isSelected', true);
  778. stack.operatingSystems.forEach(function (os) {
  779. if (os.baseUrl !== os.originalBaseUrl) {
  780. console.log("Updating local repository URL from " + os.originalBaseUrl + " -> " + os.baseUrl + ". ", os);
  781. self.addRequestToAjaxQueue({
  782. type: 'PUT',
  783. url: App.apiPrefix + App.get('stack2VersionURL') + "/operatingSystems/" + os.osType + "/repositories/" + stack.name,
  784. data: JSON.stringify({
  785. "Repositories": {
  786. "base_url": os.baseUrl
  787. }
  788. })
  789. });
  790. }
  791. });
  792. },
  793. /**
  794. * *******************************************************************
  795. * The following create* functions are called upon submitting Step 8.
  796. * *******************************************************************
  797. */
  798. /**
  799. * Create cluster using selected stack version
  800. * Queued request
  801. */
  802. createCluster: function () {
  803. if (this.get('content.controllerName') !== 'installerController') return;
  804. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  805. this.addRequestToAjaxQueue({
  806. type: 'POST',
  807. url: App.apiPrefix + '/clusters/' + this.get('clusterName'),
  808. data: JSON.stringify({ "Clusters": {"version": stackVersion }})
  809. });
  810. },
  811. /**
  812. * Create selected to install services
  813. * Queued request
  814. * Skipped if no services where selected!
  815. */
  816. createSelectedServices: function () {
  817. var data = this.createSelectedServicesData();
  818. if (!data.length) return;
  819. this.addRequestToAjaxQueue({
  820. type: 'POST',
  821. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services',
  822. data: JSON.stringify(data)
  823. });
  824. },
  825. /**
  826. * Format data for <code>createSelectedServices</code> request
  827. * @returns {Object[]}
  828. */
  829. createSelectedServicesData: function () {
  830. return this.get('selectedServices').map(function (_service) {
  831. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  832. });
  833. },
  834. /**
  835. * Create components for selected services
  836. * Queued requests
  837. * One request for each service!
  838. */
  839. createComponents: function () {
  840. var serviceComponents = require('data/service_components');
  841. this.get('selectedServices').forEach(function (_service) {
  842. var serviceName = _service.get('serviceName');
  843. var componentsData = serviceComponents.filterProperty('service_name', serviceName).map(function (_component) {
  844. return { "ServiceComponentInfo": { "component_name": _component.component_name } };
  845. });
  846. // Service must be specified in terms of a query for creating multiple components at the same time.
  847. // See AMBARI-1018.
  848. this.addRequestToAjaxQueue({
  849. type: 'POST',
  850. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/services?ServiceInfo/service_name=' + serviceName,
  851. data: JSON.stringify({"components": componentsData})
  852. });
  853. }, this);
  854. },
  855. /**
  856. * Register hosts
  857. * Queued request
  858. */
  859. registerHostsToCluster: function () {
  860. var data = this.createRegisterHostData();
  861. if (!data.length) return;
  862. this.addRequestToAjaxQueue({
  863. type: 'POST',
  864. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts',
  865. data: JSON.stringify(data)
  866. });
  867. },
  868. /**
  869. * Format request-data for <code>registerHostsToCluster</code>
  870. * @returns {Object}
  871. */
  872. createRegisterHostData: function () {
  873. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  874. return {"Hosts": { "host_name": host.hostName}};
  875. });
  876. },
  877. /**
  878. * Register master components
  879. * @uses registerHostsToComponent
  880. */
  881. createMasterHostComponents: function() {
  882. var masterHosts = this.get('content.masterComponentHosts');
  883. masterHosts.mapProperty('component').uniq().forEach(function (component) {
  884. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  885. this.registerHostsToComponent(hostNames, component);
  886. }, this);
  887. },
  888. /**
  889. * Register slave components and clients
  890. * @uses registerHostsToComponent
  891. */
  892. createSlaveAndClientsHostComponents: function() {
  893. var masterHosts = this.get('content.masterComponentHosts');
  894. var slaveHosts = this.get('content.slaveComponentHosts');
  895. var clients = this.get('content.clients');
  896. /**
  897. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  898. * @type {Object}
  899. * Format:
  900. * <code>
  901. * {
  902. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  903. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  904. * ...
  905. * }
  906. * </code>
  907. */
  908. var clientsToMasterMap = {
  909. HDFS_CLIENT: Em.A(['HBASE_MASTER', 'HBASE_REGIONSERVER', 'WEBHCAT_SERVER', 'HISTORYSERVER', 'OOZIE_SERVER']),
  910. MAPREDUCE_CLIENT: Em.A(['HIVE_SERVER', 'OOZIE_SERVER', 'NAGIOS_SERVER', 'WEBHCAT_SERVER']),
  911. OOZIE_CLIENT: Em.A(['NAGIOS_SERVER']),
  912. ZOOKEEPER_CLIENT: Em.A(['WEBHCAT_SERVER']),
  913. HIVE_CLIENT: Em.A(['WEBHCAT_SERVER','HIVE_SERVER']),
  914. HCAT: Em.A(['NAGIOS_SERVER']),
  915. YARN_CLIENT: Em.A(['NAGIOS_SERVER','HIVE_SERVER','OOZIE_SERVER','WEBHCAT_SERVER']),
  916. TEZ_CLIENT: Em.A(['NAGIOS_SERVER','HIVE_SERVER'])
  917. };
  918. slaveHosts.forEach(function (_slave) {
  919. if (_slave.componentName !== 'CLIENT') {
  920. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  921. this.registerHostsToComponent(hostNames, _slave.componentName);
  922. }
  923. else {
  924. clients.forEach(function (_client) {
  925. var hostNames = _slave.hosts.mapProperty('hostName');
  926. if (clientsToMasterMap[_client.component_name]) {
  927. clientsToMasterMap[_client.component_name].forEach(function(componentName) {
  928. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  929. hostNames.pushObject(_masterHost.hostName);
  930. });
  931. });
  932. }
  933. hostNames = hostNames.uniq();
  934. if (_client.isInstalled) {
  935. //check whether clients are already installed on selected master hosts!!!
  936. _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName').forEach(function (host) {
  937. if (hostNames.contains(host)) {
  938. hostNames.splice(hostNames.indexOf(host), 1);
  939. }
  940. }, this);
  941. }
  942. this.registerHostsToComponent(hostNames, _client.component_name);
  943. }, this);
  944. }
  945. }, this);
  946. },
  947. /**
  948. * Register additional components
  949. * Based on availability of some services
  950. * @uses registerHostsToComponent
  951. */
  952. createAdditionalHostComponents: function() {
  953. var masterHosts = this.get('content.masterComponentHosts');
  954. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  955. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  956. if (gangliaService) {
  957. var hosts = this.getRegisteredHosts();
  958. if (gangliaService.get('isInstalled')) {
  959. hosts = hosts.filterProperty('isInstalled', false);
  960. }
  961. if (hosts.length) {
  962. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  963. }
  964. }
  965. // add MySQL Server if Hive is selected
  966. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  967. if (hiveService) {
  968. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  969. if(hiveDb.value == "New MySQL Database") {
  970. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  971. }
  972. }
  973. },
  974. /**
  975. * Register component to hosts
  976. * Queued request
  977. * @param {String[]} hostNames
  978. * @param {String} componentName
  979. */
  980. registerHostsToComponent: function (hostNames, componentName) {
  981. if (!hostNames.length) return;
  982. var queryStr = '';
  983. hostNames.forEach(function (hostName) {
  984. queryStr += 'Hosts/host_name=' + hostName + '|';
  985. });
  986. //slice off last symbol '|'
  987. queryStr = queryStr.slice(0, -1);
  988. var data = {
  989. "RequestInfo": {
  990. "query": queryStr
  991. },
  992. "Body": {
  993. "host_components": [
  994. {
  995. "HostRoles": {
  996. "component_name": componentName
  997. }
  998. }
  999. ]
  1000. }
  1001. };
  1002. this.addRequestToAjaxQueue({
  1003. type: 'POST',
  1004. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/hosts',
  1005. data: JSON.stringify(data)
  1006. });
  1007. },
  1008. /**
  1009. * Create config objects for cluster and services
  1010. */
  1011. createConfigurations: function () {
  1012. var self = this;
  1013. var selectedServices = this.get('selectedServices');
  1014. var coreSiteObject = this.createCoreSiteObj();
  1015. if (this.get('content.controllerName') == 'installerController') {
  1016. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1017. this.get('serviceConfigTags').pushObject(this.createSiteObj('hdfs-site',false));
  1018. this.get('serviceConfigTags').pushObject(this.createLog4jObj('hdfs'));
  1019. }
  1020. var globalSiteObj = this.createGlobalSiteObj();
  1021. if (this.get('content.controllerName') == 'addServiceController') {
  1022. globalSiteObj.tag = 'version' + (new Date).getTime();
  1023. coreSiteObject.tag = 'version' + (new Date).getTime();
  1024. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1025. }
  1026. this.get('serviceConfigTags').pushObject(globalSiteObj);
  1027. var objMap = {
  1028. MAPREDUCE: {site: [{filename: 'mapred-site',isXmlFile: true}], log4j: ['mapreduce']},
  1029. MAPREDUCE2: {site: [{filename:'mapred-site',isXmlFile: true}], log4j: ['mapreduce2']},
  1030. YARN: {site: [{filename:'yarn-site',isXmlFile: true},{filename:'capacity-scheduler',isXmlFile: true}], log4j: ['yarn']},
  1031. HBASE: {site: [{filename:'hbase-site',isXmlFile: true}], log4j: ['hbase']},
  1032. OOZIE: {site: [{filename:'oozie-site',isXmlFile: true}], log4j: ['oozie']},
  1033. HIVE: {site: [{filename:'hive-site',isXmlFile: true}], log4j: ['hive','hive-exec']},
  1034. WEBHCAT: {site: [{filename:'webhcat-site',isXmlFile: true}], log4j: []},
  1035. HUE: {site: [{filename:'hue-site',isXmlFile: true}], log4j: []},
  1036. PIG: {site: [], log4j: ['pig']},
  1037. FALCON: {site: [{filename:'falcon-startup.properties',isXmlFile: false},{filename:'falcon-runtime.properties',isXmlFile: false}], log4j: []},
  1038. TEZ: {site: [{filename:'tez-site',isXmlFile: true}], log4j: []},
  1039. ZOOKEEPER: {site: [], log4j: ['zookeeper']}
  1040. };
  1041. if (App.supports.capacitySchedulerUi) {
  1042. objMap['MAPREDUCE'].site.pushObjects([{filename:'capacity-scheduler',isXmlFile: true},{filename:'mapred-queue-acls',isXmlFile: true}]);
  1043. }
  1044. for(var serviceName in objMap) {
  1045. if (objMap.hasOwnProperty(serviceName)) {
  1046. if (selectedServices.someProperty('serviceName', serviceName)) {
  1047. objMap[serviceName].site.forEach(function(site) {
  1048. self.get('serviceConfigTags').pushObject(self.createSiteObj(site.filename,!site.isXmlFile));
  1049. });
  1050. objMap[serviceName].log4j.forEach(function(log4j) {
  1051. self.get('serviceConfigTags').pushObject(self.createLog4jObj(log4j));
  1052. });
  1053. }
  1054. }
  1055. }
  1056. if (selectedServices.someProperty('serviceName', 'STORM')) {
  1057. this.get('serviceConfigTags').pushObject(this.createStormSiteObj());
  1058. }
  1059. if (selectedServices.someProperty('serviceName', 'ZOOKEEPER')) {
  1060. this.get('serviceConfigTags').pushObject(this.createZooCfgObj());
  1061. }
  1062. },
  1063. /**
  1064. * Send <code>serviceConfigTags</code> to server
  1065. * Queued request
  1066. * One request for each service config tag
  1067. */
  1068. applyConfigurationsToCluster: function() {
  1069. var configData = this.get('serviceConfigTags').map(function (_serviceConfig) {
  1070. return JSON.stringify({
  1071. Clusters: {
  1072. desired_config: {
  1073. type: _serviceConfig.type,
  1074. tag: _serviceConfig.tag,
  1075. properties: _serviceConfig.properties
  1076. }
  1077. }
  1078. });
  1079. }, this).toString();
  1080. this.addRequestToAjaxQueue({
  1081. type: 'PUT',
  1082. url: App.apiPrefix + '/clusters/' + this.get('clusterName'),
  1083. data: '[' + configData + ']'
  1084. });
  1085. },
  1086. /**
  1087. * Create and update config groups
  1088. */
  1089. createConfigurationGroups: function () {
  1090. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1091. var clusterName = this.get('clusterName');
  1092. var sendData = [];
  1093. var updateData = [];
  1094. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1095. var timeTag = (new Date).getTime();
  1096. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1097. if (groupsToDelete && groupsToDelete.length > 0) {
  1098. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1099. }
  1100. configGroups.forEach(function (configGroup) {
  1101. var groupConfigs = [];
  1102. var groupData = {
  1103. "cluster_name": clusterName,
  1104. "group_name": configGroup.name,
  1105. "tag": configGroup.service.id,
  1106. "description": configGroup.description,
  1107. "hosts": [],
  1108. "desired_configs": []
  1109. };
  1110. configGroup.hosts.forEach(function (hostName) {
  1111. groupData.hosts.push({"host_name": hostName});
  1112. });
  1113. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1114. configGroup.properties.forEach(function (property) {
  1115. groupConfigs.push(Em.Object.create(property));
  1116. });
  1117. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1118. // check for group from installed service
  1119. if (configGroup.isForUpdate === true) {
  1120. // if group is a new one, create it
  1121. if (!configGroup.id) {
  1122. sendData.push({"ConfigGroup": groupData});
  1123. } else {
  1124. // update an existing group
  1125. groupData.id = configGroup.id;
  1126. updateData.push({"ConfigGroup": groupData});
  1127. }
  1128. } else {
  1129. sendData.push({"ConfigGroup": groupData});
  1130. }
  1131. //each group should have unique tag to prevent overriding configs from common sites
  1132. timeTag++;
  1133. }, this);
  1134. if (sendData.length > 0) {
  1135. this.applyConfigurationGroups(sendData);
  1136. }
  1137. if (updateData.length > 0) {
  1138. this.applyInstalledServicesConfigurationGroup(updateData);
  1139. }
  1140. },
  1141. /**
  1142. * Create new config groups request
  1143. * Queued request
  1144. * @param {Object[]} sendData
  1145. */
  1146. applyConfigurationGroups: function (sendData) {
  1147. this.addRequestToAjaxQueue({
  1148. type: 'POST',
  1149. url: App.apiPrefix + '/clusters/' + this.get('clusterName') + '/config_groups',
  1150. data: JSON.stringify(sendData)
  1151. });
  1152. },
  1153. /**
  1154. * Update existed config groups
  1155. * @param {Object[]} updateData
  1156. */
  1157. applyInstalledServicesConfigurationGroup: function (updateData) {
  1158. updateData.forEach(function(item) {
  1159. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1160. });
  1161. },
  1162. /**
  1163. * Delete selected config groups
  1164. * @param {Object[]} groupsToDelete
  1165. */
  1166. removeInstalledServicesConfigurationGroups: function(groupsToDelete) {
  1167. groupsToDelete.forEach(function(item) {
  1168. App.config.deleteConfigGroup(Em.Object.create(item));
  1169. });
  1170. },
  1171. /**
  1172. * Create Global Site object
  1173. * @returns {{type: string, tag: string, properties: {}}}
  1174. */
  1175. createGlobalSiteObj: function () {
  1176. var globalSiteProperties = {};
  1177. var globalSiteObj = this.get('globals');
  1178. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1179. // screen out the GLUSTERFS-specific global config entries when they are not required
  1180. if (!isGLUSTERFSSelected) {
  1181. globalSiteObj = globalSiteObj.filter(function(_config) {
  1182. return _config.name.indexOf("fs_glusterfs") < 0;
  1183. });
  1184. }
  1185. globalSiteObj.forEach(function (_globalSiteObj) {
  1186. var heapsizeException = ['hadoop_heapsize','yarn_heapsize','nodemanager_heapsize','resourcemanager_heapsize', 'apptimelineserver_heapsize'];
  1187. // do not pass any globals whose name ends with _host or _hosts
  1188. if (_globalSiteObj.isRequiredByAgent !== false) {
  1189. // append "m" to JVM memory options except for hadoop_heapsize
  1190. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && !heapsizeException.contains(_globalSiteObj.name)) {
  1191. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1192. } else {
  1193. globalSiteProperties[_globalSiteObj.name] = App.config.escapeXMLCharacters(_globalSiteObj.value);
  1194. }
  1195. }
  1196. }, this);
  1197. // we don't expose gmond_user to the user; it needs to be the same as gmetad_user
  1198. globalSiteProperties['gmond_user'] = globalSiteProperties['gmetad_user'];
  1199. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1200. },
  1201. /**
  1202. * Create Core Site object
  1203. * @returns {{type: string, tag: string, properties: {}}}
  1204. */
  1205. createCoreSiteObj: function () {
  1206. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1207. var coreSiteProperties = {};
  1208. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1209. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1210. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  1211. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1212. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  1213. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1214. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  1215. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1216. // screen out the GLUSTERFS-specific core-site.xml entries when they are not needed
  1217. if (!isGLUSTERFSSelected) {
  1218. coreSiteObj = coreSiteObj.filter(function(_config) {
  1219. return _config.name.indexOf("fs.glusterfs") < 0;
  1220. });
  1221. }
  1222. coreSiteObj.forEach(function (_coreSiteObj) {
  1223. 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'))) {
  1224. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1225. }
  1226. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1227. coreSiteProperties[_coreSiteObj.name] = this.get('globals').someProperty('name', 'fs_glusterfs_default_name') ? App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'fs_glusterfs_default_name').value) : null;
  1228. }
  1229. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1230. coreSiteProperties[_coreSiteObj.name] = this.get('globals').someProperty('name', 'glusterfs_defaultFS_name') ? App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'glusterfs_defaultFS_name').value) : null;
  1231. }
  1232. }, this);
  1233. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1234. },
  1235. /**
  1236. * Create siteObj for custom service with it own configs
  1237. * @param {string} site
  1238. * @param {Boolean} isNonXmlFile
  1239. * @returns {{type: string, tag: string, properties: {}}}
  1240. */
  1241. createSiteObj: function(site,isNonXmlFile) {
  1242. var properties = {};
  1243. if (!!isNonXmlFile) {
  1244. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1245. properties[_configProperty.name] = _configProperty.value;
  1246. },this);
  1247. } else {
  1248. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1249. properties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1250. },this);
  1251. }
  1252. return {"type": site, "tag": "version1", "properties": properties };
  1253. },
  1254. /**
  1255. * Create log4j object for custom service with it own configs
  1256. * @param {string} site
  1257. * @returns {{type: string, tag: string, properties: {}}}
  1258. */
  1259. createLog4jObj: function (site) {
  1260. return this.createSiteObj(site + '-log4j',true);
  1261. },
  1262. /**
  1263. * Create ZooKeeper Cfg Object
  1264. * @returns {{type: string, tag: string, properties: {}}}
  1265. */
  1266. createZooCfgObj: function () {
  1267. var configs = this.get('configs').filterProperty('filename', 'zoo.cfg');
  1268. var csProperties = {};
  1269. configs.forEach(function (_configProperty) {
  1270. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1271. }, this);
  1272. return {type: 'zoo.cfg', tag: 'version1', properties: csProperties};
  1273. },
  1274. /**
  1275. * Create site obj for Storm
  1276. * Some config-properties should be modified in custom way
  1277. * @returns {{type: string, tag: string, properties: {}}}
  1278. */
  1279. createStormSiteObj: function () {
  1280. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1281. var stormProperties = {};
  1282. var specialProperties = ["storm.zookeeper.servers", "nimbus.childopts", "supervisor.childopts", "worker.childopts"];
  1283. configs.forEach(function (_configProperty) {
  1284. if (specialProperties.contains(_configProperty.name)) {
  1285. if (_configProperty.name == "storm.zookeeper.servers") {
  1286. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1287. } else {
  1288. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g,"");
  1289. }
  1290. } else {
  1291. stormProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1292. }
  1293. }, this);
  1294. return {type: 'storm-site', tag: 'version1', properties: stormProperties};
  1295. },
  1296. /**
  1297. * Navigate to next step after all requests are sended
  1298. */
  1299. ajaxQueueFinished: function () {
  1300. console.log('everything is loaded');
  1301. App.router.send('next');
  1302. },
  1303. /**
  1304. * Do ajax-call with data in <code>ajaxQueue[0]</code> and shift <code>ajaxQueue</code>
  1305. */
  1306. doNextAjaxCall: function () {
  1307. if (this.get('ajaxBusy')) return;
  1308. var queue = this.get('ajaxQueue');
  1309. if (!queue.length) {
  1310. this.ajaxQueueFinished();
  1311. return;
  1312. }
  1313. var first = queue[0];
  1314. this.set('ajaxQueue', queue.slice(1));
  1315. this.set('ajaxQueueLeft', this.get('ajaxQueue').length);
  1316. this.set('ajaxBusy', true);
  1317. $.ajax(first);
  1318. },
  1319. /**
  1320. * We need to do a lot of ajax calls async in special order. To do this,
  1321. * generate array of ajax objects and then send requests step by step. All
  1322. * ajax objects are stored in <code>ajaxQueue</code>
  1323. *
  1324. * Each ajax-request success callback contains call of <code>doNextAjaxCall</code>
  1325. *
  1326. * @param {Object} params object with ajax-request parameters like url, type, data etc
  1327. */
  1328. addRequestToAjaxQueue: function (params) {
  1329. if (App.testMode) return;
  1330. var self = this;
  1331. params = jQuery.extend({
  1332. async: true,
  1333. dataType: 'text',
  1334. statusCode: require('data/statusCodes'),
  1335. timeout: App.timeout,
  1336. error: function () {
  1337. console.log('Step8: In Error ');
  1338. },
  1339. success: function () {
  1340. console.log("TRACE: Step8 -> In success function");
  1341. }
  1342. }, params);
  1343. var success = params.success;
  1344. var error = params.error;
  1345. params.success = function () {
  1346. if (success) {
  1347. success();
  1348. }
  1349. self.set('ajaxBusy', false);
  1350. self.doNextAjaxCall();
  1351. };
  1352. params.error = function (xhr, status, error) {
  1353. var responseText = JSON.parse(xhr.responseText);
  1354. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1355. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1356. self.set('hasErrorOccurred', true);
  1357. // an error will break the ajax call chain and allow submission again
  1358. self.set('isSubmitDisabled', false);
  1359. self.set('isBackBtnDisabled', false);
  1360. App.router.get(self.get('content.controllerName')).setStepsEnable();
  1361. self.get('ajaxQueue').clear();
  1362. self.set('ajaxBusy', false);
  1363. };
  1364. this.get('ajaxQueue').pushObject(params);
  1365. }
  1366. });