step7_controller.js 48 KB

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