step7_controller.js 50 KB

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