step7_controller.js 48 KB

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