step7_controller.js 58 KB

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