step7_controller.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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. * Load config groups success callback
  185. * @param {object} data
  186. * @param {object} opt
  187. * @param {object} params
  188. * @method loadServiceTagsSuccess
  189. */
  190. loadServiceTagsSuccess: function (data, opt, params) {
  191. var serviceConfigsDef = params.serviceConfigsDef;
  192. var serviceName = params.serviceName;
  193. var service = this.get('stepConfigs').findProperty('serviceName', serviceName);
  194. // Create default configuration group
  195. var defaultConfigGroupHosts = this.get('wizardController.allHosts').mapProperty('hostName');
  196. var selectedConfigGroup;
  197. var siteToTagMap = {};
  198. for (var site in data.Clusters.desired_configs) {
  199. if (serviceConfigsDef.sites.indexOf(site) > -1) {
  200. siteToTagMap[site] = data.Clusters.desired_configs[site].tag;
  201. }
  202. }
  203. this.loadedClusterSiteToTagMap = siteToTagMap;
  204. //parse loaded config groups
  205. if (App.supports.hostOverrides) {
  206. var configGroups = [];
  207. if (data.config_groups.length) {
  208. data.config_groups.forEach(function (item) {
  209. item = item.ConfigGroup;
  210. if (item.tag === serviceName) {
  211. var groupHosts = item.hosts.mapProperty('host_name');
  212. var newConfigGroup = App.ConfigGroup.create({
  213. id: item.id,
  214. name: item.group_name,
  215. description: item.description,
  216. isDefault: false,
  217. parentConfigGroup: null,
  218. service: App.Service.find().findProperty('serviceName', item.tag),
  219. hosts: groupHosts,
  220. configSiteTags: []
  221. });
  222. groupHosts.forEach(function (host) {
  223. defaultConfigGroupHosts = defaultConfigGroupHosts.without(host);
  224. }, this);
  225. item.desired_configs.forEach(function (config) {
  226. newConfigGroup.configSiteTags.push(App.ConfigSiteTag.create({
  227. site: config.type,
  228. tag: config.tag
  229. }));
  230. }, this);
  231. configGroups.push(newConfigGroup);
  232. }
  233. }, this);
  234. }
  235. }
  236. var defaultConfigGroup = App.ConfigGroup.create({
  237. name: App.Service.DisplayNames[serviceName] + " Default",
  238. description: "Default cluster level " + serviceName + " configuration",
  239. isDefault: true,
  240. hosts: defaultConfigGroupHosts,
  241. parentConfigGroup: null,
  242. service: Em.Object.create({
  243. id: serviceName
  244. }),
  245. serviceName: serviceName,
  246. configSiteTags: []
  247. });
  248. if (!selectedConfigGroup) {
  249. selectedConfigGroup = defaultConfigGroup;
  250. }
  251. configGroups = configGroups.sortProperty('name');
  252. configGroups.unshift(defaultConfigGroup);
  253. if (App.supports.hostOverrides) {
  254. service.set('configGroups', configGroups);
  255. var loadedGroupToOverrideSiteToTagMap = {};
  256. if (App.supports.hostOverrides) {
  257. var configGroupsWithOverrides = selectedConfigGroup.get('isDefault') ? service.get('configGroups') : [selectedConfigGroup];
  258. configGroupsWithOverrides.forEach(function (item) {
  259. var groupName = item.get('name');
  260. loadedGroupToOverrideSiteToTagMap[groupName] = {};
  261. item.get('configSiteTags').forEach(function (siteTag) {
  262. var site = siteTag.get('site');
  263. loadedGroupToOverrideSiteToTagMap[groupName][site] = siteTag.get('tag');
  264. }, this);
  265. }, this);
  266. }
  267. App.config.loadServiceConfigGroupOverrides(service.get('configs'), loadedGroupToOverrideSiteToTagMap, service.get('configGroups'));
  268. var serviceConfig = App.config.createServiceConfig(serviceName);
  269. if (serviceConfig.get('serviceName') === 'HDFS') {
  270. App.config.OnNnHAHideSnn(serviceConfig);
  271. }
  272. service.set('selectedConfigGroup', selectedConfigGroup);
  273. this.loadComponentConfigs(service.get('configs'), serviceConfig, service);
  274. }
  275. service.set('configs', serviceConfig.get('configs'));
  276. },
  277. /**
  278. *
  279. * @param {Ember.Object[]} configs
  280. * @param {Ember.Object} componentConfig
  281. * @param {Ember.Object} component
  282. * @method loadComponentConfigs
  283. */
  284. loadComponentConfigs: function (configs, componentConfig, component) {
  285. var localDB = App.router.get('mainServiceInfoConfigsController').getInfoForDefaults();
  286. var recommendedDefaults = {};
  287. var s = this.get('serviceConfigsData').findProperty('serviceName', component.get('serviceName'));
  288. var defaultGroupSelected = component.get('selectedConfigGroup.isDefault');
  289. var defaults = [];
  290. if (s.defaultsProviders) {
  291. s.defaultsProviders.forEach(function(defaultsProvider) {
  292. var d = defaultsProvider.getDefaults(localDB);
  293. defaults.push(d);
  294. for (var name in d) {
  295. recommendedDefaults[name] = d[name];
  296. }
  297. });
  298. }
  299. if (s.configsValidator) {
  300. s.configsValidator.set('recommendedDefaults', recommendedDefaults);
  301. }
  302. configs.forEach(function (serviceConfigProperty) {
  303. if (!serviceConfigProperty) return;
  304. var overrides = serviceConfigProperty.get('overrides');
  305. // we will populate the override properties below
  306. serviceConfigProperty.set('overrides', null);
  307. if (serviceConfigProperty.isOverridable === undefined) {
  308. serviceConfigProperty.set('isOverridable', true);
  309. }
  310. if (serviceConfigProperty.displayType === 'checkbox') {
  311. switch (serviceConfigProperty.value) {
  312. case 'true':
  313. serviceConfigProperty.set('value', true);
  314. serviceConfigProperty.set('defaultValue', true);
  315. break;
  316. case 'false':
  317. serviceConfigProperty.set('value', false);
  318. serviceConfigProperty.set('defaultValue', false);
  319. break;
  320. }
  321. }
  322. if (serviceConfigProperty.get('serviceName') === component.get('serviceName')) {
  323. if (s.configsValidator) {
  324. var validators = s.configsValidator.get('configValidators');
  325. for (var validatorName in validators) {
  326. if (serviceConfigProperty.name == validatorName) {
  327. serviceConfigProperty.set('serviceValidator', s.configsValidator);
  328. }
  329. }
  330. }
  331. } else {
  332. serviceConfigProperty.set('isVisible', false);
  333. }
  334. if (overrides != null) {
  335. overrides.forEach(function (override) {
  336. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  337. newSCP.set('value', override.value);
  338. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  339. newSCP.set('parentSCP', serviceConfigProperty);
  340. if (App.supports.hostOverrides && defaultGroupSelected) {
  341. var group = component.get('configGroups').findProperty('name', override.group.get('name'));
  342. // prevent cycle in proto object, clean link
  343. if (group.get('properties').length == 0)
  344. group.set('properties', Em.A([]));
  345. group.get('properties').push(newSCP);
  346. newSCP.set('group', override.group);
  347. newSCP.set('isEditable', false);
  348. }
  349. var parentOverridesArray = serviceConfigProperty.get('overrides');
  350. if (parentOverridesArray == null) {
  351. parentOverridesArray = Em.A([]);
  352. serviceConfigProperty.set('overrides', parentOverridesArray);
  353. }
  354. serviceConfigProperty.get('overrides').pushObject(newSCP);
  355. }, this);
  356. } else {
  357. serviceConfigProperty.set('overrides', Em.A([]));
  358. }
  359. if (App.get('isAdmin')) {
  360. if(defaultGroupSelected && !this.get('isHostsConfigsPage')){
  361. serviceConfigProperty.set('isEditable', serviceConfigProperty.get('isReconfigurable'));
  362. } else {
  363. serviceConfigProperty.set('isEditable', false);
  364. }
  365. } else {
  366. serviceConfigProperty.set('isEditable', false);
  367. }
  368. componentConfig.get('configs').pushObject(serviceConfigProperty);
  369. serviceConfigProperty.validate();
  370. }, this);
  371. var overrideToAdd = this.get('overrideToAdd');
  372. if (overrideToAdd) {
  373. overrideToAdd = componentConfig.configs.findProperty('name', overrideToAdd.name);
  374. if (overrideToAdd) {
  375. this.addOverrideProperty(overrideToAdd);
  376. component.set('overrideToAdd', null);
  377. }
  378. }
  379. },
  380. /**
  381. * Resolve dependency between configs.
  382. * @param serviceName {String}
  383. * @param configs {Ember.Enumerable}
  384. */
  385. resolveServiceDependencyConfigs: function (serviceName, configs) {
  386. switch (serviceName) {
  387. case 'STORM':
  388. this.resolveStormConfigs(configs);
  389. break;
  390. default:
  391. break;
  392. }
  393. },
  394. /**
  395. * Update some Storm configs
  396. * If Ganglia is selected to install or already installed, Ganglia host should be added to configs
  397. * @param {Ember.Enumerable} configs
  398. * @method resolveStormConfigs
  399. */
  400. resolveStormConfigs: function(configs) {
  401. var dependentConfigs, gangliaServerHost;
  402. dependentConfigs = ['nimbus.childopts', 'supervisor.childopts', 'worker.childopts'];
  403. // if Ganglia selected or installed, set ganglia host to configs
  404. if (this.get('installedServiceNames').contains('STORM') && this.get('installedServiceNames').contains('GANGLIA')) return;
  405. if (this.get('allSelectedServiceNames').contains('GANGLIA') || this.get('installedServiceNames').contains('GANGLIA')) {
  406. gangliaServerHost = this.get('wizardController').getDBProperty('masterComponentHosts').findProperty('component', 'GANGLIA_SERVER').hostName;
  407. dependentConfigs.forEach(function(configName) {
  408. var config = configs.findProperty('name', configName);
  409. var replaceStr = '.jar=host=';
  410. config.value = config.defaultValue = config.value.replace(replaceStr, replaceStr+gangliaServerHost);
  411. config.forceUpdate = true;
  412. }, this);
  413. }
  414. },
  415. /**
  416. * On load function
  417. * @method loadStep
  418. */
  419. loadStep: function () {
  420. console.log("TRACE: Loading step7: Configure Services");
  421. if (!this.get('isAdvancedConfigLoaded')) {
  422. return;
  423. }
  424. this.clearStep();
  425. //STEP 1: Load advanced configs
  426. var advancedConfigs = this.get('content.advancedServiceConfig');
  427. //STEP 2: Load on-site configs by service from local DB
  428. var storedConfigs = this.get('content.serviceConfigProperties');
  429. //STEP 3: Merge pre-defined configs with loaded on-site configs
  430. var configs = App.config.mergePreDefinedWithStored(
  431. storedConfigs,
  432. advancedConfigs,
  433. this.get('selectedServiceNames').concat(this.get('installedServiceNames'))
  434. );
  435. //STEP 4: Add advanced configs
  436. App.config.addAdvancedConfigs(configs, advancedConfigs);
  437. //STEP 5: Add custom configs
  438. App.config.addCustomConfigs(configs);
  439. //put properties from capacity-scheduler.xml into one config with textarea view
  440. if (this.get('allSelectedServiceNames').contains('YARN') && !App.get('supports.capacitySchedulerUi')) {
  441. configs = App.config.fileConfigsIntoTextarea(configs, 'capacity-scheduler.xml');
  442. }
  443. this.set('groupsToDelete', this.get('wizardController').getDBProperty('groupsToDelete') || []);
  444. if (this.get('wizardController.name') === 'addServiceController') {
  445. this.getConfigTags();
  446. this.setInstalledServiceConfigs(this.get('serviceConfigTags'), configs);
  447. }
  448. if (this.get('allSelectedServiceNames').contains('STORM') || this.get('installedServiceNames').contains('STORM')) {
  449. this.resolveServiceDependencyConfigs('STORM', configs);
  450. }
  451. //STEP 6: Distribute configs by service and wrap each one in App.ServiceConfigProperty (configs -> serviceConfigs)
  452. this.setStepConfigs(configs, storedConfigs);
  453. this.checkHostOverrideInstaller();
  454. this.activateSpecialConfigs();
  455. this.selectProperService();
  456. if (this.get('content.skipConfigStep')) {
  457. App.router.send('next');
  458. }
  459. },
  460. /**
  461. * If <code>App.supports.hostOverridesInstaller</code> is enabled should load config groups
  462. * and (if some services are already installed) load config groups for installed services
  463. * @method checkHostOverrideInstaller
  464. */
  465. checkHostOverrideInstaller: function() {
  466. if (App.get('supports.hostOverridesInstaller')) {
  467. this.loadConfigGroups(this.get('content.configGroups'));
  468. if (this.get('installedServiceNames').length > 0) {
  469. this.loadInstalledServicesConfigGroups(this.get('installedServiceNames'));
  470. }
  471. }
  472. },
  473. /**
  474. * Set init <code>stepConfigs</code> value
  475. * Set <code>selected</code> for addable services if addServiceController is used
  476. * Remove SNameNode if HA is enabled (and if addServiceController is used)
  477. * @param {Ember.Object[]} configs
  478. * @param {Ember.Object[]} storedConfigs
  479. * @method setStepConfigs
  480. */
  481. setStepConfigs: function(configs, storedConfigs) {
  482. var localDB = {
  483. hosts: this.get('wizardController').getDBProperty('hosts'),
  484. masterComponentHosts: this.get('wizardController').getDBProperty('masterComponentHosts'),
  485. slaveComponentHosts: this.get('wizardController').getDBProperty('slaveComponentHosts')
  486. };
  487. var serviceConfigs = App.config.renderConfigs(configs, storedConfigs, this.get('allSelectedServiceNames'), this.get('installedServiceNames'), localDB);
  488. if (this.get('wizardController.name') === 'addServiceController') {
  489. serviceConfigs.setEach('showConfig', true);
  490. serviceConfigs.setEach('selected', false);
  491. this.get('selectedServiceNames').forEach(function(serviceName) {
  492. if(!serviceConfigs.findProperty('serviceName', serviceName)) return;
  493. serviceConfigs.findProperty('serviceName', serviceName).set('selected', true);
  494. });
  495. // Remove SNameNode if HA is enabled
  496. if (App.get('isHaEnabled')) {
  497. var c = serviceConfigs.findProperty('serviceName', 'HDFS').configs;
  498. var removedConfigs = c.filterProperty('category', 'SNameNode');
  499. removedConfigs.map(function(config) {
  500. c = c.without(config);
  501. });
  502. serviceConfigs.findProperty('serviceName', 'HDFS').configs = c;
  503. }
  504. }
  505. this.set('stepConfigs', serviceConfigs);
  506. },
  507. /**
  508. * Select first addable service for <code>addServiceWizard</code>
  509. * Select first service at all in other cases
  510. * @method selectProperService
  511. */
  512. selectProperService: function() {
  513. if (this.get('wizardController.name') === 'addServiceController') {
  514. this.set('selectedService', this.get('stepConfigs').filterProperty('selected', true).get('firstObject'));
  515. }
  516. else {
  517. this.set('selectedService', this.get('stepConfigs').filterProperty('showConfig', true).objectAt(0));
  518. }
  519. },
  520. /**
  521. * Load config tags
  522. * @return {$.ajax|null}
  523. * @method getConfigTags
  524. */
  525. getConfigTags: function() {
  526. return App.ajax.send({
  527. name: 'config.tags.sync',
  528. sender: this,
  529. success: 'getConfigTagsSuccess'
  530. });
  531. },
  532. /**
  533. * Success callback for config tags request
  534. * Updates <code>serviceConfigTags</code> with tags received from server
  535. * @param {object} data
  536. * @method getConfigTagsSuccess
  537. */
  538. getConfigTagsSuccess: function (data) {
  539. var installedServiceSites = [];
  540. this.get('serviceConfigsData').filter(function (service) {
  541. if (this.get('installedServiceNames').contains(service.serviceName)){
  542. installedServiceSites = installedServiceSites.concat(service.sites);
  543. }
  544. }, this);
  545. installedServiceSites = installedServiceSites.uniq();
  546. var serviceConfigTags = [];
  547. for (var site in data.Clusters.desired_configs) {
  548. if (installedServiceSites.contains(site)) {
  549. serviceConfigTags.push({
  550. siteName: site,
  551. tagName: data.Clusters.desired_configs[site].tag,
  552. newTagName: null
  553. });
  554. }
  555. }
  556. this.set('serviceConfigTags', serviceConfigTags);
  557. },
  558. /**
  559. * set configs actual values from server
  560. * @param serviceConfigTags
  561. * @param configs
  562. * @method setInstalledServiceConfigs
  563. */
  564. setInstalledServiceConfigs: function (serviceConfigTags, configs) {
  565. var configsMap = {};
  566. App.router.get('configurationController').getConfigsByTags(serviceConfigTags).forEach(function(configSite){
  567. $.extend(configsMap, configSite.properties);
  568. });
  569. configs.forEach(function (_config) {
  570. if (configsMap[_config.name] !== undefined) {
  571. // prevent overriding already edited properties
  572. if (_config.defaultValue != configsMap[_config.name])
  573. _config.value = configsMap[_config.name];
  574. _config.defaultValue = configsMap[_config.name];
  575. App.config.handleSpecialProperties(_config);
  576. }
  577. })
  578. },
  579. /**
  580. * Add group ids to <code>groupsToDelete</code>
  581. * Also save <code>groupsToDelete</code> to local storage
  582. * @param {Ember.Object[]} groups
  583. * @method setGroupsToDelete
  584. */
  585. setGroupsToDelete: function(groups) {
  586. var groupsToDelete = this.get('groupsToDelete');
  587. groups.forEach(function(group) {
  588. if (group.get('id'))
  589. groupsToDelete.push({
  590. id: group.get('id')
  591. });
  592. });
  593. this.get('wizardController').setDBProperty('groupsToDelete', groupsToDelete);
  594. },
  595. /**
  596. * Update <code>configGroups</code> with selected service configGroups
  597. * Also set default group to first position
  598. * Update <code>selectedConfigGroup</code> with new default group
  599. * @method selectedServiceObserver
  600. */
  601. selectedServiceObserver: function () {
  602. if (App.supports.hostOverridesInstaller && this.get('selectedService') && (this.get('selectedService.serviceName') !== 'MISC')) {
  603. var serviceGroups = this.get('selectedService.configGroups');
  604. serviceGroups.forEach(function (item, index, array) {
  605. if (item.isDefault) {
  606. array.unshift(item);
  607. array.splice(index + 1, 1);
  608. }
  609. });
  610. this.set('configGroups', serviceGroups);
  611. this.set('selectedConfigGroup', serviceGroups.findProperty('isDefault'));
  612. }
  613. }.observes('selectedService.configGroups.@each'),
  614. /**
  615. * load default groups for each service in case of initial load
  616. * @param serviceConfigGroups
  617. * @method loadConfigGroups
  618. */
  619. loadConfigGroups: function (serviceConfigGroups) {
  620. var services = this.get('stepConfigs');
  621. var hosts = this.get('wizardController.allHosts').mapProperty('hostName');
  622. services.forEach(function (service) {
  623. if (service.get('serviceName') === 'MISC') return;
  624. var serviceRawGroups = serviceConfigGroups.filterProperty('service.id', service.serviceName);
  625. if (!serviceRawGroups.length) {
  626. service.set('configGroups', [
  627. App.ConfigGroup.create({
  628. name: App.Service.DisplayNames[service.serviceName] + " Default",
  629. description: "Default cluster level " + service.serviceName + " configuration",
  630. isDefault: true,
  631. hosts: Em.copy(hosts),
  632. service: Em.Object.create({
  633. id: service.serviceName
  634. }),
  635. serviceName: service.serviceName
  636. })
  637. ]);
  638. }
  639. else {
  640. var defaultGroup = App.ConfigGroup.create(serviceRawGroups.findProperty('isDefault'));
  641. var serviceGroups = service.get('configGroups');
  642. serviceRawGroups.filterProperty('isDefault', false).forEach(function (configGroup) {
  643. var readyGroup = App.ConfigGroup.create(configGroup);
  644. var wrappedProperties = [];
  645. readyGroup.get('properties').forEach(function(property){
  646. wrappedProperties.pushObject(App.ServiceConfigProperty.create(property));
  647. });
  648. wrappedProperties.setEach('group', readyGroup);
  649. readyGroup.set('properties', wrappedProperties);
  650. readyGroup.set('parentConfigGroup', defaultGroup);
  651. serviceGroups.pushObject(readyGroup);
  652. });
  653. defaultGroup.set('childConfigGroups', serviceGroups);
  654. serviceGroups.pushObject(defaultGroup);
  655. }
  656. });
  657. },
  658. /**
  659. * Click-handler on config-group to make it selected
  660. * @param {object} event
  661. * @method selectConfigGroup
  662. */
  663. selectConfigGroup: function (event) {
  664. this.set('selectedConfigGroup', event.context);
  665. },
  666. /**
  667. * Rebuild list of configs switch of config group:
  668. * on default - display all configs from default group and configs from non-default groups as disabled
  669. * on non-default - display all from default group as disabled and configs from selected non-default group
  670. * @method switchConfigGroupConfigs
  671. */
  672. switchConfigGroupConfigs: function () {
  673. var serviceConfigs = this.get('selectedService.configs'),
  674. selectedGroup = this.get('selectedConfigGroup'),
  675. overrideToAdd = this.get('overrideToAdd'),
  676. overrides = [];
  677. if(!selectedGroup) return;
  678. var displayedConfigGroups = this._getDisplayedConfigGroups();
  679. displayedConfigGroups.forEach(function (group) {
  680. overrides.pushObjects(group.get('properties'));
  681. });
  682. serviceConfigs.forEach(function (config) {
  683. this._setEditableValue(config);
  684. this._setOverrides(config, overrides);
  685. }, this);
  686. }.observes('selectedConfigGroup'),
  687. /**
  688. * Get list of config groups to display
  689. * Returns empty array if no <code>selectedConfigGroup</code>
  690. * @return {Array}
  691. * @method _getDisplayedConfigGroups
  692. */
  693. _getDisplayedConfigGroups: function() {
  694. var selectedGroup = this.get('selectedConfigGroup');
  695. if (!selectedGroup) return [];
  696. return (selectedGroup.get('isDefault')) ?
  697. this.get('selectedService.configGroups').filterProperty('isDefault', false) :
  698. [this.get('selectedConfigGroup')];
  699. },
  700. /**
  701. * Set <code>isEditable</code> property to <code>config</code>
  702. * @param {Ember.Object} config
  703. * @return {Ember.Object} updated config-object
  704. * @method _setEditableValue
  705. */
  706. _setEditableValue: function(config) {
  707. var selectedGroup = this.get('selectedConfigGroup');
  708. if (!selectedGroup) return config;
  709. var isEditable = config.get('isEditable'),
  710. isServiceInstalled = this.get('installedServiceNames').contains(this.get('selectedService.serviceName'));
  711. if (isServiceInstalled) {
  712. isEditable = (!isEditable && !config.get('isReconfigurable')) ? false : selectedGroup.get('isDefault');
  713. }
  714. else {
  715. isEditable = selectedGroup.get('isDefault');
  716. }
  717. config.set('isEditable', isEditable);
  718. return config;
  719. },
  720. /**
  721. * Set <code>overrides</code> property to <code>config</code>
  722. * @param {Ember.Object} config
  723. * @param {Ember.Enumerable} overrides
  724. * @returns {Ember.Object}
  725. * @method _setOverrides
  726. */
  727. _setOverrides: function(config, overrides) {
  728. var selectedGroup = this.get('selectedConfigGroup'),
  729. overrideToAdd = this.get('overrideToAdd'),
  730. configOverrides = overrides.filterProperty('name', config.get('name'));
  731. if (!selectedGroup) return config;
  732. if (overrideToAdd && overrideToAdd.get('name') === config.get('name')) {
  733. configOverrides.push(this.addOverrideProperty(config));
  734. this.set('overrideToAdd', null);
  735. }
  736. configOverrides.setEach('isEditable', !selectedGroup.get('isDefault'));
  737. configOverrides.setEach('parentSCP', config);
  738. config.set('overrides', configOverrides);
  739. return config;
  740. },
  741. /**
  742. * create overriden property and push it into Config group
  743. * @param {App.ServiceConfigProperty} serviceConfigProperty
  744. * @return {App.ServiceConfigProperty}
  745. * @method addOverrideProperty
  746. */
  747. addOverrideProperty: function (serviceConfigProperty) {
  748. var overrides = serviceConfigProperty.get('overrides') || [];
  749. var newSCP = App.ServiceConfigProperty.create(serviceConfigProperty);
  750. var group = this.get('selectedService.configGroups').findProperty('name', this.get('selectedConfigGroup.name'));
  751. newSCP.set('group', group);
  752. newSCP.set('value', '');
  753. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  754. newSCP.set('parentSCP', serviceConfigProperty);
  755. newSCP.set('isEditable', true);
  756. group.get('properties').pushObject(newSCP);
  757. overrides.pushObject(newSCP);
  758. return newSCP;
  759. },
  760. /**
  761. * @method manageConfigurationGroup
  762. */
  763. manageConfigurationGroup: function () {
  764. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(this);
  765. },
  766. /**
  767. * Make some configs visible depending on active services
  768. * @method activateSpecialConfigs
  769. */
  770. activateSpecialConfigs: function () {
  771. var miscConfigs = this.get('stepConfigs').findProperty('serviceName', 'MISC').configs;
  772. miscConfigs = App.config.miscConfigVisibleProperty(miscConfigs, this.get('selectedServiceNames'));
  773. },
  774. /**
  775. * Click-handler on Next button
  776. * @method submit
  777. */
  778. submit: function () {
  779. if (!this.get('isSubmitDisabled')) {
  780. App.router.send('next');
  781. }
  782. }
  783. });