step7_controller.js 41 KB

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