step7_controller.js 45 KB

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