step7_controller.js 56 KB

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