step8_controller.js 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824
  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: [
  27. {
  28. config_name: 'Admin',
  29. display_name: 'Admin Name',
  30. config_value: ''
  31. },
  32. {
  33. config_name: 'cluster',
  34. display_name: 'Cluster Name',
  35. config_value: ''
  36. },
  37. {
  38. config_name: 'hosts',
  39. display_name: 'Total Hosts',
  40. config_value: ''
  41. },
  42. {
  43. config_name: 'Repo',
  44. display_name: 'Local Repository',
  45. config_value: ''
  46. }
  47. ],
  48. /**
  49. * List of data about cluster (based on formatted <code>rawContent</code>)
  50. * @type {Object[]}
  51. */
  52. clusterInfo: [],
  53. /**
  54. * List of services with components assigned to hosts
  55. * @type {Object[]}
  56. */
  57. services: [],
  58. /**
  59. * @type {Object[]}
  60. */
  61. configs: [],
  62. /**
  63. * @type {Object[]}
  64. */
  65. globals: [],
  66. /**
  67. * All configs
  68. * @type {Array}
  69. */
  70. configMapping: function () {
  71. return App.config.get('configMapping').all(true);
  72. }.property('App.config.configMapping'),
  73. /**
  74. *
  75. */
  76. slaveComponentConfig: null,
  77. /**
  78. * Should Submit button be disabled
  79. * @type {bool}
  80. */
  81. isSubmitDisabled: false,
  82. /**
  83. * Should Back button be disabled
  84. * @type {bool}
  85. */
  86. isBackBtnDisabled: false,
  87. /**
  88. * Is error appears while <code>ajaxQueue</code> executes
  89. * @type {bool}
  90. */
  91. hasErrorOccurred: false,
  92. /**
  93. * Are services installed
  94. * Used to hide Deploy Progress Bar
  95. * @type {bool}
  96. */
  97. servicesInstalled: false,
  98. /**
  99. * List of service config tags
  100. * @type {Object[]}
  101. */
  102. serviceConfigTags: [],
  103. /**
  104. * Ajax-requests queue
  105. * @type {App.ajaxQueue}
  106. */
  107. ajaxRequestsQueue: null,
  108. /**
  109. * Is cluster security enabled
  110. * @type {bool}
  111. */
  112. securityEnabled: function () {
  113. return App.router.get('mainAdminSecurityController.securityEnabled');
  114. }.property('App.router.mainAdminSecurityController.securityEnabled'),
  115. /**
  116. * During page save time, we set the host overrides to the server.
  117. * The new host -> site:tag map is stored below. This will be
  118. * useful during save, to update the host's host components. Also,
  119. * it will be useful in deletion of overrides.
  120. *
  121. * Example:
  122. * {
  123. * 'hostname1': {
  124. * 'global': {
  125. * 'tagName': 'tag3187261938_hostname1',
  126. * 'map': {
  127. * 'hadoop_heapsize': '2048m'
  128. * }
  129. * }
  130. * }
  131. * }
  132. *
  133. * @see loadedHostToOverrideSiteToTagMap
  134. */
  135. savedHostToOverrideSiteToTagMap: {},
  136. /**
  137. * Selected config group
  138. * @type {Object}
  139. */
  140. selectedConfigGroup: null,
  141. /**
  142. * List of config groups
  143. * @type {Object[]}
  144. */
  145. configGroups: [],
  146. /**
  147. * List of selected but not installed services
  148. * @type {Object[]}
  149. */
  150. selectedServices: function () {
  151. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false);
  152. }.property('content.services').cacheable(),
  153. /**
  154. * List of installed and selected services
  155. * @type {Object[]}
  156. */
  157. installedServices: function () {
  158. return this.get('content.services').filterProperty('isSelected').filterProperty('isInstalled');
  159. }.property('content.services').cacheable(),
  160. /**
  161. * Ajax-requests count
  162. * @type {number}
  163. */
  164. ajaxQueueLength: 0,
  165. /**
  166. * Current cluster name
  167. * @type {string}
  168. */
  169. clusterName: function () {
  170. return this.get('content.cluster.name');
  171. }.property('content.cluster.name'),
  172. /**
  173. * List of existing cluster names
  174. * @type {string[]}
  175. */
  176. clusterNames: [],
  177. /**
  178. * Clear current step data
  179. * @method clearStep
  180. */
  181. clearStep: function () {
  182. this.get('services').clear();
  183. this.get('configs').clear();
  184. this.get('globals').clear();
  185. this.get('clusterInfo').clear();
  186. this.get('serviceConfigTags').clear();
  187. this.set('servicesInstalled', false);
  188. this.set('ajaxQueueLength', 0);
  189. this.set('ajaxRequestsQueue', App.ajaxQueue.create());
  190. this.set('ajaxRequestsQueue.finishedCallback', this.ajaxQueueFinished);
  191. },
  192. /**
  193. * Load current step data
  194. * @method loadStep
  195. */
  196. loadStep: function () {
  197. console.log("TRACE: Loading step8: Review Page");
  198. if (this.get('content.controllerName') != 'installerController') {
  199. App.router.get('mainAdminSecurityController').setSecurityStatus();
  200. }
  201. this.clearStep();
  202. if (this.get('content.serviceConfigProperties')) {
  203. this.formatProperties();
  204. this.loadGlobals();
  205. this.loadConfigs();
  206. }
  207. this.loadClusterInfo();
  208. this.loadServices();
  209. this.set('isSubmitDisabled', false);
  210. this.set('isBackBtnDisabled', false);
  211. },
  212. /**
  213. * replace whitespace character with coma between directories
  214. * @method formatProperties
  215. */
  216. formatProperties: function () {
  217. this.get('content.serviceConfigProperties').forEach(function (_configProperty) {
  218. _configProperty.value = App.config.trimProperty(_configProperty, false);
  219. });
  220. },
  221. /**
  222. * Load global configs and remove some of them:
  223. * <ul>
  224. * <li>Unused DB properties for Hive</li>
  225. * <li>Unused DB properties for Oozie</li>
  226. * <ul>
  227. * @method loadGlobals
  228. */
  229. loadGlobals: function () {
  230. var globals = this.get('content.serviceConfigProperties').filterProperty('id', 'puppet var');
  231. if (globals.someProperty('name', 'hive_database')) {
  232. globals = this.removeHiveConfigs(globals);
  233. }
  234. if (globals.someProperty('name', 'oozie_database')) {
  235. globals = this.removeOozieConfigs(globals);
  236. }
  237. this.set('globals', globals);
  238. },
  239. /**
  240. * Remove unused Hive configs
  241. * @param {Ember.Enumerable} globals
  242. * @returns {Ember.Enumerable}
  243. * @method removeHiveConfigs
  244. */
  245. removeHiveConfigs: function (globals) {
  246. var hiveDb = globals.findProperty('name', 'hive_database');
  247. var hiveDbType = {name: 'hive_database_type', value: 'mysql'};
  248. var hive_properties = Em.A([]);
  249. if (hiveDb.value === 'New MySQL Database') {
  250. if (globals.someProperty('name', 'hive_ambari_host')) {
  251. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_ambari_host').value;
  252. hiveDbType.value = 'mysql';
  253. }
  254. hive_properties = Em.A(['hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host',
  255. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']);
  256. }
  257. else {
  258. if (hiveDb.value === 'Existing MySQL Database') {
  259. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_existing_mysql_host').value;
  260. hiveDbType.value = 'mysql';
  261. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  262. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']);
  263. }
  264. else {
  265. if (hiveDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  266. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_existing_postgresql_host').value;
  267. hiveDbType.value = 'postgres';
  268. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  269. 'hive_existing_oracle_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database']);
  270. }
  271. else { //existing oracle database
  272. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_existing_oracle_host').value;
  273. hiveDbType.value = 'oracle';
  274. hive_properties = Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_mysql_host',
  275. 'hive_existing_mysql_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']);
  276. }
  277. }
  278. }
  279. hive_properties.forEach(function (property) {
  280. globals = globals.without(globals.findProperty('name', property));
  281. });
  282. globals.pushObject(hiveDbType);
  283. return globals;
  284. },
  285. /**
  286. * Remove unused Oozie configs
  287. * @param {Ember.Enumerable} globals
  288. * @returns {Ember.Enumerable}
  289. * @method removeOozieConfigs
  290. */
  291. removeOozieConfigs: function (globals) {
  292. var oozieDb = globals.findProperty('name', 'oozie_database');
  293. var oozieDbType = {name: 'oozie_database_type'};
  294. var oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database']);
  295. if (oozieDb.value === 'New Derby Database') {
  296. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_ambari_host').value;
  297. oozieDbType.value = 'derby';
  298. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_mysql_host',
  299. 'oozie_existing_mysql_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database',
  300. 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database']);
  301. }
  302. else {
  303. if (oozieDb.value === 'Existing MySQL Database') {
  304. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_existing_mysql_host').value;
  305. oozieDbType.value = 'mysql';
  306. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_oracle_host',
  307. 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database']);
  308. }
  309. else {
  310. if (oozieDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  311. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_existing_postgresql_host').value;
  312. oozieDbType.value = 'postgresql';
  313. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_oracle_host',
  314. 'oozie_existing_oracle_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database']);
  315. }
  316. else { // existing oracle database
  317. globals.findProperty('name', 'oozie_hostname').value = globals.findProperty('name', 'oozie_existing_oracle_host').value;
  318. oozieDbType.value = 'oracle';
  319. oozie_properties = Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_mysql_host',
  320. 'oozie_existing_mysql_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database']);
  321. }
  322. }
  323. }
  324. oozie_properties.forEach(function (property) {
  325. globals = globals.without(globals.findProperty('name', property));
  326. });
  327. globals.pushObject(oozieDbType);
  328. return globals;
  329. },
  330. /**
  331. * Load all site properties
  332. * @method loadConfigs
  333. */
  334. loadConfigs: function () {
  335. //storedConfigs contains custom configs as well
  336. var serviceConfigProperties = this.get('content.serviceConfigProperties').filterProperty('id', 'site property');
  337. serviceConfigProperties.forEach(function (_config) {
  338. _config.value = (typeof _config.value === "boolean") ? _config.value.toString() : _config.value;
  339. });
  340. var mappedConfigs = App.config.excludeUnsupportedConfigs(this.get('configMapping'), this.get('selectedServices').mapProperty('serviceName'));
  341. var uiConfigs = this.loadUiSideConfigs(mappedConfigs);
  342. this.set('configs', serviceConfigProperties.concat(uiConfigs));
  343. },
  344. /**
  345. * Load UI configs
  346. * @param {Array} configMapping
  347. * @return {Array}
  348. * @method loadUiSideConfigs
  349. */
  350. loadUiSideConfigs: function (configMapping) {
  351. var uiConfig = [];
  352. var configs = configMapping.filterProperty('foreignKey', null);
  353. this.addDynamicProperties(configs);
  354. configs.forEach(function (_config) {
  355. var valueWithOverrides = this.getGlobConfigValueWithOverrides(_config.templateName, _config.value, _config.name);
  356. uiConfig.pushObject({
  357. "id": "site property",
  358. "name": _config.name,
  359. "value": valueWithOverrides.value,
  360. "filename": _config.filename,
  361. "overrides": valueWithOverrides.overrides
  362. });
  363. }, this);
  364. var dependentConfig = $.extend(true, [], configMapping.filterProperty('foreignKey'));
  365. dependentConfig.forEach(function (_config) {
  366. App.config.setConfigValue(uiConfig, this.get('content.serviceConfigProperties'), _config, this.get('globals'));
  367. uiConfig.pushObject({
  368. "id": "site property",
  369. "name": _config._name || _config.name,
  370. "value": _config.value,
  371. "filename": _config.filename
  372. });
  373. }, this);
  374. return uiConfig;
  375. },
  376. /**
  377. * Add dynamic properties to configs
  378. * @param {Array} configs
  379. * @method addDynamicProperties
  380. */
  381. addDynamicProperties: function (configs) {
  382. var templetonHiveProperty = this.get('content.serviceConfigProperties').someProperty('name', 'templeton.hive.properties');
  383. if (!templetonHiveProperty) {
  384. configs.pushObject({
  385. "name": "templeton.hive.properties",
  386. "templateName": ["hivemetastore_host"],
  387. "foreignKey": null,
  388. "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",
  389. "filename": "webhcat-site.xml"
  390. });
  391. }
  392. },
  393. /**
  394. * Format <code>content.hosts</code> from Object to Array
  395. * @returns {Array}
  396. * @method getRegisteredHosts
  397. */
  398. getRegisteredHosts: function () {
  399. var allHosts = this.get('content.hosts');
  400. var hosts = [];
  401. for (var hostName in allHosts) {
  402. if (allHosts.hasOwnProperty(hostName)) {
  403. if (allHosts[hostName].bootStatus == 'REGISTERED') {
  404. allHosts[hostName].hostName = allHosts[hostName].name;
  405. hosts.pushObject(allHosts[hostName]);
  406. }
  407. }
  408. }
  409. return hosts;
  410. },
  411. /**
  412. * Set all site property that are derived from other puppet-variable
  413. * @param {String} templateName
  414. * @param {String} expression
  415. * @param {String} name
  416. * @return {Object}
  417. * example: <code>{
  418. * value: '...',
  419. * overrides: [
  420. * {
  421. * value: 'v1',
  422. * hosts: ['h1', 'h2']
  423. * },
  424. * {
  425. * value: 'v2',
  426. * hosts: ['h2', 'h3']
  427. * },
  428. * ....
  429. * ]
  430. * }</code>
  431. * @method getGlobConfigValueWithOverrides
  432. */
  433. getGlobConfigValueWithOverrides: function (templateName, expression, name) {
  434. var express = expression.match(/<(.*?)>/g);
  435. var value = expression;
  436. if (express == null) {
  437. return { value: expression, overrides: []}; // if site property do not map any global property then return the value
  438. }
  439. var overrideHostToValue = {};
  440. express.forEach(function (_express) {
  441. //console.log("The value of template is: " + _express);
  442. var index = parseInt(_express.match(/\[([\d]*)(?=\])/)[1]);
  443. if (this.get('globals').someProperty('name', templateName[index])) {
  444. //console.log("The name of the variable is: " + this.get('content.serviceConfigProperties').findProperty('name', templateName[index]).name);
  445. var globalObj = this.get('globals').findProperty('name', templateName[index]);
  446. var globValue = globalObj.value;
  447. // Hack for templeton.zookeeper.hosts
  448. var preReplaceValue = null;
  449. 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
  450. preReplaceValue = value;
  451. value = this._replaceConfigValues(name, _express, value, globValue);
  452. }
  453. if (globalObj.overrides != null) {
  454. globalObj.overrides.forEach(function (override) {
  455. var ov = override.value;
  456. var hostsArray = override.hosts;
  457. hostsArray.forEach(function (host) {
  458. if (!(host in overrideHostToValue)) {
  459. overrideHostToValue[host] = this._replaceConfigValues(name, _express, preReplaceValue, ov);
  460. } else {
  461. overrideHostToValue[host] = this._replaceConfigValues(name, _express, overrideHostToValue[host], ov);
  462. }
  463. }, this);
  464. }, this);
  465. }
  466. } else {
  467. /*
  468. console.log("ERROR: The variable name is: " + templateName[index]);
  469. console.log("ERROR: mapped config from configMapping file has no corresponding variable in " +
  470. "content.serviceConfigProperties. Two possible reasons for the error could be: 1) The service is not selected. " +
  471. "and/OR 2) The service_config metadata file has no corresponding global var for the site property variable");
  472. */
  473. value = null;
  474. }
  475. }, this);
  476. var valueWithOverrides = {
  477. value: value,
  478. overrides: []
  479. };
  480. var overrideValueToHostMap = {};
  481. if (!jQuery.isEmptyObject(overrideHostToValue)) {
  482. for (var host in overrideHostToValue) {
  483. var hostVal = overrideHostToValue[host];
  484. if (!(hostVal in overrideValueToHostMap)) {
  485. overrideValueToHostMap[hostVal] = [];
  486. }
  487. overrideValueToHostMap[hostVal].push(host);
  488. }
  489. }
  490. for (var val in overrideValueToHostMap) {
  491. valueWithOverrides.overrides.push({
  492. value: val,
  493. hosts: overrideValueToHostMap[val]
  494. });
  495. }
  496. return valueWithOverrides;
  497. },
  498. /**
  499. * replace some values in config property
  500. * @param {string} name
  501. * @param {string} express
  502. * @param {string} value
  503. * @param {string} globValue
  504. * @return {string}
  505. * @private
  506. * @method _replaceConfigValues
  507. */
  508. _replaceConfigValues: function (name, express, value, globValue) {
  509. return value.replace(express, globValue);
  510. },
  511. /**
  512. * Load all info about cluster to <code>clusterInfo</code> variable
  513. * @method loadClusterInfo
  514. */
  515. loadClusterInfo: function () {
  516. //Admin name
  517. var admin = this.rawContent.findProperty('config_name', 'Admin');
  518. admin.config_value = App.db.getLoginName();
  519. console.log("STEP8: the value of content cluster name: " + App.db.getLoginName());
  520. if (admin.config_value) {
  521. this.get('clusterInfo').pushObject(Ember.Object.create(admin));
  522. }
  523. // cluster name
  524. var cluster = this.rawContent.findProperty('config_name', 'cluster');
  525. cluster.config_value = this.get('content.cluster.name');
  526. console.log("STEP8: the value of content cluster name: " + this.get('content.cluster.name'));
  527. this.get('clusterInfo').pushObject(Ember.Object.create(cluster));
  528. //hosts
  529. var newHostsCount = 0;
  530. var totalHostsCount = 0;
  531. var hosts = this.get('content.hosts');
  532. for (var hostName in hosts) {
  533. newHostsCount += ~~(!hosts[hostName].isInstalled);
  534. totalHostsCount++;
  535. }
  536. var totalHostsObj = this.rawContent.findProperty('config_name', 'hosts');
  537. totalHostsObj.config_value = totalHostsCount + ' (' + newHostsCount + ' new)';
  538. this.get('clusterInfo').pushObject(Em.Object.create(totalHostsObj));
  539. //repo
  540. if (['addHostController', 'addServiceController'].contains(this.get('content.controllerName'))) {
  541. this.loadRepoInfo();
  542. } else {
  543. // from install wizard
  544. var selectedStack = this.get('content.stacks').findProperty('isSelected', true);
  545. var allRepos = [];
  546. if (selectedStack && selectedStack.operatingSystems) {
  547. selectedStack.operatingSystems.forEach(function (os) {
  548. if (os.selected) {
  549. allRepos.push(Em.Object.create({
  550. base_url: os.baseUrl,
  551. os_type: os.osType,
  552. repo_id: os.repoId
  553. }));
  554. }
  555. }, this);
  556. }
  557. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  558. this.get('clusterInfo').set('repoInfo', allRepos);
  559. }
  560. },
  561. /**
  562. * Load repo info for add Service/Host wizard review page
  563. * @return {$.ajax|null}
  564. * @method loadRepoInfo
  565. */
  566. loadRepoInfo: function () {
  567. var nameVersionCombo = App.get('currentStackVersion').split('-');
  568. return App.ajax.send({
  569. name: 'cluster.load_repositories',
  570. sender: this,
  571. data: {
  572. stackName: nameVersionCombo[0],
  573. stackVersion: nameVersionCombo[1]
  574. },
  575. success: 'loadRepoInfoSuccessCallback',
  576. error: 'loadRepoInfoErrorCallback'
  577. });
  578. },
  579. /**
  580. * Save all repo base URL of all OS type to <code>repoInfo<code>
  581. * @param {object} data
  582. * @method loadRepoInfoSuccessCallback
  583. */
  584. loadRepoInfoSuccessCallback: function (data) {
  585. var allRepos = [];
  586. data.items.forEach(function (os) {
  587. if (!App.supports.ubuntu && os.OperatingSystems.os_type == 'debian12') return; // @todo: remove after Ubuntu support confirmation
  588. os.repositories.forEach(function (repository) {
  589. allRepos.push(Em.Object.create({
  590. base_url: repository.Repositories.base_url,
  591. os_type: repository.Repositories.os_type,
  592. repo_id: repository.Repositories.repo_id
  593. }));
  594. });
  595. }, this);
  596. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  597. this.get('clusterInfo').set('repoInfo', allRepos);
  598. },
  599. /**
  600. * @param {object} request
  601. * @method loadRepoInfoErrorCallback
  602. */
  603. loadRepoInfoErrorCallback: function (request) {
  604. console.log('Error message is: ' + request.responseText);
  605. var allRepos = [];
  606. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  607. this.get('clusterInfo').set('repoInfo', allRepos);
  608. },
  609. /**
  610. * Load all info about services to <code>services</code> variable
  611. * @method loadServices
  612. */
  613. loadServices: function () {
  614. this.get('selectedServices').filterProperty('isHiddenOnSelectServicePage', false).forEach(function (service) {
  615. console.log('INFO: step8: Name of the service from getService function: ' + service.get('serviceName'));
  616. var serviceObj = Em.Object.create({
  617. service_name: service.get('serviceName'),
  618. display_name: service.get('displayNameOnSelectServicePage'),
  619. service_components: Em.A([])
  620. });
  621. service.get('serviceComponents').forEach(function(component) {
  622. // show clients for services that have only clients components
  623. if ((component.get('isClient') || component.get('isClientBehavior')) && !service.get('isClientOnlyService')) return;
  624. // skip components that was hide on assign master page
  625. if (component.get('isMaster') && !component.get('isShownOnInstallerAssignMasterPage')) return;
  626. // no HA component
  627. if (App.get('isHaEnabled') && component.get('isHAComponentOnly')) return;
  628. var displayName;
  629. if (component.get('isClient')) {
  630. displayName = Em.I18n.t('common.clients')
  631. } else {
  632. // remove service name from component display name
  633. displayName = component.get('displayName').replace(new RegExp('^' + service.get('serviceName') + '\\s','i'), '');
  634. }
  635. serviceObj.get('service_components').pushObject(Em.Object.create({
  636. component_name: component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName'),
  637. display_name: displayName,
  638. component_value: this.assignComponentHosts(component)
  639. }));
  640. }, this);
  641. if (service.get('customReviewHandler')) {
  642. for (var displayName in service.get('customReviewHandler')) {
  643. serviceObj.get('service_components').pushObject(Em.Object.create({
  644. display_name: displayName,
  645. component_value: this.assignComponentHosts(Em.Object.create({
  646. customHandler: service.get('customReviewHandler.' + displayName)
  647. }))
  648. }));
  649. }
  650. }
  651. this.get('services').pushObject(serviceObj);
  652. }, this);
  653. },
  654. /**
  655. * Set <code>component_value</code> property to <code>component</code>
  656. * @param {Em.Object} component
  657. * @return {String}
  658. * @method assignComponentHosts
  659. */
  660. assignComponentHosts: function (component) {
  661. var componentValue;
  662. if (component.get('customHandler')) {
  663. componentValue = this[component.get('customHandler')].call(this, component);
  664. }
  665. else {
  666. if (component.get('isMaster') || component.get('isMasterBehavior')) {
  667. componentValue = this.getMasterComponentValue(component.get('componentName'));
  668. }
  669. else {
  670. console.log(' --- ---INFO: step8: NOT component isMaster');
  671. var hostsLength = this.get('content.slaveComponentHosts')
  672. .findProperty('componentName', component.get('isClient') ? Em.I18n.t('common.client').toUpperCase() : component.get('componentName'))
  673. .hosts.length;
  674. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  675. }
  676. }
  677. return componentValue;
  678. },
  679. getMasterComponentValue: function(componentName) {
  680. var masterComponents = this.get('content.masterComponentHosts');
  681. var hostsCount = masterComponents.filterProperty('component', componentName).length;
  682. return stringUtils.pluralize(hostsCount,
  683. masterComponents.findProperty('component', componentName).hostName,
  684. hostsCount + ' ' + Em.I18n.t('installer.step8.hosts'));
  685. },
  686. /**
  687. * Set dispalyed Hive DB value based on DB type
  688. * @param {Ember.Object} dbComponent
  689. * @method loadHiveDbValue
  690. */
  691. loadHiveDbValue: function () {
  692. var db,
  693. serviceConfigPreoprties = this.get('wizardController').getDBProperty('serviceConfigProperties'),
  694. hiveDb = serviceConfigPreoprties.findProperty('name', 'hive_database');
  695. if (hiveDb.value === 'New MySQL Database') {
  696. return 'MySQL (New Database)';
  697. }
  698. else {
  699. if (hiveDb.value === 'Existing MySQL Database') {
  700. db = serviceConfigPreoprties .findProperty('name', 'hive_existing_mysql_database');
  701. return db.value + ' (' + hiveDb.value + ')';
  702. }
  703. else {
  704. if (hiveDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  705. db = serviceConfigPreoprties .findProperty('name', 'hive_existing_postgresql_database');
  706. return db.value + ' (' + hiveDb.value + ')';
  707. }
  708. else { // existing oracle database
  709. db = serviceConfigPreoprties .findProperty('name', 'hive_existing_oracle_database');
  710. return db.value + ' (' + hiveDb.value + ')';
  711. }
  712. }
  713. }
  714. },
  715. /**
  716. * Set displayed HBase master value
  717. * @param {Object} hbaseMaster
  718. * @method loadHbaseMasterValue
  719. */
  720. loadHbaseMasterValue: function (hbaseMaster) {
  721. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  722. if (hbaseHostName.length == 1) {
  723. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  724. } else {
  725. hbaseMaster.set('component_value', hbaseHostName[0].hostName + " " + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  726. }
  727. },
  728. /**
  729. * Set displayed ZooKeeper Server value
  730. * @param {Object} serverComponent
  731. * @method loadZkServerValue
  732. */
  733. loadZkServerValue: function (serverComponent) {
  734. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  735. var hostSuffix;
  736. if (zkHostNames === 1) {
  737. hostSuffix = Em.I18n.t('installer.step8.host');
  738. } else {
  739. hostSuffix = Em.I18n.t('installer.step8.hosts');
  740. }
  741. serverComponent.set('component_value', zkHostNames + hostSuffix);
  742. },
  743. /**
  744. * Set displayed Oozie DB value based on DB type
  745. * @param {Object} dbComponent
  746. * @method loadOozieDbValue
  747. */
  748. loadOozieDbValue: function () {
  749. var db, oozieDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_database');
  750. if (oozieDb.value === 'New Derby Database') {
  751. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_derby_database');
  752. return db.value + ' (' + oozieDb.value + ')';
  753. }
  754. else {
  755. if (oozieDb.value === 'Existing MySQL Database') {
  756. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mysql_database');
  757. return db.value + ' (' + oozieDb.value + ')';
  758. }
  759. else {
  760. if (oozieDb.value === Em.I18n.t('services.service.config.hive.oozie.postgresql')) {
  761. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_postgresql_database');
  762. return db.value + ' (' + oozieDb.value + ')';
  763. }
  764. else { // existing oracle database
  765. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_oracle_database');
  766. return db.value + ' (' + oozieDb.value + ')';
  767. }
  768. }
  769. }
  770. },
  771. /**
  772. * Set displayed Nagion Admin value
  773. * @param {Object} nagiosAdmin
  774. * @method loadNagiosAdminValue
  775. */
  776. loadNagiosAdminValue: function () {
  777. var config = this.get('content.serviceConfigProperties');
  778. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  779. var adminEmail = config.findProperty('name', 'nagios_contact');
  780. return adminLoginName.value + ' / (' + adminEmail.value + ')';
  781. },
  782. /**
  783. * Onclick handler for <code>next</code> button
  784. * @method submit
  785. * @return {App.ModalPopup|null}
  786. */
  787. submit: function () {
  788. if (this.get('isSubmitDisabled')) return null;
  789. if ((this.get('content.controllerName') == 'addHostController') && this.get('securityEnabled')) {
  790. var self = this;
  791. return App.showConfirmationPopup(function () {
  792. self.submitProceed();
  793. }, Em.I18n.t('installer.step8.securityConfirmationPopupBody'));
  794. }
  795. else {
  796. return this.submitProceed();
  797. }
  798. },
  799. /**
  800. * Update configurations for installed services.
  801. * Do separated PUT-request for each siteName for each service
  802. *
  803. * @param {Array} configsToUpdate - configs need to update
  804. * Format:
  805. * <code>
  806. * [
  807. * {serviceName: 's1', id: 'site property', filename: 'f1.xml', name: 'n1', value: 'v1'},
  808. * {serviceName: 's2', id: 'site property', filename: 'f1.xml', name: 'n2', value: 'v2'},
  809. * {serviceName: 's2', id: '', filename: 'f2.xml', name: 'n3', value: 'v3'}
  810. * ]
  811. * </code>
  812. * @method updateConfigurations
  813. */
  814. updateConfigurations: function (configsToUpdate) {
  815. var configurationController = App.router.get('mainServiceInfoConfigsController');
  816. var configs = configsToUpdate.filter(function(config) {
  817. return !!config.filename && !/^(global|core)/.test(config.filename);
  818. });
  819. var serviceNames = configs.mapProperty('serviceName').uniq();
  820. var configsMap = [];
  821. serviceNames.forEach(function (serviceName) {
  822. var serviceConfigs = configs.filterProperty('serviceName', serviceName);
  823. var tagName = 'version' + (new Date).getTime();
  824. serviceConfigs.forEach(function(config) {
  825. config.value = App.config.trimProperty(config, false);
  826. });
  827. serviceConfigs.mapProperty('filename').uniq().forEach(function (siteName) {
  828. configsMap.push(configurationController.createSiteObj(siteName.replace(".xml", ""), tagName, serviceConfigs.filterProperty('filename', siteName)));
  829. });
  830. });
  831. if (!configsMap.length) return;
  832. var configData = configsMap.map(function (_serviceConfig) {
  833. return JSON.stringify({
  834. Clusters: {
  835. desired_config: {
  836. type: _serviceConfig.type,
  837. tag: _serviceConfig.tag,
  838. properties: _serviceConfig.properties
  839. }
  840. }
  841. });
  842. }, this).toString();
  843. this.addRequestToAjaxQueue({
  844. name: 'wizard.step8.apply_configuration_to_cluster',
  845. data: {
  846. data: '[' + configData + ']'
  847. }
  848. });
  849. },
  850. /**
  851. * Prepare <code>ajaxQueue</code> and start to execute it
  852. * @method submitProceed
  853. */
  854. submitProceed: function () {
  855. var self = this;
  856. this.set('isSubmitDisabled', true);
  857. this.set('isBackBtnDisabled', true);
  858. if (this.get('content.controllerName') == 'addHostController') {
  859. App.router.get('addHostController').setLowerStepsDisable(4);
  860. }
  861. // checkpoint the cluster status on the server so that the user can resume from where they left off
  862. switch (this.get('content.controllerName')) {
  863. case 'installerController':
  864. App.clusterStatus.setClusterStatus({
  865. clusterName: this.get('clusterName'),
  866. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  867. wizardControllerName: this.get('content.controllerName'),
  868. localdb: App.db.data
  869. });
  870. break;
  871. case 'addHostController':
  872. App.clusterStatus.setClusterStatus({
  873. clusterName: this.get('clusterName'),
  874. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  875. wizardControllerName: this.get('content.controllerName'),
  876. localdb: App.db.data
  877. });
  878. break;
  879. case 'addServiceController':
  880. App.clusterStatus.setClusterStatus({
  881. clusterName: this.get('clusterName'),
  882. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  883. wizardControllerName: this.get('content.controllerName'),
  884. localdb: App.db.data
  885. });
  886. break;
  887. default:
  888. break;
  889. }
  890. // delete any existing clusters to start from a clean slate
  891. // before creating a new cluster in install wizard
  892. // TODO: modify for multi-cluster support
  893. this.getExistingClusterNames().complete(function () {
  894. var clusterNames = self.get('clusterNames');
  895. if (self.get('content.controllerName') == 'installerController' && (!App.get('testMode')) && clusterNames.length) {
  896. self.deleteClusters(clusterNames);
  897. } else {
  898. self.deleteClustersCallback(null, null, {isLast: true});
  899. }
  900. });
  901. },
  902. /**
  903. * Get list of existing cluster names
  904. * @returns {object|null}
  905. * returns an array of existing cluster names.
  906. * returns an empty array if there are no existing clusters.
  907. * @method getExistingClusterNames
  908. */
  909. getExistingClusterNames: function () {
  910. return App.ajax.send({
  911. name: 'wizard.step8.existing_cluster_names',
  912. sender: this,
  913. success: 'getExistingClusterNamesSuccessCallBack',
  914. error: 'getExistingClusterNamesErrorCallback'
  915. });
  916. },
  917. /**
  918. * Save received list to <code>clusterNames</code>
  919. * @param {Object} data
  920. * @method getExistingClusterNamesSuccessCallBack
  921. */
  922. getExistingClusterNamesSuccessCallBack: function (data) {
  923. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  924. console.log("Got existing cluster names: " + clusterNames);
  925. this.set('clusterNames', clusterNames);
  926. },
  927. /**
  928. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  929. * @method getExistingClusterNamesErrorCallback
  930. */
  931. getExistingClusterNamesErrorCallback: function () {
  932. console.log("Failed to get existing cluster names");
  933. this.set('clusterNames', []);
  934. },
  935. /**
  936. * Delete cluster by name
  937. * One request for one cluster!
  938. * @param {string[]} clusterNames
  939. * @method deleteClusters
  940. */
  941. deleteClusters: function (clusterNames) {
  942. clusterNames.forEach(function (clusterName, index) {
  943. App.ajax.send({
  944. name: 'common.delete.cluster',
  945. sender: this,
  946. data: {
  947. name: clusterName,
  948. isLast: index == clusterNames.length - 1
  949. },
  950. success: 'deleteClustersCallback',
  951. error: 'deleteClustersCallback'
  952. });
  953. }, this);
  954. },
  955. deleteClustersCallback: function (response, request, data) {
  956. if (data.isLast) {
  957. this.setLocalRepositories();
  958. this.createCluster();
  959. this.createSelectedServices();
  960. if (this.get('content.controllerName') !== 'addHostController') {
  961. if (this.get('wizardController').getDBProperty('configsToUpdate') && this.get('wizardController').getDBProperty('configsToUpdate').length) {
  962. this.updateConfigurations(this.get('wizardController').getDBProperty('configsToUpdate'));
  963. }
  964. this.createConfigurations();
  965. this.applyConfigurationsToCluster();
  966. }
  967. this.createComponents();
  968. this.registerHostsToCluster();
  969. if (App.get('supports.hostOverridesInstaller')) {
  970. this.createConfigurationGroups();
  971. }
  972. this.createMasterHostComponents();
  973. this.createSlaveAndClientsHostComponents();
  974. this.createAdditionalHostComponents();
  975. this.set('ajaxQueueLength', this.get('ajaxRequestsQueue.queue.length'));
  976. this.get('ajaxRequestsQueue').start();
  977. }
  978. },
  979. /**
  980. * Updates local repositories for the Ambari server.
  981. * @method setLocalRepositories
  982. * @return {bool} true - requests are sent, false - requests not sent
  983. */
  984. setLocalRepositories: function () {
  985. if (this.get('content.controllerName') !== 'installerController' || !App.get('supports.localRepositories')) return false;
  986. var self = this,
  987. stack = this.get('content.stacks').findProperty('isSelected', true);
  988. stack.operatingSystems.forEach(function (os) {
  989. if (os.baseUrl !== os.originalBaseUrl) {
  990. console.log("Updating local repository URL from " + os.originalBaseUrl + " -> " + os.baseUrl + ". ", os);
  991. self.addRequestToAjaxQueue({
  992. name: 'wizard.step8.set_local_repos',
  993. data: {
  994. osType: os.osType,
  995. repoId: os.repoId,
  996. stackVersionURL: App.get('stackVersionURL'),
  997. data: JSON.stringify({
  998. "Repositories": {
  999. "base_url": os.baseUrl,
  1000. "verify_base_url": false
  1001. }
  1002. })
  1003. }
  1004. });
  1005. }
  1006. });
  1007. return true;
  1008. },
  1009. /**
  1010. * *******************************************************************
  1011. * The following create* functions are called upon submitting Step 8.
  1012. * *******************************************************************
  1013. */
  1014. /**
  1015. * Create cluster using selected stack version
  1016. * Queued request
  1017. * @method createCluster
  1018. */
  1019. createCluster: function () {
  1020. if (this.get('content.controllerName') !== 'installerController') return;
  1021. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  1022. this.addRequestToAjaxQueue({
  1023. name: 'wizard.step8.create_cluster',
  1024. data: {
  1025. data: JSON.stringify({ "Clusters": {"version": stackVersion }})
  1026. },
  1027. success: 'createClusterSuccess'
  1028. });
  1029. },
  1030. createClusterSuccess: function(data, xhr, params) {
  1031. App.set('clusterName', params.cluster)
  1032. },
  1033. /**
  1034. * Create selected to install services
  1035. * Queued request
  1036. * Skipped if no services where selected!
  1037. * @method createSelectedServices
  1038. */
  1039. createSelectedServices: function () {
  1040. var data = this.createSelectedServicesData();
  1041. if (!data.length) return;
  1042. this.addRequestToAjaxQueue({
  1043. name: 'wizard.step8.create_selected_services',
  1044. data: {
  1045. data: JSON.stringify(data)
  1046. }
  1047. });
  1048. },
  1049. /**
  1050. * Format data for <code>createSelectedServices</code> request
  1051. * @returns {Object[]}
  1052. * @method createSelectedServicesData
  1053. */
  1054. createSelectedServicesData: function () {
  1055. return this.get('selectedServices').map(function (_service) {
  1056. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  1057. });
  1058. },
  1059. /**
  1060. * Create components for selected services
  1061. * Queued requests
  1062. * One request for each service!
  1063. * @method createComponents
  1064. */
  1065. createComponents: function () {
  1066. var serviceComponents = App.StackServiceComponent.find();
  1067. this.get('selectedServices').forEach(function (_service) {
  1068. var serviceName = _service.get('serviceName');
  1069. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  1070. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  1071. });
  1072. // Service must be specified in terms of a query for creating multiple components at the same time.
  1073. // See AMBARI-1018.
  1074. this.addRequestToAjaxQueue({
  1075. name: 'wizard.step8.create_components',
  1076. data: {
  1077. data: JSON.stringify({"components": componentsData}),
  1078. serviceName: serviceName
  1079. }
  1080. });
  1081. }, this);
  1082. },
  1083. /**
  1084. * Error callback for new service component request
  1085. * So, if component doesn't exist we should create it
  1086. * @param {object} request
  1087. * @param {object} ajaxOptions
  1088. * @param {string} error
  1089. * @param {object} opt
  1090. * @param {object} params
  1091. * @method newServiceComponentErrorCallback
  1092. */
  1093. newServiceComponentErrorCallback: function (request, ajaxOptions, error, opt, params) {
  1094. this.addRequestToAjaxQueue({
  1095. name: 'wizard.step8.create_components',
  1096. data: {
  1097. serviceName: params.serviceName,
  1098. data: JSON.stringify({
  1099. "components": [
  1100. {
  1101. "ServiceComponentInfo": {
  1102. "component_name": params.componentName
  1103. }
  1104. }
  1105. ]
  1106. })
  1107. }
  1108. });
  1109. },
  1110. /**
  1111. * Register hosts
  1112. * Queued request
  1113. * @method registerHostsToCluster
  1114. */
  1115. registerHostsToCluster: function () {
  1116. var data = this.createRegisterHostData();
  1117. if (!data.length) return;
  1118. this.addRequestToAjaxQueue({
  1119. name: 'wizard.step8.register_host_to_cluster',
  1120. data: {
  1121. data: JSON.stringify(data)
  1122. }
  1123. });
  1124. },
  1125. /**
  1126. * Format request-data for <code>registerHostsToCluster</code>
  1127. * @returns {Object}
  1128. * @method createRegisterHostData
  1129. */
  1130. createRegisterHostData: function () {
  1131. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  1132. return {"Hosts": { "host_name": host.hostName}};
  1133. });
  1134. },
  1135. /**
  1136. * Register new master components
  1137. * @uses registerHostsToComponent
  1138. * @method createMasterHostComponents
  1139. */
  1140. createMasterHostComponents: function () {
  1141. // create master components for only selected services.
  1142. var selectedMasterComponents = this.get('content.masterComponentHosts').filter(function (_component) {
  1143. return this.get('selectedServices').mapProperty('serviceName').contains(_component.serviceId)
  1144. }, this);
  1145. selectedMasterComponents.mapProperty('component').uniq().forEach(function (component) {
  1146. var hostNames = selectedMasterComponents.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1147. this.registerHostsToComponent(hostNames, component);
  1148. }, this);
  1149. },
  1150. getClientsToMasterMap: function () {
  1151. var clientNames = App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName'),
  1152. clientsMap = {},
  1153. dependedComponents = App.StackServiceComponent.find().filterProperty('isMaster');
  1154. clientNames.forEach(function(clientName) {
  1155. clientsMap[clientName] = Em.A([]);
  1156. dependedComponents.forEach(function(component) {
  1157. if (component.get('dependencies').contains(clientName)) clientsMap[clientName].push(component.get('componentName'));
  1158. });
  1159. if (!clientsMap[clientName].length) delete clientsMap[clientName];
  1160. });
  1161. return clientsMap;
  1162. },
  1163. /**
  1164. * Register slave components and clients
  1165. * @uses registerHostsToComponent
  1166. * @method createSlaveAndClientsHostComponents
  1167. */
  1168. createSlaveAndClientsHostComponents: function () {
  1169. var masterHosts = this.get('content.masterComponentHosts'),
  1170. slaveHosts = this.get('content.slaveComponentHosts'),
  1171. clients = this.get('content.clients');
  1172. /**
  1173. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  1174. * @type {Object}
  1175. * Format:
  1176. * <code>
  1177. * {
  1178. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  1179. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  1180. * ...
  1181. * }
  1182. * </code>
  1183. */
  1184. var clientsToMasterMap = this.getClientsToMasterMap();
  1185. slaveHosts.forEach(function (_slave) {
  1186. if (_slave.componentName !== 'CLIENT') {
  1187. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1188. this.registerHostsToComponent(hostNames, _slave.componentName);
  1189. }
  1190. else {
  1191. clients.forEach(function (_client) {
  1192. var hostNames = _slave.hosts.mapProperty('hostName');
  1193. if (clientsToMasterMap[_client.component_name]) {
  1194. clientsToMasterMap[_client.component_name].forEach(function (componentName) {
  1195. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1196. hostNames.pushObject(_masterHost.hostName);
  1197. });
  1198. });
  1199. }
  1200. hostNames = hostNames.uniq();
  1201. if (_client.isInstalled) {
  1202. /**
  1203. * check whether clients are already installed on selected master hosts!!!
  1204. */
  1205. var clientHosts = [];
  1206. var installedHosts = this.get('content.hosts');
  1207. for (var hostName in installedHosts) {
  1208. if (installedHosts[hostName].isInstalled &&
  1209. installedHosts[hostName].hostComponents.filterProperty('HostRoles.state', 'INSTALLED').mapProperty('HostRoles.component_name').contains(_client.component_name)) {
  1210. clientHosts.push(hostName);
  1211. }
  1212. }
  1213. if (clientHosts.length > 0) {
  1214. clientHosts.forEach(function (hostName) {
  1215. if (hostNames.contains(hostName)) {
  1216. hostNames.splice(hostNames.indexOf(hostName), 1);
  1217. }
  1218. }, this);
  1219. }
  1220. /**
  1221. * For Add Service Only
  1222. * if client is not added to host or is not installed add Object
  1223. * {
  1224. * componentName: {String},
  1225. * hostName: {String}
  1226. * }
  1227. * to content.additionalClients
  1228. * later it will be used to install client on host before installing new services
  1229. */
  1230. if (this.get('content.controllerName') === 'addServiceController' && hostNames.length > 0) {
  1231. hostNames.forEach(function (hostName) {
  1232. this.get('content.additionalClients').push(Em.Object.create({
  1233. componentName: _client.component_name, hostName: hostName
  1234. }))
  1235. }, this)
  1236. }
  1237. }
  1238. this.registerHostsToComponent(hostNames, _client.component_name);
  1239. }, this);
  1240. }
  1241. }, this);
  1242. },
  1243. /**
  1244. * Register additional components
  1245. * Based on availability of some services
  1246. * @uses registerHostsToComponent
  1247. * @method createAdditionalHostComponents
  1248. */
  1249. createAdditionalHostComponents: function () {
  1250. var masterHosts = this.get('content.masterComponentHosts');
  1251. // add MySQL Server if Hive is selected
  1252. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  1253. var gangliaService = this.get('content.services').filterProperty('isSelected').findProperty('serviceName', 'GANGLIA');
  1254. if (gangliaService) {
  1255. var hosts = this.getRegisteredHosts();
  1256. if (gangliaService.get('isInstalled')) {
  1257. hosts = hosts.filterProperty('isInstalled', false);
  1258. }
  1259. if (hosts.length) {
  1260. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  1261. }
  1262. }
  1263. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1264. if (hiveService) {
  1265. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1266. if (hiveDb.value == "New MySQL Database") {
  1267. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1268. }
  1269. }
  1270. },
  1271. /**
  1272. * Register component to hosts
  1273. * Queued request
  1274. * @param {String[]} hostNames
  1275. * @param {String} componentName
  1276. * @method registerHostsToComponent
  1277. */
  1278. registerHostsToComponent: function (hostNames, componentName) {
  1279. if (!hostNames.length) return;
  1280. var queryStr = '';
  1281. hostNames.forEach(function (hostName) {
  1282. queryStr += 'Hosts/host_name=' + hostName + '|';
  1283. });
  1284. //slice off last symbol '|'
  1285. queryStr = queryStr.slice(0, -1);
  1286. var data = {
  1287. "RequestInfo": {
  1288. "query": queryStr
  1289. },
  1290. "Body": {
  1291. "host_components": [
  1292. {
  1293. "HostRoles": {
  1294. "component_name": componentName
  1295. }
  1296. }
  1297. ]
  1298. }
  1299. };
  1300. this.addRequestToAjaxQueue({
  1301. name: 'wizard.step8.register_host_to_component',
  1302. data: {
  1303. data: JSON.stringify(data)
  1304. }
  1305. });
  1306. },
  1307. /**
  1308. * Create config objects for cluster and services
  1309. * @method createConfigurations
  1310. */
  1311. createConfigurations: function () {
  1312. var self = this;
  1313. var selectedServices = this.get('selectedServices');
  1314. var coreSiteObject = this.createCoreSiteObj();
  1315. var tag = 'version1';
  1316. if (this.get('content.controllerName') == 'installerController') {
  1317. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1318. this.get('serviceConfigTags').pushObject(this.createSiteObj('hdfs-site', false, tag));
  1319. this.get('serviceConfigTags').pushObject(this.createLog4jObj('hdfs', tag));
  1320. }
  1321. var globalSiteObj = this.createGlobalSiteObj(tag);
  1322. if (this.get('content.controllerName') == 'addServiceController') {
  1323. tag = 'version' + (new Date).getTime();
  1324. globalSiteObj.tag = tag;
  1325. coreSiteObject.tag = tag;
  1326. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1327. }
  1328. this.get('serviceConfigTags').pushObject(globalSiteObj);
  1329. var objMap = {
  1330. MAPREDUCE: {site: [
  1331. {filename: 'mapred-site', isXmlFile: true}
  1332. ], log4j: ['mapreduce']},
  1333. MAPREDUCE2: {site: [
  1334. {filename: 'mapred-site', isXmlFile: true}
  1335. ], log4j: ['mapreduce2']},
  1336. YARN: {site: [
  1337. {filename: 'yarn-site', isXmlFile: true},
  1338. {filename: 'capacity-scheduler', isXmlFile: true}
  1339. ], log4j: ['yarn']},
  1340. HBASE: {site: [
  1341. {filename: 'hbase-site', isXmlFile: true}
  1342. ], log4j: ['hbase']},
  1343. OOZIE: {site: [
  1344. {filename: 'oozie-site', isXmlFile: true}
  1345. ], log4j: ['oozie']},
  1346. HIVE: {site: [
  1347. {filename: 'hive-site', isXmlFile: true}
  1348. ], log4j: ['hive', 'hive-exec']},
  1349. WEBHCAT: {site: [
  1350. {filename: 'webhcat-site', isXmlFile: true}
  1351. ], log4j: []},
  1352. HUE: {site: [
  1353. {filename: 'hue-site', isXmlFile: true}
  1354. ], log4j: []},
  1355. PIG: {site: [
  1356. {filename: 'pig-properties', isXmlFile: false}
  1357. ], log4j: ['pig']},
  1358. FALCON: {site: [
  1359. {filename: 'falcon-startup.properties', isXmlFile: false},
  1360. {filename: 'falcon-runtime.properties', isXmlFile: false}
  1361. ], log4j: []},
  1362. TEZ: {site: [
  1363. {filename: 'tez-site', isXmlFile: true}
  1364. ], log4j: []},
  1365. ZOOKEEPER: {site: [], log4j: ['zookeeper']},
  1366. FLUME: {site: [
  1367. {filename: 'flume-conf', isXmlFile: false}
  1368. ], log4j: []}
  1369. };
  1370. if (App.supports.capacitySchedulerUi) {
  1371. objMap['MAPREDUCE'].site.pushObjects([
  1372. {filename: 'capacity-scheduler', isXmlFile: true},
  1373. {filename: 'mapred-queue-acls', isXmlFile: true}
  1374. ]);
  1375. }
  1376. for (var serviceName in objMap) {
  1377. if (objMap.hasOwnProperty(serviceName)) {
  1378. if (selectedServices.someProperty('serviceName', serviceName)) {
  1379. objMap[serviceName].site.forEach(function (site) {
  1380. self.get('serviceConfigTags').pushObject(self.createSiteObj(site.filename, !site.isXmlFile, tag));
  1381. });
  1382. objMap[serviceName].log4j.forEach(function (log4j) {
  1383. self.get('serviceConfigTags').pushObject(self.createLog4jObj(log4j, tag));
  1384. });
  1385. }
  1386. }
  1387. }
  1388. if (selectedServices.someProperty('serviceName', 'STORM')) {
  1389. this.get('serviceConfigTags').pushObject(this.createStormSiteObj(tag));
  1390. }
  1391. if (selectedServices.someProperty('serviceName', 'ZOOKEEPER')) {
  1392. this.get('serviceConfigTags').pushObject(this.createZooCfgObj(tag));
  1393. }
  1394. },
  1395. /**
  1396. * Send <code>serviceConfigTags</code> to server
  1397. * Queued request
  1398. * One request for each service config tag
  1399. * @method applyConfigurationsToCluster
  1400. */
  1401. applyConfigurationsToCluster: function () {
  1402. var configData = this.get('serviceConfigTags').map(function (_serviceConfig) {
  1403. return JSON.stringify({
  1404. Clusters: {
  1405. desired_config: {
  1406. type: _serviceConfig.type,
  1407. tag: _serviceConfig.tag,
  1408. properties: _serviceConfig.properties
  1409. }
  1410. }
  1411. });
  1412. }, this).toString();
  1413. this.addRequestToAjaxQueue({
  1414. name: 'wizard.step8.apply_configuration_to_cluster',
  1415. data: {
  1416. data: '[' + configData + ']'
  1417. }
  1418. });
  1419. },
  1420. /**
  1421. * Create and update config groups
  1422. * @method createConfigurationGroups
  1423. */
  1424. createConfigurationGroups: function () {
  1425. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1426. var clusterName = this.get('clusterName');
  1427. var sendData = [];
  1428. var updateData = [];
  1429. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1430. var timeTag = (new Date).getTime();
  1431. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1432. if (groupsToDelete && groupsToDelete.length > 0) {
  1433. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1434. }
  1435. configGroups.forEach(function (configGroup) {
  1436. var groupConfigs = [];
  1437. var groupData = {
  1438. "cluster_name": clusterName,
  1439. "group_name": configGroup.name,
  1440. "tag": configGroup.service.id,
  1441. "description": configGroup.description,
  1442. "hosts": [],
  1443. "desired_configs": []
  1444. };
  1445. configGroup.hosts.forEach(function (hostName) {
  1446. groupData.hosts.push({"host_name": hostName});
  1447. });
  1448. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1449. configGroup.properties.forEach(function (property) {
  1450. groupConfigs.push(Em.Object.create(property));
  1451. });
  1452. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1453. // check for group from installed service
  1454. if (configGroup.isForUpdate === true) {
  1455. // if group is a new one, create it
  1456. if (!configGroup.id) {
  1457. sendData.push({"ConfigGroup": groupData});
  1458. } else {
  1459. // update an existing group
  1460. groupData.id = configGroup.id;
  1461. updateData.push({"ConfigGroup": groupData});
  1462. }
  1463. } else {
  1464. sendData.push({"ConfigGroup": groupData});
  1465. }
  1466. //each group should have unique tag to prevent overriding configs from common sites
  1467. timeTag++;
  1468. }, this);
  1469. if (sendData.length > 0) {
  1470. this.applyConfigurationGroups(sendData);
  1471. }
  1472. if (updateData.length > 0) {
  1473. this.applyInstalledServicesConfigurationGroup(updateData);
  1474. }
  1475. },
  1476. /**
  1477. * Create new config groups request
  1478. * Queued request
  1479. * @param {Object[]} sendData
  1480. * @method applyConfigurationGroups
  1481. */
  1482. applyConfigurationGroups: function (sendData) {
  1483. this.addRequestToAjaxQueue({
  1484. name: 'wizard.step8.apply_configuration_groups',
  1485. data: {
  1486. data: JSON.stringify(sendData)
  1487. }
  1488. });
  1489. },
  1490. /**
  1491. * Update existed config groups
  1492. * Separated request for each group
  1493. * @param {Object[]} updateData
  1494. * @method applyInstalledServicesConfigurationGroup
  1495. */
  1496. applyInstalledServicesConfigurationGroup: function (updateData) {
  1497. updateData.forEach(function (item) {
  1498. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1499. });
  1500. },
  1501. /**
  1502. * Delete selected config groups
  1503. * @param {Object[]} groupsToDelete
  1504. * @method removeInstalledServicesConfigurationGroups
  1505. */
  1506. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1507. groupsToDelete.forEach(function (item) {
  1508. App.config.deleteConfigGroup(Em.Object.create(item));
  1509. });
  1510. },
  1511. /**
  1512. * Create Global Site object
  1513. * @returns {{type: string, tag: string, properties: {}}}
  1514. * @method createGlobalSiteObj
  1515. */
  1516. createGlobalSiteObj: function (tag) {
  1517. var globalSiteProperties = {};
  1518. var globalSiteObj = this.get('globals');
  1519. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1520. // screen out the GLUSTERFS-specific global config entries when they are not required
  1521. if (!isGLUSTERFSSelected) {
  1522. globalSiteObj = globalSiteObj.filter(function (_config) {
  1523. return !_config.name.contains("fs_glusterfs");
  1524. });
  1525. }
  1526. globalSiteObj.forEach(function (globalConfig) {
  1527. var heapsizeExceptions = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize', 'jobhistory_heapsize'];
  1528. // do not pass any globals whose name ends with _host or _hosts
  1529. if (globalConfig.isRequiredByAgent !== false) {
  1530. // append "m" to JVM memory options except for heapsizeExtensions
  1531. if (/_heapsize|_newsize|_maxnewsize$/.test(globalConfig.name) && !heapsizeExceptions.contains(globalConfig.name)) {
  1532. globalSiteProperties[globalConfig.name] = globalConfig.value + "m";
  1533. } else {
  1534. globalSiteProperties[globalConfig.name] = App.config.escapeXMLCharacters(globalConfig.value);
  1535. }
  1536. }
  1537. }, this);
  1538. // we don't expose gmond_user to the user; it needs to be the same as gmetad_user
  1539. globalSiteProperties['gmond_user'] = globalSiteProperties['gmetad_user'];
  1540. return {"type": "global", "tag": tag, "properties": globalSiteProperties};
  1541. },
  1542. /**
  1543. * Create Core Site object
  1544. * @returns {{type: string, tag: string, properties: {}}}
  1545. * @method createCoreSiteObj
  1546. */
  1547. createCoreSiteObj: function () {
  1548. var installedAndSelectedServices = Em.A([]);
  1549. installedAndSelectedServices.pushObjects(this.get('installedServices'));
  1550. installedAndSelectedServices.pushObjects(this.get('selectedServices'));
  1551. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml'),
  1552. coreSiteProperties = {},
  1553. // some configs needs to be skipped if services are not selected
  1554. isOozieSelected = installedAndSelectedServices.someProperty('serviceName', 'OOZIE'),
  1555. oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null,
  1556. isHiveSelected = installedAndSelectedServices.someProperty('serviceName', 'HIVE'),
  1557. hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null,
  1558. isHcatSelected = installedAndSelectedServices.someProperty('serviceName', 'WEBHCAT'),
  1559. hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null,
  1560. isGLUSTERFSSelected = installedAndSelectedServices.someProperty('serviceName', 'GLUSTERFS');
  1561. // screen out the GLUSTERFS-specific core-site.xml entries when they are not needed
  1562. if (!isGLUSTERFSSelected) {
  1563. coreSiteObj = coreSiteObj.filter(function (_config) {
  1564. return !_config.name.contains("fs.glusterfs");
  1565. });
  1566. }
  1567. coreSiteObj.forEach(function (_coreSiteObj) {
  1568. // exclude some configs if service wasn't selected
  1569. if (
  1570. (isOozieSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + oozieUser + '.groups')) &&
  1571. (isHiveSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hiveUser + '.groups')) &&
  1572. (isHcatSelected || (_coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.hosts' && _coreSiteObj.name != 'hadoop.proxyuser.' + hcatUser + '.groups'))) {
  1573. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1574. }
  1575. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1576. coreSiteProperties[_coreSiteObj.name] =
  1577. this.get('globals').someProperty('name', 'fs_glusterfs_default_name') ?
  1578. App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'fs_glusterfs_default_name').value) : null;
  1579. }
  1580. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1581. coreSiteProperties[_coreSiteObj.name] =
  1582. this.get('globals').someProperty('name', 'glusterfs_defaultFS_name') ?
  1583. App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'glusterfs_defaultFS_name').value) : null;
  1584. }
  1585. }, this);
  1586. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1587. },
  1588. /**
  1589. * Create siteObj for custom service with it own configs
  1590. * @param {string} site
  1591. * @param {bool} isNonXmlFile
  1592. * @param tag
  1593. * @returns {{type: string, tag: string, properties: {}}}
  1594. * @method createSiteObj
  1595. */
  1596. createSiteObj: function (site, isNonXmlFile, tag) {
  1597. var properties = {};
  1598. if (!!isNonXmlFile) {
  1599. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1600. properties[_configProperty.name] = _configProperty.value;
  1601. }, this);
  1602. } else {
  1603. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1604. properties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1605. }, this);
  1606. }
  1607. return {"type": site, "tag": tag, "properties": properties };
  1608. },
  1609. /**
  1610. * Create log4j object for custom service with it own configs
  1611. * @param {string} site
  1612. * @param {string} tag
  1613. * @returns {{type: string, tag: string, properties: {}}}
  1614. * @method createLog4jObj
  1615. */
  1616. createLog4jObj: function (site, tag) {
  1617. return this.createSiteObj(site + '-log4j', true, tag);
  1618. },
  1619. /**
  1620. * Create ZooKeeper Cfg Object
  1621. * @param tag
  1622. * @returns {{type: string, tag: string, properties: {}}}
  1623. * @method createZooCfgObj
  1624. */
  1625. createZooCfgObj: function (tag) {
  1626. var configs = this.get('configs').filterProperty('filename', 'zoo.cfg');
  1627. var csProperties = {};
  1628. configs.forEach(function (_configProperty) {
  1629. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1630. }, this);
  1631. return {type: 'zoo.cfg', tag: tag, properties: csProperties};
  1632. },
  1633. /**
  1634. * Create site obj for Storm
  1635. * Some config-properties should be modified in custom way
  1636. * @param tag
  1637. * @returns {{type: string, tag: string, properties: {}}}
  1638. * @method createStormSiteObj
  1639. */
  1640. createStormSiteObj: function (tag) {
  1641. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1642. var stormProperties = {};
  1643. var specialProperties = ["storm.zookeeper.servers", "nimbus.childopts", "supervisor.childopts", "worker.childopts"];
  1644. configs.forEach(function (_configProperty) {
  1645. if (specialProperties.contains(_configProperty.name)) {
  1646. if (_configProperty.name == "storm.zookeeper.servers") {
  1647. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1648. } else {
  1649. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "");
  1650. }
  1651. } else {
  1652. stormProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1653. }
  1654. }, this);
  1655. return {type: 'storm-site', tag: tag, properties: stormProperties};
  1656. },
  1657. /**
  1658. * Navigate to next step after all requests are sent
  1659. * @method ajaxQueueFinished
  1660. */
  1661. ajaxQueueFinished: function () {
  1662. console.log('everything is loaded');
  1663. App.router.send('next');
  1664. },
  1665. /**
  1666. * We need to do a lot of ajax calls async in special order. To do this,
  1667. * generate array of ajax objects and then send requests step by step. All
  1668. * ajax objects are stored in <code>ajaxRequestsQueue</code>
  1669. *
  1670. * @param {Object} params object with ajax-request parameters like url, type, data etc
  1671. * @method addRequestToAjaxQueue
  1672. */
  1673. addRequestToAjaxQueue: function (params) {
  1674. if (App.get('testMode')) return;
  1675. params = jQuery.extend({
  1676. sender: this,
  1677. error: 'ajaxQueueRequestErrorCallback'
  1678. }, params);
  1679. params.data['cluster'] = this.get('clusterName');
  1680. this.get('ajaxRequestsQueue').addRequest(params);
  1681. },
  1682. /**
  1683. * Error callback for each queued ajax-request
  1684. * @param {object} xhr
  1685. * @param {string} status
  1686. * @param {string} error
  1687. * @method ajaxQueueRequestErrorCallback
  1688. */
  1689. ajaxQueueRequestErrorCallback: function (xhr, status, error) {
  1690. var responseText = JSON.parse(xhr.responseText);
  1691. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1692. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1693. this.set('hasErrorOccurred', true);
  1694. // an error will break the ajax call chain and allow submission again
  1695. this.set('isSubmitDisabled', false);
  1696. this.set('isBackBtnDisabled', false);
  1697. App.router.get(this.get('content.controllerName')).setStepsEnable();
  1698. }
  1699. });