step7_controller.js 36 KB

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