step7_controller.js 55 KB

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