step7_controller.js 40 KB

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