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