step7_controller.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533
  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. /**
  20. * By Step 7, we have the following information stored in App.db and set on this
  21. * controller by the router.
  22. *
  23. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  24. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  25. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  26. *
  27. */
  28. /**
  29. * @typedef {object} masterComponentHost
  30. * @property {string} component
  31. * @property {string} hostName
  32. * @property {boolean} isInstalled is component already installed on the this host or just going to be installed
  33. */
  34. /**
  35. * @typedef {object} topologyLocalDB
  36. * @property {object[]} hosts list of hosts with information of their disks usage and dirs
  37. * @property {masterComponentHost[]} masterComponentHosts
  38. * @property {?object[]} slaveComponentHosts
  39. */
  40. App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.EnhancedConfigsMixin, App.ToggleIsRequiredMixin, {
  41. name: 'wizardStep7Controller',
  42. /**
  43. * Contains all field properties that are viewed in this step
  44. * @type {object[]}
  45. */
  46. stepConfigs: [],
  47. hash: null,
  48. selectedService: null,
  49. slaveHostToGroup: null,
  50. addMiscTabToPage: true,
  51. selectedServiceNameTrigger: null,
  52. /**
  53. * Is Submit-click processing now
  54. * @type {bool}
  55. */
  56. submitButtonClicked: false,
  57. isRecommendedLoaded: false,
  58. /**
  59. * used in services_config.js view to mark a config with security icon
  60. */
  61. secureConfigs: require('data/HDP2/secure_mapping'),
  62. /**
  63. * If configChangeObserver Modal is shown
  64. * @type {bool}
  65. */
  66. miscModalVisible: false,
  67. overrideToAdd: null,
  68. /**
  69. * Is installer controller used
  70. * @type {bool}
  71. */
  72. isInstaller: true,
  73. /**
  74. * List of config groups
  75. * @type {object[]}
  76. */
  77. configGroups: [],
  78. /**
  79. * List of config group to be deleted
  80. * @type {object[]}
  81. */
  82. groupsToDelete: [],
  83. preSelectedConfigGroup: null,
  84. /**
  85. * Currently selected config group
  86. * @type {object}
  87. */
  88. selectedConfigGroup: null,
  89. /**
  90. * Config tags of actually installed services
  91. * @type {array}
  92. */
  93. serviceConfigTags: [],
  94. /**
  95. * Are applied to service configs loaded
  96. * @type {bool}
  97. */
  98. isAppliedConfigLoaded: true,
  99. isConfigsLoaded: Em.computed.and('wizardController.stackConfigsLoaded', 'isAppliedConfigLoaded'),
  100. /**
  101. * PreInstall Checks allowed only for Install
  102. * @type {boolean}
  103. */
  104. supportsPreInstallChecks: function () {
  105. return App.get('supports.preInstallChecks') && 'installerController' === this.get('content.controllerName');
  106. }.property('App.supports.preInstallChecks', 'wizardController.name'),
  107. /**
  108. * Number of errors in the configs in the selected service
  109. * @type {number}
  110. */
  111. errorsCount: function () {
  112. return this.get('selectedService.configs').filter(function (config) {
  113. return Em.isNone(config.get('widgetType'));
  114. }).filter(function(config) {
  115. return !config.get('isValid') || (config.get('overrides') || []).someProperty('isValid', false);
  116. }).filterProperty('isVisible').length;
  117. }.property('selectedService.configs.@each.isValid', 'selectedService.configs.@each.isVisible','selectedService.configs.@each.overrideErrorTrigger'),
  118. /**
  119. * Should Next-button be disabled
  120. * @type {bool}
  121. */
  122. isSubmitDisabled: function () {
  123. if (!this.get('stepConfigs.length')) return true;
  124. if (this.get('submitButtonClicked')) return true;
  125. return (!this.get('stepConfigs').filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  126. }.property('stepConfigs.@each.errorCount', 'miscModalVisible', 'submitButtonClicked'),
  127. /**
  128. * List of selected to install service names
  129. * @type {string[]}
  130. */
  131. selectedServiceNames: function () {
  132. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  133. }.property('content.services', 'content.services.@each.isSelected', 'content.services.@each.isInstalled', 'content.stacks.@each.isSelected').cacheable(),
  134. /**
  135. * List of installed and selected to install service names
  136. * @type {string[]}
  137. */
  138. allSelectedServiceNames: function () {
  139. return this.get('content.services').filter(function (service) {
  140. return service.get('isInstalled') || service.get('isSelected');
  141. }).mapProperty('serviceName');
  142. }.property('content.services', 'content.services.@each.isSelected', 'content.services.@each.isInstalled', 'content.stacks.@each.isSelected').cacheable(),
  143. /**
  144. * List of installed service names
  145. * @type {string[]}
  146. */
  147. installedServiceNames: function () {
  148. var serviceNames = this.get('content.services').filterProperty('isInstalled').mapProperty('serviceName');
  149. if (this.get('content.controllerName') !== 'installerController') {
  150. serviceNames = serviceNames.filter(function (_serviceName) {
  151. return !App.get('services.noConfigTypes').contains(_serviceName);
  152. });
  153. }
  154. return serviceNames;
  155. }.property('content.services').cacheable(),
  156. /**
  157. * List of master components
  158. * @type {Ember.Enumerable}
  159. */
  160. masterComponentHosts: Em.computed.alias('content.masterComponentHosts'),
  161. /**
  162. * List of slave components
  163. * @type {Ember.Enumerable}
  164. */
  165. slaveComponentHosts: Em.computed.alias('content.slaveGroupProperties'),
  166. customData: [],
  167. /**
  168. * Filter text will be located here
  169. * @type {string}
  170. */
  171. filter: '',
  172. /**
  173. * List of filters for config properties to populate filter combobox
  174. */
  175. propertyFilters: [
  176. {
  177. attributeName: 'isOverridden',
  178. attributeValue: true,
  179. caption: 'common.combobox.dropdown.overridden'
  180. },
  181. {
  182. attributeName: 'isFinal',
  183. attributeValue: true,
  184. caption: 'common.combobox.dropdown.final'
  185. },
  186. {
  187. attributeName: 'hasIssues',
  188. attributeValue: true,
  189. caption: 'common.combobox.dropdown.issues'
  190. }
  191. ],
  192. issuesFilterText: function () {
  193. return (this.get('isSubmitDisabled') && !this.get('submitButtonClicked') &&
  194. this.get('filterColumns').findProperty('attributeName', 'hasIssues').get('selected')) ?
  195. Em.I18n.t('installer.step7.showingPropertiesWithIssues') : '';
  196. }.property('isSubmitDisabled', 'submitButtonClicked', 'filterColumns.@each.selected'),
  197. issuesFilterLinkText: function () {
  198. if (this.get('filterColumns').findProperty('attributeName', 'hasIssues').get('selected')) {
  199. return Em.I18n.t('installer.step7.showAllProperties');
  200. }
  201. return (this.get('isSubmitDisabled') && !this.get('submitButtonClicked')) ?
  202. (
  203. this.get('filterColumns').findProperty('attributeName', 'hasIssues').get('selected') ?
  204. Em.I18n.t('installer.step7.showAllProperties') : Em.I18n.t('installer.step7.showPropertiesWithIssues')
  205. ) : '';
  206. }.property('isSubmitDisabled', 'submitButtonClicked', 'filterColumns.@each.selected'),
  207. /**
  208. * Dropdown menu items in filter combobox
  209. */
  210. filterColumns: function () {
  211. return this.get('propertyFilters').map(function (filter) {
  212. return Ember.Object.create({
  213. attributeName: filter.attributeName,
  214. attributeValue: filter.attributeValue,
  215. name: this.t(filter.caption),
  216. selected: false
  217. });
  218. }, this);
  219. }.property('propertyFilters'),
  220. /**
  221. * Clear controller's properties:
  222. * <ul>
  223. * <li>stepConfigs</li>
  224. * <li>filter</li>
  225. * </ul>
  226. * and desect all <code>filterColumns</code>
  227. * @method clearStep
  228. */
  229. clearStep: function () {
  230. this.setProperties({
  231. configValidationGlobalMessage: [],
  232. submitButtonClicked: false,
  233. isSubmitDisabled: true,
  234. isRecommendedLoaded: false
  235. });
  236. this.get('stepConfigs').clear();
  237. this.set('filter', '');
  238. this.get('filterColumns').setEach('selected', false);
  239. },
  240. /**
  241. * Generate "finger-print" for current <code>stepConfigs[0]</code>
  242. * Used to determine, if user has some unsaved changes (comparing with <code>hash</code>)
  243. * @returns {string|null}
  244. * @method getHash
  245. */
  246. getHash: function () {
  247. if (!this.get('stepConfigs')[0]) {
  248. return null;
  249. }
  250. var hash = {};
  251. this.get('stepConfigs').forEach(function(stepConfig){
  252. stepConfig.configs.forEach(function (config) {
  253. hash[config.get('name')] = {value: config.get('value'), overrides: [], isFinal: config.get('isFinal')};
  254. if (!config.get('overrides')) return;
  255. if (!config.get('overrides.length')) return;
  256. config.get('overrides').forEach(function (override) {
  257. hash[config.get('name')].overrides.push(override.get('value'));
  258. });
  259. });
  260. });
  261. return JSON.stringify(hash);
  262. },
  263. /**
  264. * Are some changes available
  265. */
  266. hasChanges: function () {
  267. return this.get('hash') != this.getHash();
  268. },
  269. /**
  270. * Load config groups for installed services
  271. * One ajax-request for each service
  272. * @param {string[]} servicesNames
  273. * @method loadInstalledServicesConfigGroups
  274. */
  275. loadInstalledServicesConfigGroups: function (servicesNames) {
  276. servicesNames.forEach(function (serviceName) {
  277. App.ajax.send({
  278. name: 'config.tags_and_groups',
  279. sender: this,
  280. data: {
  281. serviceName: serviceName,
  282. serviceConfigsDef: App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName)
  283. },
  284. success: 'loadServiceTagsSuccess'
  285. });
  286. }, this);
  287. },
  288. /**
  289. * Create site to tag map. Format:
  290. * <code>
  291. * {
  292. * site1: tag1,
  293. * site1: tag2,
  294. * site2: tag3
  295. * ...
  296. * }
  297. * </code>
  298. * @param {object} desired_configs
  299. * @param {string[]} sites
  300. * @returns {object}
  301. * @private
  302. * @method _createSiteToTagMap
  303. */
  304. _createSiteToTagMap: function (desired_configs, sites) {
  305. var siteToTagMap = {};
  306. for (var site in desired_configs) {
  307. if (desired_configs.hasOwnProperty(site)) {
  308. if (!!sites[site]) {
  309. siteToTagMap[site] = desired_configs[site].tag;
  310. }
  311. }
  312. }
  313. return siteToTagMap;
  314. },
  315. /**
  316. * Load config groups success callback
  317. * @param {object} data
  318. * @param {object} opt
  319. * @param {object} params
  320. * @method loadServiceTagsSuccess
  321. */
  322. loadServiceTagsSuccess: function (data, opt, params) {
  323. var serviceName = params.serviceName,
  324. service = this.get('stepConfigs').findProperty('serviceName', serviceName),
  325. defaultConfigGroupHosts = this.get('wizardController.allHosts').mapProperty('hostName'),
  326. siteToTagMap = this._createSiteToTagMap(data.Clusters.desired_configs, params.serviceConfigsDef.get('configTypes'));
  327. this.set('loadedClusterSiteToTagMap', siteToTagMap);
  328. //parse loaded config groups
  329. var configGroups = [];
  330. if (data.config_groups.length) {
  331. data.config_groups.forEach(function (item) {
  332. item = item.ConfigGroup;
  333. if (item.tag === serviceName) {
  334. var groupHosts = item.hosts.mapProperty('host_name');
  335. configGroups.push({
  336. id: serviceName + item.id,
  337. config_group_id: item.id,
  338. name: item.group_name,
  339. description: item.description,
  340. is_default: false,
  341. parent_config_group_id: App.ServiceConfigGroup.getParentConfigGroupId(serviceName),
  342. service_id: serviceName,
  343. service_name: serviceName,
  344. hosts: groupHosts,
  345. desired_configs: item.desired_configs
  346. });
  347. groupHosts.forEach(function (host) {
  348. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  349. }, this);
  350. }
  351. }, this);
  352. }
  353. var defaultConfigGroup = App.configGroupsMapper.generateDefaultGroup(serviceName, defaultConfigGroupHosts);
  354. configGroups = configGroups.sortProperty('name');
  355. configGroups.unshift(defaultConfigGroup);
  356. App.store.loadMany(App.ServiceConfigGroup, configGroups);
  357. App.store.commit();
  358. service.set('configGroups', App.ServiceConfigGroup.find().filterProperty('serviceName', serviceName));
  359. var loadedGroupToOverrideSiteToTagMap = {};
  360. configGroups.forEach(function (item) {
  361. var groupName = item.name;
  362. loadedGroupToOverrideSiteToTagMap[groupName] = {};
  363. item.desired_configs.forEach(function (site) {
  364. loadedGroupToOverrideSiteToTagMap[groupName][site.type] = site.tag;
  365. }, this);
  366. }, this);
  367. this.set('preSelectedConfigGroup', App.ServiceConfigGroup.find(App.ServiceConfigGroup.getParentConfigGroupId(serviceName)));
  368. App.config.loadServiceConfigGroupOverrides(service.get('configs'), loadedGroupToOverrideSiteToTagMap, service.get('configGroups'), this.onLoadOverrides, this);
  369. },
  370. onLoadOverrides: function (configs) {
  371. var serviceName = configs[0].serviceName,
  372. service = this.get('stepConfigs').findProperty('serviceName', serviceName);
  373. var serviceConfig = App.config.createServiceConfig(serviceName);
  374. service.set('selectedConfigGroup', this.get('preSelectedConfigGroup'));
  375. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  376. // override if a property isRequired or not
  377. this.overrideConfigIsRequired(service);
  378. service.set('configs', serviceConfig.get('configs'));
  379. },
  380. /**
  381. * Set <code>isEditable</code>-property to <code>serviceConfigProperty</code>
  382. * Based on user's permissions and selected config group
  383. * @param {Ember.Object} serviceConfigProperty
  384. * @param {bool} defaultGroupSelected
  385. * @returns {Ember.Object} Updated config-object
  386. * @method _updateIsEditableFlagForConfig
  387. */
  388. _updateIsEditableFlagForConfig: function (serviceConfigProperty, defaultGroupSelected) {
  389. if (App.isAccessible('ADMIN')) {
  390. if (defaultGroupSelected && !this.get('isHostsConfigsPage') && !Em.get(serviceConfigProperty, 'group')) {
  391. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  392. } else if (Em.get(serviceConfigProperty, 'group') && Em.get(serviceConfigProperty, 'group.name') == this.get('selectedConfigGroup.name')) {
  393. serviceConfigProperty.set('isEditable', true);
  394. } else {
  395. serviceConfigProperty.set('isEditable', false);
  396. }
  397. }
  398. else {
  399. serviceConfigProperty.set('isEditable', false);
  400. }
  401. return serviceConfigProperty;
  402. },
  403. /**
  404. * Set <code>overrides</code>-property to <code>serviceConfigProperty<code>
  405. * @param {Ember.Object} serviceConfigProperty
  406. * @param {Ember.Object} component
  407. * @return {Ember.Object} Updated config-object
  408. * @method _updateOverridesForConfig
  409. */
  410. _updateOverridesForConfig: function (serviceConfigProperty, component) {
  411. var overrides = serviceConfigProperty.get('overrides');
  412. if (Em.isNone(overrides)) {
  413. serviceConfigProperty.set('overrides', Em.A([]));
  414. return serviceConfigProperty;
  415. }
  416. serviceConfigProperty.set('overrides', null);
  417. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  418. // Wrap each override to App.ServiceConfigProperty
  419. overrides.forEach(function (override) {
  420. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  421. newSCP.set('value', override.value);
  422. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  423. newSCP.set('parentSCP', serviceConfigProperty);
  424. if (defaultGroupSelected) {
  425. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  426. // prevent cycle in proto object, clean link
  427. if (group.get('properties').length == 0) {
  428. group.set('properties', Em.A([]));
  429. }
  430. group.get('properties').push(newSCP);
  431. newSCP.set('group', override.group);
  432. newSCP.set('isEditable', false);
  433. }
  434. var parentOverridesArray = serviceConfigProperty.get('overrides');
  435. if (Em.isNone(parentOverridesArray)) {
  436. parentOverridesArray = Em.A([]);
  437. serviceConfigProperty.set('overrides', parentOverridesArray);
  438. }
  439. serviceConfigProperty.get('overrides').pushObject(newSCP);
  440. newSCP.validate();
  441. }, this);
  442. return serviceConfigProperty;
  443. },
  444. /**
  445. * Set configs with overrides, recommended defaults to component
  446. * @param {Ember.Object[]} configs
  447. * @param {Ember.Object} componentConfig
  448. * @param {Ember.Object} component
  449. * @method loadComponentConfigs
  450. */
  451. loadComponentConfigs: function (configs, componentConfig, component) {
  452. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  453. configs.forEach(function (serviceConfigProperty) {
  454. if (!serviceConfigProperty) return;
  455. if (Em.isNone(serviceConfigProperty.get('isOverridable'))) {
  456. serviceConfigProperty.set('isOverridable', true);
  457. }
  458. this._updateOverridesForConfig(serviceConfigProperty, component);
  459. this._updateIsEditableFlagForConfig(serviceConfigProperty, defaultGroupSelected);
  460. componentConfig.get('configs').pushObject(serviceConfigProperty);
  461. serviceConfigProperty.validate();
  462. }, this);
  463. component.get('configGroups').filterProperty('isDefault', false).forEach(function (configGroup) {
  464. configGroup.set('hash', this.get('wizardController').getConfigGroupHash(configGroup));
  465. }, this);
  466. var overrideToAdd = this.get('overrideToAdd');
  467. if (overrideToAdd) {
  468. overrideToAdd = componentConfig.get('configs').findProperty('name', overrideToAdd.name);
  469. if (overrideToAdd) {
  470. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  471. var newSCP = App.config.createOverride(overrideToAdd, {isEditable: true}, group);
  472. group.get('properties').pushObject(newSCP);
  473. component.set('overrideToAdd', null);
  474. }
  475. }
  476. },
  477. /**
  478. * Resolve dependency between configs.
  479. * @param serviceName {String}
  480. * @param configs {Ember.Enumerable}
  481. */
  482. resolveServiceDependencyConfigs: function (serviceName, configs) {
  483. switch (serviceName) {
  484. case 'YARN':
  485. this.resolveYarnConfigs(configs);
  486. break;
  487. }
  488. },
  489. /**
  490. * Update some Storm configs
  491. * If SLIDER is selected to install or already installed,
  492. * some Yarn properties must be changed
  493. * @param {Ember.Enumerable} configs
  494. * @method resolveYarnConfigs
  495. */
  496. resolveYarnConfigs: function (configs) {
  497. var cfgToChange = configs.findProperty('name', 'hadoop.registry.rm.enabled');
  498. if (cfgToChange) {
  499. var res = this.get('allSelectedServiceNames').contains('SLIDER').toString();
  500. if (Em.get(cfgToChange, 'value') !== res) {
  501. Em.set(cfgToChange, 'recommendedValue', res);
  502. Em.set(cfgToChange, 'value', res);
  503. }
  504. }
  505. },
  506. /**
  507. * On load function
  508. * @method loadStep
  509. */
  510. loadStep: function () {
  511. if (!this.get('isConfigsLoaded')) {
  512. return;
  513. }
  514. console.time('wizard loadStep: ');
  515. this.clearStep();
  516. var self = this;
  517. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  518. var storedConfigs = this.get('content.serviceConfigProperties');
  519. var configs = (storedConfigs && storedConfigs.length) ? storedConfigs : App.configsCollection.getAll();
  520. this.resolveConfigThemeConditions(configs);
  521. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  522. if (this.get('wizardController.name') === 'addServiceController') {
  523. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function (loadedConfigs) {
  524. configs = self.setInstalledServiceConfigs(configs, loadedConfigs, self.get('installedServiceNames'));
  525. self.applyServicesConfigs(configs, storedConfigs);
  526. });
  527. } else {
  528. this.applyServicesConfigs(configs, storedConfigs);
  529. }
  530. },
  531. /**
  532. * Resolve config theme conditions
  533. * in order to correctly calculate config errors number of service
  534. * @param {Array} configs
  535. */
  536. resolveConfigThemeConditions: function (configs) {
  537. App.ThemeCondition.find().forEach(function (configCondition) {
  538. var _configs = Em.A(configCondition.get('configs'));
  539. if (configCondition.get("resource") === 'config' && _configs.length > 0) {
  540. var isConditionTrue = App.config.calculateConfigCondition(configCondition.get("if"), configs);
  541. var action = isConditionTrue ? configCondition.get("then") : configCondition.get("else");
  542. if (configCondition.get('id')) {
  543. var valueAttributes = action.property_value_attributes;
  544. if (valueAttributes && !Em.none(valueAttributes['visible'])) {
  545. var themeResource;
  546. if (configCondition.get('type') === 'subsection') {
  547. themeResource = App.SubSection.find().findProperty('name', configCondition.get('name'));
  548. } else if (configCondition.get('type') === 'subsectionTab') {
  549. themeResource = App.SubSectionTab.find().findProperty('name', configCondition.get('name'));
  550. }
  551. if (themeResource) {
  552. themeResource.get('configProperties').forEach(function (_configId) {
  553. configs.find(function (item) {
  554. if (App.config.configId(item.name, item.filename) === _configId) {
  555. item.hiddenBySection = !valueAttributes['visible'];
  556. return true;
  557. }
  558. return false;
  559. });
  560. }, this);
  561. }
  562. }
  563. }
  564. }
  565. });
  566. },
  567. applyServicesConfigs: function (configs, storedConfigs) {
  568. if (this.get('allSelectedServiceNames').contains('YARN')) {
  569. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml', []);
  570. }
  571. ["YARN"].forEach(function (serviceName) {
  572. if (this.get('allSelectedServiceNames').contains(serviceName)) {
  573. this.resolveServiceDependencyConfigs(serviceName, configs);
  574. }
  575. }, this);
  576. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  577. if (App.get('isKerberosEnabled') && this.get('wizardController.name') == 'addServiceController') {
  578. this.addKerberosDescriptorConfigs(configs, this.get('wizardController.kerberosDescriptorConfigs') || []);
  579. }
  580. var serviceConfigs = this.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'));
  581. this.setStepConfigs(serviceConfigs);
  582. this.checkHostOverrideInstaller();
  583. this.activateSpecialConfigs();
  584. this.selectProperService();
  585. var self = this;
  586. var rangerService = App.StackService.find().findProperty('serviceName', 'RANGER');
  587. if (rangerService && !rangerService.get('isInstalled') && !rangerService.get('isSelected')) {
  588. App.config.removeRangerConfigs(self.get('stepConfigs'));
  589. }
  590. if (this.get('content.serviceConfigProperties.length') > 0) {
  591. this.completeConfigLoading();
  592. } else {
  593. this.loadServerSideConfigsRecommendations().always(function () {
  594. if (self.get('wizardController.name') == 'addServiceController') {
  595. // for Add Service just remove or add dependent properties and ignore config values changes
  596. // for installed services only
  597. self.addRemoveDependentConfigs(self.get('installedServiceNames'));
  598. self.clearDependenciesForInstalledServices(self.get('installedServiceNames'), self.get('stepConfigs'));
  599. }
  600. // * add dependencies based on recommendations
  601. // * update config values with recommended
  602. // * remove properties received from recommendations
  603. self.updateDependentConfigs();
  604. self.completeConfigLoading();
  605. });
  606. }
  607. },
  608. completeConfigLoading: function() {
  609. this.clearDependentConfigsByService(App.StackService.find().filterProperty('isSelected').mapProperty('serviceName'));
  610. console.timeEnd('wizard loadStep: ');
  611. this.set('isRecommendedLoaded', true);
  612. if (this.get('content.skipConfigStep')) {
  613. App.router.send('next');
  614. }
  615. this.set('hash', this.getHash());
  616. },
  617. /**
  618. * Mark descriptor properties in configuration object.
  619. *
  620. * @param {Object[]} configs - config properties to change
  621. * @param {App.ServiceConfigProperty[]} descriptor - parsed kerberos descriptor
  622. * @method addKerberosDescriptorConfigs
  623. */
  624. addKerberosDescriptorConfigs: function (configs, descriptor) {
  625. descriptor.forEach(function (item) {
  626. var property = configs.findProperty('name', item.get('name'));
  627. if (property) {
  628. Em.setProperties(property, {
  629. isSecureConfig: true,
  630. displayName: Em.get(item, 'name'),
  631. isUserProperty: false,
  632. isOverridable: false,
  633. category: 'Advanced ' + Em.get(item, 'filename')
  634. });
  635. }
  636. });
  637. },
  638. /**
  639. * Load config groups
  640. * and (if some services are already installed) load config groups for installed services
  641. * @method checkHostOverrideInstaller
  642. */
  643. checkHostOverrideInstaller: function () {
  644. if (this.get('wizardController.name') !== 'kerberosWizardController') {
  645. this.loadConfigGroups(this.get('content.configGroups'));
  646. }
  647. if (this.get('installedServiceNames').length > 0 && !this.get('wizardController.areInstalledConfigGroupsLoaded')) {
  648. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  649. }
  650. },
  651. /**
  652. * Set init <code>stepConfigs</code> value
  653. * Set <code>selected</code> for addable services if addServiceController is used
  654. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  655. * @param {Ember.Object[]} serviceConfigs
  656. * @method setStepConfigs
  657. */
  658. setStepConfigs: function (serviceConfigs) {
  659. if (this.get('wizardController.name') === 'addServiceController') {
  660. serviceConfigs.setEach('showConfig', true);
  661. serviceConfigs.setEach('selected', false);
  662. this.get('selectedServiceNames').forEach(function (serviceName) {
  663. if (!serviceConfigs.findProperty('serviceName', serviceName)) return;
  664. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  665. }, this);
  666. this.get('installedServiceNames').forEach(function (serviceName) {
  667. var serviceConfigObj = serviceConfigs.findProperty('serviceName', serviceName);
  668. var isInstallableService = App.StackService.find(serviceName).get('isInstallable');
  669. if (!isInstallableService) serviceConfigObj.set('showConfig', false);
  670. }, this);
  671. // if HA is enabled -> Remove SNameNode
  672. if (App.get('isHaEnabled')) {
  673. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs,
  674. removedConfigs = c.filterProperty('category', 'SECONDARY_NAMENODE');
  675. removedConfigs.setEach('isVisible', false);
  676. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  677. serviceConfigs = this._reconfigureServicesOnNnHa(serviceConfigs);
  678. }
  679. }
  680. // Remove Notifications from MISC if it isn't Installer Controller
  681. if (this.get('wizardController.name') !== 'installerController') {
  682. var miscService = serviceConfigs.findProperty('serviceName', 'MISC');
  683. if (miscService) {
  684. c = miscService.configs;
  685. removedConfigs = c.filterProperty('category', 'Notifications');
  686. removedConfigs.map(function (config) {
  687. c = c.without(config);
  688. });
  689. miscService.configs = c;
  690. }
  691. }
  692. this.set('stepConfigs', serviceConfigs);
  693. },
  694. /**
  695. * render configs, distribute them by service
  696. * and wrap each in ServiceConfigProperty object
  697. * @param configs
  698. * @param storedConfigs
  699. * @param allSelectedServiceNames
  700. * @param installedServiceNames
  701. * @return {App.ServiceConfig[]}
  702. */
  703. renderConfigs: function (configs, storedConfigs, allSelectedServiceNames, installedServiceNames) {
  704. var localDB = {
  705. hosts: this.get('wizardController.content.hosts'),
  706. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  707. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  708. };
  709. var renderedServiceConfigs = [];
  710. var services = [];
  711. App.config.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  712. var serviceName = serviceConfig.get('serviceName');
  713. if (allSelectedServiceNames.contains(serviceName) || serviceName === 'MISC') {
  714. if (!installedServiceNames.contains(serviceName) || serviceName === 'MISC') {
  715. serviceConfig.set('showConfig', true);
  716. }
  717. services.push(serviceConfig);
  718. }
  719. });
  720. services.forEach(function (service) {
  721. var configsByService = [];
  722. var dependencies = {};
  723. var serviceConfigs = [];
  724. configs.forEach(function (config) {
  725. if (config.serviceName === service.get('serviceName')) {
  726. serviceConfigs.push(config);
  727. }
  728. if (config.filename === 'hive-site.xml' && config.name === 'hive.metastore.uris') {
  729. dependencies['hive.metastore.uris'] = config.recommendedValue;
  730. }
  731. if (config.filename === 'zoo.cfg.xml' && config.name === 'clientPort') {
  732. dependencies['clientPort'] = config.recommendedValue;
  733. }
  734. }, this);
  735. serviceConfigs.forEach(function (_config) {
  736. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  737. this.updateHostOverrides(serviceConfigProperty, _config);
  738. if (!storedConfigs && !serviceConfigProperty.get('hasInitialValue')) {
  739. App.ConfigInitializer.initialValue(serviceConfigProperty, localDB, dependencies);
  740. }
  741. serviceConfigProperty.validate();
  742. configsByService.pushObject(serviceConfigProperty);
  743. }, this);
  744. var serviceConfig = App.config.createServiceConfig(service.get('serviceName'));
  745. serviceConfig.set('showConfig', service.get('showConfig'));
  746. serviceConfig.set('configs', configsByService);
  747. if (['addServiceController', 'installerController'].contains(this.get('wizardController.name'))) {
  748. this.addHostNamesToConfigs(serviceConfig, localDB.masterComponentHosts, localDB.slaveComponentHosts);
  749. }
  750. renderedServiceConfigs.push(serviceConfig);
  751. }, this);
  752. return renderedServiceConfigs;
  753. },
  754. /**
  755. * Add host name properties to appropriate categories (for installer and add service)
  756. * @param serviceConfig
  757. * @param masterComponents
  758. * @param slaveComponents
  759. */
  760. addHostNamesToConfigs: function(serviceConfig, masterComponents, slaveComponents) {
  761. serviceConfig.get('configCategories').forEach(function(c) {
  762. if (c.showHost) {
  763. var value = [];
  764. var componentName = c.name;
  765. var masters = masterComponents.filterProperty('component', componentName);
  766. if (masters.length) {
  767. value = masters.mapProperty('hostName');
  768. } else {
  769. var slaves = slaveComponents.findProperty('componentName', componentName);
  770. if (slaves) {
  771. value = slaves.hosts.mapProperty('hostName');
  772. }
  773. }
  774. var stackComponent = App.StackServiceComponent.find(componentName);
  775. var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), componentName, value, stackComponent);
  776. var newConfigName = Em.get(hProperty, 'name');
  777. if (!serviceConfig.get('configs').someProperty('name', newConfigName)) {
  778. serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
  779. }
  780. }
  781. }, this);
  782. },
  783. /**
  784. * create new child configs from overrides, attach them to parent config
  785. * override - value of config, related to particular host(s)
  786. * @param configProperty
  787. * @param storedConfigProperty
  788. */
  789. updateHostOverrides: function (configProperty, storedConfigProperty) {
  790. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  791. var overrides = [];
  792. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  793. // create new override with new value
  794. var newSCP = App.ServiceConfigProperty.create(configProperty);
  795. newSCP.set('value', overrideEntry.value);
  796. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  797. newSCP.set('parentSCP', configProperty);
  798. overrides.pushObject(newSCP);
  799. });
  800. configProperty.set('overrides', overrides);
  801. }
  802. },
  803. /**
  804. * When NameNode HA is enabled some configs based on <code>dfs.nameservices</code> should be changed
  805. * This happens only if service is added AFTER NN HA is enabled
  806. *
  807. * @param {App.ServiceConfig[]} serviceConfigs
  808. * @method _reconfigureServiceOnNnHa
  809. * @private
  810. * @returns {App.ServiceConfig[]}
  811. */
  812. _reconfigureServicesOnNnHa: function (serviceConfigs) {
  813. var selectedServiceNames = this.get('selectedServiceNames');
  814. var nameServiceId = serviceConfigs.findProperty('serviceName', 'HDFS').configs.findProperty('name', 'dfs.nameservices');
  815. Em.A([
  816. {
  817. serviceName: 'HBASE',
  818. configToUpdate: 'hbase.rootdir'
  819. },
  820. {
  821. serviceName: 'ACCUMULO',
  822. configToUpdate: 'instance.volumes'
  823. }
  824. ]).forEach(function (c) {
  825. if (selectedServiceNames.contains(c.serviceName) && nameServiceId) {
  826. var cfg = serviceConfigs.findProperty('serviceName', c.serviceName).configs.findProperty('name', c.configToUpdate),
  827. newValue = cfg.get('value').replace(/\/\/.*:[0-9]+/i, '//' + nameServiceId.get('value'));
  828. cfg.setProperties({
  829. value: newValue,
  830. recommendedValue: newValue
  831. });
  832. }
  833. });
  834. return serviceConfigs;
  835. },
  836. /**
  837. * Select first addable service for <code>addServiceWizard</code>
  838. * Select first service at all in other cases
  839. * @method selectProperService
  840. */
  841. selectProperService: function () {
  842. if (this.get('wizardController.name') === 'addServiceController') {
  843. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  844. } else {
  845. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  846. }
  847. },
  848. /**
  849. * Load config tags
  850. * @return {$.ajax|null}
  851. * @method getConfigTags
  852. */
  853. getConfigTags: function () {
  854. this.set('isAppliedConfigLoaded', false);
  855. return App.ajax.send({
  856. name: 'config.tags',
  857. sender: this,
  858. success: 'getConfigTagsSuccess'
  859. });
  860. },
  861. /**
  862. * Success callback for config tags request
  863. * Updates <code>serviceConfigTags</code> with tags received from server
  864. * @param {object} data
  865. * @method getConfigTagsSuccess
  866. */
  867. getConfigTagsSuccess: function (data) {
  868. var installedServiceSites = [];
  869. App.StackService.find().filterProperty('isInstalled').forEach(function (service) {
  870. if (!service.get('configTypes')) return;
  871. var configTypes = Object.keys(service.get('configTypes'));
  872. installedServiceSites = installedServiceSites.concat(configTypes);
  873. }, this);
  874. installedServiceSites = installedServiceSites.uniq();
  875. var serviceConfigTags = [];
  876. for (var site in data.Clusters.desired_configs) {
  877. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  878. if (installedServiceSites.contains(site) || site == 'cluster-env') {
  879. serviceConfigTags.push({
  880. siteName: site,
  881. tagName: data.Clusters.desired_configs[site].tag,
  882. newTagName: null
  883. });
  884. }
  885. }
  886. }
  887. this.set('serviceConfigTags', serviceConfigTags);
  888. this.set('isAppliedConfigLoaded', true);
  889. },
  890. /**
  891. * set configs actual values from server
  892. * @param configs
  893. * @param configsByTags
  894. * @param installedServiceNames
  895. * @method setInstalledServiceConfigs
  896. */
  897. setInstalledServiceConfigs: function (configs, configsByTags, installedServiceNames) {
  898. var configsMap = {};
  899. configsByTags.forEach(function (configSite) {
  900. configsMap[configSite.type] = configSite.properties || {};
  901. });
  902. var allConfigs = configs.filter(function (_config) {
  903. if ((['MISC'].concat(installedServiceNames).contains(_config.serviceName))) {
  904. var type = _config.filename ? App.config.getConfigTagFromFileName(_config.filename) : null;
  905. var mappedConfigValue = type && configsMap[type] ? configsMap[type][_config.name] : null;
  906. if (Em.isNone(mappedConfigValue)) {
  907. //for now ranger plugin properties are not sending by recommendations if they are missed - it should be added
  908. return _config.serviceName == 'MISC' || /^ranger-/.test(_config.filename);
  909. } else {
  910. if (_config.savedValue != mappedConfigValue) {
  911. _config.savedValue = App.config.formatPropertyValue(_config, mappedConfigValue);
  912. }
  913. _config.value = App.config.formatPropertyValue(_config, mappedConfigValue);
  914. _config.hasInitialValue = true;
  915. delete configsMap[type][_config.name];
  916. return true;
  917. }
  918. } else {
  919. return true;
  920. }
  921. });
  922. //add user properties
  923. Em.keys(configsMap).forEach(function (filename) {
  924. Em.keys(configsMap[filename]).forEach(function (propertyName) {
  925. allConfigs.push(App.config.createDefaultConfig(propertyName,
  926. App.config.getServiceByConfigType(filename) ? App.config.getServiceByConfigType(filename).get('serviceName') : 'MISC',
  927. App.config.getOriginalFileName(filename),
  928. false, {
  929. value: configsMap[filename][propertyName],
  930. savedValue: configsMap[filename][propertyName],
  931. hasInitialValue: true
  932. }));
  933. });
  934. });
  935. return allConfigs;
  936. },
  937. /**
  938. * Add group ids to <code>groupsToDelete</code>
  939. * Also save <code>groupsToDelete</code> to local storage
  940. * @param {Ember.Object[]} groups
  941. * @method setGroupsToDelete
  942. */
  943. setGroupsToDelete: function (groups) {
  944. var groupsToDelete = this.get('groupsToDelete');
  945. groups.forEach(function (group) {
  946. if (group.get('id'))
  947. groupsToDelete.push({
  948. id: group.get('id')
  949. });
  950. });
  951. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  952. },
  953. /**
  954. * Update <code>configGroups</code> with selected service configGroups
  955. * Also set default group to first position
  956. * Update <code>selectedConfigGroup</code> with new default group
  957. * @method selectedServiceObserver
  958. */
  959. selectedServiceObserver: function () {
  960. if (this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  961. var serviceGroups = this.get('selectedService.configGroups');
  962. serviceGroups.forEach(function (item, index, array) {
  963. if (item.isDefault) {
  964. array.unshift(item);
  965. array.splice(index + 1, 1);
  966. }
  967. });
  968. this.set('configGroups', serviceGroups);
  969. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  970. }
  971. }.observes('selectedService.configGroups.@each'),
  972. /**
  973. * load default groups for each service in case of initial load
  974. * @param serviceConfigGroups
  975. * @method loadConfigGroups
  976. */
  977. loadConfigGroups: function (serviceConfigGroups) {
  978. var services = this.get('stepConfigs');
  979. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  980. services.forEach(function (service) {
  981. if (service.get('serviceName') === 'MISC') return;
  982. var serviceRawGroups = serviceConfigGroups.filterProperty('service_name', service.serviceName);
  983. var id = App.ServiceConfigGroup.getParentConfigGroupId(service.get('serviceName'));
  984. if (!serviceRawGroups.length) {
  985. App.store.load(App.ServiceConfigGroup, App.configGroupsMapper.generateDefaultGroup(service.get('serviceName'), hosts));
  986. App.store.commit();
  987. service.set('configGroups', [App.ServiceConfigGroup.find(id)]);
  988. }
  989. else {
  990. App.store.loadMany(App.ServiceConfigGroup, serviceRawGroups);
  991. App.store.commit();
  992. serviceRawGroups.forEach(function(item){
  993. var modelGroup = App.ServiceConfigGroup.find(item.id);
  994. var wrappedProperties = [];
  995. item.properties.forEach(function (propertyData) {
  996. var parentSCP = service.configs.filterProperty('filename', propertyData.filename).findProperty('name', propertyData.name);
  997. var overriddenSCP = App.ServiceConfigProperty.create(parentSCP);
  998. overriddenSCP.set('isOriginalSCP', false);
  999. overriddenSCP.set('parentSCP', parentSCP);
  1000. overriddenSCP.set('group', modelGroup);
  1001. overriddenSCP.setProperties(propertyData);
  1002. wrappedProperties.pushObject(App.ServiceConfigProperty.create(overriddenSCP));
  1003. });
  1004. modelGroup.set('properties', wrappedProperties);
  1005. }, this);
  1006. service.set('configGroups', App.ServiceConfigGroup.find().filterProperty('serviceName', service.get('serviceName')));
  1007. }
  1008. });
  1009. },
  1010. /**
  1011. * Click-handler on config-group to make it selected
  1012. * @param {object} event
  1013. * @method selectConfigGroup
  1014. */
  1015. selectConfigGroup: function (event) {
  1016. this.set('selectedConfigGroup', event.context);
  1017. },
  1018. /**
  1019. * Rebuild list of configs switch of config group:
  1020. * on default - display all configs from default group and configs from non-default groups as disabled
  1021. * on non-default - display all from default group as disabled and configs from selected non-default group
  1022. * @method switchConfigGroupConfigs
  1023. */
  1024. switchConfigGroupConfigs: function () {
  1025. var serviceConfigs = this.get('selectedService.configs'),
  1026. selectedGroup = this.get('selectedConfigGroup'),
  1027. overrideToAdd = this.get('overrideToAdd'),
  1028. overrides = [];
  1029. if (!selectedGroup) return;
  1030. var displayedConfigGroups = this._getDisplayedConfigGroups();
  1031. displayedConfigGroups.forEach(function (group) {
  1032. overrides.pushObjects(group.get('properties'));
  1033. });
  1034. serviceConfigs.forEach(function (config) {
  1035. this._setEditableValue(config);
  1036. this._setOverrides(config, overrides);
  1037. }, this);
  1038. }.observes('selectedConfigGroup'),
  1039. /**
  1040. * Get list of config groups to display
  1041. * Returns empty array if no <code>selectedConfigGroup</code>
  1042. * @return {Array}
  1043. * @method _getDisplayedConfigGroups
  1044. */
  1045. _getDisplayedConfigGroups: function () {
  1046. var selectedGroup = this.get('selectedConfigGroup');
  1047. if (!selectedGroup) return [];
  1048. return (selectedGroup.get('isDefault')) ?
  1049. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  1050. [this.get('selectedConfigGroup')];
  1051. },
  1052. /**
  1053. * Set <code>isEditable</code> property to <code>config</code>
  1054. * @param {Ember.Object} config
  1055. * @return {Ember.Object} updated config-object
  1056. * @method _setEditableValue
  1057. */
  1058. _setEditableValue: function (config) {
  1059. var selectedGroup = this.get('selectedConfigGroup');
  1060. if (!selectedGroup) return config;
  1061. var isEditable = config.get('isEditable'),
  1062. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  1063. if (isServiceInstalled) {
  1064. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  1065. }
  1066. else {
  1067. isEditable = selectedGroup.get('isDefault');
  1068. }
  1069. if (config.get('group')) {
  1070. isEditable = config.get('group.name') == this.get('selectedConfigGroup.name');
  1071. }
  1072. config.set('isEditable', isEditable);
  1073. return config;
  1074. },
  1075. /**
  1076. * Set <code>overrides</code> property to <code>config</code>
  1077. * @param {Ember.Object} config
  1078. * @param {Ember.Enumerable} overrides
  1079. * @returns {Ember.Object}
  1080. * @method _setOverrides
  1081. */
  1082. _setOverrides: function (config, overrides) {
  1083. var selectedGroup = this.get('selectedConfigGroup'),
  1084. overrideToAdd = this.get('overrideToAdd'),
  1085. configOverrides = overrides.filterProperty('name', config.get('name'));
  1086. if (!selectedGroup) return config;
  1087. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  1088. var valueForOverride = (config.get('widget') || config.get('displayType') == 'checkbox') ? config.get('value') : '';
  1089. var group = this.get('selectedService.configGroups').findProperty('name', selectedGroup.get('name'));
  1090. var newSCP = App.config.createOverride(config, {value: valueForOverride, recommendedValue: valueForOverride}, group);
  1091. configOverrides.push(newSCP);
  1092. group.get('properties').pushObject(newSCP);
  1093. this.set('overrideToAdd', null);
  1094. }
  1095. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  1096. configOverrides.setEach('parentSCP', config);
  1097. config.set('overrides', configOverrides);
  1098. return config;
  1099. },
  1100. /**
  1101. * @method manageConfigurationGroup
  1102. */
  1103. manageConfigurationGroup: function () {
  1104. App.router.get('manageConfigGroupsController').manageConfigurationGroups(this);
  1105. },
  1106. /**
  1107. * Make some configs visible depending on active services
  1108. * @method activateSpecialConfigs
  1109. */
  1110. activateSpecialConfigs: function () {
  1111. if (this.get('addMiscTabToPage')) {
  1112. var serviceToShow = this.get('selectedServiceNames').concat('MISC');
  1113. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  1114. if (this.get('wizardController.name') == "addServiceController") {
  1115. miscConfigs.findProperty('name', 'smokeuser').set('isEditable', false);
  1116. miscConfigs.findProperty('name', 'user_group').set('isEditable', false);
  1117. if (this.get('content.smokeuser')) {
  1118. miscConfigs.findProperty('name', 'smokeuser').set('value', this.get('content.smokeuser'));
  1119. }
  1120. if (this.get('content.group')) {
  1121. miscConfigs.findProperty('name', 'user_group').set('value', this.get('content.group'));
  1122. }
  1123. }
  1124. }
  1125. var wizardController = this.get('wizardController');
  1126. if (wizardController.get('name') === "kerberosWizardController") {
  1127. var kerberosConfigs = this.get('stepConfigs').findProperty('serviceName', 'KERBEROS').configs;
  1128. kerberosConfigs.findProperty('name', 'kdc_type').set('value', wizardController.get('content.kerberosOption'));
  1129. }
  1130. },
  1131. /**
  1132. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1133. * @return {$.ajax|null}
  1134. * @method checkMySQLHost
  1135. */
  1136. checkMySQLHost: function () {
  1137. // get ambari database type and hostname
  1138. return App.ajax.send({
  1139. name: 'ambari.service',
  1140. data: {
  1141. fields : "?fields=hostComponents/RootServiceHostComponents/properties/server.jdbc.database_name,hostComponents/RootServiceHostComponents/properties/server.jdbc.url"
  1142. },
  1143. sender: this,
  1144. success: 'getAmbariDatabaseSuccess'
  1145. });
  1146. },
  1147. /**
  1148. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  1149. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1150. * @param {object} data
  1151. * @method getAmbariDatabaseSuccess
  1152. */
  1153. getAmbariDatabaseSuccess: function (data) {
  1154. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_hostname').value;
  1155. var ambariServiceHostComponents = data.hostComponents;
  1156. if (ambariServiceHostComponents.length) {
  1157. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  1158. this.set('mySQLServerConflict', ambariDBInfo.contains('mysql') && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  1159. } else {
  1160. this.set('mySQLServerConflict', false);
  1161. }
  1162. },
  1163. /**
  1164. * Check if new MySql database was chosen for Hive service
  1165. * and it is not located on the same host as Ambari server
  1166. * that using MySql database too.
  1167. *
  1168. * @method resolveHiveMysqlDatabase
  1169. **/
  1170. resolveHiveMysqlDatabase: function () {
  1171. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  1172. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  1173. this.moveNext();
  1174. return;
  1175. }
  1176. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  1177. if (hiveDBType == 'New MySQL Database') {
  1178. var self = this;
  1179. return this.checkMySQLHost().done(function () {
  1180. self.mySQLWarningHandler();
  1181. });
  1182. }
  1183. else {
  1184. this.moveNext();
  1185. }
  1186. },
  1187. /**
  1188. * Show warning popup about MySQL-DB issues (on post-submit)
  1189. *
  1190. * @returns {*}
  1191. * @method mySQLWarningHandler
  1192. */
  1193. mySQLWarningHandler: function () {
  1194. var self = this;
  1195. if (this.get('mySQLServerConflict')) {
  1196. // error popup before you can proceed
  1197. return App.ModalPopup.show({
  1198. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  1199. body:Em.I18n.t('installer.step7.popup.mySQLWarning.body'),
  1200. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  1201. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  1202. encodeBody: false,
  1203. onPrimary: function () {
  1204. this._super();
  1205. self.set('submitButtonClicked', false);
  1206. },
  1207. onSecondary: function () {
  1208. var parent = this;
  1209. return App.ModalPopup.show({
  1210. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  1211. body: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'),
  1212. onPrimary: function () {
  1213. this.hide();
  1214. parent.hide();
  1215. // go back to step 5: assign masters and disable default navigation warning
  1216. if ('installerController' === self.get('content.controllerName')) {
  1217. App.router.get('installerController').gotoStep(5, true);
  1218. }
  1219. else {
  1220. if ('addServiceController' === self.get('content.controllerName')) {
  1221. App.router.get('addServiceController').gotoStep(2, true);
  1222. }
  1223. }
  1224. },
  1225. onSecondary: function () {
  1226. this._super();
  1227. self.set('submitButtonClicked', false);
  1228. }
  1229. });
  1230. }
  1231. });
  1232. }
  1233. else {
  1234. return this.moveNext();
  1235. }
  1236. },
  1237. checkDatabaseConnectionTest: function () {
  1238. var deferred = $.Deferred();
  1239. var configMap = [
  1240. {
  1241. serviceName: 'OOZIE',
  1242. ignored: [Em.I18n.t('installer.step7.oozie.database.new')]
  1243. },
  1244. {
  1245. serviceName: 'HIVE',
  1246. ignored: [Em.I18n.t('installer.step7.hive.database.new.mysql'), Em.I18n.t('installer.step7.hive.database.new.postgres')]
  1247. }
  1248. ];
  1249. configMap.forEach(function (config) {
  1250. var isConnectionNotTested = false;
  1251. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1252. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1253. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1254. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1255. if (!config.ignored.contains(serviceDatabase)) {
  1256. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1257. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1258. isConnectionNotTested = true;
  1259. } else {
  1260. for (var key in filledProperties) {
  1261. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1262. isConnectionNotTested = true;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. config.isCheckIgnored = isConnectionNotTested;
  1268. }, this);
  1269. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1270. if (ignoredServices.length) {
  1271. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function (serviceName) {
  1272. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1273. }, this);
  1274. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1275. }
  1276. else {
  1277. deferred.resolve();
  1278. }
  1279. return deferred;
  1280. },
  1281. showChangesWarningPopup: function(goToNextStep) {
  1282. return App.ModalPopup.show({
  1283. header: Em.I18n.t('common.warning'),
  1284. body: Em.I18n.t('services.service.config.exitChangesPopup.body'),
  1285. secondary: Em.I18n.t('common.cancel'),
  1286. primary: Em.I18n.t('yes'),
  1287. onPrimary: function () {
  1288. if (goToNextStep) {
  1289. goToNextStep();
  1290. this.hide();
  1291. }
  1292. },
  1293. onSecondary: function () {
  1294. this.hide();
  1295. }
  1296. });
  1297. },
  1298. showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
  1299. var self = this;
  1300. return App.ModalPopup.show({
  1301. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1302. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1303. secondary: Em.I18n.t('common.cancel'),
  1304. primary: Em.I18n.t('common.proceedAnyway'),
  1305. onPrimary: function () {
  1306. deferred.resolve();
  1307. this._super();
  1308. },
  1309. onSecondary: function () {
  1310. self.set('submitButtonClicked', false);
  1311. deferred.reject();
  1312. this._super();
  1313. }
  1314. });
  1315. },
  1316. showOozieDerbyWarningPopup: function(callback) {
  1317. var self = this;
  1318. if (this.get('selectedServiceNames').contains('OOZIE')) {
  1319. var databaseType = Em.getWithDefault(this.findConfigProperty('oozie_database', 'oozie-env.xml') || {}, 'value', '');
  1320. if (databaseType == Em.I18n.t('installer.step7.oozie.database.new')) {
  1321. return App.ModalPopup.show({
  1322. header: Em.I18n.t('common.warning'),
  1323. body: Em.I18n.t('installer.step7.popup.oozie.derby.warning'),
  1324. secondary: Em.I18n.t('common.cancel'),
  1325. primary: Em.I18n.t('common.proceedAnyway'),
  1326. onPrimary: function() {
  1327. this.hide();
  1328. if (callback) {
  1329. callback();
  1330. }
  1331. },
  1332. onSecondary: function() {
  1333. self.set('submitButtonClicked', false);
  1334. this.hide();
  1335. },
  1336. onClose: function() {
  1337. this.onSecondary();
  1338. }
  1339. });
  1340. }
  1341. }
  1342. if (callback) {
  1343. callback();
  1344. }
  1345. return false;
  1346. },
  1347. /**
  1348. * Proceed to the next step
  1349. **/
  1350. moveNext: function () {
  1351. App.router.send('next');
  1352. this.set('submitButtonClicked', false);
  1353. },
  1354. /**
  1355. * Click-handler on Next button
  1356. * Disable "Submit"-button while server-side processes are running
  1357. * @method submit
  1358. */
  1359. submit: function () {
  1360. if (this.get('isSubmitDisabled')) {
  1361. return false;
  1362. }
  1363. var preInstallChecksController = App.router.get('preInstallChecksController');
  1364. if (this.get('supportsPreInstallChecks')) {
  1365. if (preInstallChecksController.get('preInstallChecksWhereRun')) {
  1366. return this.postSubmit();
  1367. }
  1368. return preInstallChecksController.notRunChecksWarnPopup(this.postSubmit.bind(this));
  1369. }
  1370. return this.postSubmit();
  1371. },
  1372. postSubmit: function () {
  1373. var self = this;
  1374. this.set('submitButtonClicked', true);
  1375. this.serverSideValidation().done(function() {
  1376. self.serverSideValidationCallback();
  1377. })
  1378. .fail(function (value) {
  1379. if ("invalid_configs" == value) {
  1380. self.set('submitButtonClicked', false);
  1381. } else {
  1382. // Failed due to validation mechanism failure.
  1383. // Should proceed with other checks
  1384. self.serverSideValidationCallback();
  1385. }
  1386. });
  1387. },
  1388. /**
  1389. * @method serverSideValidationCallback
  1390. */
  1391. serverSideValidationCallback: function() {
  1392. var self = this;
  1393. this.showOozieDerbyWarningPopup(function() {
  1394. self.checkDatabaseConnectionTest().done(function () {
  1395. self.resolveHiveMysqlDatabase();
  1396. });
  1397. });
  1398. },
  1399. toggleIssuesFilter: function () {
  1400. this.get('filterColumns').findProperty('attributeName', 'hasIssues').toggleProperty('selected');
  1401. // if currently selected service does not have issue, jump to the first service with issue.
  1402. if (this.get('selectedService.errorCount') == 0 )
  1403. {
  1404. var errorServices = this.get('stepConfigs').filterProperty('errorCount');
  1405. if (errorServices.length > 0)
  1406. {
  1407. var service = errorServices[0];
  1408. this.set('selectedService', service);
  1409. this.propertyDidChange('selectedServiceNameTrigger');
  1410. $('a[href="#' + service.serviceName + '"]').tab('show');
  1411. }
  1412. }
  1413. }
  1414. });