step7_controller.js 59 KB

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