step7_controller.js 55 KB

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