step7_controller.js 48 KB

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