step7_controller.js 54 KB

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