step7_controller.js 57 KB

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