step8_controller.js 63 KB

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