step7_controller.js 49 KB

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