step7_controller.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  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. var numberUtils = require('utils/number_utils');
  20. /**
  21. * By Step 7, we have the following information stored in App.db and set on this
  22. * controller by the router.
  23. *
  24. * selectedServices: App.db.selectedServices (the services that the user selected in Step 4)
  25. * masterComponentHosts: App.db.masterComponentHosts (master-components-to-hosts mapping the user selected in Step 5)
  26. * slaveComponentHosts: App.db.slaveComponentHosts (slave-components-to-hosts mapping the user selected in Step 6)
  27. *
  28. */
  29. App.WizardStep7Controller = Em.Controller.extend({
  30. name: 'wizardStep7Controller',
  31. /**
  32. * Contains all field properties that are viewed in this step
  33. * @type {object[]}
  34. */
  35. stepConfigs: [],
  36. selectedService: null,
  37. slaveHostToGroup: null,
  38. secureConfigs: require('data/secure_mapping'),
  39. /**
  40. * If miscConfigChange Modal is shown
  41. * @type {bool}
  42. */
  43. miscModalVisible: false,
  44. gangliaAvailableSpace: null,
  45. /**
  46. * @type {string}
  47. */
  48. gangliaMoutDir: '/',
  49. overrideToAdd: null,
  50. /**
  51. * Is installer controller used
  52. * @type {bool}
  53. */
  54. isInstaller: true,
  55. /**
  56. * List of config groups
  57. * @type {object[]}
  58. */
  59. configGroups: [],
  60. /**
  61. * List of config group to be deleted
  62. * @type {object[]}
  63. */
  64. groupsToDelete: [],
  65. /**
  66. * Currently selected config group
  67. * @type {object}
  68. */
  69. selectedConfigGroup: null,
  70. /**
  71. * Config tags of actually installed services
  72. * @type {array}
  73. */
  74. serviceConfigTags: [],
  75. serviceConfigsData: require('data/service_configs'),
  76. /**
  77. * Are advanced configs loaded
  78. * @type {bool}
  79. */
  80. isAdvancedConfigLoaded: true,
  81. /**
  82. * Should Next-button be disabled
  83. * @type {bool}
  84. */
  85. isSubmitDisabled: function () {
  86. return (!this.stepConfigs.filterProperty('showConfig', true).everyProperty('errorCount', 0) || this.get("miscModalVisible"));
  87. }.property('stepConfigs.@each.errorCount', 'miscModalVisible'),
  88. /**
  89. * List of selected to install service names
  90. * @type {string[]}
  91. */
  92. selectedServiceNames: function () {
  93. return this.get('content.services').filterProperty('isSelected', true).filterProperty('isInstalled', false).mapProperty('serviceName');
  94. }.property('content.services').cacheable(),
  95. /**
  96. * List of installed and selected to install service names
  97. * @type {string[]}
  98. */
  99. allSelectedServiceNames: function () {
  100. return this.get('content.services').filterProperty('isSelected').mapProperty('serviceName');
  101. }.property('content.services').cacheable(),
  102. /**
  103. * List of installed service names
  104. * Sqoop and HCatalog are excluded if not installer wizard running
  105. * @type {string[]}
  106. */
  107. installedServiceNames: function () {
  108. var serviceNames = this.get('content.services').filterProperty('isInstalled').mapProperty('serviceName');
  109. if (this.get('content.controllerName') !== 'installerController') {
  110. return serviceNames.without('SQOOP').without('HCATALOG');
  111. }
  112. return serviceNames;
  113. }.property('content.services').cacheable(),
  114. /**
  115. * List of master components
  116. * @type {Ember.Enumerable}
  117. */
  118. masterComponentHosts: function () {
  119. return this.get('content.masterComponentHosts');
  120. }.property('content.masterComponentHosts'),
  121. /**
  122. * List of slave components
  123. * @type {Ember.Enumerable}
  124. */
  125. slaveComponentHosts: function () {
  126. return this.get('content.slaveGroupProperties');
  127. }.property('content.slaveGroupProperties', 'content.slaveComponentHosts'),
  128. customData: [],
  129. /**
  130. * Filter text will be located here
  131. * @type {string}
  132. */
  133. filter: '',
  134. /**
  135. * Dropdown menu items in filter combobox
  136. * @type {Ember.Object[]}
  137. */
  138. filterColumns: function () {
  139. var result = [];
  140. for (var i = 1; i < 2; i++) {
  141. result.push(Em.Object.create({
  142. name: this.t('common.combobox.dropdown.' + i),
  143. selected: false
  144. }));
  145. }
  146. return result;
  147. }.property(),
  148. /**
  149. * Clear controller's properties:
  150. * <ul>
  151. * <li>serviceConfigTags</li>
  152. * <li>stepConfigs</li>
  153. * <li>filter</li>
  154. * </ul>
  155. * and desect all <code>filterColumns</code>
  156. * @method clearStep
  157. */
  158. clearStep: function () {
  159. this.get('serviceConfigTags').clear();
  160. this.get('stepConfigs').clear();
  161. this.set('filter', '');
  162. this.get('filterColumns').setEach('selected', false);
  163. },
  164. /**
  165. * Load config groups for installed services
  166. * One ajax-request for each service
  167. * @param {string[]} servicesNames
  168. * @method loadInstalledServicesConfigGroups
  169. */
  170. loadInstalledServicesConfigGroups: function (servicesNames) {
  171. servicesNames.forEach(function (serviceName) {
  172. App.ajax.send({
  173. name: 'config.tags_and_groups',
  174. sender: this,
  175. data: {
  176. serviceName: serviceName,
  177. serviceConfigsDef: App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName)
  178. },
  179. success: 'loadServiceTagsSuccess'
  180. });
  181. }, this);
  182. },
  183. /**
  184. * Create site to tag map. Format:
  185. * <code>
  186. * {
  187. * site1: tag1,
  188. * site1: tag2,
  189. * site2: tag3
  190. * ...
  191. * }
  192. * </code>
  193. * @param {object} desired_configs
  194. * @param {string[]} sites
  195. * @returns {object}
  196. * @private
  197. * @method _createSiteToTagMap
  198. */
  199. _createSiteToTagMap: function (desired_configs, sites) {
  200. var siteToTagMap = {};
  201. for (var site in desired_configs) {
  202. if (desired_configs.hasOwnProperty(site)) {
  203. if (sites.indexOf(site) > -1) {
  204. siteToTagMap[site] = desired_configs[site].tag;
  205. }
  206. }
  207. }
  208. return siteToTagMap;
  209. },
  210. /**
  211. * Load config groups success callback
  212. * @param {object} data
  213. * @param {object} opt
  214. * @param {object} params
  215. * @method loadServiceTagsSuccess
  216. */
  217. loadServiceTagsSuccess: function (data, opt, params) {
  218. var serviceName = params.serviceName,
  219. service = this.get('stepConfigs').findProperty('serviceName', serviceName),
  220. defaultConfigGroupHosts = this.get('wizardController.allHosts').mapProperty('hostName'),
  221. siteToTagMap = this._createSiteToTagMap(data.Clusters.desired_configs, params.serviceConfigsDef.sites),
  222. selectedConfigGroup;
  223. this.set('loadedClusterSiteToTagMap', siteToTagMap);
  224. //parse loaded config groups
  225. if (App.get('supports.hostOverrides')) {
  226. var configGroups = [];
  227. if (data.config_groups.length) {
  228. data.config_groups.forEach(function (item) {
  229. item = item.ConfigGroup;
  230. if (item.tag === serviceName) {
  231. var groupHosts = item.hosts.mapProperty('host_name');
  232. var newConfigGroup = App.ConfigGroup.create({
  233. id: item.id,
  234. name: item.group_name,
  235. description: item.description,
  236. isDefault: false,
  237. parentConfigGroup: null,
  238. service: App.Service.find().findProperty('serviceName', item.tag),
  239. hosts: groupHosts,
  240. configSiteTags: []
  241. });
  242. groupHosts.forEach(function (host) {
  243. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  244. }, this);
  245. item.desired_configs.forEach(function (config) {
  246. newConfigGroup.configSiteTags.push(App.ConfigSiteTag.create({
  247. site: config.type,
  248. tag: config.tag
  249. }));
  250. }, this);
  251. configGroups.push(newConfigGroup);
  252. }
  253. }, this);
  254. }
  255. }
  256. var defaultConfigGroup = App.ConfigGroup.create({
  257. name: App.Service.DisplayNames[serviceName] + " Default",
  258. description: "Default cluster level " + serviceName + " configuration",
  259. isDefault: true,
  260. hosts: defaultConfigGroupHosts,
  261. parentConfigGroup: null,
  262. service: Em.Object.create({
  263. id: serviceName
  264. }),
  265. serviceName: serviceName,
  266. configSiteTags: []
  267. });
  268. if (!selectedConfigGroup) {
  269. selectedConfigGroup = defaultConfigGroup;
  270. }
  271. configGroups = configGroups.sortProperty('name');
  272. configGroups.unshift(defaultConfigGroup);
  273. if (App.get('supports.hostOverrides')) {
  274. service.set('configGroups', configGroups);
  275. var loadedGroupToOverrideSiteToTagMap = {};
  276. if (App.get('supports.hostOverrides')) {
  277. var configGroupsWithOverrides = selectedConfigGroup.get('isDefault') ? service.get('configGroups') : [selectedConfigGroup];
  278. configGroupsWithOverrides.forEach(function (item) {
  279. var groupName = item.get('name');
  280. loadedGroupToOverrideSiteToTagMap[groupName] = {};
  281. item.get('configSiteTags').forEach(function (siteTag) {
  282. var site = siteTag.get('site');
  283. loadedGroupToOverrideSiteToTagMap[groupName][site] = siteTag.get('tag');
  284. }, this);
  285. }, this);
  286. }
  287. App.config.loadServiceConfigGroupOverrides(service.get('configs'), loadedGroupToOverrideSiteToTagMap, service.get('configGroups'));
  288. var serviceConfig = App.config.createServiceConfig(serviceName);
  289. if (serviceConfig.get('serviceName') === 'HDFS') {
  290. App.config.OnNnHAHideSnn(serviceConfig);
  291. }
  292. service.set('selectedConfigGroup', selectedConfigGroup);
  293. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  294. }
  295. service.set('configs', serviceConfig.get('configs'));
  296. },
  297. /**
  298. * Get object with recommended default values for config properties
  299. * Format:
  300. * <code>
  301. * {
  302. * configName1: configValue1,
  303. * configName2: configValue2
  304. * ...
  305. * }
  306. * </code>
  307. * @param {string} serviceName
  308. * @returns {object}
  309. * @method _getRecommendedDefaultsForComponent
  310. */
  311. _getRecommendedDefaultsForComponent: function (serviceName) {
  312. var s = this.get('serviceConfigsData').findProperty('serviceName', serviceName),
  313. recommendedDefaults = {},
  314. localDB = App.router.get('mainServiceInfoConfigsController').getInfoForDefaults();
  315. if (s.defaultsProviders) {
  316. s.defaultsProviders.forEach(function (defaultsProvider) {
  317. var d = defaultsProvider.getDefaults(localDB);
  318. for (var name in d) {
  319. if (d.hasOwnProperty(name)) {
  320. recommendedDefaults[name] = d[name];
  321. }
  322. }
  323. });
  324. }
  325. return recommendedDefaults;
  326. },
  327. /**
  328. * By default <code>value</code>-property is string "true|false".
  329. * Should update it to boolean type
  330. * Also affects <code>defaultValue</code>
  331. * @param {Ember.Object} serviceConfigProperty
  332. * @returns {Ember.Object} Updated config-object
  333. * @method _updateValueForCheckBoxConfig
  334. */
  335. _updateValueForCheckBoxConfig: function (serviceConfigProperty) {
  336. var v = serviceConfigProperty.get('value');
  337. switch (serviceConfigProperty.get('value')) {
  338. case 'true':
  339. v = true;
  340. break;
  341. case 'false':
  342. v = false;
  343. break;
  344. }
  345. serviceConfigProperty.setProperties({value: v, defaultValue: v});
  346. return serviceConfigProperty;
  347. },
  348. /**
  349. * Set <code>isEditable</code>-property to <code>serviceConfigProperty</code>
  350. * Based on user's permissions and selected config group
  351. * @param {Ember.Object} serviceConfigProperty
  352. * @param {bool} defaultGroupSelected
  353. * @returns {Ember.Object} Updated config-object
  354. * @method _updateIsEditableFlagForConfig
  355. */
  356. _updateIsEditableFlagForConfig: function (serviceConfigProperty, defaultGroupSelected) {
  357. if (App.get('isAdmin')) {
  358. if (defaultGroupSelected && !this.get('isHostsConfigsPage')) {
  359. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  360. }
  361. else {
  362. serviceConfigProperty.set('isEditable', false);
  363. }
  364. }
  365. else {
  366. serviceConfigProperty.set('isEditable', false);
  367. }
  368. return serviceConfigProperty;
  369. },
  370. /**
  371. * Set <code>overrides</code>-property to <code>serviceConfigProperty<code>
  372. * @param {Ember.Object} serviceConfigProperty
  373. * @param {Ember.Object} component
  374. * @return {Ember.Object} Updated config-object
  375. * @method _updateOverridesForConfig
  376. */
  377. _updateOverridesForConfig: function (serviceConfigProperty, component) {
  378. var overrides = serviceConfigProperty.get('overrides');
  379. if (Em.isNone(overrides)) {
  380. serviceConfigProperty.set('overrides', Em.A([]));
  381. return serviceConfigProperty;
  382. }
  383. serviceConfigProperty.set('overrides', null);
  384. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  385. // Wrap each override to App.ServiceConfigProperty
  386. overrides.forEach(function (override) {
  387. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  388. newSCP.set('value', override.value);
  389. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  390. newSCP.set('parentSCP', serviceConfigProperty);
  391. if (App.get('supports.hostOverrides') && defaultGroupSelected) {
  392. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  393. // prevent cycle in proto object, clean link
  394. if (group.get('properties').length == 0) {
  395. group.set('properties', Em.A([]));
  396. }
  397. group.get('properties').push(newSCP);
  398. newSCP.set('group', override.group);
  399. newSCP.set('isEditable', false);
  400. }
  401. var parentOverridesArray = serviceConfigProperty.get('overrides');
  402. if (Em.isNone(parentOverridesArray)) {
  403. parentOverridesArray = Em.A([]);
  404. serviceConfigProperty.set('overrides', parentOverridesArray);
  405. }
  406. serviceConfigProperty.get('overrides').pushObject(newSCP);
  407. }, this);
  408. return serviceConfigProperty;
  409. },
  410. /**
  411. * Set <code>serviceValidator</code>-property to <code>serviceConfigProperty</code> if config's serviceName is equal
  412. * to component's serviceName
  413. * othervise set <code>isVisible</code>-property to <code>false</code>
  414. * @param {Ember.Object} serviceConfigProperty
  415. * @param {Ember.Object} component
  416. * @param {object} serviceConfigsData
  417. * @returns {Ember.Object} updated config-object
  418. * @mrthod _updateValidatorsForConfig
  419. */
  420. _updateValidatorsForConfig: function (serviceConfigProperty, component, serviceConfigsData) {
  421. if (serviceConfigProperty.get('serviceName') === component.get('serviceName')) {
  422. if (serviceConfigsData.configsValidator) {
  423. var validators = serviceConfigsData.configsValidator.get('configValidators');
  424. for (var validatorName in validators) {
  425. if (validators.hasOwnProperty(validatorName)) {
  426. if (serviceConfigProperty.get('name') == validatorName) {
  427. serviceConfigProperty.set('serviceValidator', serviceConfigsData.configsValidator);
  428. }
  429. }
  430. }
  431. }
  432. }
  433. else {
  434. serviceConfigProperty.set('isVisible', false);
  435. }
  436. return serviceConfigProperty;
  437. },
  438. /**
  439. * Set configs with overrides, recommended defaults to component
  440. * @param {Ember.Object[]} configs
  441. * @param {Ember.Object} componentConfig
  442. * @param {Ember.Object} component
  443. * @method loadComponentConfigs
  444. */
  445. loadComponentConfigs: function (configs, componentConfig, component) {
  446. var s = this.get('serviceConfigsData').findProperty('serviceName', component.get('serviceName')),
  447. defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  448. if (s.configsValidator) {
  449. var recommendedDefaults = this._getRecommendedDefaultsForComponent(component.get('serviceName'));
  450. s.configsValidator.set('recommendedDefaults', recommendedDefaults);
  451. }
  452. configs.forEach(function (serviceConfigProperty) {
  453. if (!serviceConfigProperty) return;
  454. if (Em.isNone(serviceConfigProperty.get('isOverridable'))) {
  455. serviceConfigProperty.set('isOverridable', true);
  456. }
  457. if (serviceConfigProperty.get('displayType') === 'checkbox') {
  458. this._updateValueForCheckBoxConfig(serviceConfigProperty);
  459. }
  460. this._updateValidatorsForConfig(serviceConfigProperty, component, s);
  461. this._updateOverridesForConfig(serviceConfigProperty, component);
  462. this._updateIsEditableFlagForConfig(serviceConfigProperty, defaultGroupSelected);
  463. componentConfig.get('configs').pushObject(serviceConfigProperty);
  464. serviceConfigProperty.validate();
  465. }, this);
  466. var overrideToAdd = this.get('overrideToAdd');
  467. if (overrideToAdd) {
  468. overrideToAdd = componentConfig.get('configs').findProperty('name', overrideToAdd.name);
  469. if (overrideToAdd) {
  470. this.addOverrideProperty(overrideToAdd);
  471. component.set('overrideToAdd', null);
  472. }
  473. }
  474. },
  475. /**
  476. * Resolve dependency between configs.
  477. * @param serviceName {String}
  478. * @param configs {Ember.Enumerable}
  479. */
  480. resolveServiceDependencyConfigs: function (serviceName, configs) {
  481. switch (serviceName) {
  482. case 'STORM':
  483. this.resolveStormConfigs(configs);
  484. break;
  485. default:
  486. break;
  487. }
  488. },
  489. /**
  490. * Update some Storm configs
  491. * If Ganglia is selected to install or already installed, Ganglia host should be added to configs
  492. * @param {Ember.Enumerable} configs
  493. * @method resolveStormConfigs
  494. */
  495. resolveStormConfigs: function (configs) {
  496. var dependentConfigs, gangliaServerHost;
  497. dependentConfigs = ['nimbus.childopts', 'supervisor.childopts', 'worker.childopts'];
  498. // if Ganglia selected or installed, set ganglia host to configs
  499. if (this.get('installedServiceNames').contains('STORM') && this.get('installedServiceNames').contains('GANGLIA')) return;
  500. if (this.get('allSelectedServiceNames').contains('GANGLIA') || this.get('installedServiceNames').contains('GANGLIA')) {
  501. gangliaServerHost = this.get('wizardController').getDBProperty('masterComponentHosts').findProperty('component', 'GANGLIA_SERVER').hostName;
  502. dependentConfigs.forEach(function (configName) {
  503. var config = configs.findProperty('name', configName);
  504. var replaceStr = config.value.match(/.jar=host[^,]+/)[0];
  505. var replaceWith = replaceStr.slice(0, replaceStr.lastIndexOf('=') - replaceStr.length + 1) + gangliaServerHost;
  506. config.value = config.defaultValue = config.value.replace(replaceStr, replaceWith);
  507. config.forceUpdate = true;
  508. }, this);
  509. }
  510. },
  511. /**
  512. * On load function
  513. * @method loadStep
  514. */
  515. loadStep: function () {
  516. console.log("TRACE: Loading step7: Configure Services");
  517. if (!this.get('isAdvancedConfigLoaded')) {
  518. return;
  519. }
  520. this.clearStep();
  521. //STEP 1: Load advanced configs
  522. var advancedConfigs = this.get('content.advancedServiceConfig');
  523. //STEP 2: Load on-site configs by service from local DB
  524. var storedConfigs = this.get('content.serviceConfigProperties');
  525. //STEP 3: Merge pre-defined configs with loaded on-site configs
  526. var configs = App.config.mergePreDefinedWithStored(
  527. storedConfigs,
  528. advancedConfigs,
  529. this.get('selectedServiceNames').concat(this.get('installedServiceNames'))
  530. );
  531. //STEP 4: Add advanced configs
  532. App.config.addAdvancedConfigs(configs, advancedConfigs);
  533. //STEP 5: Add custom configs
  534. App.config.addCustomConfigs(configs);
  535. //put properties from capacity-scheduler.xml into one config with textarea view
  536. if (this.get('allSelectedServiceNames').contains('YARN') && !App.get('supports.capacitySchedulerUi')) {
  537. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  538. }
  539. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  540. if (this.get('wizardController.name') === 'addServiceController') {
  541. this.getConfigTags();
  542. this.setInstalledServiceConfigs(this.get('serviceConfigTags'), configs);
  543. }
  544. if (this.get('allSelectedServiceNames').contains('STORM') || this.get('installedServiceNames').contains('STORM')) {
  545. this.resolveServiceDependencyConfigs('STORM', configs);
  546. }
  547. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  548. this.setStepConfigs(configs, storedConfigs);
  549. this.checkHostOverrideInstaller();
  550. this.activateSpecialConfigs();
  551. this.selectProperService();
  552. if (this.get('content.skipConfigStep')) {
  553. App.router.send('next');
  554. }
  555. },
  556. /**
  557. * If <code>App.supports.hostOverridesInstaller</code> is enabled should load config groups
  558. * and (if some services are already installed) load config groups for installed services
  559. * @method checkHostOverrideInstaller
  560. */
  561. checkHostOverrideInstaller: function () {
  562. if (App.get('supports.hostOverridesInstaller')) {
  563. this.loadConfigGroups(this.get('content.configGroups'));
  564. if (this.get('installedServiceNames').length > 0) {
  565. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  566. }
  567. }
  568. },
  569. /**
  570. * Set init <code>stepConfigs</code> value
  571. * Set <code>selected</code> for addable services if addServiceController is used
  572. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  573. * @param {Ember.Object[]} configs
  574. * @param {Ember.Object[]} storedConfigs
  575. * @method setStepConfigs
  576. */
  577. setStepConfigs: function (configs, storedConfigs) {
  578. var localDB = {
  579. hosts: this.get('wizardController').getDBProperty('hosts'),
  580. masterComponentHosts: this.get('wizardController').getDBProperty('masterComponentHosts'),
  581. slaveComponentHosts: this.get('wizardController').getDBProperty('slaveComponentHosts')
  582. };
  583. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB);
  584. if (this.get('wizardController.name') === 'addServiceController') {
  585. serviceConfigs.setEach('showConfig', true);
  586. serviceConfigs.setEach('selected', false);
  587. this.get('selectedServiceNames').forEach(function (serviceName) {
  588. if (!serviceConfigs.findProperty('serviceName', serviceName)) return;
  589. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  590. });
  591. // Remove SNameNode if HA is enabled
  592. if (App.get('isHaEnabled')) {
  593. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  594. var removedConfigs = c.filterProperty('category', 'SNameNode');
  595. removedConfigs.map(function (config) {
  596. c = c.without(config);
  597. });
  598. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  599. }
  600. }
  601. this.set('stepConfigs', serviceConfigs);
  602. },
  603. /**
  604. * Select first addable service for <code>addServiceWizard</code>
  605. * Select first service at all in other cases
  606. * @method selectProperService
  607. */
  608. selectProperService: function () {
  609. if (this.get('wizardController.name') === 'addServiceController') {
  610. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  611. }
  612. else {
  613. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  614. }
  615. },
  616. /**
  617. * Load config tags
  618. * @return {$.ajax|null}
  619. * @method getConfigTags
  620. */
  621. getConfigTags: function () {
  622. return App.ajax.send({
  623. name: 'config.tags.sync',
  624. sender: this,
  625. success: 'getConfigTagsSuccess'
  626. });
  627. },
  628. /**
  629. * Success callback for config tags request
  630. * Updates <code>serviceConfigTags</code> with tags received from server
  631. * @param {object} data
  632. * @method getConfigTagsSuccess
  633. */
  634. getConfigTagsSuccess: function (data) {
  635. var installedServiceSites = [];
  636. this.get('serviceConfigsData').filter(function (service) {
  637. if (this.get('installedServiceNames').contains(service.serviceName)) {
  638. installedServiceSites = installedServiceSites.concat(service.sites);
  639. }
  640. }, this);
  641. installedServiceSites = installedServiceSites.uniq();
  642. var serviceConfigTags = [];
  643. for (var site in data.Clusters.desired_configs) {
  644. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  645. if (installedServiceSites.contains(site)) {
  646. serviceConfigTags.push({
  647. siteName: site,
  648. tagName: data.Clusters.desired_configs[site].tag,
  649. newTagName: null
  650. });
  651. }
  652. }
  653. }
  654. this.set('serviceConfigTags', serviceConfigTags);
  655. },
  656. /**
  657. * set configs actual values from server
  658. * @param serviceConfigTags
  659. * @param configs
  660. * @method setInstalledServiceConfigs
  661. */
  662. setInstalledServiceConfigs: function (serviceConfigTags, configs) {
  663. var configsMap = {};
  664. App.router.get('configurationController').getConfigsByTags(serviceConfigTags).forEach(function (configSite) {
  665. $.extend(configsMap, configSite.properties);
  666. });
  667. configs.forEach(function (_config) {
  668. if (configsMap[_config.name] !== undefined) {
  669. // prevent overriding already edited properties
  670. if (_config.defaultValue != configsMap[_config.name])
  671. _config.value = configsMap[_config.name];
  672. _config.defaultValue = configsMap[_config.name];
  673. App.config.handleSpecialProperties(_config);
  674. }
  675. })
  676. },
  677. /**
  678. * Add group ids to <code>groupsToDelete</code>
  679. * Also save <code>groupsToDelete</code> to local storage
  680. * @param {Ember.Object[]} groups
  681. * @method setGroupsToDelete
  682. */
  683. setGroupsToDelete: function (groups) {
  684. var groupsToDelete = this.get('groupsToDelete');
  685. groups.forEach(function (group) {
  686. if (group.get('id'))
  687. groupsToDelete.push({
  688. id: group.get('id')
  689. });
  690. });
  691. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  692. },
  693. /**
  694. * Update <code>configGroups</code> with selected service configGroups
  695. * Also set default group to first position
  696. * Update <code>selectedConfigGroup</code> with new default group
  697. * @method selectedServiceObserver
  698. */
  699. selectedServiceObserver: function () {
  700. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  701. var serviceGroups = this.get('selectedService.configGroups');
  702. serviceGroups.forEach(function (item, index, array) {
  703. if (item.isDefault) {
  704. array.unshift(item);
  705. array.splice(index + 1, 1);
  706. }
  707. });
  708. this.set('configGroups', serviceGroups);
  709. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  710. }
  711. }.observes('selectedService.configGroups.@each'),
  712. /**
  713. * load default groups for each service in case of initial load
  714. * @param serviceConfigGroups
  715. * @method loadConfigGroups
  716. */
  717. loadConfigGroups: function (serviceConfigGroups) {
  718. var services = this.get('stepConfigs');
  719. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  720. services.forEach(function (service) {
  721. if (service.get('serviceName') === 'MISC') return;
  722. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  723. if (!serviceRawGroups.length) {
  724. service.set('configGroups', [
  725. App.ConfigGroup.create({
  726. name: App.Service.DisplayNames[service.serviceName] + " Default",
  727. description: "Default cluster level " + service.serviceName + " configuration",
  728. isDefault: true,
  729. hosts: Em.copy(hosts),
  730. service: Em.Object.create({
  731. id: service.serviceName
  732. }),
  733. serviceName: service.serviceName
  734. })
  735. ]);
  736. }
  737. else {
  738. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  739. var serviceGroups = service.get('configGroups');
  740. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  741. var readyGroup = App.ConfigGroup.create(configGroup);
  742. var wrappedProperties = [];
  743. readyGroup.get('properties').forEach(function (property) {
  744. wrappedProperties.pushObject(App.ServiceConfigProperty.create(property));
  745. });
  746. wrappedProperties.setEach('group', readyGroup);
  747. readyGroup.set('properties', wrappedProperties);
  748. readyGroup.set('parentConfigGroup', defaultGroup);
  749. serviceGroups.pushObject(readyGroup);
  750. });
  751. defaultGroup.set('childConfigGroups', serviceGroups);
  752. serviceGroups.pushObject(defaultGroup);
  753. }
  754. });
  755. },
  756. /**
  757. * Click-handler on config-group to make it selected
  758. * @param {object} event
  759. * @method selectConfigGroup
  760. */
  761. selectConfigGroup: function (event) {
  762. this.set('selectedConfigGroup', event.context);
  763. },
  764. /**
  765. * Rebuild list of configs switch of config group:
  766. * on default - display all configs from default group and configs from non-default groups as disabled
  767. * on non-default - display all from default group as disabled and configs from selected non-default group
  768. * @method switchConfigGroupConfigs
  769. */
  770. switchConfigGroupConfigs: function () {
  771. var serviceConfigs = this.get('selectedService.configs'),
  772. selectedGroup = this.get('selectedConfigGroup'),
  773. overrideToAdd = this.get('overrideToAdd'),
  774. overrides = [];
  775. if (!selectedGroup) return;
  776. var displayedConfigGroups = this._getDisplayedConfigGroups();
  777. displayedConfigGroups.forEach(function (group) {
  778. overrides.pushObjects(group.get('properties'));
  779. });
  780. serviceConfigs.forEach(function (config) {
  781. this._setEditableValue(config);
  782. this._setOverrides(config, overrides);
  783. }, this);
  784. }.observes('selectedConfigGroup'),
  785. /**
  786. * Get list of config groups to display
  787. * Returns empty array if no <code>selectedConfigGroup</code>
  788. * @return {Array}
  789. * @method _getDisplayedConfigGroups
  790. */
  791. _getDisplayedConfigGroups: function () {
  792. var selectedGroup = this.get('selectedConfigGroup');
  793. if (!selectedGroup) return [];
  794. return (selectedGroup.get('isDefault')) ?
  795. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  796. [this.get('selectedConfigGroup')];
  797. },
  798. /**
  799. * Set <code>isEditable</code> property to <code>config</code>
  800. * @param {Ember.Object} config
  801. * @return {Ember.Object} updated config-object
  802. * @method _setEditableValue
  803. */
  804. _setEditableValue: function (config) {
  805. var selectedGroup = this.get('selectedConfigGroup');
  806. if (!selectedGroup) return config;
  807. var isEditable = config.get('isEditable'),
  808. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  809. if (isServiceInstalled) {
  810. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  811. }
  812. else {
  813. isEditable = selectedGroup.get('isDefault');
  814. }
  815. config.set('isEditable', isEditable);
  816. return config;
  817. },
  818. /**
  819. * Set <code>overrides</code> property to <code>config</code>
  820. * @param {Ember.Object} config
  821. * @param {Ember.Enumerable} overrides
  822. * @returns {Ember.Object}
  823. * @method _setOverrides
  824. */
  825. _setOverrides: function (config, overrides) {
  826. var selectedGroup = this.get('selectedConfigGroup'),
  827. overrideToAdd = this.get('overrideToAdd'),
  828. configOverrides = overrides.filterProperty('name', config.get('name'));
  829. if (!selectedGroup) return config;
  830. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  831. configOverrides.push(this.addOverrideProperty(config));
  832. this.set('overrideToAdd', null);
  833. }
  834. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  835. configOverrides.setEach('parentSCP', config);
  836. config.set('overrides', configOverrides);
  837. return config;
  838. },
  839. /**
  840. * create overriden property and push it into Config group
  841. * @param {App.ServiceConfigProperty} serviceConfigProperty
  842. * @return {App.ServiceConfigProperty}
  843. * @method addOverrideProperty
  844. */
  845. addOverrideProperty: function (serviceConfigProperty) {
  846. var overrides = serviceConfigProperty.get('overrides') || [];
  847. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  848. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  849. newSCP.set('group', group);
  850. newSCP.set('value', '');
  851. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  852. newSCP.set('parentSCP', serviceConfigProperty);
  853. newSCP.set('isEditable', true);
  854. group.get('properties').pushObject(newSCP);
  855. overrides.pushObject(newSCP);
  856. return newSCP;
  857. },
  858. /**
  859. * @method manageConfigurationGroup
  860. */
  861. manageConfigurationGroup: function () {
  862. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  863. },
  864. /**
  865. * Make some configs visible depending on active services
  866. * @method activateSpecialConfigs
  867. */
  868. activateSpecialConfigs: function () {
  869. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  870. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  871. },
  872. /**
  873. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  874. * @return {$.ajax|null}
  875. * @method checkMySQLHost
  876. */
  877. checkMySQLHost: function () {
  878. // get ambari database type and hostname
  879. return App.ajax.send({
  880. name: 'config.ambari.database.info',
  881. sender: this,
  882. success: 'getAmbariDatabaseSuccess'
  883. });
  884. },
  885. /**
  886. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  887. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  888. * @param {object} data
  889. * @method getAmbariDatabaseSuccess
  890. */
  891. getAmbariDatabaseSuccess: function (data) {
  892. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host').value;
  893. var ambariServiceHostComponents = data.hostComponents;
  894. if (!!ambariServiceHostComponents.length) {
  895. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  896. this.set('mySQLServerConflict', ambariDBInfo.indexOf('mysql') > 0 && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  897. } else {
  898. this.set('mySQLServerConflict', false);
  899. }
  900. },
  901. /**
  902. * Check if new MySql database was chosen for Hive service
  903. * and it is not located on the same host as Ambari server
  904. * that using MySql database too.
  905. *
  906. * @method resolveHiveMysqlDatabase
  907. **/
  908. resolveHiveMysqlDatabase: function() {
  909. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  910. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  911. this.moveNext();
  912. return;
  913. }
  914. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  915. if (hiveDBType == 'New MySQL Database') {
  916. var self= this;
  917. this.checkMySQLHost().done(function () {
  918. if (self.get('mySQLServerConflict')) {
  919. // error popup before you can proceed
  920. return App.ModalPopup.show({
  921. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  922. bodyClass: Ember.View.extend({
  923. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.body'))
  924. }),
  925. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  926. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  927. onSecondary: function (){
  928. var parent = this;
  929. return App.ModalPopup.show({
  930. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  931. bodyClass: Ember.View.extend({
  932. template: Ember.Handlebars.compile( Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'))
  933. }),
  934. onPrimary: function (){
  935. this.hide();
  936. parent.hide();
  937. // go back to step 5: assign masters and disable default navigation warning
  938. App.router.get('installerController').gotoStep(5, true);
  939. }
  940. });
  941. }
  942. });
  943. } else {
  944. self.moveNext();
  945. }
  946. });
  947. } else {
  948. this.moveNext();
  949. }
  950. },
  951. checkDatabaseConnectionTest: function() {
  952. var deferred = $.Deferred();
  953. if (!App.supports.databaseConnection) {
  954. deferred.resolve();
  955. return deferred;
  956. }
  957. var configMap = [
  958. {
  959. serviceName: 'OOZIE',
  960. ignored: Em.I18n.t('installer.step7.oozie.database.new')
  961. },
  962. {
  963. serviceName: 'HIVE',
  964. ignored: Em.I18n.t('installer.step7.hive.database.new')
  965. }
  966. ];
  967. configMap.forEach(function(config) {
  968. var isConnectionNotTested = false;
  969. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  970. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  971. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  972. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  973. if (serviceDatabase !== config.ignored) {
  974. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  975. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  976. isConnectionNotTested = true;
  977. } else {
  978. for (var key in filledProperties) {
  979. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  980. isConnectionNotTested = true;
  981. }
  982. }
  983. }
  984. }
  985. config.isCheckIgnored = isConnectionNotTested;
  986. }, this);
  987. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  988. if (ignoredServices.length) {
  989. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function(serviceName) {
  990. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  991. }, this);
  992. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  993. }
  994. else {
  995. deferred.resolve();
  996. }
  997. return deferred;
  998. },
  999. showDatabaseConnectionWarningPopup: function(serviceNames, deferred) {
  1000. return App.ModalPopup.show({
  1001. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1002. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1003. secondary: Em.I18n.t('common.cancel'),
  1004. primary: Em.I18n.t('common.proceedAnyway'),
  1005. onPrimary: function() {
  1006. deferred.resolve();
  1007. this._super();
  1008. },
  1009. onSecondary: function() {
  1010. deferred.reject();
  1011. this._super();
  1012. }
  1013. })
  1014. },
  1015. /**
  1016. * Proceed to the next step
  1017. **/
  1018. moveNext: function() {
  1019. App.router.send('next');
  1020. },
  1021. /**
  1022. * Click-handler on Next button
  1023. * @method submit
  1024. */
  1025. submit: function () {
  1026. var _this = this;
  1027. if (!this.get('isSubmitDisabled')) {
  1028. this.checkDatabaseConnectionTest().done(function() {
  1029. _this.resolveHiveMysqlDatabase();
  1030. });
  1031. }
  1032. }
  1033. });