step7_controller.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529
  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} masterComponentHost
  30. * @property {string} component
  31. * @property {string} hostName
  32. * @property {boolean} isInstalled is component already installed on the this host or just going to be installed
  33. */
  34. /**
  35. * @typedef {object} topologyLocalDB
  36. * @property {object[]} hosts list of hosts with information of their disks usage and dirs
  37. * @property {masterComponentHost[]} masterComponentHosts
  38. * @property {?object[]} slaveComponentHosts
  39. */
  40. App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.EnhancedConfigsMixin, App.ToggleIsRequiredMixin, {
  41. name: 'wizardStep7Controller',
  42. /**
  43. * Contains all field properties that are viewed in this step
  44. * @type {object[]}
  45. */
  46. stepConfigs: [],
  47. hash: null,
  48. selectedService: null,
  49. slaveHostToGroup: null,
  50. addMiscTabToPage: true,
  51. /**
  52. * Is Submit-click processing now
  53. * @type {bool}
  54. */
  55. submitButtonClicked: false,
  56. isRecommendedLoaded: false,
  57. /**
  58. * used in services_config.js view to mark a config with security icon
  59. */
  60. secureConfigs: require('data/HDP2/secure_mapping'),
  61. /**
  62. * If configChangeObserver Modal is shown
  63. * @type {bool}
  64. */
  65. miscModalVisible: false,
  66. overrideToAdd: null,
  67. /**
  68. * Is installer controller used
  69. * @type {bool}
  70. */
  71. isInstaller: true,
  72. /**
  73. * List of config groups
  74. * @type {object[]}
  75. */
  76. configGroups: [],
  77. /**
  78. * List of config group to be deleted
  79. * @type {object[]}
  80. */
  81. groupsToDelete: [],
  82. preSelectedConfigGroup: null,
  83. /**
  84. * Currently selected config group
  85. * @type {object}
  86. */
  87. selectedConfigGroup: null,
  88. /**
  89. * Config tags of actually installed services
  90. * @type {array}
  91. */
  92. serviceConfigTags: [],
  93. /**
  94. * Are applied to service configs loaded
  95. * @type {bool}
  96. */
  97. isAppliedConfigLoaded: true,
  98. isConfigsLoaded: Em.computed.and('wizardController.stackConfigsLoaded', 'isAppliedConfigLoaded'),
  99. /**
  100. * PreInstall Checks allowed only for Install
  101. * @type {boolean}
  102. */
  103. supportsPreInstallChecks: function () {
  104. return App.get('supports.preInstallChecks') && 'installerController' === this.get('content.controllerName');
  105. }.property('App.supports.preInstallChecks', 'wizardController.name'),
  106. /**
  107. * Number of errors in the configs in the selected service
  108. * @type {number}
  109. */
  110. errorsCount: function() {
  111. return this.get('selectedService.configsWithErrors').filter(function(c) {
  112. return Em.isNone(c.get('widget'));
  113. }).length;
  114. }.property('selectedService.configsWithErrors.length'),
  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: Em.computed.alias('content.masterComponentHosts'),
  158. /**
  159. * List of slave components
  160. * @type {Ember.Enumerable}
  161. */
  162. slaveComponentHosts: Em.computed.alias('content.slaveGroupProperties'),
  163. customData: [],
  164. /**
  165. * Filter text will be located here
  166. * @type {string}
  167. */
  168. filter: '',
  169. /**
  170. * list of dependencies that are user to set init value of config
  171. *
  172. * @type {Object}
  173. */
  174. configDependencies: function() {
  175. var dependencies = {
  176. 'sliderSelected': this.get('allSelectedServiceNames').contains('SLIDER')
  177. };
  178. var hiveMetastore = App.configsCollection.getConfigByName('hive.metastore.uris', 'hive-site.xml');
  179. var clientPort = App.configsCollection.getConfigByName('clientPort', 'zoo.cfg.xml');
  180. if (hiveMetastore) dependencies['hive.metastore.uris'] = hiveMetastore.recommendedValue;
  181. if (clientPort) dependencies['clientPort'] = clientPort.recommendedValue;
  182. return dependencies
  183. }.property('allSelectedServiceNames'),
  184. /**
  185. * List of filters for config properties to populate filter combobox
  186. */
  187. propertyFilters: [
  188. {
  189. attributeName: 'isOverridden',
  190. attributeValue: true,
  191. caption: 'common.combobox.dropdown.overridden'
  192. },
  193. {
  194. attributeName: 'isFinal',
  195. attributeValue: true,
  196. caption: 'common.combobox.dropdown.final'
  197. },
  198. {
  199. attributeName: 'hasIssues',
  200. attributeValue: true,
  201. caption: 'common.combobox.dropdown.issues'
  202. }
  203. ],
  204. issuesFilterText: function () {
  205. return (this.get('isSubmitDisabled') && !this.get('submitButtonClicked') &&
  206. this.get('filterColumns').findProperty('attributeName', 'hasIssues').get('selected')) ?
  207. Em.I18n.t('installer.step7.showingPropertiesWithIssues') : '';
  208. }.property('isSubmitDisabled', 'submitButtonClicked', 'filterColumns.@each.selected'),
  209. issuesFilterLinkText: function () {
  210. if (this.get('filterColumns').findProperty('attributeName', 'hasIssues').get('selected')) {
  211. return Em.I18n.t('installer.step7.showAllProperties');
  212. }
  213. return (this.get('isSubmitDisabled') && !this.get('submitButtonClicked')) ?
  214. (
  215. this.get('filterColumns').findProperty('attributeName', 'hasIssues').get('selected') ?
  216. Em.I18n.t('installer.step7.showAllProperties') : Em.I18n.t('installer.step7.showPropertiesWithIssues')
  217. ) : '';
  218. }.property('isSubmitDisabled', 'submitButtonClicked', 'filterColumns.@each.selected'),
  219. /**
  220. * Dropdown menu items in filter combobox
  221. */
  222. filterColumns: function () {
  223. return this.get('propertyFilters').map(function (filter) {
  224. return Ember.Object.create({
  225. attributeName: filter.attributeName,
  226. attributeValue: filter.attributeValue,
  227. name: this.t(filter.caption),
  228. selected: false
  229. });
  230. }, this);
  231. }.property('propertyFilters'),
  232. /**
  233. * Clear controller's properties:
  234. * <ul>
  235. * <li>stepConfigs</li>
  236. * <li>filter</li>
  237. * </ul>
  238. * and desect all <code>filterColumns</code>
  239. * @method clearStep
  240. */
  241. clearStep: function () {
  242. this.setProperties({
  243. configValidationGlobalMessage: [],
  244. submitButtonClicked: false,
  245. isSubmitDisabled: true,
  246. isRecommendedLoaded: false
  247. });
  248. this.get('stepConfigs').clear();
  249. this.set('filter', '');
  250. this.get('filterColumns').setEach('selected', false);
  251. },
  252. /**
  253. * Generate "finger-print" for current <code>stepConfigs[0]</code>
  254. * Used to determine, if user has some unsaved changes (comparing with <code>hash</code>)
  255. * @returns {string|null}
  256. * @method getHash
  257. */
  258. getHash: function () {
  259. if (!this.get('stepConfigs')[0]) {
  260. return null;
  261. }
  262. var hash = {};
  263. this.get('stepConfigs').forEach(function(stepConfig){
  264. stepConfig.configs.forEach(function (config) {
  265. hash[config.get('name')] = {value: config.get('value'), overrides: [], isFinal: config.get('isFinal')};
  266. if (!config.get('overrides')) return;
  267. if (!config.get('overrides.length')) return;
  268. config.get('overrides').forEach(function (override) {
  269. hash[config.get('name')].overrides.push(override.get('value'));
  270. });
  271. });
  272. });
  273. return JSON.stringify(hash);
  274. },
  275. /**
  276. * Are some changes available
  277. */
  278. hasChanges: function () {
  279. return this.get('hash') != this.getHash();
  280. },
  281. /**
  282. * Load config groups for installed services
  283. * One ajax-request for each service
  284. * @param {string[]} servicesNames
  285. * @method loadInstalledServicesConfigGroups
  286. */
  287. loadInstalledServicesConfigGroups: function (servicesNames) {
  288. servicesNames.forEach(function (serviceName) {
  289. App.ajax.send({
  290. name: 'config.tags_and_groups',
  291. sender: this,
  292. data: {
  293. serviceName: serviceName,
  294. serviceConfigsDef: App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName)
  295. },
  296. success: 'loadServiceTagsSuccess'
  297. });
  298. }, this);
  299. },
  300. /**
  301. * Create site to tag map. Format:
  302. * <code>
  303. * {
  304. * site1: tag1,
  305. * site1: tag2,
  306. * site2: tag3
  307. * ...
  308. * }
  309. * </code>
  310. * @param {object} desired_configs
  311. * @param {string[]} sites
  312. * @returns {object}
  313. * @private
  314. * @method _createSiteToTagMap
  315. */
  316. _createSiteToTagMap: function (desired_configs, sites) {
  317. var siteToTagMap = {};
  318. for (var site in desired_configs) {
  319. if (desired_configs.hasOwnProperty(site)) {
  320. if (!!sites[site]) {
  321. siteToTagMap[site] = desired_configs[site].tag;
  322. }
  323. }
  324. }
  325. return siteToTagMap;
  326. },
  327. /**
  328. * Load config groups success callback
  329. * @param {object} data
  330. * @param {object} opt
  331. * @param {object} params
  332. * @method loadServiceTagsSuccess
  333. */
  334. loadServiceTagsSuccess: function (data, opt, params) {
  335. var serviceName = params.serviceName,
  336. service = this.get('stepConfigs').findProperty('serviceName', serviceName),
  337. defaultConfigGroupHosts = this.get('wizardController.allHosts').mapProperty('hostName'),
  338. siteToTagMap = this._createSiteToTagMap(data.Clusters.desired_configs, params.serviceConfigsDef.get('configTypes'));
  339. this.set('loadedClusterSiteToTagMap', siteToTagMap);
  340. //parse loaded config groups
  341. var configGroups = [];
  342. if (data.config_groups.length) {
  343. data.config_groups.forEach(function (item) {
  344. item = item.ConfigGroup;
  345. if (item.tag === serviceName) {
  346. var groupHosts = item.hosts.mapProperty('host_name');
  347. configGroups.push({
  348. id: serviceName + item.id,
  349. config_group_id: item.id,
  350. name: item.group_name,
  351. description: item.description,
  352. is_default: false,
  353. parent_config_group_id: App.ServiceConfigGroup.getParentConfigGroupId(serviceName),
  354. service_id: serviceName,
  355. service_name: serviceName,
  356. hosts: groupHosts,
  357. desired_configs: item.desired_configs
  358. });
  359. groupHosts.forEach(function (host) {
  360. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  361. }, this);
  362. }
  363. }, this);
  364. }
  365. var defaultConfigGroup = App.configGroupsMapper.generateDefaultGroup(serviceName, defaultConfigGroupHosts);
  366. configGroups = configGroups.sortProperty('name');
  367. configGroups.unshift(defaultConfigGroup);
  368. App.store.loadMany(App.ServiceConfigGroup, configGroups);
  369. App.store.commit();
  370. service.set('configGroups', App.ServiceConfigGroup.find().filterProperty('serviceName', serviceName));
  371. var loadedGroupToOverrideSiteToTagMap = {};
  372. configGroups.forEach(function (item) {
  373. var groupName = item.name;
  374. loadedGroupToOverrideSiteToTagMap[groupName] = {};
  375. item.desired_configs.forEach(function (site) {
  376. loadedGroupToOverrideSiteToTagMap[groupName][site.type] = site.tag;
  377. }, this);
  378. }, this);
  379. this.set('preSelectedConfigGroup', App.ServiceConfigGroup.find(App.ServiceConfigGroup.getParentConfigGroupId(serviceName)));
  380. this.loadServiceConfigGroupOverrides(service.get('configs'), loadedGroupToOverrideSiteToTagMap, service.get('configGroups'));
  381. },
  382. /**
  383. * Get properties from server by type and tag with properties, that belong to group
  384. * push them to common {serviceConfigs} and call callback function
  385. */
  386. loadServiceConfigGroupOverrides: function (serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups) {
  387. var configKeyToConfigMap = {};
  388. serviceConfigs.forEach(function (item) {
  389. if (!configKeyToConfigMap[item.filename]) {
  390. configKeyToConfigMap[item.filename] = {};
  391. }
  392. configKeyToConfigMap[item.filename][item.name] = item;
  393. });
  394. var typeTagToGroupMap = {};
  395. var urlParams = [];
  396. for (var group in loadedGroupToOverrideSiteToTagMap) {
  397. var overrideTypeTags = loadedGroupToOverrideSiteToTagMap[group];
  398. for (var type in overrideTypeTags) {
  399. var tag = overrideTypeTags[type];
  400. typeTagToGroupMap[type + "///" + tag] = configGroups.findProperty('name', group);
  401. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  402. }
  403. }
  404. var params = urlParams.join('|');
  405. if (urlParams.length) {
  406. App.ajax.send({
  407. name: 'config.host_overrides',
  408. sender: this,
  409. data: {
  410. params: params,
  411. configKeyToConfigMap: configKeyToConfigMap,
  412. typeTagToGroupMap: typeTagToGroupMap,
  413. serviceConfigs: serviceConfigs
  414. },
  415. success: 'loadServiceConfigGroupOverridesSuccess'
  416. });
  417. } else {
  418. this.onLoadOverrides(serviceConfigs);
  419. }
  420. },
  421. loadServiceConfigGroupOverridesSuccess: function (data, opt, params) {
  422. data.items.forEach(function (config) {
  423. var group = params.typeTagToGroupMap[config.type + "///" + config.tag];
  424. var properties = config.properties;
  425. for (var prop in properties) {
  426. var fileName = App.config.getOriginalFileName(config.type);
  427. var serviceConfig = !!params.configKeyToConfigMap[fileName] ? params.configKeyToConfigMap[fileName][prop] : false;
  428. var hostOverrideValue = App.config.formatPropertyValue(serviceConfig, properties[prop]);
  429. var hostOverrideIsFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]);
  430. if (serviceConfig) {
  431. // Value of this property is different for this host.
  432. if (!Em.get(serviceConfig, 'overrides')) Em.set(serviceConfig, 'overrides', []);
  433. serviceConfig.overrides.pushObject({value: hostOverrideValue, group: group, isFinal: hostOverrideIsFinal});
  434. } else {
  435. params.serviceConfigs.push(App.config.createCustomGroupConfig(prop, fileName, config.properties[prop], group));
  436. }
  437. }
  438. });
  439. this.onLoadOverrides(params.serviceConfigs);
  440. },
  441. onLoadOverrides: function (configs) {
  442. var serviceName = configs[0].serviceName,
  443. service = this.get('stepConfigs').findProperty('serviceName', serviceName);
  444. var serviceConfig = App.config.createServiceConfig(serviceName);
  445. service.set('selectedConfigGroup', this.get('preSelectedConfigGroup'));
  446. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  447. // override if a property isRequired or not
  448. this.overrideConfigIsRequired(service);
  449. service.set('configs', serviceConfig.get('configs'));
  450. },
  451. /**
  452. * Set <code>isEditable</code>-property to <code>serviceConfigProperty</code>
  453. * Based on user's permissions and selected config group
  454. * @param {Ember.Object} serviceConfigProperty
  455. * @param {bool} defaultGroupSelected
  456. * @returns {Ember.Object} Updated config-object
  457. * @method _updateIsEditableFlagForConfig
  458. */
  459. _updateIsEditableFlagForConfig: function (serviceConfigProperty, defaultGroupSelected) {
  460. if (App.isAuthorized('AMBARI.ADD_DELETE_CLUSTERS')) {
  461. if (defaultGroupSelected && !this.get('isHostsConfigsPage') && !Em.get(serviceConfigProperty, 'group')) {
  462. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  463. } else if (Em.get(serviceConfigProperty, 'group') && Em.get(serviceConfigProperty, 'group.name') == this.get('selectedConfigGroup.name')) {
  464. serviceConfigProperty.set('isEditable', true);
  465. } else {
  466. serviceConfigProperty.set('isEditable', false);
  467. }
  468. }
  469. else {
  470. serviceConfigProperty.set('isEditable', false);
  471. }
  472. return serviceConfigProperty;
  473. },
  474. /**
  475. * Set <code>overrides</code>-property to <code>serviceConfigProperty<code>
  476. * @param {Ember.Object} serviceConfigProperty
  477. * @param {Ember.Object} component
  478. * @return {Ember.Object} Updated config-object
  479. * @method _updateOverridesForConfig
  480. */
  481. _updateOverridesForConfig: function (serviceConfigProperty, component) {
  482. var overrides = serviceConfigProperty.get('overrides');
  483. if (Em.isNone(overrides)) {
  484. serviceConfigProperty.set('overrides', Em.A([]));
  485. return serviceConfigProperty;
  486. }
  487. serviceConfigProperty.set('overrides', null);
  488. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  489. // Wrap each override to App.ServiceConfigProperty
  490. overrides.forEach(function (override) {
  491. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  492. newSCP.set('value', override.value);
  493. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  494. newSCP.set('parentSCP', serviceConfigProperty);
  495. if (defaultGroupSelected) {
  496. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  497. // prevent cycle in proto object, clean link
  498. if (group.get('properties').length == 0) {
  499. group.set('properties', Em.A([]));
  500. }
  501. group.get('properties').push(newSCP);
  502. newSCP.set('group', override.group);
  503. newSCP.set('isEditable', false);
  504. }
  505. var parentOverridesArray = serviceConfigProperty.get('overrides');
  506. if (Em.isNone(parentOverridesArray)) {
  507. parentOverridesArray = Em.A([]);
  508. serviceConfigProperty.set('overrides', parentOverridesArray);
  509. }
  510. serviceConfigProperty.get('overrides').pushObject(newSCP);
  511. newSCP.validate();
  512. }, this);
  513. return serviceConfigProperty;
  514. },
  515. /**
  516. * Set configs with overrides, recommended defaults to component
  517. * @param {Ember.Object[]} configs
  518. * @param {Ember.Object} componentConfig
  519. * @param {Ember.Object} component
  520. * @method loadComponentConfigs
  521. */
  522. loadComponentConfigs: function (configs, componentConfig, component) {
  523. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  524. configs.forEach(function (serviceConfigProperty) {
  525. if (!serviceConfigProperty) return;
  526. if (Em.isNone(serviceConfigProperty.get('isOverridable'))) {
  527. serviceConfigProperty.set('isOverridable', true);
  528. }
  529. this._updateOverridesForConfig(serviceConfigProperty, component);
  530. this._updateIsEditableFlagForConfig(serviceConfigProperty, defaultGroupSelected);
  531. componentConfig.get('configs').pushObject(serviceConfigProperty);
  532. serviceConfigProperty.validate();
  533. }, this);
  534. component.get('configGroups').filterProperty('isDefault', false).forEach(function (configGroup) {
  535. configGroup.set('hash', this.get('wizardController').getConfigGroupHash(configGroup));
  536. }, this);
  537. var overrideToAdd = this.get('overrideToAdd');
  538. if (overrideToAdd) {
  539. overrideToAdd = componentConfig.get('configs').findProperty('name', overrideToAdd.name);
  540. if (overrideToAdd) {
  541. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  542. var newSCP = App.config.createOverride(overrideToAdd, {isEditable: true}, group);
  543. group.get('properties').pushObject(newSCP);
  544. component.set('overrideToAdd', null);
  545. }
  546. }
  547. },
  548. /**
  549. * On load function
  550. * @method loadStep
  551. */
  552. loadStep: function () {
  553. if (!this.get('isConfigsLoaded')) {
  554. return;
  555. }
  556. console.time('wizard loadStep: ');
  557. this.clearStep();
  558. var self = this;
  559. App.config.setPreDefinedServiceConfigs(this.get('addMiscTabToPage'));
  560. var storedConfigs = this.get('content.serviceConfigProperties');
  561. var configs = (storedConfigs && storedConfigs.length) ? storedConfigs : App.configsCollection.getAll();
  562. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  563. if (this.get('wizardController.name') === 'addServiceController' && !this.get('content.serviceConfigProperties.length')) {
  564. App.router.get('configurationController').getConfigsByTags(this.get('serviceConfigTags')).done(function (loadedConfigs) {
  565. configs = self.setInstalledServiceConfigs(configs, loadedConfigs, self.get('installedServiceNames'));
  566. self.applyServicesConfigs(configs);
  567. });
  568. } else {
  569. this.applyServicesConfigs(configs);
  570. }
  571. },
  572. /**
  573. * Resolve config theme conditions
  574. * in order to correctly calculate config errors number of service
  575. * @param {Array} configs
  576. */
  577. resolveConfigThemeConditions: function (configs) {
  578. App.ThemeCondition.find().forEach(function (configCondition) {
  579. var _configs = Em.A(configCondition.get('configs'));
  580. if (configCondition.get("resource") === 'config' && _configs.length > 0) {
  581. var isConditionTrue = App.config.calculateConfigCondition(configCondition.get("if"), configs);
  582. var action = isConditionTrue ? configCondition.get("then") : configCondition.get("else");
  583. if (configCondition.get('id')) {
  584. var valueAttributes = action.property_value_attributes;
  585. if (valueAttributes && !Em.none(valueAttributes['visible'])) {
  586. var themeResource;
  587. if (configCondition.get('type') === 'subsection') {
  588. themeResource = App.SubSection.find().findProperty('name', configCondition.get('name'));
  589. } else if (configCondition.get('type') === 'subsectionTab') {
  590. themeResource = App.SubSectionTab.find().findProperty('name', configCondition.get('name'));
  591. } else if (configCondition.get('type') === 'config') {
  592. //simulate section wrapper for condition type "config"
  593. themeResource = Em.Object.create({
  594. configProperties: [App.config.configId(configCondition.get('configName'), configCondition.get('fileName'))]
  595. });
  596. }
  597. if (themeResource) {
  598. themeResource.get('configProperties').forEach(function (_configId) {
  599. configs.forEach(function (item) {
  600. if (App.config.configId(item.name, item.filename) === _configId) {
  601. // if config has already been hidden by condition with "subsection" or "subsectionTab" type
  602. // then ignore condition of "config" type
  603. if (configCondition.get('type') === 'config' && item.hiddenBySection) return false;
  604. item.hiddenBySection = !valueAttributes['visible'];
  605. }
  606. });
  607. }, this);
  608. }
  609. }
  610. }
  611. }
  612. });
  613. },
  614. applyServicesConfigs: function (configs) {
  615. if (this.get('allSelectedServiceNames').contains('YARN')) {
  616. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml', []);
  617. }
  618. if (App.get('isKerberosEnabled') && this.get('wizardController.name') == 'addServiceController') {
  619. this.addKerberosDescriptorConfigs(configs, this.get('wizardController.kerberosDescriptorConfigs') || []);
  620. }
  621. this.resolveConfigThemeConditions(configs);
  622. var stepConfigs = this.createStepConfigs();
  623. var serviceConfigs = this.renderConfigs(stepConfigs, configs);
  624. // if HA is enabled -> Make some reconfigurations
  625. if (this.get('wizardController.name') === 'addServiceController' && App.get('isHaEnabled')) {
  626. serviceConfigs = this._reconfigureServicesOnNnHa(serviceConfigs);
  627. }
  628. this.set('stepConfigs', serviceConfigs);
  629. this.checkHostOverrideInstaller();
  630. this.selectProperService();
  631. var self = this;
  632. var rangerService = App.StackService.find().findProperty('serviceName', 'RANGER');
  633. if (rangerService && !rangerService.get('isInstalled') && !rangerService.get('isSelected')) {
  634. App.config.removeRangerConfigs(self.get('stepConfigs'));
  635. }
  636. this.loadServerSideConfigsRecommendations().always(function() {
  637. if (self.get('wizardController.name') == 'addServiceController') {
  638. // for Add Service just remove or add dependent properties and ignore config values changes
  639. // for installed services only
  640. self.clearDependenciesForInstalledServices(self.get('installedServiceNames'), self.get('stepConfigs'));
  641. }
  642. self.completeConfigLoading();
  643. });
  644. },
  645. completeConfigLoading: function() {
  646. this.clearDependentConfigsByService(App.StackService.find().filterProperty('isSelected').mapProperty('serviceName'));
  647. console.timeEnd('wizard loadStep: ');
  648. this.set('isRecommendedLoaded', true);
  649. if (this.get('content.skipConfigStep')) {
  650. App.router.send('next');
  651. }
  652. this.set('hash', this.getHash());
  653. },
  654. /**
  655. * Mark descriptor properties in configuration object.
  656. *
  657. * @param {Object[]} configs - config properties to change
  658. * @param {App.ServiceConfigProperty[]} descriptor - parsed kerberos descriptor
  659. * @method addKerberosDescriptorConfigs
  660. */
  661. addKerberosDescriptorConfigs: function (configs, descriptor) {
  662. descriptor.forEach(function (item) {
  663. var property = configs.findProperty('name', item.get('name'));
  664. if (property) {
  665. Em.setProperties(property, {
  666. isSecureConfig: true,
  667. displayName: Em.get(item, 'name'),
  668. isUserProperty: false,
  669. isOverridable: false,
  670. category: 'Advanced ' + Em.get(item, 'filename')
  671. });
  672. }
  673. });
  674. },
  675. /**
  676. * Load config groups
  677. * and (if some services are already installed) load config groups for installed services
  678. * @method checkHostOverrideInstaller
  679. */
  680. checkHostOverrideInstaller: function () {
  681. if (this.get('wizardController.name') !== 'kerberosWizardController') {
  682. this.loadConfigGroups(this.get('content.configGroups'));
  683. }
  684. if (this.get('installedServiceNames').length > 0 && !this.get('wizardController.areInstalledConfigGroupsLoaded')) {
  685. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  686. }
  687. },
  688. /**
  689. * Create stepConfigs array with all info except configs list
  690. *
  691. * @return {Object[]}
  692. * @method createStepConfigs
  693. */
  694. createStepConfigs: function() {
  695. var stepConfigs = [];
  696. App.config.get('preDefinedServiceConfigs').forEach(function (service) {
  697. var serviceName = service.get('serviceName');
  698. if (['MISC'].concat(this.get('allSelectedServiceNames')).contains(serviceName)) {
  699. var serviceConfig = App.config.createServiceConfig(serviceName);
  700. serviceConfig.set('showConfig', App.StackService.find(serviceName).get('isInstallable'));
  701. if (this.get('wizardController.name') == 'addServiceController') {
  702. serviceConfig.set('selected', !this.get('installedServiceNames').concat('MISC').contains(serviceName));
  703. if (serviceName === 'MISC') {
  704. serviceConfig.set('configCategories', serviceConfig.get('configCategories').rejectProperty('name', 'Notifications'));
  705. }
  706. } else if (this.get('wizardController.name') == 'kerberosWizardController') {
  707. serviceConfig.set('showConfig', true);
  708. }
  709. stepConfigs.pushObject(serviceConfig);
  710. }
  711. }, this);
  712. return stepConfigs;
  713. },
  714. /**
  715. * render configs, distribute them by service
  716. * and wrap each in ServiceConfigProperty object
  717. * @param stepConfigs
  718. * @param configs
  719. * @return {App.ServiceConfig[]}
  720. */
  721. renderConfigs: function (stepConfigs, configs) {
  722. var localDB = {
  723. hosts: this.get('wizardController.content.hosts'),
  724. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  725. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  726. };
  727. var configsByService = {}, dependencies = this.get('configDependencies');
  728. configs.forEach(function (_config) {
  729. if (!configsByService[_config.serviceName]) {
  730. configsByService[_config.serviceName] = [];
  731. }
  732. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  733. this.updateHostOverrides(serviceConfigProperty, _config);
  734. if (this.get('wizardController.name') === 'addServiceController') {
  735. this._updateIsEditableFlagForConfig(serviceConfigProperty, true);
  736. }
  737. if (!this.get('content.serviceConfigProperties.length') && !serviceConfigProperty.get('hasInitialValue')) {
  738. App.ConfigInitializer.initialValue(serviceConfigProperty, localDB, dependencies);
  739. }
  740. serviceConfigProperty.validate();
  741. configsByService[_config.serviceName].pushObject(serviceConfigProperty);
  742. }, this);
  743. stepConfigs.forEach(function (service) {
  744. service.set('configs', configsByService[service.get('serviceName')]);
  745. if (['addServiceController', 'installerController'].contains(this.get('wizardController.name'))) {
  746. this.addHostNamesToConfigs(service, localDB.masterComponentHosts, localDB.slaveComponentHosts);
  747. }
  748. }, this);
  749. return stepConfigs;
  750. },
  751. /**
  752. * Add host name properties to appropriate categories (for installer and add service)
  753. *
  754. * @param {Object} serviceConfig
  755. * @param {Object[]} masterComponents - info from localStorage
  756. * @param {Object[]} slaveComponents - info from localStorage
  757. */
  758. addHostNamesToConfigs: function(serviceConfig, masterComponents, slaveComponents) {
  759. serviceConfig.get('configCategories').forEach(function(c) {
  760. if (c.showHost) {
  761. var value = [];
  762. var componentName = c.name;
  763. var masters = masterComponents && masterComponents.filterProperty('component', componentName);
  764. if (masters.length) {
  765. value = masters.mapProperty('hostName');
  766. } else {
  767. var slaves = slaveComponents && slaveComponents.findProperty('componentName', componentName);
  768. if (slaves) {
  769. value = slaves.hosts.mapProperty('hostName');
  770. }
  771. }
  772. var stackComponent = App.StackServiceComponent.find(componentName);
  773. var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), componentName, value, stackComponent);
  774. var newConfigName = Em.get(hProperty, 'name');
  775. if (!serviceConfig.get('configs').someProperty('name', newConfigName)) {
  776. serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
  777. }
  778. }
  779. }, this);
  780. },
  781. /**
  782. * create new child configs from overrides, attach them to parent config
  783. * override - value of config, related to particular host(s)
  784. * @param configProperty
  785. * @param storedConfigProperty
  786. */
  787. updateHostOverrides: function (configProperty, storedConfigProperty) {
  788. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  789. var overrides = [];
  790. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  791. // create new override with new value
  792. var newSCP = App.ServiceConfigProperty.create(configProperty);
  793. newSCP.set('value', overrideEntry.value);
  794. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  795. newSCP.set('parentSCP', configProperty);
  796. overrides.pushObject(newSCP);
  797. });
  798. configProperty.set('overrides', overrides);
  799. }
  800. },
  801. /**
  802. * When NameNode HA is enabled some configs based on <code>dfs.nameservices</code> should be changed
  803. * This happens only if service is added AFTER NN HA is enabled
  804. *
  805. * @param {App.ServiceConfig[]} serviceConfigs
  806. * @method _reconfigureServiceOnNnHa
  807. * @private
  808. * @returns {App.ServiceConfig[]}
  809. */
  810. _reconfigureServicesOnNnHa: function (serviceConfigs) {
  811. var selectedServiceNames = this.get('selectedServiceNames');
  812. var nameServiceId = serviceConfigs.findProperty('serviceName', 'HDFS').configs.findProperty('name', 'dfs.nameservices');
  813. Em.A([
  814. {
  815. serviceName: 'HBASE',
  816. configToUpdate: 'hbase.rootdir'
  817. },
  818. {
  819. serviceName: 'ACCUMULO',
  820. configToUpdate: 'instance.volumes'
  821. },
  822. {
  823. serviceName: 'HAWQ',
  824. configToUpdate: 'hawq_dfs_url',
  825. regexPattern: /(^.*:[0-9]+)(?=\/)/,
  826. replacementValue: nameServiceId.get('value')
  827. }
  828. ]).forEach(function (c) {
  829. if (selectedServiceNames.contains(c.serviceName) && nameServiceId) {
  830. var cfg = serviceConfigs.findProperty('serviceName', c.serviceName).configs.findProperty('name', c.configToUpdate);
  831. var regexPattern = /\/\/.*:[0-9]+/i;
  832. var replacementValue = '//' + nameServiceId.get('value');
  833. if (typeof(c.regexPattern) !== "undefined" && typeof(c.replacementValue) !== "undefined") {
  834. regexPattern = c.regexPattern;
  835. replacementValue = c.replacementValue;
  836. }
  837. var newValue = cfg.get('value').replace(regexPattern, replacementValue);
  838. cfg.setProperties({
  839. value: newValue,
  840. recommendedValue: newValue
  841. });
  842. }
  843. });
  844. return serviceConfigs;
  845. },
  846. /**
  847. * Select first addable service for <code>addServiceWizard</code>
  848. * Select first service at all in other cases
  849. * @method selectProperService
  850. */
  851. selectProperService: function () {
  852. if (this.get('wizardController.name') === 'addServiceController') {
  853. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  854. } else {
  855. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  856. }
  857. },
  858. /**
  859. * Load config tags
  860. * @return {$.ajax|null}
  861. * @method getConfigTags
  862. */
  863. getConfigTags: function () {
  864. this.set('isAppliedConfigLoaded', false);
  865. return App.ajax.send({
  866. name: 'config.tags',
  867. sender: this,
  868. success: 'getConfigTagsSuccess'
  869. });
  870. },
  871. /**
  872. * Success callback for config tags request
  873. * Updates <code>serviceConfigTags</code> with tags received from server
  874. * @param {object} data
  875. * @method getConfigTagsSuccess
  876. */
  877. getConfigTagsSuccess: function (data) {
  878. var installedServiceSites = [];
  879. App.StackService.find().filterProperty('isInstalled').forEach(function (service) {
  880. if (!service.get('configTypes')) return;
  881. var configTypes = Object.keys(service.get('configTypes'));
  882. installedServiceSites = installedServiceSites.concat(configTypes);
  883. }, this);
  884. installedServiceSites = installedServiceSites.uniq();
  885. var serviceConfigTags = [];
  886. for (var site in data.Clusters.desired_configs) {
  887. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  888. if (installedServiceSites.contains(site) || site == 'cluster-env') {
  889. serviceConfigTags.push({
  890. siteName: site,
  891. tagName: data.Clusters.desired_configs[site].tag,
  892. newTagName: null
  893. });
  894. }
  895. }
  896. }
  897. this.set('serviceConfigTags', serviceConfigTags);
  898. this.set('isAppliedConfigLoaded', true);
  899. },
  900. /**
  901. * set configs actual values from server
  902. * @param configs
  903. * @param configsByTags
  904. * @param installedServiceNames
  905. * @method setInstalledServiceConfigs
  906. */
  907. setInstalledServiceConfigs: function (configs, configsByTags, installedServiceNames) {
  908. var configsMap = {};
  909. configsByTags.forEach(function (configSite) {
  910. configsMap[configSite.type] = configSite.properties || {};
  911. });
  912. var allConfigs = configs.filter(function (_config) {
  913. // filter out alert_notification configs on add service //TODO find better place for this!
  914. if (_config.filename === 'alert_notification') return false;
  915. if ((['MISC'].concat(installedServiceNames).contains(_config.serviceName))) {
  916. var type = _config.filename ? App.config.getConfigTagFromFileName(_config.filename) : null;
  917. var mappedConfigValue = type && configsMap[type] ? configsMap[type][_config.name] : null;
  918. if (Em.isNone(mappedConfigValue)) {
  919. //for now ranger plugin properties are not sending by recommendations if they are missed - it should be added
  920. return _config.serviceName == 'MISC' || /^ranger-/.test(_config.filename);
  921. } else {
  922. if (_config.savedValue != mappedConfigValue) {
  923. _config.savedValue = App.config.formatPropertyValue(_config, mappedConfigValue);
  924. }
  925. _config.value = App.config.formatPropertyValue(_config, mappedConfigValue);
  926. _config.hasInitialValue = true;
  927. this.updateDependencies(_config);
  928. delete configsMap[type][_config.name];
  929. return true;
  930. }
  931. } else {
  932. return true;
  933. }
  934. }, this);
  935. //add user properties
  936. Em.keys(configsMap).forEach(function (filename) {
  937. Em.keys(configsMap[filename]).forEach(function (propertyName) {
  938. allConfigs.push(App.config.createDefaultConfig(propertyName,
  939. App.config.getServiceByConfigType(filename) ? App.config.getServiceByConfigType(filename).get('serviceName') : 'MISC',
  940. App.config.getOriginalFileName(filename),
  941. false, {
  942. value: configsMap[filename][propertyName],
  943. savedValue: configsMap[filename][propertyName],
  944. hasInitialValue: true
  945. }));
  946. });
  947. });
  948. return allConfigs;
  949. },
  950. /**
  951. * update dependencies according to current config value
  952. *
  953. * @param config
  954. */
  955. updateDependencies: function(config) {
  956. if (config.name === 'hive.metastore.uris' && config.filename === 'hive-site.xml') {
  957. this.get('configDependencies')['hive.metastore.uris'] = config.savedValue;
  958. } else if (config.name === 'clientPort' && config.filename === 'hive-site.xml') {
  959. this.get('configDependencies')['clientPort'] = config.savedValue;
  960. }
  961. },
  962. /**
  963. * Add group ids to <code>groupsToDelete</code>
  964. * Also save <code>groupsToDelete</code> to local storage
  965. * @param {Ember.Object[]} groups
  966. * @method setGroupsToDelete
  967. */
  968. setGroupsToDelete: function (groups) {
  969. var groupsToDelete = this.get('groupsToDelete');
  970. groups.forEach(function (group) {
  971. if (group.get('id'))
  972. groupsToDelete.push({
  973. id: group.get('id')
  974. });
  975. });
  976. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  977. },
  978. /**
  979. * Update <code>configGroups</code> with selected service configGroups
  980. * Also set default group to first position
  981. * Update <code>selectedConfigGroup</code> with new default group
  982. * @method selectedServiceObserver
  983. */
  984. selectedServiceObserver: function () {
  985. if (this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  986. var serviceGroups = this.get('selectedService.configGroups');
  987. serviceGroups.forEach(function (item, index, array) {
  988. if (item.isDefault) {
  989. array.unshift(item);
  990. array.splice(index + 1, 1);
  991. }
  992. });
  993. this.set('configGroups', serviceGroups);
  994. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  995. }
  996. }.observes('selectedService.configGroups.@each'),
  997. /**
  998. * load default groups for each service in case of initial load
  999. * @param serviceConfigGroups
  1000. * @method loadConfigGroups
  1001. */
  1002. loadConfigGroups: function (serviceConfigGroups) {
  1003. var services = this.get('stepConfigs');
  1004. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  1005. services.forEach(function (service) {
  1006. if (service.get('serviceName') === 'MISC') return;
  1007. var serviceRawGroups = serviceConfigGroups.filterProperty('service_name', service.serviceName);
  1008. var id = App.ServiceConfigGroup.getParentConfigGroupId(service.get('serviceName'));
  1009. if (!serviceRawGroups.length) {
  1010. App.store.load(App.ServiceConfigGroup, App.configGroupsMapper.generateDefaultGroup(service.get('serviceName'), hosts));
  1011. App.store.commit();
  1012. service.set('configGroups', [App.ServiceConfigGroup.find(id)]);
  1013. }
  1014. else {
  1015. App.store.loadMany(App.ServiceConfigGroup, serviceRawGroups);
  1016. App.store.commit();
  1017. serviceRawGroups.forEach(function(item){
  1018. var modelGroup = App.ServiceConfigGroup.find(item.id);
  1019. var wrappedProperties = [];
  1020. item.properties.forEach(function (propertyData) {
  1021. var parentSCP = service.configs.filterProperty('filename', propertyData.filename).findProperty('name', propertyData.name);
  1022. var overriddenSCP = App.ServiceConfigProperty.create(parentSCP);
  1023. overriddenSCP.set('isOriginalSCP', false);
  1024. overriddenSCP.set('parentSCP', parentSCP);
  1025. overriddenSCP.set('group', modelGroup);
  1026. overriddenSCP.setProperties(propertyData);
  1027. wrappedProperties.pushObject(App.ServiceConfigProperty.create(overriddenSCP));
  1028. });
  1029. modelGroup.set('properties', wrappedProperties);
  1030. }, this);
  1031. service.set('configGroups', App.ServiceConfigGroup.find().filterProperty('serviceName', service.get('serviceName')));
  1032. }
  1033. });
  1034. },
  1035. /**
  1036. * Click-handler on config-group to make it selected
  1037. * @param {object} event
  1038. * @method selectConfigGroup
  1039. */
  1040. selectConfigGroup: function (event) {
  1041. this.set('selectedConfigGroup', event.context);
  1042. },
  1043. /**
  1044. * Rebuild list of configs switch of config group:
  1045. * on default - display all configs from default group and configs from non-default groups as disabled
  1046. * on non-default - display all from default group as disabled and configs from selected non-default group
  1047. * @method switchConfigGroupConfigs
  1048. */
  1049. switchConfigGroupConfigs: function () {
  1050. var serviceConfigs = this.get('selectedService.configs'),
  1051. selectedGroup = this.get('selectedConfigGroup'),
  1052. overrideToAdd = this.get('overrideToAdd'),
  1053. overrides = [];
  1054. if (!selectedGroup) return;
  1055. var displayedConfigGroups = this._getDisplayedConfigGroups();
  1056. displayedConfigGroups.forEach(function (group) {
  1057. overrides.pushObjects(group.get('properties'));
  1058. });
  1059. serviceConfigs.forEach(function (config) {
  1060. this._setEditableValue(config);
  1061. this._setOverrides(config, overrides);
  1062. }, this);
  1063. }.observes('selectedConfigGroup'),
  1064. /**
  1065. * Get list of config groups to display
  1066. * Returns empty array if no <code>selectedConfigGroup</code>
  1067. * @return {Array}
  1068. * @method _getDisplayedConfigGroups
  1069. */
  1070. _getDisplayedConfigGroups: function () {
  1071. var selectedGroup = this.get('selectedConfigGroup');
  1072. if (!selectedGroup) return [];
  1073. return (selectedGroup.get('isDefault')) ?
  1074. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  1075. [this.get('selectedConfigGroup')];
  1076. },
  1077. /**
  1078. * Set <code>isEditable</code> property to <code>config</code>
  1079. * @param {Ember.Object} config
  1080. * @return {Ember.Object} updated config-object
  1081. * @method _setEditableValue
  1082. */
  1083. _setEditableValue: function (config) {
  1084. var selectedGroup = this.get('selectedConfigGroup');
  1085. if (!selectedGroup) return config;
  1086. var isEditable = config.get('isEditable'),
  1087. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  1088. if (isServiceInstalled) {
  1089. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  1090. }
  1091. else {
  1092. isEditable = selectedGroup.get('isDefault');
  1093. }
  1094. if (config.get('group')) {
  1095. isEditable = config.get('group.name') == this.get('selectedConfigGroup.name');
  1096. }
  1097. config.set('isEditable', isEditable);
  1098. return config;
  1099. },
  1100. /**
  1101. * Set <code>overrides</code> property to <code>config</code>
  1102. * @param {Ember.Object} config
  1103. * @param {Ember.Enumerable} overrides
  1104. * @returns {Ember.Object}
  1105. * @method _setOverrides
  1106. */
  1107. _setOverrides: function (config, overrides) {
  1108. var selectedGroup = this.get('selectedConfigGroup'),
  1109. overrideToAdd = this.get('overrideToAdd'),
  1110. configOverrides = overrides.filterProperty('name', config.get('name'));
  1111. if (!selectedGroup) return config;
  1112. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  1113. var valueForOverride = (config.get('widget') || config.get('displayType') == 'checkbox') ? config.get('value') : '';
  1114. var group = this.get('selectedService.configGroups').findProperty('name', selectedGroup.get('name'));
  1115. var newSCP = App.config.createOverride(config, {value: valueForOverride, recommendedValue: valueForOverride}, group);
  1116. configOverrides.push(newSCP);
  1117. group.get('properties').pushObject(newSCP);
  1118. this.set('overrideToAdd', null);
  1119. }
  1120. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  1121. configOverrides.setEach('parentSCP', config);
  1122. config.set('overrides', configOverrides);
  1123. return config;
  1124. },
  1125. /**
  1126. * @method manageConfigurationGroup
  1127. */
  1128. manageConfigurationGroup: function () {
  1129. App.router.get('manageConfigGroupsController').manageConfigurationGroups(this);
  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. $('a[href="#' + service.serviceName + '"]').tab('show');
  1410. }
  1411. }
  1412. }
  1413. });