step8_controller.js 60 KB

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