step7_controller.js 56 KB

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