step7_controller.js 49 KB

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