step7_controller.js 53 KB

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