step7_controller.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  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 HA is enabled and HAWQ is selected to be installed -> Add HAWQ related configs
  619. if (this.get('wizardController.name') === 'addServiceController' && App.get('isHaEnabled') && this.get('allSelectedServiceNames').contains('HAWQ')) {
  620. this.addHawqConfigsOnNnHa(configs);
  621. }
  622. if (App.get('isKerberosEnabled') && this.get('wizardController.name') == 'addServiceController') {
  623. this.addKerberosDescriptorConfigs(configs, this.get('wizardController.kerberosDescriptorConfigs') || []);
  624. }
  625. this.resolveConfigThemeConditions(configs);
  626. var stepConfigs = this.createStepConfigs();
  627. var serviceConfigs = this.renderConfigs(stepConfigs, configs);
  628. // if HA is enabled -> Make some reconfigurations
  629. if (this.get('wizardController.name') === 'addServiceController' && App.get('isHaEnabled')) {
  630. serviceConfigs = this._reconfigureServicesOnNnHa(serviceConfigs);
  631. }
  632. this.set('stepConfigs', serviceConfigs);
  633. this.checkHostOverrideInstaller();
  634. this.selectProperService();
  635. var self = this;
  636. var rangerService = App.StackService.find().findProperty('serviceName', 'RANGER');
  637. if (rangerService && !rangerService.get('isInstalled') && !rangerService.get('isSelected')) {
  638. App.config.removeRangerConfigs(self.get('stepConfigs'));
  639. }
  640. this.loadServerSideConfigsRecommendations().always(this.completeConfigLoading.bind(this));
  641. },
  642. completeConfigLoading: function() {
  643. this.clearRecommendationsByServiceName(App.StackService.find().filterProperty('isSelected').mapProperty('serviceName'));
  644. console.timeEnd('wizard loadStep: ');
  645. this.set('isRecommendedLoaded', true);
  646. if (this.get('content.skipConfigStep')) {
  647. App.router.send('next');
  648. }
  649. this.set('hash', this.getHash());
  650. },
  651. /**
  652. * Update initialValues only while loading recommendations first time
  653. *
  654. * @param serviceName
  655. * @returns {boolean}
  656. * @override
  657. */
  658. updateInitialOnRecommendations: function(serviceName) {
  659. return this._super(serviceName) && !this.get('isRecommendedLoaded');
  660. },
  661. /**
  662. * Mark descriptor properties in configuration object.
  663. *
  664. * @param {Object[]} configs - config properties to change
  665. * @param {App.ServiceConfigProperty[]} descriptor - parsed kerberos descriptor
  666. * @method addKerberosDescriptorConfigs
  667. */
  668. addKerberosDescriptorConfigs: function (configs, descriptor) {
  669. descriptor.forEach(function (item) {
  670. var property = configs.findProperty('name', item.get('name'));
  671. if (property) {
  672. Em.setProperties(property, {
  673. isSecureConfig: true,
  674. displayName: Em.get(item, 'name'),
  675. isUserProperty: false,
  676. isOverridable: false,
  677. category: 'Advanced ' + Em.get(item, 'filename')
  678. });
  679. }
  680. });
  681. },
  682. /**
  683. * Load config groups
  684. * and (if some services are already installed) load config groups for installed services
  685. * @method checkHostOverrideInstaller
  686. */
  687. checkHostOverrideInstaller: function () {
  688. if (this.get('wizardController.name') !== 'kerberosWizardController') {
  689. this.loadConfigGroups(this.get('content.configGroups'));
  690. }
  691. if (this.get('installedServiceNames').length > 0 && !this.get('wizardController.areInstalledConfigGroupsLoaded')) {
  692. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  693. }
  694. },
  695. /**
  696. * Create stepConfigs array with all info except configs list
  697. *
  698. * @return {Object[]}
  699. * @method createStepConfigs
  700. */
  701. createStepConfigs: function() {
  702. var stepConfigs = [];
  703. App.config.get('preDefinedServiceConfigs').forEach(function (service) {
  704. var serviceName = service.get('serviceName');
  705. if (['MISC'].concat(this.get('allSelectedServiceNames')).contains(serviceName)) {
  706. var serviceConfig = App.config.createServiceConfig(serviceName);
  707. serviceConfig.set('showConfig', App.StackService.find(serviceName).get('isInstallable'));
  708. if (this.get('wizardController.name') == 'addServiceController') {
  709. serviceConfig.set('selected', !this.get('installedServiceNames').concat('MISC').contains(serviceName));
  710. if (serviceName === 'MISC') {
  711. serviceConfig.set('configCategories', serviceConfig.get('configCategories').rejectProperty('name', 'Notifications'));
  712. }
  713. } else if (this.get('wizardController.name') == 'kerberosWizardController') {
  714. serviceConfig.set('showConfig', true);
  715. }
  716. stepConfigs.pushObject(serviceConfig);
  717. }
  718. }, this);
  719. return stepConfigs;
  720. },
  721. /**
  722. * For Namenode HA, HAWQ service requires additional config parameters in hdfs-client.xml
  723. * This method ensures that these additional parameters are added to hdfs-client.xml
  724. * @param configs existing configs on cluster
  725. * @returns {Object[]} existing configs + additional config parameters in hdfs-client.xml
  726. * @private
  727. */
  728. addHawqConfigsOnNnHa: function(configs) {
  729. var nameService = configs.findProperty('id', 'dfs.nameservices__hdfs-site').value;
  730. var propertyNames = [
  731. 'dfs.nameservices',
  732. 'dfs.ha.namenodes.' + nameService,
  733. 'dfs.namenode.rpc-address.'+ nameService +'.nn1',
  734. 'dfs.namenode.rpc-address.'+ nameService +'.nn2',
  735. 'dfs.namenode.http-address.'+ nameService +'.nn1',
  736. 'dfs.namenode.http-address.'+ nameService +'.nn2'
  737. ];
  738. propertyNames.forEach(function(propertyName, propertyIndex) {
  739. var propertyFromHdfs = configs.findProperty('id', propertyName + '__hdfs-site');
  740. var newProperty = App.config.createDefaultConfig(propertyName, 'HAWQ', 'hdfs-client.xml', true);
  741. Em.setProperties(newProperty, {
  742. description: propertyFromHdfs.description,
  743. displayName: propertyFromHdfs.displayName,
  744. displayType: 'string',
  745. index: propertyIndex,
  746. isOverridable: false,
  747. isReconfigurable: false,
  748. name: propertyFromHdfs.name,
  749. value: propertyFromHdfs.value,
  750. recommendedValue: propertyFromHdfs.recommendedValue
  751. });
  752. configs.push(App.ServiceConfigProperty.create(newProperty));
  753. });
  754. return configs;
  755. },
  756. /**
  757. * render configs, distribute them by service
  758. * and wrap each in ServiceConfigProperty object
  759. * @param stepConfigs
  760. * @param configs
  761. * @return {App.ServiceConfig[]}
  762. */
  763. renderConfigs: function (stepConfigs, configs) {
  764. var localDB = {
  765. hosts: this.get('wizardController.content.hosts'),
  766. masterComponentHosts: this.get('wizardController.content.masterComponentHosts'),
  767. slaveComponentHosts: this.get('wizardController.content.slaveComponentHosts')
  768. };
  769. var configsByService = {}, dependencies = this.get('configDependencies');
  770. configs.forEach(function (_config) {
  771. if (!configsByService[_config.serviceName]) {
  772. configsByService[_config.serviceName] = [];
  773. }
  774. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  775. this.updateHostOverrides(serviceConfigProperty, _config);
  776. if (this.get('wizardController.name') === 'addServiceController') {
  777. this._updateIsEditableFlagForConfig(serviceConfigProperty, true);
  778. }
  779. if (!this.get('content.serviceConfigProperties.length') && !serviceConfigProperty.get('hasInitialValue')) {
  780. App.ConfigInitializer.initialValue(serviceConfigProperty, localDB, dependencies);
  781. }
  782. serviceConfigProperty.validate();
  783. configsByService[_config.serviceName].pushObject(serviceConfigProperty);
  784. }, this);
  785. stepConfigs.forEach(function (service) {
  786. service.set('configs', configsByService[service.get('serviceName')]);
  787. if (['addServiceController', 'installerController'].contains(this.get('wizardController.name'))) {
  788. this.addHostNamesToConfigs(service, localDB.masterComponentHosts, localDB.slaveComponentHosts);
  789. }
  790. }, this);
  791. return stepConfigs;
  792. },
  793. /**
  794. * Add host name properties to appropriate categories (for installer and add service)
  795. *
  796. * @param {Object} serviceConfig
  797. * @param {Object[]} masterComponents - info from localStorage
  798. * @param {Object[]} slaveComponents - info from localStorage
  799. */
  800. addHostNamesToConfigs: function(serviceConfig, masterComponents, slaveComponents) {
  801. serviceConfig.get('configCategories').forEach(function(c) {
  802. if (c.showHost) {
  803. var value = [];
  804. var componentName = c.name;
  805. var masters = masterComponents && masterComponents.filterProperty('component', componentName);
  806. if (masters.length) {
  807. value = masters.mapProperty('hostName');
  808. } else {
  809. var slaves = slaveComponents && slaveComponents.findProperty('componentName', componentName);
  810. if (slaves) {
  811. value = slaves.hosts.mapProperty('hostName');
  812. }
  813. }
  814. var stackComponent = App.StackServiceComponent.find(componentName);
  815. var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), componentName, value, stackComponent);
  816. var newConfigName = Em.get(hProperty, 'name');
  817. if (!serviceConfig.get('configs').someProperty('name', newConfigName)) {
  818. serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
  819. }
  820. }
  821. }, this);
  822. },
  823. /**
  824. * create new child configs from overrides, attach them to parent config
  825. * override - value of config, related to particular host(s)
  826. * @param configProperty
  827. * @param storedConfigProperty
  828. */
  829. updateHostOverrides: function (configProperty, storedConfigProperty) {
  830. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  831. var overrides = [];
  832. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  833. // create new override with new value
  834. var newSCP = App.ServiceConfigProperty.create(configProperty);
  835. newSCP.set('value', overrideEntry.value);
  836. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  837. newSCP.set('parentSCP', configProperty);
  838. overrides.pushObject(newSCP);
  839. });
  840. configProperty.set('overrides', overrides);
  841. }
  842. },
  843. /**
  844. * When NameNode HA is enabled some configs based on <code>dfs.nameservices</code> should be changed
  845. * This happens only if service is added AFTER NN HA is enabled
  846. *
  847. * @param {App.ServiceConfig[]} serviceConfigs
  848. * @method _reconfigureServiceOnNnHa
  849. * @private
  850. * @returns {App.ServiceConfig[]}
  851. */
  852. _reconfigureServicesOnNnHa: function (serviceConfigs) {
  853. var selectedServiceNames = this.get('selectedServiceNames');
  854. var nameServiceId = serviceConfigs.findProperty('serviceName', 'HDFS').configs.findProperty('name', 'dfs.nameservices');
  855. Em.A([
  856. {
  857. serviceName: 'HBASE',
  858. configToUpdate: 'hbase.rootdir'
  859. },
  860. {
  861. serviceName: 'ACCUMULO',
  862. configToUpdate: 'instance.volumes'
  863. },
  864. {
  865. serviceName: 'HAWQ',
  866. configToUpdate: 'hawq_dfs_url',
  867. regexPattern: /(^.*:[0-9]+)(?=\/)/,
  868. replacementValue: nameServiceId.get('value')
  869. }
  870. ]).forEach(function (c) {
  871. if (selectedServiceNames.contains(c.serviceName) && nameServiceId) {
  872. var cfg = serviceConfigs.findProperty('serviceName', c.serviceName).configs.findProperty('name', c.configToUpdate);
  873. var regexPattern = /\/\/.*:[0-9]+/i;
  874. var replacementValue = '//' + nameServiceId.get('value');
  875. if (typeof(c.regexPattern) !== "undefined" && typeof(c.replacementValue) !== "undefined") {
  876. regexPattern = c.regexPattern;
  877. replacementValue = c.replacementValue;
  878. }
  879. var newValue = cfg.get('value').replace(regexPattern, replacementValue);
  880. cfg.setProperties({
  881. value: newValue,
  882. recommendedValue: newValue
  883. });
  884. }
  885. });
  886. return serviceConfigs;
  887. },
  888. /**
  889. * Select first addable service for <code>addServiceWizard</code>
  890. * Select first service at all in other cases
  891. * @method selectProperService
  892. */
  893. selectProperService: function () {
  894. if (this.get('wizardController.name') === 'addServiceController') {
  895. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  896. } else {
  897. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  898. }
  899. },
  900. /**
  901. * Load config tags
  902. * @return {$.ajax|null}
  903. * @method getConfigTags
  904. */
  905. getConfigTags: function () {
  906. this.set('isAppliedConfigLoaded', false);
  907. return App.ajax.send({
  908. name: 'config.tags',
  909. sender: this,
  910. success: 'getConfigTagsSuccess'
  911. });
  912. },
  913. /**
  914. * Success callback for config tags request
  915. * Updates <code>serviceConfigTags</code> with tags received from server
  916. * @param {object} data
  917. * @method getConfigTagsSuccess
  918. */
  919. getConfigTagsSuccess: function (data) {
  920. var installedServiceSites = [];
  921. App.StackService.find().filterProperty('isInstalled').forEach(function (service) {
  922. if (!service.get('configTypes')) return;
  923. var configTypes = Object.keys(service.get('configTypes'));
  924. installedServiceSites = installedServiceSites.concat(configTypes);
  925. }, this);
  926. installedServiceSites = installedServiceSites.uniq();
  927. var serviceConfigTags = [];
  928. for (var site in data.Clusters.desired_configs) {
  929. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  930. if (installedServiceSites.contains(site) || site == 'cluster-env') {
  931. serviceConfigTags.push({
  932. siteName: site,
  933. tagName: data.Clusters.desired_configs[site].tag,
  934. newTagName: null
  935. });
  936. }
  937. }
  938. }
  939. this.set('serviceConfigTags', serviceConfigTags);
  940. this.set('isAppliedConfigLoaded', true);
  941. },
  942. /**
  943. * set configs actual values from server
  944. * @param configs
  945. * @param configsByTags
  946. * @param installedServiceNames
  947. * @method setInstalledServiceConfigs
  948. */
  949. setInstalledServiceConfigs: function (configs, configsByTags, installedServiceNames) {
  950. var configsMap = {};
  951. configsByTags.forEach(function (configSite) {
  952. configsMap[configSite.type] = configSite.properties || {};
  953. });
  954. var allConfigs = configs.filter(function (_config) {
  955. // filter out alert_notification configs on add service //TODO find better place for this!
  956. if (_config.filename === 'alert_notification') return false;
  957. if ((['MISC'].concat(installedServiceNames).contains(_config.serviceName))) {
  958. var type = _config.filename ? App.config.getConfigTagFromFileName(_config.filename) : null;
  959. var mappedConfigValue = type && configsMap[type] ? configsMap[type][_config.name] : null;
  960. if (Em.isNone(mappedConfigValue)) {
  961. //for now ranger plugin properties are not sending by recommendations if they are missed - it should be added
  962. return _config.serviceName == 'MISC' || /^ranger-/.test(_config.filename);
  963. } else {
  964. if (_config.savedValue != mappedConfigValue) {
  965. _config.savedValue = App.config.formatPropertyValue(_config, mappedConfigValue);
  966. }
  967. _config.value = App.config.formatPropertyValue(_config, mappedConfigValue);
  968. _config.hasInitialValue = true;
  969. this.updateDependencies(_config);
  970. delete configsMap[type][_config.name];
  971. return true;
  972. }
  973. } else {
  974. return true;
  975. }
  976. }, this);
  977. //add user properties
  978. Em.keys(configsMap).forEach(function (filename) {
  979. Em.keys(configsMap[filename]).forEach(function (propertyName) {
  980. allConfigs.push(App.config.createDefaultConfig(propertyName,
  981. App.config.getServiceByConfigType(filename) ? App.config.getServiceByConfigType(filename).get('serviceName') : 'MISC',
  982. App.config.getOriginalFileName(filename),
  983. false, {
  984. value: configsMap[filename][propertyName],
  985. savedValue: configsMap[filename][propertyName],
  986. hasInitialValue: true
  987. }));
  988. });
  989. });
  990. return allConfigs;
  991. },
  992. /**
  993. * update dependencies according to current config value
  994. *
  995. * @param config
  996. */
  997. updateDependencies: function(config) {
  998. if (config.name === 'hive.metastore.uris' && config.filename === 'hive-site.xml') {
  999. this.get('configDependencies')['hive.metastore.uris'] = config.savedValue;
  1000. } else if (config.name === 'clientPort' && config.filename === 'hive-site.xml') {
  1001. this.get('configDependencies')['clientPort'] = config.savedValue;
  1002. }
  1003. },
  1004. /**
  1005. * Add group ids to <code>groupsToDelete</code>
  1006. * Also save <code>groupsToDelete</code> to local storage
  1007. * @param {Ember.Object[]} groups
  1008. * @method setGroupsToDelete
  1009. */
  1010. setGroupsToDelete: function (groups) {
  1011. var groupsToDelete = this.get('groupsToDelete');
  1012. groups.forEach(function (group) {
  1013. if (group.get('id'))
  1014. groupsToDelete.push({
  1015. id: group.get('id')
  1016. });
  1017. });
  1018. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  1019. },
  1020. /**
  1021. * Update <code>configGroups</code> with selected service configGroups
  1022. * Also set default group to first position
  1023. * Update <code>selectedConfigGroup</code> with new default group
  1024. * @method selectedServiceObserver
  1025. */
  1026. selectedServiceObserver: function () {
  1027. if (this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  1028. var serviceGroups = this.get('selectedService.configGroups');
  1029. serviceGroups.forEach(function (item, index, array) {
  1030. if (item.isDefault) {
  1031. array.unshift(item);
  1032. array.splice(index + 1, 1);
  1033. }
  1034. });
  1035. this.set('configGroups', serviceGroups);
  1036. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  1037. }
  1038. }.observes('selectedService.configGroups.@each'),
  1039. /**
  1040. * load default groups for each service in case of initial load
  1041. * @param serviceConfigGroups
  1042. * @method loadConfigGroups
  1043. */
  1044. loadConfigGroups: function (serviceConfigGroups) {
  1045. var services = this.get('stepConfigs');
  1046. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  1047. services.forEach(function (service) {
  1048. if (service.get('serviceName') === 'MISC') return;
  1049. var serviceRawGroups = serviceConfigGroups.filterProperty('service_name', service.serviceName);
  1050. var id = App.ServiceConfigGroup.getParentConfigGroupId(service.get('serviceName'));
  1051. if (!serviceRawGroups.length) {
  1052. App.store.load(App.ServiceConfigGroup, App.configGroupsMapper.generateDefaultGroup(service.get('serviceName'), hosts));
  1053. App.store.commit();
  1054. service.set('configGroups', [App.ServiceConfigGroup.find(id)]);
  1055. }
  1056. else {
  1057. App.store.loadMany(App.ServiceConfigGroup, serviceRawGroups);
  1058. App.store.commit();
  1059. serviceRawGroups.forEach(function(item){
  1060. var modelGroup = App.ServiceConfigGroup.find(item.id);
  1061. var wrappedProperties = [];
  1062. item.properties.forEach(function (propertyData) {
  1063. var parentSCP = service.configs.filterProperty('filename', propertyData.filename).findProperty('name', propertyData.name);
  1064. var overriddenSCP = App.ServiceConfigProperty.create(parentSCP);
  1065. overriddenSCP.set('isOriginalSCP', false);
  1066. overriddenSCP.set('parentSCP', parentSCP);
  1067. overriddenSCP.set('group', modelGroup);
  1068. overriddenSCP.setProperties(propertyData);
  1069. wrappedProperties.pushObject(App.ServiceConfigProperty.create(overriddenSCP));
  1070. });
  1071. modelGroup.set('properties', wrappedProperties);
  1072. }, this);
  1073. service.set('configGroups', App.ServiceConfigGroup.find().filterProperty('serviceName', service.get('serviceName')));
  1074. }
  1075. });
  1076. },
  1077. /**
  1078. * Click-handler on config-group to make it selected
  1079. * @param {object} event
  1080. * @method selectConfigGroup
  1081. */
  1082. selectConfigGroup: function (event) {
  1083. this.set('selectedConfigGroup', event.context);
  1084. },
  1085. /**
  1086. * Rebuild list of configs switch of config group:
  1087. * on default - display all configs from default group and configs from non-default groups as disabled
  1088. * on non-default - display all from default group as disabled and configs from selected non-default group
  1089. * @method switchConfigGroupConfigs
  1090. */
  1091. switchConfigGroupConfigs: function () {
  1092. var serviceConfigs = this.get('selectedService.configs'),
  1093. selectedGroup = this.get('selectedConfigGroup'),
  1094. overrideToAdd = this.get('overrideToAdd'),
  1095. overrides = [];
  1096. if (!selectedGroup) return;
  1097. var displayedConfigGroups = this._getDisplayedConfigGroups();
  1098. displayedConfigGroups.forEach(function (group) {
  1099. overrides.pushObjects(group.get('properties'));
  1100. });
  1101. serviceConfigs.forEach(function (config) {
  1102. this._setEditableValue(config);
  1103. this._setOverrides(config, overrides);
  1104. }, this);
  1105. }.observes('selectedConfigGroup'),
  1106. /**
  1107. * Get list of config groups to display
  1108. * Returns empty array if no <code>selectedConfigGroup</code>
  1109. * @return {Array}
  1110. * @method _getDisplayedConfigGroups
  1111. */
  1112. _getDisplayedConfigGroups: function () {
  1113. var selectedGroup = this.get('selectedConfigGroup');
  1114. if (!selectedGroup) return [];
  1115. return (selectedGroup.get('isDefault')) ?
  1116. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  1117. [this.get('selectedConfigGroup')];
  1118. },
  1119. /**
  1120. * Set <code>isEditable</code> property to <code>config</code>
  1121. * @param {Ember.Object} config
  1122. * @return {Ember.Object} updated config-object
  1123. * @method _setEditableValue
  1124. */
  1125. _setEditableValue: function (config) {
  1126. var selectedGroup = this.get('selectedConfigGroup');
  1127. if (!selectedGroup) return config;
  1128. var isEditable = config.get('isEditable'),
  1129. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  1130. if (isServiceInstalled) {
  1131. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  1132. }
  1133. else {
  1134. isEditable = selectedGroup.get('isDefault');
  1135. }
  1136. if (config.get('group')) {
  1137. isEditable = config.get('group.name') == this.get('selectedConfigGroup.name');
  1138. }
  1139. config.set('isEditable', isEditable);
  1140. return config;
  1141. },
  1142. /**
  1143. * Set <code>overrides</code> property to <code>config</code>
  1144. * @param {Ember.Object} config
  1145. * @param {Ember.Enumerable} overrides
  1146. * @returns {Ember.Object}
  1147. * @method _setOverrides
  1148. */
  1149. _setOverrides: function (config, overrides) {
  1150. var selectedGroup = this.get('selectedConfigGroup'),
  1151. overrideToAdd = this.get('overrideToAdd'),
  1152. configOverrides = overrides.filterProperty('name', config.get('name'));
  1153. if (!selectedGroup) return config;
  1154. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  1155. var valueForOverride = (config.get('widget') || config.get('displayType') == 'checkbox') ? config.get('value') : '';
  1156. var group = this.get('selectedService.configGroups').findProperty('name', selectedGroup.get('name'));
  1157. var newSCP = App.config.createOverride(config, {value: valueForOverride, recommendedValue: valueForOverride}, group);
  1158. configOverrides.push(newSCP);
  1159. group.get('properties').pushObject(newSCP);
  1160. this.set('overrideToAdd', null);
  1161. }
  1162. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  1163. configOverrides.setEach('parentSCP', config);
  1164. config.set('overrides', configOverrides);
  1165. return config;
  1166. },
  1167. /**
  1168. * @param serviceName
  1169. * @returns {boolean}
  1170. * @override
  1171. */
  1172. useInitialValue: function(serviceName) {
  1173. return !App.Service.find(serviceName).get('serviceName', serviceName);
  1174. },
  1175. /**
  1176. *
  1177. * @param parentProperties
  1178. * @param name
  1179. * @param fileName
  1180. * @returns {*}
  1181. * @override
  1182. */
  1183. allowUpdateProperty: function(parentProperties, name, fileName) {
  1184. if (['installerController'].contains(this.get('wizardController.name')) || !!(parentProperties && parentProperties.length)) {
  1185. return true;
  1186. } else if (['addServiceController'].contains(this.get('wizardController.name'))) {
  1187. var stackProperty = App.configsCollection.getConfigByName(name, fileName);
  1188. if (!stackProperty || !this.get('installedServices')[stackProperty.serviceName]) {
  1189. return true;
  1190. } else if (stackProperty.propertyDependsOn.length) {
  1191. return stackProperty.propertyDependsOn.filter(function (p) {
  1192. var service = App.config.getServiceByConfigType(p.type);
  1193. return service && !this.get('installedServices')[service.get('serviceName')];
  1194. }, this).length;
  1195. } else {
  1196. return false;
  1197. }
  1198. }
  1199. return true;
  1200. },
  1201. /**
  1202. * remove config based on recommendations
  1203. * @param config
  1204. * @param configsCollection
  1205. * @param parentProperties
  1206. * @protected
  1207. * @override
  1208. */
  1209. _removeConfigByRecommendation: function (config, configsCollection, parentProperties) {
  1210. this._super(config, configsCollection, parentProperties);
  1211. /**
  1212. * need to update wizard info when removing configs for installed services;
  1213. */
  1214. var installedServices = this.get('installedServices'), wizardController = this.get('wizardController'),
  1215. fileNamesToUpdate = wizardController ? wizardController.getDBProperty('fileNamesToUpdate') || [] : [],
  1216. fileName = Em.get(config, 'filename'), serviceName = Em.get(config, 'serviceName');
  1217. var modifiedFileNames = this.get('modifiedFileNames');
  1218. if (modifiedFileNames && !modifiedFileNames.contains(fileName)) {
  1219. modifiedFileNames.push(fileName);
  1220. } else if (wizardController && installedServices[serviceName]) {
  1221. if (!fileNamesToUpdate.contains(fileName)) {
  1222. fileNamesToUpdate.push(fileName);
  1223. }
  1224. }
  1225. if (wizardController) {
  1226. wizardController.setDBProperty('fileNamesToUpdate', fileNamesToUpdate.uniq());
  1227. }
  1228. },
  1229. /**
  1230. * @method manageConfigurationGroup
  1231. */
  1232. manageConfigurationGroup: function () {
  1233. App.router.get('manageConfigGroupsController').manageConfigurationGroups(this);
  1234. },
  1235. /**
  1236. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1237. * @return {$.ajax|null}
  1238. * @method checkMySQLHost
  1239. */
  1240. checkMySQLHost: function () {
  1241. // get ambari database type and hostname
  1242. return App.ajax.send({
  1243. name: 'ambari.service',
  1244. data: {
  1245. fields : "?fields=hostComponents/RootServiceHostComponents/properties/server.jdbc.database_name,hostComponents/RootServiceHostComponents/properties/server.jdbc.url"
  1246. },
  1247. sender: this,
  1248. success: 'getAmbariDatabaseSuccess'
  1249. });
  1250. },
  1251. /**
  1252. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  1253. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  1254. * @param {object} data
  1255. * @method getAmbariDatabaseSuccess
  1256. */
  1257. getAmbariDatabaseSuccess: function (data) {
  1258. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_hostname').value;
  1259. var ambariServiceHostComponents = data.hostComponents;
  1260. if (ambariServiceHostComponents.length) {
  1261. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  1262. this.set('mySQLServerConflict', ambariDBInfo.contains('mysql') && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  1263. } else {
  1264. this.set('mySQLServerConflict', false);
  1265. }
  1266. },
  1267. /**
  1268. * Check if new MySql database was chosen for Hive service
  1269. * and it is not located on the same host as Ambari server
  1270. * that using MySql database too.
  1271. *
  1272. * @method resolveHiveMysqlDatabase
  1273. **/
  1274. resolveHiveMysqlDatabase: function () {
  1275. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  1276. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  1277. this.moveNext();
  1278. return;
  1279. }
  1280. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  1281. if (hiveDBType == 'New MySQL Database') {
  1282. var self = this;
  1283. return this.checkMySQLHost().done(function () {
  1284. self.mySQLWarningHandler();
  1285. });
  1286. }
  1287. else {
  1288. this.moveNext();
  1289. }
  1290. },
  1291. /**
  1292. * Show warning popup about MySQL-DB issues (on post-submit)
  1293. *
  1294. * @returns {*}
  1295. * @method mySQLWarningHandler
  1296. */
  1297. mySQLWarningHandler: function () {
  1298. var self = this;
  1299. if (this.get('mySQLServerConflict')) {
  1300. // error popup before you can proceed
  1301. return App.ModalPopup.show({
  1302. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  1303. body:Em.I18n.t('installer.step7.popup.mySQLWarning.body'),
  1304. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  1305. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  1306. encodeBody: false,
  1307. onPrimary: function () {
  1308. this._super();
  1309. self.set('submitButtonClicked', false);
  1310. },
  1311. onSecondary: function () {
  1312. var parent = this;
  1313. return App.ModalPopup.show({
  1314. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  1315. body: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'),
  1316. onPrimary: function () {
  1317. this.hide();
  1318. parent.hide();
  1319. // go back to step 5: assign masters and disable default navigation warning
  1320. if ('installerController' === self.get('content.controllerName')) {
  1321. App.router.get('installerController').gotoStep(5, true);
  1322. }
  1323. else {
  1324. if ('addServiceController' === self.get('content.controllerName')) {
  1325. App.router.get('addServiceController').gotoStep(2, true);
  1326. }
  1327. }
  1328. },
  1329. onSecondary: function () {
  1330. this._super();
  1331. self.set('submitButtonClicked', false);
  1332. }
  1333. });
  1334. }
  1335. });
  1336. }
  1337. else {
  1338. return this.moveNext();
  1339. }
  1340. },
  1341. checkDatabaseConnectionTest: function () {
  1342. var deferred = $.Deferred();
  1343. var configMap = [
  1344. {
  1345. serviceName: 'OOZIE',
  1346. ignored: [Em.I18n.t('installer.step7.oozie.database.new')]
  1347. },
  1348. {
  1349. serviceName: 'HIVE',
  1350. ignored: [Em.I18n.t('installer.step7.hive.database.new.mysql'), Em.I18n.t('installer.step7.hive.database.new.postgres')]
  1351. }
  1352. ];
  1353. configMap.forEach(function (config) {
  1354. var isConnectionNotTested = false;
  1355. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1356. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1357. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1358. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1359. if (!config.ignored.contains(serviceDatabase)) {
  1360. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1361. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1362. isConnectionNotTested = true;
  1363. } else {
  1364. for (var key in filledProperties) {
  1365. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1366. isConnectionNotTested = true;
  1367. }
  1368. }
  1369. }
  1370. }
  1371. config.isCheckIgnored = isConnectionNotTested;
  1372. }, this);
  1373. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1374. if (ignoredServices.length) {
  1375. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function (serviceName) {
  1376. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1377. }, this);
  1378. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1379. }
  1380. else {
  1381. deferred.resolve();
  1382. }
  1383. return deferred;
  1384. },
  1385. showChangesWarningPopup: function(goToNextStep) {
  1386. return App.ModalPopup.show({
  1387. header: Em.I18n.t('common.warning'),
  1388. body: Em.I18n.t('services.service.config.exitChangesPopup.body'),
  1389. secondary: Em.I18n.t('common.cancel'),
  1390. primary: Em.I18n.t('yes'),
  1391. onPrimary: function () {
  1392. if (goToNextStep) {
  1393. goToNextStep();
  1394. this.hide();
  1395. }
  1396. },
  1397. onSecondary: function () {
  1398. this.hide();
  1399. }
  1400. });
  1401. },
  1402. showDatabaseConnectionWarningPopup: function (serviceNames, deferred) {
  1403. var self = this;
  1404. return App.ModalPopup.show({
  1405. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1406. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1407. secondary: Em.I18n.t('common.cancel'),
  1408. primary: Em.I18n.t('common.proceedAnyway'),
  1409. onPrimary: function () {
  1410. deferred.resolve();
  1411. this._super();
  1412. },
  1413. onSecondary: function () {
  1414. self.set('submitButtonClicked', false);
  1415. deferred.reject();
  1416. this._super();
  1417. }
  1418. });
  1419. },
  1420. showOozieDerbyWarningPopup: function(callback) {
  1421. var self = this;
  1422. if (this.get('selectedServiceNames').contains('OOZIE')) {
  1423. var databaseType = Em.getWithDefault(this.findConfigProperty('oozie_database', 'oozie-env.xml') || {}, 'value', '');
  1424. if (databaseType == Em.I18n.t('installer.step7.oozie.database.new')) {
  1425. return App.ModalPopup.show({
  1426. header: Em.I18n.t('common.warning'),
  1427. body: Em.I18n.t('installer.step7.popup.oozie.derby.warning'),
  1428. secondary: Em.I18n.t('common.cancel'),
  1429. primary: Em.I18n.t('common.proceedAnyway'),
  1430. onPrimary: function() {
  1431. this.hide();
  1432. if (callback) {
  1433. callback();
  1434. }
  1435. },
  1436. onSecondary: function() {
  1437. self.set('submitButtonClicked', false);
  1438. this.hide();
  1439. },
  1440. onClose: function() {
  1441. this.onSecondary();
  1442. }
  1443. });
  1444. }
  1445. }
  1446. if (callback) {
  1447. callback();
  1448. }
  1449. return false;
  1450. },
  1451. /**
  1452. * Proceed to the next step
  1453. **/
  1454. moveNext: function () {
  1455. App.router.send('next');
  1456. this.set('submitButtonClicked', false);
  1457. },
  1458. /**
  1459. * Click-handler on Next button
  1460. * Disable "Submit"-button while server-side processes are running
  1461. * @method submit
  1462. */
  1463. submit: function () {
  1464. if (this.get('isSubmitDisabled')) {
  1465. return false;
  1466. }
  1467. var preInstallChecksController = App.router.get('preInstallChecksController');
  1468. if (this.get('supportsPreInstallChecks')) {
  1469. if (preInstallChecksController.get('preInstallChecksWhereRun')) {
  1470. return this.postSubmit();
  1471. }
  1472. return preInstallChecksController.notRunChecksWarnPopup(this.postSubmit.bind(this));
  1473. }
  1474. return this.postSubmit();
  1475. },
  1476. postSubmit: function () {
  1477. var self = this;
  1478. this.set('submitButtonClicked', true);
  1479. this.serverSideValidation().done(function() {
  1480. self.serverSideValidationCallback();
  1481. })
  1482. .fail(function (value) {
  1483. if ("invalid_configs" == value) {
  1484. self.set('submitButtonClicked', false);
  1485. } else {
  1486. // Failed due to validation mechanism failure.
  1487. // Should proceed with other checks
  1488. self.serverSideValidationCallback();
  1489. }
  1490. });
  1491. },
  1492. /**
  1493. * @method serverSideValidationCallback
  1494. */
  1495. serverSideValidationCallback: function() {
  1496. var self = this;
  1497. this.showOozieDerbyWarningPopup(function() {
  1498. self.checkDatabaseConnectionTest().done(function () {
  1499. self.resolveHiveMysqlDatabase();
  1500. });
  1501. });
  1502. },
  1503. toggleIssuesFilter: function () {
  1504. this.get('filterColumns').findProperty('attributeName', 'hasIssues').toggleProperty('selected');
  1505. // if currently selected service does not have issue, jump to the first service with issue.
  1506. if (this.get('selectedService.errorCount') == 0 )
  1507. {
  1508. var errorServices = this.get('stepConfigs').filterProperty('errorCount');
  1509. if (errorServices.length > 0)
  1510. {
  1511. var service = errorServices[0];
  1512. this.set('selectedService', service);
  1513. $('a[href="#' + service.serviceName + '"]').tab('show');
  1514. }
  1515. }
  1516. }
  1517. });