step7_controller.js 50 KB

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