step7_controller.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381
  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. hosts = this.get('wizardController').getDBProperty('hosts');
  628. gangliaHostId = this.get('wizardController').getDBProperty('masterComponentHosts').findProperty('component', 'GANGLIA_SERVER').host_id;
  629. for (var hostName in hosts) {
  630. if (hosts[hostName].id == gangliaHostId) gangliaServerHost = hosts[hostName].name;
  631. }
  632. dependentConfigs.forEach(function (configName) {
  633. var config = configs.findProperty('name', configName);
  634. if (!Em.isNone(config.value)) {
  635. var replaceStr = config.value.match(/.jar=host[^,]+/)[0];
  636. var replaceWith = replaceStr.slice(0, replaceStr.lastIndexOf('=') - replaceStr.length + 1) + gangliaServerHost;
  637. config.value = config.defaultValue = config.value.replace(replaceStr, replaceWith);
  638. }
  639. config.forceUpdate = true;
  640. }, this);
  641. }
  642. },
  643. /**
  644. * On load function
  645. * @method loadStep
  646. */
  647. loadStep: function () {
  648. console.log("TRACE: Loading step7: Configure Services");
  649. if (!this.get('isConfigsLoaded')) {
  650. return;
  651. }
  652. this.clearStep();
  653. var self = this;
  654. //STEP 1: Load advanced configs
  655. var advancedConfigs = this.get('content.advancedServiceConfig');
  656. //STEP 2: Load on-site configs by service from local DB
  657. var storedConfigs = this.get('content.serviceConfigProperties');
  658. //STEP 3: Merge pre-defined configs with loaded on-site configs
  659. var configs = App.config.mergePreDefinedWithStored(
  660. storedConfigs,
  661. advancedConfigs,
  662. this.get('selectedServiceNames').concat(this.get('installedServiceNames'))
  663. );
  664. App.config.setPreDefinedServiceConfigs();
  665. //STEP 4: Add advanced configs
  666. App.config.addAdvancedConfigs(configs, advancedConfigs);
  667. //STEP 5: Add custom configs
  668. App.config.addCustomConfigs(configs);
  669. //put properties from capacity-scheduler.xml into one config with textarea view
  670. if (this.get('allSelectedServiceNames').contains('YARN') && !App.get('supports.capacitySchedulerUi')) {
  671. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  672. }
  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('STORM') || this.get('installedServiceNames').contains('STORM')) {
  685. this.resolveServiceDependencyConfigs('STORM', configs);
  686. }
  687. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  688. var self = this;
  689. this.loadServerSideConfigsRecommendations().always(function() {
  690. self.set('isRecommendedLoaded', true);
  691. self.setStepConfigs(configs, storedConfigs);
  692. self.checkHostOverrideInstaller();
  693. self.activateSpecialConfigs();
  694. self.selectProperService();
  695. if (self.get('content.skipConfigStep')) {
  696. App.router.send('next');
  697. }
  698. });
  699. },
  700. /**
  701. * If <code>App.supports.hostOverridesInstaller</code> is enabled should load config groups
  702. * and (if some services are already installed) load config groups for installed services
  703. * @method checkHostOverrideInstaller
  704. */
  705. checkHostOverrideInstaller: function () {
  706. if (App.get('supports.hostOverridesInstaller')) {
  707. this.loadConfigGroups(this.get('content.configGroups'));
  708. if (this.get('installedServiceNames').length > 0) {
  709. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  710. }
  711. }
  712. },
  713. /**
  714. * Set init <code>stepConfigs</code> value
  715. * Set <code>selected</code> for addable services if addServiceController is used
  716. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  717. * @param {Ember.Object[]} configs
  718. * @param {Ember.Object[]} storedConfigs
  719. * @method setStepConfigs
  720. */
  721. setStepConfigs: function (configs, storedConfigs) {
  722. var localDB = {
  723. hosts: this.get('wizardController.content.hosts'),
  724. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  725. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  726. };
  727. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB, this.get('recommendationsConfigs'));
  728. if (this.get('wizardController.name') === 'addServiceController') {
  729. serviceConfigs.setEach('showConfig', true);
  730. serviceConfigs.setEach('selected', false);
  731. this.get('selectedServiceNames').forEach(function (serviceName) {
  732. if (!serviceConfigs.findProperty('serviceName', serviceName)) return;
  733. var selectedService = serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  734. // add secure configs when security is enabled
  735. if(this.get('securityEnabled')) {
  736. this.addSecureConfigs(selectedService, serviceName) ;
  737. }
  738. }, this);
  739. // Remove SNameNode if HA is enabled
  740. if (App.get('isHaEnabled')) {
  741. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  742. var removedConfigs = c.filterProperty('category', 'SECONDARY_NAMENODE');
  743. removedConfigs.map(function (config) {
  744. c = c.without(config);
  745. });
  746. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  747. }
  748. }
  749. this.set('stepConfigs', serviceConfigs);
  750. },
  751. /**
  752. *
  753. * @param selectedService
  754. * @param serviceName
  755. */
  756. addSecureConfigs: function(selectedService, serviceName) {
  757. var secureService = this.get('secureServices').findProperty('serviceName', serviceName);
  758. if (!secureService) {
  759. return;
  760. }
  761. secureService.configCategories.forEach(function (category) {
  762. selectedService.get('configCategories').push(category);
  763. });
  764. secureService.configs.forEach(function (conf) {
  765. conf.isVisible = !conf.displayType.contains('masterHost') && !conf.displayType.contains('slaveHost');
  766. var config = App.ServiceConfigProperty.create(conf);
  767. selectedService.get('configs').push(config);
  768. }, this);
  769. },
  770. /**
  771. * Select first addable service for <code>addServiceWizard</code>
  772. * Select first service at all in other cases
  773. * @method selectProperService
  774. */
  775. selectProperService: function () {
  776. if (this.get('wizardController.name') === 'addServiceController') {
  777. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  778. } else {
  779. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  780. }
  781. },
  782. /**
  783. * Load config tags
  784. * @return {$.ajax|null}
  785. * @method getConfigTags
  786. */
  787. getConfigTags: function () {
  788. this.set('isAppliedConfigLoaded', false);
  789. return App.ajax.send({
  790. name: 'config.tags',
  791. sender: this,
  792. success: 'getConfigTagsSuccess'
  793. });
  794. },
  795. /**
  796. * Success callback for config tags request
  797. * Updates <code>serviceConfigTags</code> with tags received from server
  798. * @param {object} data
  799. * @method getConfigTagsSuccess
  800. */
  801. getConfigTagsSuccess: function (data) {
  802. var installedServiceSites = [];
  803. App.StackService.find().filterProperty('isInstalled').forEach(function (service) {
  804. if (!service.get('configTypes')) return;
  805. var configTypes = Object.keys(service.get('configTypes'));
  806. installedServiceSites = installedServiceSites.concat(configTypes);
  807. }, this);
  808. installedServiceSites = installedServiceSites.uniq();
  809. var serviceConfigTags = [];
  810. for (var site in data.Clusters.desired_configs) {
  811. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  812. if (installedServiceSites.contains(site)) {
  813. serviceConfigTags.push({
  814. siteName: site,
  815. tagName: data.Clusters.desired_configs[site].tag,
  816. newTagName: null
  817. });
  818. }
  819. }
  820. }
  821. this.set('serviceConfigTags', serviceConfigTags);
  822. this.set('isAppliedConfigLoaded', true);
  823. },
  824. /**
  825. * set configs actual values from server
  826. * @param serviceConfigTags
  827. * @param configs
  828. * @param configsByTags
  829. * @param installedServiceNames
  830. * @method setInstalledServiceConfigs
  831. */
  832. setInstalledServiceConfigs: function (serviceConfigTags, configs, configsByTags, installedServiceNames) {
  833. var configsMap = {};
  834. var configTypeMap = {};
  835. var configMixin = App.get('config');
  836. var self = this;
  837. configsByTags.forEach(function (configSite) {
  838. $.extend(configsMap, configSite.properties);
  839. for (var name in configSite.properties) {
  840. configTypeMap[name] = configSite.type;
  841. }
  842. });
  843. configs.forEach(function (_config) {
  844. var nonServiceTab = require('data/service_configs');
  845. if (!Em.isNone(configsMap[_config.name]) && ((installedServiceNames && installedServiceNames.contains(_config.serviceName) || nonServiceTab.someProperty('serviceName',_config.serviceName))) ) {
  846. // prevent overriding already edited properties
  847. if (_config.defaultValue != configsMap[_config.name])
  848. _config.value = configsMap[_config.name];
  849. _config.defaultValue = configsMap[_config.name];
  850. _config.hasInitialValue = true;
  851. App.config.handleSpecialProperties(_config);
  852. delete configsMap[_config.name];
  853. }
  854. });
  855. self.setServiceDatabaseConfigs(configs);
  856. //add user properties
  857. for (var name in configsMap) {
  858. configs.push(configMixin.addUserProperty({
  859. id: 'site property',
  860. name: name,
  861. serviceName: configMixin.getServiceNameByConfigType(configTypeMap[name]),
  862. value: configsMap[name],
  863. defaultValue: configsMap[name],
  864. filename: (configMixin.get('filenameExceptions').contains(configTypeMap[name])) ? configTypeMap[name] : configTypeMap[name] + '.xml',
  865. category: 'Advanced',
  866. hasInitialValue: true,
  867. isUserProperty: true,
  868. isOverridable: true,
  869. overrides: [],
  870. isRequired: true,
  871. isVisible: true,
  872. showLabel: true
  873. }, false, []));
  874. }
  875. },
  876. /**
  877. * Check if Oozie or Hive use existing database then need
  878. * to restore missed properties
  879. *
  880. * @param {Object[]} configs
  881. **/
  882. setServiceDatabaseConfigs: function(configs) {
  883. var serviceNames = this.get('installedServiceNames').filter(function(serviceName) {
  884. return ['OOZIE', 'HIVE'].contains(serviceName);
  885. });
  886. serviceNames.forEach(function(serviceName) {
  887. var dbTypeConfig = configs.findProperty('name', serviceName.toLowerCase() + '_database');
  888. if (!/existing/gi.test(dbTypeConfig.value)) return;
  889. var dbHostName = serviceName.toLowerCase() + '_hostname';
  890. var database = dbTypeConfig.value.match(/MySQL|PostgreSQL|Oracle|Derby/gi)[0];
  891. var existingDBConfig = configs.findProperty('name', serviceName.toLowerCase() + '_existing_' + database.toLowerCase() + '_host');
  892. if (!existingDBConfig.value)
  893. existingDBConfig.value = existingDBConfig.defaultValue = configs.findProperty('name', dbHostName).value;
  894. }, this);
  895. },
  896. /**
  897. * Add group ids to <code>groupsToDelete</code>
  898. * Also save <code>groupsToDelete</code> to local storage
  899. * @param {Ember.Object[]} groups
  900. * @method setGroupsToDelete
  901. */
  902. setGroupsToDelete: function (groups) {
  903. var groupsToDelete = this.get('groupsToDelete');
  904. groups.forEach(function (group) {
  905. if (group.get('id'))
  906. groupsToDelete.push({
  907. id: group.get('id')
  908. });
  909. });
  910. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  911. },
  912. /**
  913. * Update <code>configGroups</code> with selected service configGroups
  914. * Also set default group to first position
  915. * Update <code>selectedConfigGroup</code> with new default group
  916. * @method selectedServiceObserver
  917. */
  918. selectedServiceObserver: function () {
  919. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  920. var serviceGroups = this.get('selectedService.configGroups');
  921. serviceGroups.forEach(function (item, index, array) {
  922. if (item.isDefault) {
  923. array.unshift(item);
  924. array.splice(index + 1, 1);
  925. }
  926. });
  927. this.set('configGroups', serviceGroups);
  928. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  929. }
  930. }.observes('selectedService.configGroups.@each'),
  931. /**
  932. * load default groups for each service in case of initial load
  933. * @param serviceConfigGroups
  934. * @method loadConfigGroups
  935. */
  936. loadConfigGroups: function (serviceConfigGroups) {
  937. var services = this.get('stepConfigs');
  938. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  939. var manageCGController = App.router.get('manageConfigGroupsController');
  940. this.setupManageConfigGroupsController();
  941. services.forEach(function (service) {
  942. if (service.get('serviceName') === 'MISC') return;
  943. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  944. if (!serviceRawGroups.length) {
  945. service.set('configGroups', [
  946. App.ConfigGroup.create({
  947. name: service.displayName + " Default",
  948. description: "Default cluster level " + service.serviceName + " configuration",
  949. isDefault: true,
  950. hosts: Em.copy(hosts),
  951. publicHosts: Em.copy(manageCGController.hostsToPublic(hosts)),
  952. service: Em.Object.create({
  953. id: service.serviceName
  954. }),
  955. serviceName: service.serviceName
  956. })
  957. ]);
  958. }
  959. else {
  960. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  961. var serviceGroups = service.get('configGroups');
  962. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  963. var readyGroup = App.ConfigGroup.create(configGroup);
  964. var wrappedProperties = [];
  965. readyGroup.get('properties').forEach(function (propertyData) {
  966. var parentSCP = service.configs.filterProperty('filename', propertyData.filename).findProperty('name', propertyData.name);
  967. var overriddenSCP = App.ServiceConfigProperty.create(parentSCP);
  968. overriddenSCP.set('isOriginalSCP', false);
  969. overriddenSCP.set('parentSCP', parentSCP);
  970. overriddenSCP.set('group', readyGroup);
  971. overriddenSCP.setProperties(propertyData);
  972. wrappedProperties.pushObject(App.ServiceConfigProperty.create(overriddenSCP));
  973. });
  974. wrappedProperties.setEach('group', readyGroup);
  975. readyGroup.set('properties', wrappedProperties);
  976. readyGroup.set('parentConfigGroup', defaultGroup);
  977. serviceGroups.pushObject(readyGroup);
  978. });
  979. defaultGroup.set('childConfigGroups', serviceGroups);
  980. serviceGroups.pushObject(defaultGroup);
  981. }
  982. });
  983. },
  984. setupManageConfigGroupsController: function() {
  985. var manageCGController = App.router.get('manageConfigGroupsController');
  986. manageCGController.set('isInstaller', true);
  987. manageCGController.set('isAddService', this.get('wizardController.name') === 'addServiceController');
  988. },
  989. /**
  990. * Click-handler on config-group to make it selected
  991. * @param {object} event
  992. * @method selectConfigGroup
  993. */
  994. selectConfigGroup: function (event) {
  995. this.set('selectedConfigGroup', event.context);
  996. },
  997. /**
  998. * Rebuild list of configs switch of config group:
  999. * on default - display all configs from default group and configs from non-default groups as disabled
  1000. * on non-default - display all from default group as disabled and configs from selected non-default group
  1001. * @method switchConfigGroupConfigs
  1002. */
  1003. switchConfigGroupConfigs: function () {
  1004. var serviceConfigs = this.get('selectedService.configs'),
  1005. selectedGroup = this.get('selectedConfigGroup'),
  1006. overrideToAdd = this.get('overrideToAdd'),
  1007. overrides = [];
  1008. if (!selectedGroup) return;
  1009. var displayedConfigGroups = this._getDisplayedConfigGroups();
  1010. displayedConfigGroups.forEach(function (group) {
  1011. overrides.pushObjects(group.get('properties'));
  1012. });
  1013. serviceConfigs.forEach(function (config) {
  1014. this._setEditableValue(config);
  1015. this._setOverrides(config, overrides);
  1016. }, this);
  1017. }.observes('selectedConfigGroup'),
  1018. /**
  1019. * Get list of config groups to display
  1020. * Returns empty array if no <code>selectedConfigGroup</code>
  1021. * @return {Array}
  1022. * @method _getDisplayedConfigGroups
  1023. */
  1024. _getDisplayedConfigGroups: function () {
  1025. var selectedGroup = this.get('selectedConfigGroup');
  1026. if (!selectedGroup) return [];
  1027. return (selectedGroup.get('isDefault')) ?
  1028. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  1029. [this.get('selectedConfigGroup')];
  1030. },
  1031. /**
  1032. * Set <code>isEditable</code> property to <code>config</code>
  1033. * @param {Ember.Object} config
  1034. * @return {Ember.Object} updated config-object
  1035. * @method _setEditableValue
  1036. */
  1037. _setEditableValue: function (config) {
  1038. var selectedGroup = this.get('selectedConfigGroup');
  1039. if (!selectedGroup) return config;
  1040. var isEditable = config.get('isEditable'),
  1041. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  1042. if (isServiceInstalled) {
  1043. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  1044. }
  1045. else {
  1046. isEditable = selectedGroup.get('isDefault');
  1047. }
  1048. if (config.get('group')) {
  1049. isEditable = config.get('group.name') == this.get('selectedConfigGroup.name');
  1050. }
  1051. config.set('isEditable', isEditable);
  1052. return config;
  1053. },
  1054. /**
  1055. * Set <code>overrides</code> property to <code>config</code>
  1056. * @param {Ember.Object} config
  1057. * @param {Ember.Enumerable} overrides
  1058. * @returns {Ember.Object}
  1059. * @method _setOverrides
  1060. */
  1061. _setOverrides: function (config, overrides) {
  1062. var selectedGroup = this.get('selectedConfigGroup'),
  1063. overrideToAdd = this.get('overrideToAdd'),
  1064. configOverrides = overrides.filterProperty('name', config.get('name'));
  1065. if (!selectedGroup) return config;
  1066. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  1067. configOverrides.push(this.addOverrideProperty(config));
  1068. this.set('overrideToAdd', null);
  1069. }
  1070. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  1071. configOverrides.setEach('parentSCP', config);
  1072. config.set('overrides', configOverrides);
  1073. return config;
  1074. },
  1075. /**
  1076. * create overriden property and push it into Config group
  1077. * @param {App.ServiceConfigProperty} serviceConfigProperty
  1078. * @return {App.ServiceConfigProperty}
  1079. * @method addOverrideProperty
  1080. */
  1081. addOverrideProperty: function (serviceConfigProperty) {
  1082. var overrides = serviceConfigProperty.get('overrides') || [];
  1083. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  1084. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  1085. newSCP.set('group', group);
  1086. newSCP.set('value', '');
  1087. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  1088. newSCP.set('parentSCP', serviceConfigProperty);
  1089. newSCP.set('isEditable', true);
  1090. group.get('properties').pushObject(newSCP);
  1091. overrides.pushObject(newSCP);
  1092. return newSCP;
  1093. },
  1094. /**
  1095. * @method manageConfigurationGroup
  1096. */
  1097. manageConfigurationGroup: function () {
  1098. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  1099. },
  1100. /**
  1101. * Make some configs visible depending on active services
  1102. * @method activateSpecialConfigs
  1103. */
  1104. activateSpecialConfigs: function () {
  1105. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  1106. App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  1107. },
  1108. /**
  1109. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1110. * @return {$.ajax|null}
  1111. * @method checkMySQLHost
  1112. */
  1113. checkMySQLHost: function () {
  1114. // get ambari database type and hostname
  1115. return App.ajax.send({
  1116. name: 'config.ambari.database.info',
  1117. sender: this,
  1118. success: 'getAmbariDatabaseSuccess'
  1119. });
  1120. },
  1121. /**
  1122. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  1123. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1124. * @param {object} data
  1125. * @method getAmbariDatabaseSuccess
  1126. */
  1127. getAmbariDatabaseSuccess: function (data) {
  1128. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host').value;
  1129. var ambariServiceHostComponents = data.hostComponents;
  1130. if (!!ambariServiceHostComponents.length) {
  1131. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  1132. this.set('mySQLServerConflict', ambariDBInfo.indexOf('mysql') > 0 && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  1133. } else {
  1134. this.set('mySQLServerConflict', false);
  1135. }
  1136. },
  1137. /**
  1138. * Check if new MySql database was chosen for Hive service
  1139. * and it is not located on the same host as Ambari server
  1140. * that using MySql database too.
  1141. *
  1142. * @method resolveHiveMysqlDatabase
  1143. **/
  1144. resolveHiveMysqlDatabase: function () {
  1145. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  1146. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  1147. this.moveNext();
  1148. return;
  1149. }
  1150. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  1151. if (hiveDBType == 'New MySQL Database') {
  1152. var self = this;
  1153. this.checkMySQLHost().done(function () {
  1154. if (self.get('mySQLServerConflict')) {
  1155. // error popup before you can proceed
  1156. return App.ModalPopup.show({
  1157. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  1158. bodyClass: Ember.View.extend({
  1159. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.body'))
  1160. }),
  1161. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  1162. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  1163. onSecondary: function () {
  1164. var parent = this;
  1165. return App.ModalPopup.show({
  1166. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  1167. bodyClass: Ember.View.extend({
  1168. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'))
  1169. }),
  1170. onPrimary: function () {
  1171. this.hide();
  1172. parent.hide();
  1173. // go back to step 5: assign masters and disable default navigation warning
  1174. App.router.get('installerController').gotoStep(5, true);
  1175. }
  1176. });
  1177. }
  1178. });
  1179. } else {
  1180. self.moveNext();
  1181. }
  1182. });
  1183. } else {
  1184. this.moveNext();
  1185. }
  1186. },
  1187. checkDatabaseConnectionTest: function () {
  1188. var deferred = $.Deferred();
  1189. if (!App.supports.databaseConnection) {
  1190. deferred.resolve();
  1191. return deferred;
  1192. }
  1193. var configMap = [
  1194. {
  1195. serviceName: 'OOZIE',
  1196. ignored: Em.I18n.t('installer.step7.oozie.database.new')
  1197. },
  1198. {
  1199. serviceName: 'HIVE',
  1200. ignored: Em.I18n.t('installer.step7.hive.database.new')
  1201. }
  1202. ];
  1203. configMap.forEach(function (config) {
  1204. var isConnectionNotTested = false;
  1205. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1206. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1207. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1208. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1209. if (serviceDatabase !== config.ignored) {
  1210. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1211. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1212. isConnectionNotTested = true;
  1213. } else {
  1214. for (var key in filledProperties) {
  1215. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1216. isConnectionNotTested = true;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. config.isCheckIgnored = isConnectionNotTested;
  1222. }, this);
  1223. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1224. if (ignoredServices.length) {
  1225. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function (serviceName) {
  1226. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1227. }, this);
  1228. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1229. }
  1230. else {
  1231. deferred.resolve();
  1232. }
  1233. return deferred;
  1234. },
  1235. showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
  1236. return App.ModalPopup.show({
  1237. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1238. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1239. secondary: Em.I18n.t('common.cancel'),
  1240. primary: Em.I18n.t('common.proceedAnyway'),
  1241. onPrimary: function () {
  1242. deferred.resolve();
  1243. this._super();
  1244. },
  1245. onSecondary: function () {
  1246. deferred.reject();
  1247. this._super();
  1248. }
  1249. })
  1250. },
  1251. /**
  1252. * Proceed to the next step
  1253. **/
  1254. moveNext: function () {
  1255. App.router.send('next');
  1256. },
  1257. /**
  1258. * Click-handler on Next button
  1259. * Disable "Submit"-button while server-side processes are running
  1260. * @method submit
  1261. */
  1262. submit: function () {
  1263. if (this.get('isSubmitDisabled')) {
  1264. return;
  1265. }
  1266. var self = this;
  1267. this.set('submitButtonClicked', true);
  1268. this.serverSideValidation().done(function() {
  1269. self.checkDatabaseConnectionTest().done(function() {
  1270. self.resolveHiveMysqlDatabase();
  1271. self.set('submitButtonClicked', false);
  1272. });
  1273. }).fail(function(value){
  1274. if ("invalid_configs" == value) {
  1275. self.set('submitButtonClicked', false);
  1276. } else {
  1277. // Failed due to validation mechanism failure.
  1278. // Should proceed with other checks
  1279. self.checkDatabaseConnectionTest().done(function() {
  1280. self.resolveHiveMysqlDatabase();
  1281. self.set('submitButtonClicked', false);
  1282. });
  1283. }
  1284. });
  1285. }
  1286. });