step7_controller.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  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 = this.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. * Get info about hosts and host components to configDefaultsProviders
  329. * Work specifically in Add Service wizard
  330. * @slaveComponentHosts - contains slaves and clients as well
  331. * @returns {{masterComponentHosts: Array, slaveComponentHosts: Array, hosts: {}}}
  332. */
  333. getInfoForDefaults: function() {
  334. var slaveComponentHosts = [];
  335. var hosts = this.get('content.hosts');
  336. var slaveHostMap = {};
  337. //get clients and slaves from stack
  338. App.StackServiceComponent.find().forEach(function (component) {
  339. if (component.get('isClient') || component.get('isSlave')) {
  340. slaveHostMap[component.get('componentName')] = [];
  341. }
  342. });
  343. //assign hosts of every component
  344. for (var hostName in hosts) {
  345. hosts[hostName].hostComponents.forEach(function (componentName) {
  346. if (slaveHostMap[componentName]) {
  347. slaveHostMap[componentName].push({hostName: hostName});
  348. }
  349. });
  350. }
  351. //push slaves and clients into @slaveComponentHosts
  352. for (var componentName in slaveHostMap) {
  353. if(slaveHostMap[componentName].length > 0) {
  354. slaveComponentHosts.push({
  355. componentName: componentName,
  356. hosts: slaveHostMap[componentName]
  357. })
  358. }
  359. }
  360. var masterComponentHosts = App.HostComponent.find().filterProperty('isMaster', true).map(function(item) {
  361. return {
  362. component: item.get('componentName'),
  363. serviceId: item.get('service.serviceName'),
  364. host: item.get('hostName')
  365. }
  366. });
  367. return {
  368. masterComponentHosts: masterComponentHosts,
  369. slaveComponentHosts: slaveComponentHosts,
  370. hosts: hosts
  371. };
  372. },
  373. /**
  374. * By default <code>value</code>-property is string "true|false".
  375. * Should update it to boolean type
  376. * Also affects <code>defaultValue</code>
  377. * @param {Ember.Object} serviceConfigProperty
  378. * @returns {Ember.Object} Updated config-object
  379. * @method _updateValueForCheckBoxConfig
  380. */
  381. _updateValueForCheckBoxConfig: function (serviceConfigProperty) {
  382. var v = serviceConfigProperty.get('value');
  383. switch (serviceConfigProperty.get('value')) {
  384. case 'true':
  385. v = true;
  386. break;
  387. case 'false':
  388. v = false;
  389. break;
  390. }
  391. serviceConfigProperty.setProperties({value: v, defaultValue: v});
  392. return serviceConfigProperty;
  393. },
  394. /**
  395. * Set <code>isEditable</code>-property to <code>serviceConfigProperty</code>
  396. * Based on user's permissions and selected config group
  397. * @param {Ember.Object} serviceConfigProperty
  398. * @param {bool} defaultGroupSelected
  399. * @returns {Ember.Object} Updated config-object
  400. * @method _updateIsEditableFlagForConfig
  401. */
  402. _updateIsEditableFlagForConfig: function (serviceConfigProperty, defaultGroupSelected) {
  403. if (App.get('isAdmin')) {
  404. if (defaultGroupSelected && !this.get('isHostsConfigsPage')) {
  405. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  406. }
  407. else {
  408. serviceConfigProperty.set('isEditable', false);
  409. }
  410. }
  411. else {
  412. serviceConfigProperty.set('isEditable', false);
  413. }
  414. return serviceConfigProperty;
  415. },
  416. /**
  417. * Set <code>overrides</code>-property to <code>serviceConfigProperty<code>
  418. * @param {Ember.Object} serviceConfigProperty
  419. * @param {Ember.Object} component
  420. * @return {Ember.Object} Updated config-object
  421. * @method _updateOverridesForConfig
  422. */
  423. _updateOverridesForConfig: function (serviceConfigProperty, component) {
  424. var overrides = serviceConfigProperty.get('overrides');
  425. if (Em.isNone(overrides)) {
  426. serviceConfigProperty.set('overrides', Em.A([]));
  427. return serviceConfigProperty;
  428. }
  429. serviceConfigProperty.set('overrides', null);
  430. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  431. // Wrap each override to App.ServiceConfigProperty
  432. overrides.forEach(function (override) {
  433. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  434. newSCP.set('value', override.value);
  435. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  436. newSCP.set('parentSCP', serviceConfigProperty);
  437. if (App.get('supports.hostOverrides') && defaultGroupSelected) {
  438. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  439. // prevent cycle in proto object, clean link
  440. if (group.get('properties').length == 0) {
  441. group.set('properties', Em.A([]));
  442. }
  443. group.get('properties').push(newSCP);
  444. newSCP.set('group', override.group);
  445. newSCP.set('isEditable', false);
  446. }
  447. var parentOverridesArray = serviceConfigProperty.get('overrides');
  448. if (Em.isNone(parentOverridesArray)) {
  449. parentOverridesArray = Em.A([]);
  450. serviceConfigProperty.set('overrides', parentOverridesArray);
  451. }
  452. serviceConfigProperty.get('overrides').pushObject(newSCP);
  453. }, this);
  454. return serviceConfigProperty;
  455. },
  456. /**
  457. * Set <code>serviceValidator</code>-property to <code>serviceConfigProperty</code> if config's serviceName is equal
  458. * to component's serviceName
  459. * othervise set <code>isVisible</code>-property to <code>false</code>
  460. * @param {Ember.Object} serviceConfigProperty
  461. * @param {Ember.Object} component
  462. * @param {object} serviceConfigsData
  463. * @returns {Ember.Object} updated config-object
  464. * @mrthod _updateValidatorsForConfig
  465. */
  466. _updateValidatorsForConfig: function (serviceConfigProperty, component, serviceConfigsData) {
  467. if (serviceConfigProperty.get('serviceName') === component.get('serviceName')) {
  468. if (serviceConfigsData.configsValidator) {
  469. var validators = serviceConfigsData.configsValidator.get('configValidators');
  470. for (var validatorName in validators) {
  471. if (validators.hasOwnProperty(validatorName)) {
  472. if (serviceConfigProperty.get('name') == validatorName) {
  473. serviceConfigProperty.set('serviceValidator', serviceConfigsData.configsValidator);
  474. }
  475. }
  476. }
  477. }
  478. }
  479. else {
  480. serviceConfigProperty.set('isVisible', false);
  481. }
  482. return serviceConfigProperty;
  483. },
  484. /**
  485. * Set configs with overrides, recommended defaults to component
  486. * @param {Ember.Object[]} configs
  487. * @param {Ember.Object} componentConfig
  488. * @param {Ember.Object} component
  489. * @method loadComponentConfigs
  490. */
  491. loadComponentConfigs: function (configs, componentConfig, component) {
  492. var s = this.get('serviceConfigsData').findProperty('serviceName', component.get('serviceName')),
  493. defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  494. if (s.configsValidator) {
  495. var recommendedDefaults = this._getRecommendedDefaultsForComponent(component.get('serviceName'));
  496. s.configsValidator.set('recommendedDefaults', recommendedDefaults);
  497. }
  498. configs.forEach(function (serviceConfigProperty) {
  499. if (!serviceConfigProperty) return;
  500. if (Em.isNone(serviceConfigProperty.get('isOverridable'))) {
  501. serviceConfigProperty.set('isOverridable', true);
  502. }
  503. if (serviceConfigProperty.get('displayType') === 'checkbox') {
  504. this._updateValueForCheckBoxConfig(serviceConfigProperty);
  505. }
  506. this._updateValidatorsForConfig(serviceConfigProperty, component, s);
  507. this._updateOverridesForConfig(serviceConfigProperty, component);
  508. this._updateIsEditableFlagForConfig(serviceConfigProperty, defaultGroupSelected);
  509. componentConfig.get('configs').pushObject(serviceConfigProperty);
  510. serviceConfigProperty.validate();
  511. }, this);
  512. var overrideToAdd = this.get('overrideToAdd');
  513. if (overrideToAdd) {
  514. overrideToAdd = componentConfig.get('configs').findProperty('name', overrideToAdd.name);
  515. if (overrideToAdd) {
  516. this.addOverrideProperty(overrideToAdd);
  517. component.set('overrideToAdd', null);
  518. }
  519. }
  520. },
  521. /**
  522. * Resolve dependency between configs.
  523. * @param serviceName {String}
  524. * @param configs {Ember.Enumerable}
  525. */
  526. resolveServiceDependencyConfigs: function (serviceName, configs) {
  527. switch (serviceName) {
  528. case 'STORM':
  529. this.resolveStormConfigs(configs);
  530. break;
  531. default:
  532. break;
  533. }
  534. },
  535. /**
  536. * Update some Storm configs
  537. * If Ganglia is selected to install or already installed, Ganglia host should be added to configs
  538. * @param {Ember.Enumerable} configs
  539. * @method resolveStormConfigs
  540. */
  541. resolveStormConfigs: function (configs) {
  542. var dependentConfigs, gangliaServerHost;
  543. dependentConfigs = ['nimbus.childopts', 'supervisor.childopts', 'worker.childopts'];
  544. // if Ganglia selected or installed, set ganglia host to configs
  545. if (this.get('installedServiceNames').contains('STORM') && this.get('installedServiceNames').contains('GANGLIA')) return;
  546. if (this.get('allSelectedServiceNames').contains('GANGLIA') || this.get('installedServiceNames').contains('GANGLIA')) {
  547. gangliaServerHost = this.get('wizardController').getDBProperty('masterComponentHosts').findProperty('component', 'GANGLIA_SERVER').hostName;
  548. dependentConfigs.forEach(function (configName) {
  549. var config = configs.findProperty('name', configName);
  550. var replaceStr = config.value.match(/.jar=host[^,]+/)[0];
  551. var replaceWith = replaceStr.slice(0, replaceStr.lastIndexOf('=') - replaceStr.length + 1) + gangliaServerHost;
  552. config.value = config.defaultValue = config.value.replace(replaceStr, replaceWith);
  553. config.forceUpdate = true;
  554. }, this);
  555. }
  556. },
  557. /**
  558. * On load function
  559. * @method loadStep
  560. */
  561. loadStep: function () {
  562. console.log("TRACE: Loading step7: Configure Services");
  563. if (!this.get('isAdvancedConfigLoaded')) {
  564. return;
  565. }
  566. this.clearStep();
  567. //STEP 1: Load advanced configs
  568. var advancedConfigs = this.get('content.advancedServiceConfig');
  569. //STEP 2: Load on-site configs by service from local DB
  570. var storedConfigs = this.get('content.serviceConfigProperties');
  571. //STEP 3: Merge pre-defined configs with loaded on-site configs
  572. var configs = App.config.mergePreDefinedWithStored(
  573. storedConfigs,
  574. advancedConfigs,
  575. this.get('selectedServiceNames').concat(this.get('installedServiceNames'))
  576. );
  577. //STEP 4: Add advanced configs
  578. App.config.addAdvancedConfigs(configs, advancedConfigs);
  579. //STEP 5: Add custom configs
  580. App.config.addCustomConfigs(configs);
  581. //put properties from capacity-scheduler.xml into one config with textarea view
  582. if (this.get('allSelectedServiceNames').contains('YARN') && !App.get('supports.capacitySchedulerUi')) {
  583. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  584. }
  585. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  586. if (this.get('wizardController.name') === 'addServiceController') {
  587. this.getConfigTags();
  588. this.setInstalledServiceConfigs(this.get('serviceConfigTags'), configs);
  589. }
  590. if (this.get('allSelectedServiceNames').contains('STORM') || this.get('installedServiceNames').contains('STORM')) {
  591. this.resolveServiceDependencyConfigs('STORM', configs);
  592. }
  593. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  594. this.setStepConfigs(configs, storedConfigs);
  595. this.checkHostOverrideInstaller();
  596. this.activateSpecialConfigs();
  597. this.selectProperService();
  598. if (this.get('content.skipConfigStep')) {
  599. App.router.send('next');
  600. }
  601. },
  602. /**
  603. * If <code>App.supports.hostOverridesInstaller</code> is enabled should load config groups
  604. * and (if some services are already installed) load config groups for installed services
  605. * @method checkHostOverrideInstaller
  606. */
  607. checkHostOverrideInstaller: function () {
  608. if (App.get('supports.hostOverridesInstaller')) {
  609. this.loadConfigGroups(this.get('content.configGroups'));
  610. if (this.get('installedServiceNames').length > 0) {
  611. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  612. }
  613. }
  614. },
  615. /**
  616. * Set init <code>stepConfigs</code> value
  617. * Set <code>selected</code> for addable services if addServiceController is used
  618. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  619. * @param {Ember.Object[]} configs
  620. * @param {Ember.Object[]} storedConfigs
  621. * @method setStepConfigs
  622. */
  623. setStepConfigs: function (configs, storedConfigs) {
  624. var localDB = {
  625. hosts: this.get('wizardController').getDBProperty('hosts'),
  626. masterComponentHosts: this.get('wizardController').getDBProperty('masterComponentHosts'),
  627. slaveComponentHosts: this.get('wizardController').getDBProperty('slaveComponentHosts')
  628. };
  629. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB);
  630. if (this.get('wizardController.name') === 'addServiceController') {
  631. serviceConfigs.setEach('showConfig', true);
  632. serviceConfigs.setEach('selected', false);
  633. this.get('selectedServiceNames').forEach(function (serviceName) {
  634. if (!serviceConfigs.findProperty('serviceName', serviceName)) return;
  635. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  636. });
  637. // Remove SNameNode if HA is enabled
  638. if (App.get('isHaEnabled')) {
  639. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  640. var removedConfigs = c.filterProperty('category', 'SNameNode');
  641. removedConfigs.map(function (config) {
  642. c = c.without(config);
  643. });
  644. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  645. }
  646. }
  647. this.set('stepConfigs', serviceConfigs);
  648. },
  649. /**
  650. * Select first addable service for <code>addServiceWizard</code>
  651. * Select first service at all in other cases
  652. * @method selectProperService
  653. */
  654. selectProperService: function () {
  655. if (this.get('wizardController.name') === 'addServiceController') {
  656. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  657. }
  658. else {
  659. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  660. }
  661. },
  662. /**
  663. * Load config tags
  664. * @return {$.ajax|null}
  665. * @method getConfigTags
  666. */
  667. getConfigTags: function () {
  668. return App.ajax.send({
  669. name: 'config.tags.sync',
  670. sender: this,
  671. success: 'getConfigTagsSuccess'
  672. });
  673. },
  674. /**
  675. * Success callback for config tags request
  676. * Updates <code>serviceConfigTags</code> with tags received from server
  677. * @param {object} data
  678. * @method getConfigTagsSuccess
  679. */
  680. getConfigTagsSuccess: function (data) {
  681. var installedServiceSites = [];
  682. this.get('serviceConfigsData').filter(function (service) {
  683. if (this.get('installedServiceNames').contains(service.serviceName)) {
  684. installedServiceSites = installedServiceSites.concat(service.sites);
  685. }
  686. }, this);
  687. installedServiceSites = installedServiceSites.uniq();
  688. var serviceConfigTags = [];
  689. for (var site in data.Clusters.desired_configs) {
  690. if (data.Clusters.desired_configs.hasOwnProperty(site)) {
  691. if (installedServiceSites.contains(site)) {
  692. serviceConfigTags.push({
  693. siteName: site,
  694. tagName: data.Clusters.desired_configs[site].tag,
  695. newTagName: null
  696. });
  697. }
  698. }
  699. }
  700. this.set('serviceConfigTags', serviceConfigTags);
  701. },
  702. /**
  703. * set configs actual values from server
  704. * @param serviceConfigTags
  705. * @param configs
  706. * @method setInstalledServiceConfigs
  707. */
  708. setInstalledServiceConfigs: function (serviceConfigTags, configs) {
  709. var configsMap = {};
  710. App.router.get('configurationController').getConfigsByTags(serviceConfigTags).forEach(function (configSite) {
  711. $.extend(configsMap, configSite.properties);
  712. });
  713. configs.forEach(function (_config) {
  714. if (configsMap[_config.name] !== undefined) {
  715. // prevent overriding already edited properties
  716. if (_config.defaultValue != configsMap[_config.name])
  717. _config.value = configsMap[_config.name];
  718. _config.defaultValue = configsMap[_config.name];
  719. App.config.handleSpecialProperties(_config);
  720. }
  721. })
  722. },
  723. /**
  724. * Add group ids to <code>groupsToDelete</code>
  725. * Also save <code>groupsToDelete</code> to local storage
  726. * @param {Ember.Object[]} groups
  727. * @method setGroupsToDelete
  728. */
  729. setGroupsToDelete: function (groups) {
  730. var groupsToDelete = this.get('groupsToDelete');
  731. groups.forEach(function (group) {
  732. if (group.get('id'))
  733. groupsToDelete.push({
  734. id: group.get('id')
  735. });
  736. });
  737. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  738. },
  739. /**
  740. * Update <code>configGroups</code> with selected service configGroups
  741. * Also set default group to first position
  742. * Update <code>selectedConfigGroup</code> with new default group
  743. * @method selectedServiceObserver
  744. */
  745. selectedServiceObserver: function () {
  746. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  747. var serviceGroups = this.get('selectedService.configGroups');
  748. serviceGroups.forEach(function (item, index, array) {
  749. if (item.isDefault) {
  750. array.unshift(item);
  751. array.splice(index + 1, 1);
  752. }
  753. });
  754. this.set('configGroups', serviceGroups);
  755. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  756. }
  757. }.observes('selectedService.configGroups.@each'),
  758. /**
  759. * load default groups for each service in case of initial load
  760. * @param serviceConfigGroups
  761. * @method loadConfigGroups
  762. */
  763. loadConfigGroups: function (serviceConfigGroups) {
  764. var services = this.get('stepConfigs');
  765. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  766. services.forEach(function (service) {
  767. if (service.get('serviceName') === 'MISC') return;
  768. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  769. if (!serviceRawGroups.length) {
  770. service.set('configGroups', [
  771. App.ConfigGroup.create({
  772. name: App.Service.DisplayNames[service.serviceName] + " Default",
  773. description: "Default cluster level " + service.serviceName + " configuration",
  774. isDefault: true,
  775. hosts: Em.copy(hosts),
  776. service: Em.Object.create({
  777. id: service.serviceName
  778. }),
  779. serviceName: service.serviceName
  780. })
  781. ]);
  782. }
  783. else {
  784. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  785. var serviceGroups = service.get('configGroups');
  786. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  787. var readyGroup = App.ConfigGroup.create(configGroup);
  788. var wrappedProperties = [];
  789. readyGroup.get('properties').forEach(function (property) {
  790. wrappedProperties.pushObject(App.ServiceConfigProperty.create(property));
  791. });
  792. wrappedProperties.setEach('group', readyGroup);
  793. readyGroup.set('properties', wrappedProperties);
  794. readyGroup.set('parentConfigGroup', defaultGroup);
  795. serviceGroups.pushObject(readyGroup);
  796. });
  797. defaultGroup.set('childConfigGroups', serviceGroups);
  798. serviceGroups.pushObject(defaultGroup);
  799. }
  800. });
  801. },
  802. /**
  803. * Click-handler on config-group to make it selected
  804. * @param {object} event
  805. * @method selectConfigGroup
  806. */
  807. selectConfigGroup: function (event) {
  808. this.set('selectedConfigGroup', event.context);
  809. },
  810. /**
  811. * Rebuild list of configs switch of config group:
  812. * on default - display all configs from default group and configs from non-default groups as disabled
  813. * on non-default - display all from default group as disabled and configs from selected non-default group
  814. * @method switchConfigGroupConfigs
  815. */
  816. switchConfigGroupConfigs: function () {
  817. var serviceConfigs = this.get('selectedService.configs'),
  818. selectedGroup = this.get('selectedConfigGroup'),
  819. overrideToAdd = this.get('overrideToAdd'),
  820. overrides = [];
  821. if (!selectedGroup) return;
  822. var displayedConfigGroups = this._getDisplayedConfigGroups();
  823. displayedConfigGroups.forEach(function (group) {
  824. overrides.pushObjects(group.get('properties'));
  825. });
  826. serviceConfigs.forEach(function (config) {
  827. this._setEditableValue(config);
  828. this._setOverrides(config, overrides);
  829. }, this);
  830. }.observes('selectedConfigGroup'),
  831. /**
  832. * Get list of config groups to display
  833. * Returns empty array if no <code>selectedConfigGroup</code>
  834. * @return {Array}
  835. * @method _getDisplayedConfigGroups
  836. */
  837. _getDisplayedConfigGroups: function () {
  838. var selectedGroup = this.get('selectedConfigGroup');
  839. if (!selectedGroup) return [];
  840. return (selectedGroup.get('isDefault')) ?
  841. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  842. [this.get('selectedConfigGroup')];
  843. },
  844. /**
  845. * Set <code>isEditable</code> property to <code>config</code>
  846. * @param {Ember.Object} config
  847. * @return {Ember.Object} updated config-object
  848. * @method _setEditableValue
  849. */
  850. _setEditableValue: function (config) {
  851. var selectedGroup = this.get('selectedConfigGroup');
  852. if (!selectedGroup) return config;
  853. var isEditable = config.get('isEditable'),
  854. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  855. if (isServiceInstalled) {
  856. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  857. }
  858. else {
  859. isEditable = selectedGroup.get('isDefault');
  860. }
  861. config.set('isEditable', isEditable);
  862. return config;
  863. },
  864. /**
  865. * Set <code>overrides</code> property to <code>config</code>
  866. * @param {Ember.Object} config
  867. * @param {Ember.Enumerable} overrides
  868. * @returns {Ember.Object}
  869. * @method _setOverrides
  870. */
  871. _setOverrides: function (config, overrides) {
  872. var selectedGroup = this.get('selectedConfigGroup'),
  873. overrideToAdd = this.get('overrideToAdd'),
  874. configOverrides = overrides.filterProperty('name', config.get('name'));
  875. if (!selectedGroup) return config;
  876. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  877. configOverrides.push(this.addOverrideProperty(config));
  878. this.set('overrideToAdd', null);
  879. }
  880. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  881. configOverrides.setEach('parentSCP', config);
  882. config.set('overrides', configOverrides);
  883. return config;
  884. },
  885. /**
  886. * create overriden property and push it into Config group
  887. * @param {App.ServiceConfigProperty} serviceConfigProperty
  888. * @return {App.ServiceConfigProperty}
  889. * @method addOverrideProperty
  890. */
  891. addOverrideProperty: function (serviceConfigProperty) {
  892. var overrides = serviceConfigProperty.get('overrides') || [];
  893. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  894. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  895. newSCP.set('group', group);
  896. newSCP.set('value', '');
  897. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  898. newSCP.set('parentSCP', serviceConfigProperty);
  899. newSCP.set('isEditable', true);
  900. group.get('properties').pushObject(newSCP);
  901. overrides.pushObject(newSCP);
  902. return newSCP;
  903. },
  904. /**
  905. * @method manageConfigurationGroup
  906. */
  907. manageConfigurationGroup: function () {
  908. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  909. },
  910. /**
  911. * Make some configs visible depending on active services
  912. * @method activateSpecialConfigs
  913. */
  914. activateSpecialConfigs: function () {
  915. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  916. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  917. },
  918. /**
  919. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  920. * @return {$.ajax|null}
  921. * @method checkMySQLHost
  922. */
  923. checkMySQLHost: function () {
  924. // get ambari database type and hostname
  925. return App.ajax.send({
  926. name: 'config.ambari.database.info',
  927. sender: this,
  928. success: 'getAmbariDatabaseSuccess'
  929. });
  930. },
  931. /**
  932. * Success callback for ambari database, get Ambari DB type and DB server hostname, then
  933. * Check whether hive New MySQL database is on the same host as Ambari server MySQL server
  934. * @param {object} data
  935. * @method getAmbariDatabaseSuccess
  936. */
  937. getAmbariDatabaseSuccess: function (data) {
  938. var hiveDBHostname = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hivemetastore_host').value;
  939. var ambariServiceHostComponents = data.hostComponents;
  940. if (!!ambariServiceHostComponents.length) {
  941. var ambariDBInfo = JSON.stringify(ambariServiceHostComponents[0].RootServiceHostComponents.properties);
  942. this.set('mySQLServerConflict', ambariDBInfo.indexOf('mysql') > 0 && ambariDBInfo.indexOf(hiveDBHostname) > 0);
  943. } else {
  944. this.set('mySQLServerConflict', false);
  945. }
  946. },
  947. /**
  948. * Check if new MySql database was chosen for Hive service
  949. * and it is not located on the same host as Ambari server
  950. * that using MySql database too.
  951. *
  952. * @method resolveHiveMysqlDatabase
  953. **/
  954. resolveHiveMysqlDatabase: function() {
  955. var hiveService = this.get('content.services').findProperty('serviceName', 'HIVE');
  956. if (!hiveService || !hiveService.get('isSelected') || hiveService.get('isInstalled')) {
  957. this.moveNext();
  958. return;
  959. }
  960. var hiveDBType = this.get('stepConfigs').findProperty('serviceName', 'HIVE').configs.findProperty('name', 'hive_database').value;
  961. if (hiveDBType == 'New MySQL Database') {
  962. var self= this;
  963. this.checkMySQLHost().done(function () {
  964. if (self.get('mySQLServerConflict')) {
  965. // error popup before you can proceed
  966. return App.ModalPopup.show({
  967. header: Em.I18n.t('installer.step7.popup.mySQLWarning.header'),
  968. bodyClass: Ember.View.extend({
  969. template: Ember.Handlebars.compile(Em.I18n.t('installer.step7.popup.mySQLWarning.body'))
  970. }),
  971. secondary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.gotostep5'),
  972. primary: Em.I18n.t('installer.step7.popup.mySQLWarning.button.dismiss'),
  973. onSecondary: function (){
  974. var parent = this;
  975. return App.ModalPopup.show({
  976. header: Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.header'),
  977. bodyClass: Ember.View.extend({
  978. template: Ember.Handlebars.compile( Em.I18n.t('installer.step7.popup.mySQLWarning.confirmation.body'))
  979. }),
  980. onPrimary: function (){
  981. this.hide();
  982. parent.hide();
  983. // go back to step 5: assign masters and disable default navigation warning
  984. App.router.get('installerController').gotoStep(5, true);
  985. }
  986. });
  987. }
  988. });
  989. } else {
  990. self.moveNext();
  991. }
  992. });
  993. } else {
  994. this.moveNext();
  995. }
  996. },
  997. checkDatabaseConnectionTest: function() {
  998. var deferred = $.Deferred();
  999. if (!App.supports.databaseConnection) {
  1000. deferred.resolve();
  1001. return deferred;
  1002. }
  1003. var configMap = [
  1004. {
  1005. serviceName: 'OOZIE',
  1006. ignored: Em.I18n.t('installer.step7.oozie.database.new')
  1007. },
  1008. {
  1009. serviceName: 'HIVE',
  1010. ignored: Em.I18n.t('installer.step7.hive.database.new')
  1011. }
  1012. ];
  1013. configMap.forEach(function(config) {
  1014. var isConnectionNotTested = false;
  1015. var service = this.get('content.services').findProperty('serviceName', config.serviceName);
  1016. if (service && service.get('isSelected') && !service.get('isInstalled')) {
  1017. var serviceConfigs = this.get('stepConfigs').findProperty('serviceName', config.serviceName).configs;
  1018. var serviceDatabase = serviceConfigs.findProperty('name', config.serviceName.toLowerCase() + '_database').get('value');
  1019. if (serviceDatabase !== config.ignored) {
  1020. var filledProperties = App.db.get('tmp', config.serviceName + '_connection');
  1021. if (!filledProperties || App.isEmptyObject(filledProperties)) {
  1022. isConnectionNotTested = true;
  1023. } else {
  1024. for (var key in filledProperties) {
  1025. if (serviceConfigs.findProperty('name', key).get('value') !== filledProperties[key])
  1026. isConnectionNotTested = true;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. config.isCheckIgnored = isConnectionNotTested;
  1032. }, this);
  1033. var ignoredServices = configMap.filterProperty('isCheckIgnored', true);
  1034. if (ignoredServices.length) {
  1035. var displayedServiceNames = ignoredServices.mapProperty('serviceName').map(function(serviceName) {
  1036. return this.get('content.services').findProperty('serviceName', serviceName).get('displayName');
  1037. }, this);
  1038. this.showDatabaseConnectionWarningPopup(displayedServiceNames, deferred);
  1039. }
  1040. else {
  1041. deferred.resolve();
  1042. }
  1043. return deferred;
  1044. },
  1045. showDatabaseConnectionWarningPopup: function(serviceNames, deferred) {
  1046. return App.ModalPopup.show({
  1047. header: Em.I18n.t('installer.step7.popup.database.connection.header'),
  1048. body: Em.I18n.t('installer.step7.popup.database.connection.body').format(serviceNames.join(', ')),
  1049. secondary: Em.I18n.t('common.cancel'),
  1050. primary: Em.I18n.t('common.proceedAnyway'),
  1051. onPrimary: function() {
  1052. deferred.resolve();
  1053. this._super();
  1054. },
  1055. onSecondary: function() {
  1056. deferred.reject();
  1057. this._super();
  1058. }
  1059. })
  1060. },
  1061. /**
  1062. * Proceed to the next step
  1063. **/
  1064. moveNext: function() {
  1065. App.router.send('next');
  1066. },
  1067. /**
  1068. * Click-handler on Next button
  1069. * @method submit
  1070. */
  1071. submit: function () {
  1072. var _this = this;
  1073. if (!this.get('isSubmitDisabled')) {
  1074. this.checkDatabaseConnectionTest().done(function() {
  1075. _this.resolveHiveMysqlDatabase();
  1076. });
  1077. }
  1078. }
  1079. });