step8_controller.js 61 KB

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