step7_controller.js 54 KB

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