step8_controller.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  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_hos', '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 === 'Existing Postgresql Database') {
  242. globals.findProperty('name', 'hive_hostname').value = globals.findProperty('name', 'hive_existing_postgresql_host').value;
  243. hiveDbType.value = 'postgresql';
  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 === 'Existing Postgresql Database') {
  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(Ember.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. * @method loadRepoInfo
  539. */
  540. loadRepoInfo: function () {
  541. var nameVersionCombo = App.get('currentStackVersion');
  542. var stackName = nameVersionCombo.split('-')[0];
  543. var stackVersion = nameVersionCombo.split('-')[1];
  544. App.ajax.send({
  545. name: 'cluster.load_repositories',
  546. sender: this,
  547. data: {
  548. stackName: stackName,
  549. stackVersion: stackVersion
  550. },
  551. success: 'loadRepoInfoSuccessCallback',
  552. error: 'loadRepoInfoErrorCallback'
  553. });
  554. },
  555. /**
  556. *
  557. * @param {object} data
  558. * @method loadRepoInfoSuccessCallback
  559. */
  560. loadRepoInfoSuccessCallback: function (data) {
  561. var allRepos = [];
  562. var supportedOs = ['redhat5', 'redhat6', 'sles11'];
  563. data.items.forEach(function (item) {
  564. var os = item.repositories[0].Repositories;
  565. if (supportedOs.contains(os.os_type)) {
  566. allRepos.push(Em.Object.create({
  567. base_url: os.base_url,
  568. os_type: Em.I18n.t("installer.step8.repoInfo.osType." + os.os_type)
  569. }));
  570. }
  571. }, this);
  572. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  573. this.get('clusterInfo').set('repoInfo', allRepos);
  574. },
  575. /**
  576. *
  577. * @param {object} request
  578. * @method loadRepoInfoErrorCallback
  579. */
  580. loadRepoInfoErrorCallback: function (request) {
  581. console.log('Error message is: ' + request.responseText);
  582. var allRepos = [];
  583. allRepos.set('display_name', Em.I18n.t("installer.step8.repoInfo.displayName"));
  584. this.get('clusterInfo').set('repoInfo', allRepos);
  585. },
  586. /**
  587. * Load all info about services to <code>services</code> variable
  588. * @method loadServices
  589. */
  590. loadServices: function () {
  591. var reviewService = this.rawContent.findProperty('config_name', 'services');
  592. this.get('selectedServices').forEach(function (_service) {
  593. console.log('INFO: step8: Name of the service from getService function: ' + _service.serviceName);
  594. var serviceObj = reviewService.config_value.findProperty('service_name', _service.serviceName);
  595. if (serviceObj) {
  596. serviceObj.get('service_components').forEach(function (_component) {
  597. this.assignComponentHosts(_component);
  598. }, this);
  599. this.get('services').pushObject(serviceObj);
  600. }
  601. }, this);
  602. },
  603. /**
  604. *
  605. * @param {Em.Object} component
  606. * @method assignComponentHosts
  607. */
  608. assignComponentHosts: function (component) {
  609. var componentValue;
  610. if (component.get('customHandler')) {
  611. this[component.get('customHandler')].call(this, component);
  612. } else {
  613. if (component.get('isMaster')) {
  614. componentValue = this.get('content.masterComponentHosts')
  615. .findProperty('component', component.component_name).hostName;
  616. } else {
  617. var hostsLength = this.get('content.slaveComponentHosts')
  618. .findProperty('componentName', component.component_name)
  619. .hosts.length;
  620. componentValue = hostsLength + Em.I18n.t('installer.step8.host' + ((hostsLength > 1) ? 's' : ''));
  621. }
  622. component.set('component_value', componentValue);
  623. }
  624. },
  625. /**
  626. * Set dispalyed Hive DB value based on DB type
  627. * @param {Ember.Object} dbComponent
  628. * @method loadHiveDbValue
  629. */
  630. loadHiveDbValue: function (dbComponent) {
  631. var db, hiveDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_database');
  632. if (hiveDb.value === 'New MySQL Database') {
  633. dbComponent.set('component_value', 'MySQL (New Database)');
  634. }
  635. else {
  636. if (hiveDb.value === 'Existing MySQL Database') {
  637. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_existing_mysql_database');
  638. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  639. }
  640. else {
  641. if (hiveDb.value === 'Existing Postgresql Database') {
  642. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_existing_postgresql_database');
  643. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  644. }
  645. else { // existing oracle database
  646. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'hive_existing_oracle_database');
  647. dbComponent.set('component_value', db.value + ' (' + hiveDb.value + ')');
  648. }
  649. }
  650. }
  651. },
  652. /**
  653. * Set displayed HBase master value
  654. * @param {Object} hbaseMaster
  655. * @method loadHbaseMasterValue
  656. */
  657. loadHbaseMasterValue: function (hbaseMaster) {
  658. var hbaseHostName = this.get('content.masterComponentHosts').filterProperty('component', hbaseMaster.component_name);
  659. if (hbaseHostName.length == 1) {
  660. hbaseMaster.set('component_value', hbaseHostName[0].hostName);
  661. } else {
  662. hbaseMaster.set('component_value', hbaseHostName[0].hostName + Em.I18n.t('installer.step8.other').format(hbaseHostName.length - 1));
  663. }
  664. },
  665. /**
  666. * Set displayed ZooKeeper Server value
  667. * @param {Object} serverComponent
  668. * @method loadZkServerValue
  669. */
  670. loadZkServerValue: function (serverComponent) {
  671. var zkHostNames = this.get('content.masterComponentHosts').filterProperty('component', serverComponent.component_name).length;
  672. var hostSuffix;
  673. if (zkHostNames === 1) {
  674. hostSuffix = Em.I18n.t('installer.step8.host');
  675. } else {
  676. hostSuffix = Em.I18n.t('installer.step8.hosts');
  677. }
  678. serverComponent.set('component_value', zkHostNames + ' ' + hostSuffix);
  679. },
  680. /**
  681. * Set displayed Oozie DB value based on DB type
  682. * @param {Object} dbComponent
  683. * @method loadOozieDbValue
  684. */
  685. loadOozieDbValue: function (dbComponent) {
  686. var db, oozieDb = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_database');
  687. if (oozieDb.value === 'New Derby Database') {
  688. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_derby_database');
  689. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  690. }
  691. else {
  692. if (oozieDb.value === 'Existing MySQL Database') {
  693. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_mysql_database');
  694. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  695. }
  696. else {
  697. if (oozieDb.value === 'Existing Postgresql Database') {
  698. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_postgresql_database');
  699. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  700. }
  701. else { // existing oracle database
  702. db = this.get('wizardController').getDBProperty('serviceConfigProperties').findProperty('name', 'oozie_existing_oracle_database');
  703. dbComponent.set('component_value', db.value + ' (' + oozieDb.value + ')');
  704. }
  705. }
  706. }
  707. },
  708. /**
  709. * Set displayed Nagion Admin value
  710. * @param {Object} nagiosAdmin
  711. * @method loadNagiosAdminValue
  712. */
  713. loadNagiosAdminValue: function (nagiosAdmin) {
  714. var config = this.get('content.serviceConfigProperties');
  715. var adminLoginName = config.findProperty('name', 'nagios_web_login');
  716. var adminEmail = config.findProperty('name', 'nagios_contact');
  717. nagiosAdmin.set('component_value', adminLoginName.value + ' / (' + adminEmail.value + ')');
  718. },
  719. /**
  720. * Onclick handler for <code>next</code> button
  721. * @method submit
  722. */
  723. submit: function () {
  724. if (this.get('isSubmitDisabled')) return;
  725. if ((this.get('content.controllerName') == 'addHostController') && this.get('securityEnabled')) {
  726. var self = this;
  727. App.showConfirmationPopup(function () {
  728. self.submitProceed();
  729. }, Em.I18n.t('installer.step8.securityConfirmationPopupBody'));
  730. }
  731. else {
  732. this.submitProceed();
  733. }
  734. },
  735. /**
  736. * Update configurations for installed services.
  737. *
  738. * @param {Array} configsToUpdate - configs need to update
  739. * @method updateConfigurations
  740. */
  741. updateConfigurations: function (configsToUpdate) {
  742. var configurationController = App.router.get('mainServiceInfoConfigsController');
  743. var serviceNames = configsToUpdate.mapProperty('serviceName').uniq();
  744. serviceNames.forEach(function (serviceName) {
  745. var configs = configsToUpdate.filterProperty('serviceName', serviceName);
  746. configurationController.setNewTagNames(configs);
  747. var tagName = configs.objectAt(0).newTagName;
  748. var siteConfigs = configs.filterProperty('id', 'site property');
  749. siteConfigs.mapProperty('filename').uniq().forEach(function (siteName) {
  750. var formattedConfigs = configurationController.createSiteObj(siteName.replace(".xml", ""), tagName, configs.filterProperty('filename', siteName));
  751. configurationController.doPUTClusterConfigurationSite(formattedConfigs);
  752. });
  753. });
  754. },
  755. /**
  756. * Prepare <code>ajaxQueue</code> and start to execute it
  757. * @method submitProceed
  758. */
  759. submitProceed: function () {
  760. this.set('isSubmitDisabled', true);
  761. this.set('isBackBtnDisabled', true);
  762. if (this.get('content.controllerName') == 'addHostController') {
  763. App.router.get('addHostController').setLowerStepsDisable(4);
  764. }
  765. // checkpoint the cluster status on the server so that the user can resume from where they left off
  766. switch (this.get('content.controllerName')) {
  767. case 'installerController':
  768. App.clusterStatus.setClusterStatus({
  769. clusterName: this.get('clusterName'),
  770. clusterState: 'CLUSTER_DEPLOY_PREP_2',
  771. wizardControllerName: this.get('content.controllerName'),
  772. localdb: App.db.data
  773. });
  774. break;
  775. case 'addHostController':
  776. App.clusterStatus.setClusterStatus({
  777. clusterName: this.get('clusterName'),
  778. clusterState: 'ADD_HOSTS_DEPLOY_PREP_2',
  779. wizardControllerName: this.get('content.controllerName'),
  780. localdb: App.db.data
  781. });
  782. break;
  783. case 'addServiceController':
  784. App.clusterStatus.setClusterStatus({
  785. clusterName: this.get('clusterName'),
  786. clusterState: 'ADD_SERVICES_DEPLOY_PREP_2',
  787. wizardControllerName: this.get('content.controllerName'),
  788. localdb: App.db.data
  789. });
  790. break;
  791. default:
  792. break;
  793. }
  794. // delete any existing clusters to start from a clean slate
  795. // before creating a new cluster in install wizard
  796. // TODO: modify for multi-cluster support
  797. if (this.get('content.controllerName') == 'installerController' && (!App.testMode)) {
  798. this.deleteClusters(this.getExistingClusterNames());
  799. }
  800. if (this.get('wizardController').getDBProperty('configsToUpdate')) {
  801. this.updateConfigurations(this.get('wizardController').getDBProperty('configsToUpdate'));
  802. }
  803. this.setLocalRepositories();
  804. this.createCluster();
  805. this.createSelectedServices();
  806. if (this.get('content.controllerName') !== 'addHostController') {
  807. this.createConfigurations();
  808. this.applyConfigurationsToCluster();
  809. }
  810. this.createComponents();
  811. this.registerHostsToCluster();
  812. if (App.supports.hostOverridesInstaller) {
  813. this.createConfigurationGroups();
  814. }
  815. this.createMasterHostComponents();
  816. this.createSlaveAndClientsHostComponents();
  817. this.createAdditionalHostComponents();
  818. this.set('ajaxQueueLength', this.get('ajaxRequestsQueue.queue.length'));
  819. this.get('ajaxRequestsQueue').start();
  820. },
  821. /**
  822. * Get list of existing cluster names
  823. * @returns {string[]}
  824. * returns an array of existing cluster names.
  825. * returns an empty array if there are no existing clusters.
  826. * @method getExistingClusterNames
  827. */
  828. getExistingClusterNames: function () {
  829. App.ajax.send({
  830. name: 'wizard.step8.existing_cluster_names',
  831. sender: this,
  832. success: 'getExistingClusterNamesSuccessCallBack',
  833. error: 'getExistingClusterNamesErrorCallback'
  834. });
  835. return this.get('clusterNames');
  836. },
  837. /**
  838. * Save received list to <code>clusterNames</code>
  839. * @param {Object} data
  840. * @method getExistingClusterNamesSuccessCallBack
  841. */
  842. getExistingClusterNamesSuccessCallBack: function (data) {
  843. var clusterNames = data.items.mapProperty('Clusters.cluster_name');
  844. console.log("Got existing cluster names: " + clusterNames);
  845. this.set('clusterNames', clusterNames);
  846. },
  847. /**
  848. * If error appears, set <code>clusterNames</code> to <code>[]</code>
  849. * @method getExistingClusterNamesErrorCallback
  850. */
  851. getExistingClusterNamesErrorCallback: function () {
  852. console.log("Failed to get existing cluster names");
  853. this.set('clusterNames', []);
  854. },
  855. /**
  856. * Delete cluster by name
  857. * One request for one cluster!
  858. * @param {string[]} clusterNames
  859. * @method deleteClusters
  860. */
  861. deleteClusters: function (clusterNames) {
  862. clusterNames.forEach(function (clusterName) {
  863. App.ajax.send({
  864. name: 'wizard.step8.delete_cluster',
  865. sender: this,
  866. data: {
  867. name: clusterName
  868. }
  869. });
  870. }, this);
  871. },
  872. /**
  873. * Updates local repositories for the Ambari server.
  874. * @method setLocalRepositories
  875. */
  876. setLocalRepositories: function () {
  877. if (this.get('content.controllerName') !== 'installerController' || !App.supports.localRepositories) return;
  878. var self = this;
  879. var stack = this.get('content.stacks').findProperty('isSelected', true);
  880. stack.operatingSystems.forEach(function (os) {
  881. if (os.baseUrl !== os.originalBaseUrl) {
  882. console.log("Updating local repository URL from " + os.originalBaseUrl + " -> " + os.baseUrl + ". ", os);
  883. self.addRequestToAjaxQueue({
  884. name: 'wizard.step8.set_local_repos',
  885. data: {
  886. osType: os.osType,
  887. name: stack.name,
  888. stack2VersionURL: App.get('stack2VersionURL'),
  889. data: JSON.stringify({
  890. "Repositories": {
  891. "base_url": os.baseUrl,
  892. "verify_base_url": false
  893. }
  894. })
  895. }
  896. });
  897. }
  898. });
  899. },
  900. /**
  901. * *******************************************************************
  902. * The following create* functions are called upon submitting Step 8.
  903. * *******************************************************************
  904. */
  905. /**
  906. * Create cluster using selected stack version
  907. * Queued request
  908. * @method createCluster
  909. */
  910. createCluster: function () {
  911. if (this.get('content.controllerName') !== 'installerController') return;
  912. var stackVersion = (this.get('content.installOptions.localRepo')) ? App.currentStackVersion.replace(/(-\d+(\.\d)*)/ig, "Local$&") : App.currentStackVersion;
  913. this.addRequestToAjaxQueue({
  914. name: 'wizard.step8.create_cluster',
  915. data: {
  916. data: JSON.stringify({ "Clusters": {"version": stackVersion }})
  917. }
  918. });
  919. },
  920. /**
  921. * Create selected to install services
  922. * Queued request
  923. * Skipped if no services where selected!
  924. * @method createSelectedServices
  925. */
  926. createSelectedServices: function () {
  927. var data = this.createSelectedServicesData();
  928. if (!data.length) return;
  929. this.addRequestToAjaxQueue({
  930. name: 'wizard.step8.create_selected_services',
  931. data: {
  932. data: JSON.stringify(data)
  933. }
  934. });
  935. },
  936. /**
  937. * Format data for <code>createSelectedServices</code> request
  938. * @returns {Object[]}
  939. * @method createSelectedServicesData
  940. */
  941. createSelectedServicesData: function () {
  942. return this.get('selectedServices').map(function (_service) {
  943. return {"ServiceInfo": { "service_name": _service.get('serviceName') }};
  944. });
  945. },
  946. /**
  947. * Create components for selected services
  948. * Queued requests
  949. * One request for each service!
  950. * @method createComponents
  951. */
  952. createComponents: function () {
  953. var serviceComponents = App.StackServiceComponent.find();
  954. this.get('selectedServices').forEach(function (_service) {
  955. var serviceName = _service.get('serviceName');
  956. var componentsData = serviceComponents.filterProperty('serviceName', serviceName).map(function (_component) {
  957. return { "ServiceComponentInfo": { "component_name": _component.get('componentName') } };
  958. });
  959. // Service must be specified in terms of a query for creating multiple components at the same time.
  960. // See AMBARI-1018.
  961. this.addRequestToAjaxQueue({
  962. name: 'wizard.step8.create_components',
  963. data: {
  964. data: JSON.stringify({"components": componentsData}),
  965. serviceName: serviceName
  966. }
  967. });
  968. }, this);
  969. if (this.get('content.controllerName') == 'addServiceController' && !App.testMode) {
  970. // Add service-components which show up in newer versions but did not
  971. // exist in older ones.
  972. var self = this;
  973. var newServiceComponents = {};
  974. if (App.get('isHadoop21Stack')) {
  975. if (App.YARNService.find().objectAt(0)) {
  976. newServiceComponents['APP_TIMELINE_SERVER'] = 'YARN';
  977. }
  978. }
  979. for (var componentName in newServiceComponents) {
  980. if (newServiceComponents.hasOwnProperty(componentName)) {
  981. var serviceName = newServiceComponents[componentName];
  982. // Create only if it doesnt exist
  983. App.ajax.send({
  984. name: 'service.service_component',
  985. sender: self,
  986. data: {
  987. serviceName: serviceName,
  988. componentName: componentName,
  989. async: false
  990. },
  991. error: 'newServiceComponentErrorCallback'
  992. });
  993. }
  994. }
  995. }
  996. },
  997. /**
  998. * Error callback for new service component request
  999. * So, if component doesn't exist we should create it
  1000. * @param {object} request
  1001. * @param {object} ajaxOptions
  1002. * @param {string} error
  1003. * @param {object} opt
  1004. * @param {object} params
  1005. * @method newServiceComponentErrorCallback
  1006. */
  1007. newServiceComponentErrorCallback: function(request, ajaxOptions, error, opt, params) {
  1008. this.addRequestToAjaxQueue({
  1009. name: 'wizard.step8.create_components',
  1010. data: {
  1011. serviceName: params.serviceName,
  1012. data: JSON.stringify({
  1013. "components": [{
  1014. "ServiceComponentInfo": {
  1015. "component_name": params.componentName
  1016. }
  1017. }]
  1018. })
  1019. }
  1020. });
  1021. },
  1022. /**
  1023. * Register hosts
  1024. * Queued request
  1025. * @method registerHostsToCluster
  1026. */
  1027. registerHostsToCluster: function () {
  1028. var data = this.createRegisterHostData();
  1029. if (!data.length) return;
  1030. this.addRequestToAjaxQueue({
  1031. name: 'wizard.step8.register_host_to_cluster',
  1032. data: {
  1033. data: JSON.stringify(data)
  1034. }
  1035. });
  1036. },
  1037. /**
  1038. * Format request-data for <code>registerHostsToCluster</code>
  1039. * @returns {Object}
  1040. * @method createRegisterHostData
  1041. */
  1042. createRegisterHostData: function () {
  1043. return this.getRegisteredHosts().filterProperty('isInstalled', false).map(function (host) {
  1044. return {"Hosts": { "host_name": host.hostName}};
  1045. });
  1046. },
  1047. /**
  1048. * Register master components
  1049. * @uses registerHostsToComponent
  1050. * @method createMasterHostComponents
  1051. */
  1052. createMasterHostComponents: function () {
  1053. var masterHosts = this.get('content.masterComponentHosts');
  1054. masterHosts.mapProperty('component').uniq().forEach(function (component) {
  1055. var hostNames = masterHosts.filterProperty('component', component).filterProperty('isInstalled', false).mapProperty('hostName');
  1056. this.registerHostsToComponent(hostNames, component);
  1057. }, this);
  1058. },
  1059. /**
  1060. * Register slave components and clients
  1061. * @uses registerHostsToComponent
  1062. * @method createSlaveAndClientsHostComponents
  1063. */
  1064. createSlaveAndClientsHostComponents: function () {
  1065. var masterHosts = this.get('content.masterComponentHosts');
  1066. var slaveHosts = this.get('content.slaveComponentHosts');
  1067. var clients = this.get('content.clients');
  1068. /**
  1069. * Determines on which hosts client should be installed (based on availability of master components on hosts)
  1070. * @type {Object}
  1071. * Format:
  1072. * <code>
  1073. * {
  1074. * CLIENT1: Em.A([MASTER1, MASTER2, ...]),
  1075. * CLIENT2: Em.A([MASTER3, MASTER1, ...])
  1076. * ...
  1077. * }
  1078. * </code>
  1079. */
  1080. var clientsToMasterMap = {
  1081. HDFS_CLIENT: Em.A(['HBASE_MASTER', 'HBASE_REGIONSERVER', 'WEBHCAT_SERVER', 'HISTORYSERVER', 'OOZIE_SERVER']),
  1082. MAPREDUCE_CLIENT: Em.A(['HIVE_SERVER', 'OOZIE_SERVER', 'NAGIOS_SERVER', 'WEBHCAT_SERVER']),
  1083. OOZIE_CLIENT: Em.A(['NAGIOS_SERVER']),
  1084. ZOOKEEPER_CLIENT: Em.A(['WEBHCAT_SERVER']),
  1085. HIVE_CLIENT: Em.A(['WEBHCAT_SERVER', 'HIVE_SERVER']),
  1086. HCAT: Em.A(['NAGIOS_SERVER']),
  1087. YARN_CLIENT: Em.A(['NAGIOS_SERVER', 'HIVE_SERVER', 'OOZIE_SERVER', 'WEBHCAT_SERVER']),
  1088. TEZ_CLIENT: Em.A(['NAGIOS_SERVER', 'HIVE_SERVER'])
  1089. };
  1090. slaveHosts.forEach(function (_slave) {
  1091. if (_slave.componentName !== 'CLIENT') {
  1092. var hostNames = _slave.hosts.filterProperty('isInstalled', false).mapProperty('hostName');
  1093. this.registerHostsToComponent(hostNames, _slave.componentName);
  1094. }
  1095. else {
  1096. clients.forEach(function (_client) {
  1097. var hostNames = _slave.hosts.mapProperty('hostName');
  1098. if (clientsToMasterMap[_client.component_name]) {
  1099. clientsToMasterMap[_client.component_name].forEach(function (componentName) {
  1100. masterHosts.filterProperty('component', componentName).filterProperty('isInstalled', false).forEach(function (_masterHost) {
  1101. hostNames.pushObject(_masterHost.hostName);
  1102. });
  1103. });
  1104. }
  1105. hostNames = hostNames.uniq();
  1106. if (_client.isInstalled) {
  1107. //check whether clients are already installed on selected master hosts!!!
  1108. _slave.hosts.filterProperty('isInstalled', true).mapProperty('hostName').forEach(function (host) {
  1109. if (hostNames.contains(host)) {
  1110. hostNames.splice(hostNames.indexOf(host), 1);
  1111. }
  1112. }, this);
  1113. }
  1114. this.registerHostsToComponent(hostNames, _client.component_name);
  1115. }, this);
  1116. }
  1117. }, this);
  1118. },
  1119. /**
  1120. * Register additional components
  1121. * Based on availability of some services
  1122. * @uses registerHostsToComponent
  1123. * @method createAdditionalHostComponents
  1124. */
  1125. createAdditionalHostComponents: function () {
  1126. var masterHosts = this.get('content.masterComponentHosts');
  1127. // add Ganglia Monitor (Slave) to all hosts if Ganglia service is selected
  1128. var gangliaService = this.get('content.services').filterProperty('isSelected', true).findProperty('serviceName', 'GANGLIA');
  1129. if (gangliaService) {
  1130. var hosts = this.getRegisteredHosts();
  1131. if (gangliaService.get('isInstalled')) {
  1132. hosts = hosts.filterProperty('isInstalled', false);
  1133. }
  1134. if (hosts.length) {
  1135. this.registerHostsToComponent(hosts.mapProperty('hostName'), 'GANGLIA_MONITOR');
  1136. }
  1137. }
  1138. // add MySQL Server if Hive is selected
  1139. var hiveService = this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).findProperty('serviceName', 'HIVE');
  1140. if (hiveService) {
  1141. var hiveDb = this.get('content.serviceConfigProperties').findProperty('name', 'hive_database');
  1142. if (hiveDb.value == "New MySQL Database") {
  1143. this.registerHostsToComponent(masterHosts.filterProperty('component', 'HIVE_SERVER').mapProperty('hostName'), 'MYSQL_SERVER');
  1144. }
  1145. }
  1146. },
  1147. /**
  1148. * Register component to hosts
  1149. * Queued request
  1150. * @param {String[]} hostNames
  1151. * @param {String} componentName
  1152. * @method registerHostsToComponent
  1153. */
  1154. registerHostsToComponent: function (hostNames, componentName) {
  1155. if (!hostNames.length) return;
  1156. var queryStr = '';
  1157. hostNames.forEach(function (hostName) {
  1158. queryStr += 'Hosts/host_name=' + hostName + '|';
  1159. });
  1160. //slice off last symbol '|'
  1161. queryStr = queryStr.slice(0, -1);
  1162. var data = {
  1163. "RequestInfo": {
  1164. "query": queryStr
  1165. },
  1166. "Body": {
  1167. "host_components": [
  1168. {
  1169. "HostRoles": {
  1170. "component_name": componentName
  1171. }
  1172. }
  1173. ]
  1174. }
  1175. };
  1176. this.addRequestToAjaxQueue({
  1177. name: 'wizard.step8.register_host_to_component',
  1178. data: {
  1179. data: JSON.stringify(data)
  1180. }
  1181. });
  1182. },
  1183. /**
  1184. * Create config objects for cluster and services
  1185. * @method createConfigurations
  1186. */
  1187. createConfigurations: function () {
  1188. var self = this;
  1189. var selectedServices = this.get('selectedServices');
  1190. var coreSiteObject = this.createCoreSiteObj();
  1191. if (this.get('content.controllerName') == 'installerController') {
  1192. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1193. this.get('serviceConfigTags').pushObject(this.createSiteObj('hdfs-site', false));
  1194. this.get('serviceConfigTags').pushObject(this.createLog4jObj('hdfs'));
  1195. }
  1196. var globalSiteObj = this.createGlobalSiteObj();
  1197. if (this.get('content.controllerName') == 'addServiceController') {
  1198. globalSiteObj.tag = 'version' + (new Date).getTime();
  1199. coreSiteObject.tag = 'version' + (new Date).getTime();
  1200. this.get('serviceConfigTags').pushObject(coreSiteObject);
  1201. }
  1202. this.get('serviceConfigTags').pushObject(globalSiteObj);
  1203. var objMap = {
  1204. MAPREDUCE: {site: [
  1205. {filename: 'mapred-site', isXmlFile: true}
  1206. ], log4j: ['mapreduce']},
  1207. MAPREDUCE2: {site: [
  1208. {filename: 'mapred-site', isXmlFile: true}
  1209. ], log4j: ['mapreduce2']},
  1210. YARN: {site: [
  1211. {filename: 'yarn-site', isXmlFile: true},
  1212. {filename: 'capacity-scheduler', isXmlFile: true}
  1213. ], log4j: ['yarn']},
  1214. HBASE: {site: [
  1215. {filename: 'hbase-site', isXmlFile: true}
  1216. ], log4j: ['hbase']},
  1217. OOZIE: {site: [
  1218. {filename: 'oozie-site', isXmlFile: true}
  1219. ], log4j: ['oozie']},
  1220. HIVE: {site: [
  1221. {filename: 'hive-site', isXmlFile: true}
  1222. ], log4j: ['hive', 'hive-exec']},
  1223. WEBHCAT: {site: [
  1224. {filename: 'webhcat-site', isXmlFile: true}
  1225. ], log4j: []},
  1226. HUE: {site: [
  1227. {filename: 'hue-site', isXmlFile: true}
  1228. ], log4j: []},
  1229. PIG: {site: [], log4j: ['pig']},
  1230. FALCON: {site: [
  1231. {filename: 'falcon-startup.properties', isXmlFile: false},
  1232. {filename: 'falcon-runtime.properties', isXmlFile: false}
  1233. ], log4j: []},
  1234. TEZ: {site: [
  1235. {filename: 'tez-site', isXmlFile: true}
  1236. ], log4j: []},
  1237. ZOOKEEPER: {site: [], log4j: ['zookeeper']},
  1238. FLUME: {site: [
  1239. {filename: 'flume-agent', isXmlFile: false},
  1240. {filename: 'flume-conf', isXmlFile: false}
  1241. ], log4j: []}
  1242. };
  1243. if (App.supports.capacitySchedulerUi) {
  1244. objMap['MAPREDUCE'].site.pushObjects([
  1245. {filename: 'capacity-scheduler', isXmlFile: true},
  1246. {filename: 'mapred-queue-acls', isXmlFile: true}
  1247. ]);
  1248. }
  1249. for (var serviceName in objMap) {
  1250. if (objMap.hasOwnProperty(serviceName)) {
  1251. if (selectedServices.someProperty('serviceName', serviceName)) {
  1252. objMap[serviceName].site.forEach(function (site) {
  1253. self.get('serviceConfigTags').pushObject(self.createSiteObj(site.filename, !site.isXmlFile));
  1254. });
  1255. objMap[serviceName].log4j.forEach(function (log4j) {
  1256. self.get('serviceConfigTags').pushObject(self.createLog4jObj(log4j));
  1257. });
  1258. }
  1259. }
  1260. }
  1261. if (selectedServices.someProperty('serviceName', 'STORM')) {
  1262. this.get('serviceConfigTags').pushObject(this.createStormSiteObj());
  1263. }
  1264. if (selectedServices.someProperty('serviceName', 'ZOOKEEPER')) {
  1265. this.get('serviceConfigTags').pushObject(this.createZooCfgObj());
  1266. }
  1267. },
  1268. /**
  1269. * Send <code>serviceConfigTags</code> to server
  1270. * Queued request
  1271. * One request for each service config tag
  1272. * @method applyConfigurationsToCluster
  1273. */
  1274. applyConfigurationsToCluster: function () {
  1275. var configData = this.get('serviceConfigTags').map(function (_serviceConfig) {
  1276. return JSON.stringify({
  1277. Clusters: {
  1278. desired_config: {
  1279. type: _serviceConfig.type,
  1280. tag: _serviceConfig.tag,
  1281. properties: _serviceConfig.properties
  1282. }
  1283. }
  1284. });
  1285. }, this).toString();
  1286. this.addRequestToAjaxQueue({
  1287. name: 'wizard.step8.apply_configuration_to_cluster',
  1288. data: {
  1289. data: '[' + configData + ']'
  1290. }
  1291. });
  1292. },
  1293. /**
  1294. * Create and update config groups
  1295. * @method createConfigurationGroups
  1296. */
  1297. createConfigurationGroups: function () {
  1298. var configGroups = this.get('content.configGroups').filterProperty('isDefault', false);
  1299. var clusterName = this.get('clusterName');
  1300. var sendData = [];
  1301. var updateData = [];
  1302. var serviceConfigController = App.router.get('mainServiceInfoConfigsController');
  1303. var timeTag = (new Date).getTime();
  1304. var groupsToDelete = App.router.get(this.get('content.controllerName')).getDBProperty('groupsToDelete');
  1305. if (groupsToDelete && groupsToDelete.length > 0) {
  1306. this.removeInstalledServicesConfigurationGroups(groupsToDelete);
  1307. }
  1308. configGroups.forEach(function (configGroup) {
  1309. var groupConfigs = [];
  1310. var groupData = {
  1311. "cluster_name": clusterName,
  1312. "group_name": configGroup.name,
  1313. "tag": configGroup.service.id,
  1314. "description": configGroup.description,
  1315. "hosts": [],
  1316. "desired_configs": []
  1317. };
  1318. configGroup.hosts.forEach(function (hostName) {
  1319. groupData.hosts.push({"host_name": hostName});
  1320. });
  1321. //wrap properties into Em.Object to make them compatible with buildGroupDesiredConfigs method
  1322. configGroup.properties.forEach(function (property) {
  1323. groupConfigs.push(Em.Object.create(property));
  1324. });
  1325. groupData.desired_configs = serviceConfigController.buildGroupDesiredConfigs.call(serviceConfigController, groupConfigs, timeTag);
  1326. // check for group from installed service
  1327. if (configGroup.isForUpdate === true) {
  1328. // if group is a new one, create it
  1329. if (!configGroup.id) {
  1330. sendData.push({"ConfigGroup": groupData});
  1331. } else {
  1332. // update an existing group
  1333. groupData.id = configGroup.id;
  1334. updateData.push({"ConfigGroup": groupData});
  1335. }
  1336. } else {
  1337. sendData.push({"ConfigGroup": groupData});
  1338. }
  1339. //each group should have unique tag to prevent overriding configs from common sites
  1340. timeTag++;
  1341. }, this);
  1342. if (sendData.length > 0) {
  1343. this.applyConfigurationGroups(sendData);
  1344. }
  1345. if (updateData.length > 0) {
  1346. this.applyInstalledServicesConfigurationGroup(updateData);
  1347. }
  1348. },
  1349. /**
  1350. * Create new config groups request
  1351. * Queued request
  1352. * @param {Object[]} sendData
  1353. * @method applyConfigurationGroups
  1354. */
  1355. applyConfigurationGroups: function (sendData) {
  1356. this.addRequestToAjaxQueue({
  1357. name: 'wizard.step8.apply_configuration_groups',
  1358. data: {
  1359. data: JSON.stringify(sendData)
  1360. }
  1361. });
  1362. },
  1363. /**
  1364. * Update existed config groups
  1365. * @param {Object[]} updateData
  1366. * @method applyInstalledServicesConfigurationGroup
  1367. */
  1368. applyInstalledServicesConfigurationGroup: function (updateData) {
  1369. updateData.forEach(function (item) {
  1370. App.router.get('mainServiceInfoConfigsController').putConfigGroupChanges(item);
  1371. });
  1372. },
  1373. /**
  1374. * Delete selected config groups
  1375. * @param {Object[]} groupsToDelete
  1376. * @method removeInstalledServicesConfigurationGroups
  1377. */
  1378. removeInstalledServicesConfigurationGroups: function (groupsToDelete) {
  1379. groupsToDelete.forEach(function (item) {
  1380. App.config.deleteConfigGroup(Em.Object.create(item));
  1381. });
  1382. },
  1383. /**
  1384. * Create Global Site object
  1385. * @returns {{type: string, tag: string, properties: {}}}
  1386. * @method createGlobalSiteObj
  1387. */
  1388. createGlobalSiteObj: function () {
  1389. var globalSiteProperties = {};
  1390. var globalSiteObj = this.get('globals');
  1391. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1392. // screen out the GLUSTERFS-specific global config entries when they are not required
  1393. if (!isGLUSTERFSSelected) {
  1394. globalSiteObj = globalSiteObj.filter(function (_config) {
  1395. return _config.name.indexOf("fs_glusterfs") < 0;
  1396. });
  1397. }
  1398. globalSiteObj.forEach(function (_globalSiteObj) {
  1399. var heapsizeException = ['hadoop_heapsize', 'yarn_heapsize', 'nodemanager_heapsize', 'resourcemanager_heapsize', 'apptimelineserver_heapsize'];
  1400. // do not pass any globals whose name ends with _host or _hosts
  1401. if (_globalSiteObj.isRequiredByAgent !== false) {
  1402. // append "m" to JVM memory options except for hadoop_heapsize
  1403. if (/_heapsize|_newsize|_maxnewsize$/.test(_globalSiteObj.name) && !heapsizeException.contains(_globalSiteObj.name)) {
  1404. globalSiteProperties[_globalSiteObj.name] = _globalSiteObj.value + "m";
  1405. } else {
  1406. globalSiteProperties[_globalSiteObj.name] = App.config.escapeXMLCharacters(_globalSiteObj.value);
  1407. }
  1408. }
  1409. }, this);
  1410. // we don't expose gmond_user to the user; it needs to be the same as gmetad_user
  1411. globalSiteProperties['gmond_user'] = globalSiteProperties['gmetad_user'];
  1412. return {"type": "global", "tag": "version1", "properties": globalSiteProperties};
  1413. },
  1414. /**
  1415. * Create Core Site object
  1416. * @returns {{type: string, tag: string, properties: {}}}
  1417. * @method createCoreSiteObj
  1418. */
  1419. createCoreSiteObj: function () {
  1420. var coreSiteObj = this.get('configs').filterProperty('filename', 'core-site.xml');
  1421. var coreSiteProperties = {};
  1422. // hadoop.proxyuser.oozie.hosts needs to be skipped if oozie is not selected
  1423. var isOozieSelected = this.get('selectedServices').someProperty('serviceName', 'OOZIE');
  1424. var oozieUser = this.get('globals').someProperty('name', 'oozie_user') ? this.get('globals').findProperty('name', 'oozie_user').value : null;
  1425. var isHiveSelected = this.get('selectedServices').someProperty('serviceName', 'HIVE');
  1426. var hiveUser = this.get('globals').someProperty('name', 'hive_user') ? this.get('globals').findProperty('name', 'hive_user').value : null;
  1427. var isHcatSelected = this.get('selectedServices').someProperty('serviceName', 'WEBHCAT');
  1428. var hcatUser = this.get('globals').someProperty('name', 'hcat_user') ? this.get('globals').findProperty('name', 'hcat_user').value : null;
  1429. var isGLUSTERFSSelected = this.get('selectedServices').someProperty('serviceName', 'GLUSTERFS');
  1430. // screen out the GLUSTERFS-specific core-site.xml entries when they are not needed
  1431. if (!isGLUSTERFSSelected) {
  1432. coreSiteObj = coreSiteObj.filter(function (_config) {
  1433. return _config.name.indexOf("fs.glusterfs") < 0;
  1434. });
  1435. }
  1436. coreSiteObj.forEach(function (_coreSiteObj) {
  1437. 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'))) {
  1438. coreSiteProperties[_coreSiteObj.name] = App.config.escapeXMLCharacters(_coreSiteObj.value);
  1439. }
  1440. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.default.name") {
  1441. 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;
  1442. }
  1443. if (isGLUSTERFSSelected && _coreSiteObj.name == "fs.defaultFS") {
  1444. coreSiteProperties[_coreSiteObj.name] = this.get('globals').someProperty('name', 'glusterfs_defaultFS_name') ? App.config.escapeXMLCharacters(this.get('globals').findProperty('name', 'glusterfs_defaultFS_name').value) : null;
  1445. }
  1446. }, this);
  1447. return {"type": "core-site", "tag": "version1", "properties": coreSiteProperties};
  1448. },
  1449. /**
  1450. * Create siteObj for custom service with it own configs
  1451. * @param {string} site
  1452. * @param {bool} isNonXmlFile
  1453. * @returns {{type: string, tag: string, properties: {}}}
  1454. * @method createSiteObj
  1455. */
  1456. createSiteObj: function (site, isNonXmlFile) {
  1457. var properties = {};
  1458. if (!!isNonXmlFile) {
  1459. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1460. properties[_configProperty.name] = _configProperty.value;
  1461. }, this);
  1462. } else {
  1463. this.get('configs').filterProperty('filename', site + '.xml').forEach(function (_configProperty) {
  1464. properties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1465. }, this);
  1466. }
  1467. return {"type": site, "tag": "version1", "properties": properties };
  1468. },
  1469. /**
  1470. * Create log4j object for custom service with it own configs
  1471. * @param {string} site
  1472. * @returns {{type: string, tag: string, properties: {}}}
  1473. * @method createLog4jObj
  1474. */
  1475. createLog4jObj: function (site) {
  1476. return this.createSiteObj(site + '-log4j', true);
  1477. },
  1478. /**
  1479. * Create ZooKeeper Cfg Object
  1480. * @returns {{type: string, tag: string, properties: {}}}
  1481. * @method createZooCfgObj
  1482. */
  1483. createZooCfgObj: function () {
  1484. var configs = this.get('configs').filterProperty('filename', 'zoo.cfg');
  1485. var csProperties = {};
  1486. configs.forEach(function (_configProperty) {
  1487. csProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1488. }, this);
  1489. return {type: 'zoo.cfg', tag: 'version1', properties: csProperties};
  1490. },
  1491. /**
  1492. * Create site obj for Storm
  1493. * Some config-properties should be modified in custom way
  1494. * @returns {{type: string, tag: string, properties: {}}}
  1495. * @method createStormSiteObj
  1496. */
  1497. createStormSiteObj: function () {
  1498. var configs = this.get('configs').filterProperty('filename', 'storm-site.xml');
  1499. var stormProperties = {};
  1500. var specialProperties = ["storm.zookeeper.servers", "nimbus.childopts", "supervisor.childopts", "worker.childopts"];
  1501. configs.forEach(function (_configProperty) {
  1502. if (specialProperties.contains(_configProperty.name)) {
  1503. if (_configProperty.name == "storm.zookeeper.servers") {
  1504. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "'");
  1505. } else {
  1506. stormProperties[_configProperty.name] = JSON.stringify(_configProperty.value).replace(/"/g, "");
  1507. }
  1508. } else {
  1509. stormProperties[_configProperty.name] = App.config.escapeXMLCharacters(_configProperty.value);
  1510. }
  1511. }, this);
  1512. return {type: 'storm-site', tag: 'version1', properties: stormProperties};
  1513. },
  1514. /**
  1515. * Navigate to next step after all requests are sent
  1516. * @method ajaxQueueFinished
  1517. */
  1518. ajaxQueueFinished: function () {
  1519. console.log('everything is loaded');
  1520. App.router.send('next');
  1521. },
  1522. /**
  1523. * We need to do a lot of ajax calls async in special order. To do this,
  1524. * generate array of ajax objects and then send requests step by step. All
  1525. * ajax objects are stored in <code>ajaxRequestsQueue</code>
  1526. *
  1527. * @param {Object} params object with ajax-request parameters like url, type, data etc
  1528. * @method addRequestToAjaxQueue
  1529. */
  1530. addRequestToAjaxQueue: function (params) {
  1531. if (App.testMode) return;
  1532. params = jQuery.extend({
  1533. sender: this,
  1534. error: 'ajaxQueueRequestErrorCallback'
  1535. }, params);
  1536. params.data['cluster'] = this.get('clusterName');
  1537. this.get('ajaxRequestsQueue').addRequest(params);
  1538. },
  1539. /**
  1540. * Error callback for each queued ajax-request
  1541. * @param {object} xhr
  1542. * @param {string} status
  1543. * @param {string} error
  1544. * @method ajaxQueueRequestErrorCallback
  1545. */
  1546. ajaxQueueRequestErrorCallback: function (xhr, status, error) {
  1547. var responseText = JSON.parse(xhr.responseText);
  1548. var controller = App.router.get(App.clusterStatus.wizardControllerName);
  1549. controller.registerErrPopup(Em.I18n.t('common.error'), responseText.message);
  1550. this.set('hasErrorOccurred', true);
  1551. // an error will break the ajax call chain and allow submission again
  1552. this.set('isSubmitDisabled', false);
  1553. this.set('isBackBtnDisabled', false);
  1554. App.router.get(this.get('content.controllerName')).setStepsEnable();
  1555. }
  1556. });