step7_controller.js 48 KB

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