configs.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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 batchUtils = require('utils/batch_scheduled_requests');
  20. var databaseUtils = require('utils/configs/database');
  21. App.MainServiceInfoConfigsController = Em.Controller.extend(App.ConfigsLoader, App.ServerValidatorMixin, App.EnhancedConfigsMixin, App.ThemesMappingMixin, App.VersionsMappingMixin, App.ConfigsSaverMixin, App.ConfigsComparator, {
  22. name: 'mainServiceInfoConfigsController',
  23. isHostsConfigsPage: false,
  24. isRecommendedLoaded: true,
  25. dataIsLoaded: false,
  26. stepConfigs: [], //contains all field properties that are viewed in this service
  27. selectedService: null,
  28. selectedConfigGroup: null,
  29. requestsInProgress: [],
  30. groupsStore: App.ServiceConfigGroup.find(),
  31. /**
  32. * config groups for current service
  33. * @type {App.ConfigGroup[]}
  34. */
  35. configGroups: function() {
  36. return this.get('groupsStore').filterProperty('serviceName', this.get('content.serviceName'));
  37. }.property('content.serviceName', 'groupsStore'),
  38. dependentConfigGroups: function() {
  39. if (this.get('dependentServiceNames.length') === 0) return [];
  40. return this.get('groupsStore').filter(function(group) {
  41. return this.get('dependentServiceNames').contains(group.get('serviceName'));
  42. }, this);
  43. }.property('content.serviceName', 'dependentServiceNames', 'groupsStore.length', 'groupStore.@each.name'),
  44. allConfigs: [],
  45. /**
  46. * Determines if save configs is in progress
  47. * @type {boolean}
  48. */
  49. saveInProgress: false,
  50. isCompareMode: false,
  51. preSelectedConfigVersion: null,
  52. /**
  53. * contain Service Config Property, when user proceed from Select Config Group dialog
  54. */
  55. overrideToAdd: null,
  56. /**
  57. * version selected to view
  58. */
  59. selectedVersion: null,
  60. /**
  61. * note passed on configs save
  62. * @type {string}
  63. */
  64. serviceConfigVersionNote: '',
  65. versionLoaded: false,
  66. /**
  67. * Determines when data about config groups is loaded
  68. * Including recommendations with information about hosts in the each group
  69. * @type {boolean}
  70. */
  71. configGroupsAreLoaded: false,
  72. dependentServiceNames: [],
  73. /**
  74. * defines which service configs need to be loaded to stepConfigs
  75. * @type {string[]}
  76. */
  77. servicesToLoad: function() {
  78. return [this.get('content.serviceName')].concat(this.get('dependentServiceNames')).uniq();
  79. }.property('content.serviceName', 'dependentServiceNames.length'),
  80. /**
  81. * @type {boolean}
  82. */
  83. isCurrentSelected: function () {
  84. return App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + this.get('selectedVersion')).get('isCurrent');
  85. }.property('selectedVersion', 'content.serviceName', 'dataIsLoaded', 'versionLoaded'),
  86. /**
  87. * @type {boolean}
  88. */
  89. canEdit: function () {
  90. return (this.get('selectedVersion') == this.get('currentDefaultVersion') || !this.get('selectedConfigGroup.isDefault'))
  91. && !this.get('isCompareMode') && App.isAuthorized('SERVICE.MODIFY_CONFIGS') && !this.get('isHostsConfigsPage');
  92. }.property('selectedVersion', 'isCompareMode', 'currentDefaultVersion', 'selectedConfigGroup.isDefault'),
  93. serviceConfigs: Em.computed.alias('App.config.preDefinedServiceConfigs'),
  94. /**
  95. * Number of errors in the configs in the selected service (only for AdvancedTab if App supports Enhanced Configs)
  96. * @type {number}
  97. */
  98. errorsCount: function() {
  99. return this.get('selectedService.configsWithErrors').filter(function(c) {
  100. return Em.isNone(c.get('widget'));
  101. }).length;
  102. }.property('selectedService.configsWithErrors'),
  103. /**
  104. * Determines if Save-button should be disabled
  105. * Disabled if some configs have invalid values for selected service
  106. * or save-process currently in progress
  107. *
  108. * @type {boolean}
  109. */
  110. isSubmitDisabled: function () {
  111. if (!this.get('selectedService')) return true;
  112. return this.get('selectedService').get('errorCount') !== 0 || this.get('saveInProgress');
  113. }.property('selectedService.errorCount', 'saveInProgress'),
  114. /**
  115. * Determines if some config value is changed
  116. * @type {boolean}
  117. */
  118. isPropertiesChanged: Em.computed.alias('selectedService.isPropertiesChanged'),
  119. /**
  120. * Filter text will be located here
  121. * @type {string}
  122. */
  123. filter: '',
  124. /**
  125. * List of filters for config properties to populate filter combobox
  126. * @type {{attributeName: string, attributeValue: boolean, caption: string}[]}
  127. */
  128. propertyFilters: [
  129. {
  130. attributeName: 'isOverridden',
  131. attributeValue: true,
  132. caption: 'common.combobox.dropdown.overridden'
  133. },
  134. {
  135. attributeName: 'isFinal',
  136. attributeValue: true,
  137. caption: 'common.combobox.dropdown.final'
  138. },
  139. {
  140. attributeName: 'hasCompareDiffs',
  141. attributeValue: true,
  142. caption: 'common.combobox.dropdown.changed',
  143. dependentOn: 'isCompareMode'
  144. },
  145. {
  146. attributeName: 'hasIssues',
  147. attributeValue: true,
  148. caption: 'common.combobox.dropdown.issues'
  149. }
  150. ],
  151. /**
  152. * Dropdown menu items in filter combobox
  153. * @type {{attributeName: string, attributeValue: string, name: string, selected: boolean}[]}
  154. */
  155. filterColumns: function () {
  156. var filterColumns = [];
  157. this.get('propertyFilters').forEach(function(filter) {
  158. if (Em.isNone(filter.dependentOn) || this.get(filter.dependentOn)) {
  159. filterColumns.push(Ember.Object.create({
  160. attributeName: filter.attributeName,
  161. attributeValue: filter.attributeValue,
  162. name: this.t(filter.caption),
  163. selected: filter.dependentOn ? this.get(filter.dependentOn) : false
  164. }));
  165. }
  166. }, this);
  167. return filterColumns;
  168. }.property('propertyFilters', 'isCompareMode'),
  169. /**
  170. * Detects of some of the `password`-configs has not default value
  171. *
  172. * @type {boolean}
  173. */
  174. passwordConfigsAreChanged: function () {
  175. return this.get('stepConfigs')
  176. .findProperty('serviceName', this.get('selectedService.serviceName'))
  177. .get('configs')
  178. .filterProperty('displayType', 'password')
  179. .someProperty('isNotDefaultValue');
  180. }.property('stepConfigs.[].configs', 'selectedService.serviceName'),
  181. /**
  182. * indicate whether service config version belongs to default config group
  183. * @param {object} version
  184. * @return {Boolean}
  185. * @private
  186. * @method isVersionDefault
  187. */
  188. isVersionDefault: function(version) {
  189. return (App.ServiceConfigVersion.find(this.get('content.serviceName') + "_" + version).get('groupId') == -1);
  190. },
  191. /**
  192. * register request to view to track his progress
  193. * @param {$.ajax} request
  194. * @method trackRequest
  195. */
  196. trackRequest: function (request) {
  197. this.get('requestsInProgress').push(request);
  198. },
  199. /**
  200. * clear and set properties to default value
  201. * @method clearStep
  202. */
  203. clearStep: function () {
  204. this.get('requestsInProgress').forEach(function(r) {
  205. if (r && r.readyState !== 4) {
  206. r.abort();
  207. }
  208. });
  209. this.get('requestsInProgress').clear();
  210. this.clearLoadInfo();
  211. this.clearSaveInfo();
  212. this.clearRecommendationsInfo();
  213. this.clearAllRecommendations();
  214. this.setProperties({
  215. saveInProgress: false,
  216. isInit: true,
  217. hash: null,
  218. dataIsLoaded: false,
  219. versionLoaded: false,
  220. filter: '',
  221. serviceConfigVersionNote: '',
  222. dependentServiceNames: [],
  223. configGroupsAreLoaded: false
  224. });
  225. this.get('filterColumns').setEach('selected', false);
  226. this.clearConfigs();
  227. },
  228. clearConfigs: function() {
  229. this.get('selectedConfigGroup', null);
  230. this.get('allConfigs').invoke('destroy');
  231. this.get('stepConfigs').invoke('destroy');
  232. this.set('stepConfigs', []);
  233. this.set('allConfigs', []);
  234. this.set('selectedService', null);
  235. },
  236. /**
  237. * "Finger-print" of the <code>stepConfigs</code>. Filled after first configGroup selecting
  238. * Used to determine if some changes were made (when user navigates away from this page)
  239. * @type {String|null}
  240. */
  241. hash: null,
  242. /**
  243. * Is this initial config group changing
  244. * @type {Boolean}
  245. */
  246. isInit: true,
  247. /**
  248. * On load function
  249. * @method loadStep
  250. */
  251. loadStep: function () {
  252. var self = this;
  253. var serviceName = this.get('content.serviceName');
  254. this.clearStep();
  255. this.set('dependentServiceNames', App.StackService.find(serviceName).get('dependentServiceNames'));
  256. if (App.get('isClusterSupportsEnhancedConfigs')) {
  257. this.loadConfigTheme(serviceName).always(function() {
  258. App.themesMapper.generateAdvancedTabs([serviceName]);
  259. // Theme mapper has UI only configs that needs to be merged with current service version configs
  260. // This requires calling `loadCurrentVersions` after theme has loaded
  261. self.loadCurrentVersions();
  262. });
  263. }
  264. else {
  265. this.loadCurrentVersions();
  266. }
  267. this.loadServiceConfigVersions();
  268. },
  269. /**
  270. * Generate "finger-print" for current <code>stepConfigs[0]</code>
  271. * Used to determine, if user has some unsaved changes (comparing with <code>hash</code>)
  272. * @returns {string|null}
  273. * @method getHash
  274. */
  275. getHash: function () {
  276. if (!this.get('selectedService.configs.length')) {
  277. return null;
  278. }
  279. var hash = {};
  280. this.get('selectedService.configs').forEach(function (config) {
  281. hash[config.get('name')] = {value: App.config.formatPropertyValue(config), overrides: [], isFinal: config.get('isFinal')};
  282. if (!config.get('overrides')) return;
  283. if (!config.get('overrides.length')) return;
  284. config.get('overrides').forEach(function (override) {
  285. hash[config.get('name')].overrides.push(App.config.formatPropertyValue(override));
  286. });
  287. });
  288. return JSON.stringify(hash);
  289. },
  290. parseConfigData: function(data) {
  291. this.prepareConfigObjects(data, this.get('content.serviceName'));
  292. var self = this;
  293. this.loadCompareVersionConfigs(this.get('allConfigs')).done(function() {
  294. self.addOverrides(data, self.get('allConfigs'));
  295. self.onLoadOverrides(self.get('allConfigs'));
  296. });
  297. },
  298. prepareConfigObjects: function(data, serviceName) {
  299. this.get('stepConfigs').clear();
  300. var configs = [];
  301. data.items.forEach(function (version) {
  302. if (version.group_name == 'default') {
  303. version.configurations.forEach(function (configObject) {
  304. configs = configs.concat(App.config.getConfigsFromJSON(configObject, true));
  305. });
  306. }
  307. });
  308. configs = App.config.sortConfigs(configs);
  309. /**
  310. * if property defined in stack but somehow it missed from cluster properties (can be after stack upgrade)
  311. * ui should add this properties to step configs
  312. */
  313. configs = this.mergeWithStackProperties(configs);
  314. //put properties from capacity-scheduler.xml into one config with textarea view
  315. if (this.get('content.serviceName') === 'YARN') {
  316. configs = App.config.addYarnCapacityScheduler(configs);
  317. }
  318. if (this.get('content.serviceName') === 'KERBEROS') {
  319. var kdc_type = configs.findProperty('name', 'kdc_type');
  320. if (kdc_type.get('value') === 'none') {
  321. configs.findProperty('name', 'kdc_host').set('isVisible', false);
  322. configs.findProperty('name', 'admin_server_host').set('isVisible', false);
  323. configs.findProperty('name', 'domains').set('isVisible', false);
  324. } else if (kdc_type.get('value') === 'active-directory') {
  325. configs.findProperty('name', 'container_dn').set('isVisible', true);
  326. configs.findProperty('name', 'ldap_url').set('isVisible', true);
  327. }
  328. }
  329. this.setPropertyIsEditable(configs);
  330. this.set('allConfigs', configs);
  331. },
  332. /**
  333. * Set <code>isEditable<code> proeperty based on selected group, security
  334. * and controller restriction
  335. * @param configs
  336. */
  337. setPropertyIsEditable: function(configs) {
  338. if (!this.get('selectedConfigGroup.isDefault') || !this.get('canEdit')) {
  339. configs.setEach('isEditable', false);
  340. } else if (App.get('isKerberosEnabled')) {
  341. configs.filterProperty('isSecureConfig').setEach('isEditable', false);
  342. }
  343. },
  344. /**
  345. * adds properties form stack that doesn't belong to cluster
  346. * to step configs
  347. * also set recommended value if isn't exists
  348. *
  349. * @return {App.ServiceConfigProperty[]}
  350. * @method mergeWithStackProperties
  351. */
  352. mergeWithStackProperties: function (configs) {
  353. App.config.getPropertiesFromTheme(this.get('content.serviceName')).forEach(function (advanced_id) {
  354. if (!configs.someProperty('id', advanced_id)) {
  355. var advanced = App.configsCollection.getConfig(advanced_id);
  356. if (advanced) {
  357. advanced.savedValue = null;
  358. advanced.isNotSaved = true;
  359. configs.pushObject(App.ServiceConfigProperty.create(advanced));
  360. }
  361. }
  362. });
  363. return configs;
  364. },
  365. addOverrides: function(data, allConfigs) {
  366. var self = this;
  367. data.items.forEach(function(group) {
  368. if (group.group_name != 'default') {
  369. var configGroup = App.ServiceConfigGroup.find().filterProperty('serviceName', group.service_name).findProperty('name', group.group_name);
  370. group.configurations.forEach(function(config) {
  371. for (var prop in config.properties) {
  372. var fileName = App.config.getOriginalFileName(config.type);
  373. var serviceConfig = allConfigs.filterProperty('name', prop).findProperty('filename', fileName);
  374. if (serviceConfig) {
  375. var value = App.config.formatPropertyValue(serviceConfig, config.properties[prop]);
  376. var isFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]);
  377. if (self.get('selectedConfigGroup.isDefault') || configGroup.get('name') == self.get('selectedConfigGroup.name')) {
  378. var overridePlainObject = {
  379. "value": value,
  380. "savedValue": value,
  381. "isFinal": isFinal,
  382. "savedIsFinal": isFinal,
  383. "isEditable": self.get('canEdit') && configGroup.get('name') == self.get('selectedConfigGroup.name')
  384. };
  385. App.config.createOverride(serviceConfig, overridePlainObject, configGroup);
  386. }
  387. } else {
  388. var isEditable = self.get('canEdit') && configGroup.get('name') == self.get('selectedConfigGroup.name');
  389. allConfigs.push(App.config.createCustomGroupConfig(prop, fileName, config.properties[prop], configGroup, isEditable));
  390. }
  391. }
  392. });
  393. }
  394. });
  395. },
  396. /**
  397. * @param allConfigs
  398. * @private
  399. * @method onLoadOverrides
  400. */
  401. onLoadOverrides: function (allConfigs) {
  402. this.get('servicesToLoad').forEach(function(serviceName) {
  403. var configGroups = serviceName == this.get('content.serviceName') ? this.get('configGroups') : this.get('dependentConfigGroups').filterProperty('serviceName', serviceName);
  404. var configTypes = App.StackService.find(serviceName).get('configTypeList');
  405. var configsByService = this.get('allConfigs').filter(function (c) {
  406. return configTypes.contains(App.config.getConfigTagFromFileName(c.get('filename')));
  407. });
  408. var serviceConfig = App.config.createServiceConfig(serviceName, configGroups, configsByService, configsByService.length);
  409. this.addHostNamesToConfigs(serviceConfig);
  410. this.get('stepConfigs').pushObject(serviceConfig);
  411. }, this);
  412. var selectedService = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName'));
  413. this.set('selectedService', selectedService);
  414. this.checkOverrideProperty(selectedService);
  415. if (App.Service.find().someProperty('serviceName', 'RANGER')) {
  416. this.setVisibilityForRangerProperties(selectedService);
  417. } else {
  418. App.config.removeRangerConfigs(this.get('stepConfigs'));
  419. }
  420. this.loadConfigRecommendations(null, this._onLoadComplete.bind(this));
  421. App.loadTimer.finish('Service Configs Page');
  422. },
  423. /**
  424. * @method _getRecommendationsForDependenciesCallback
  425. */
  426. _onLoadComplete: function () {
  427. this.get('stepConfigs').forEach(function(serviceConfig){
  428. serviceConfig.set('initConfigsLength', serviceConfig.get('configs.length'));
  429. });
  430. this.setProperties({
  431. dataIsLoaded: true,
  432. versionLoaded: true,
  433. isInit: false,
  434. hash: this.getHash()
  435. });
  436. },
  437. /**
  438. * hide properties from Advanced ranger category that match pattern
  439. * if property with dependentConfigPattern is false otherwise don't hide
  440. * @param serviceConfig
  441. * @private
  442. * @method setVisibilityForRangerProperties
  443. */
  444. setVisibilityForRangerProperties: function(serviceConfig) {
  445. var category = "Advanced ranger-{0}-plugin-properties".format(this.get('content.serviceName').toLowerCase());
  446. if (serviceConfig.configCategories.findProperty('name', category)) {
  447. var patternConfig = serviceConfig.configs.findProperty('dependentConfigPattern');
  448. if (patternConfig) {
  449. var value = patternConfig.get('value') === true || ["yes", "true"].contains(patternConfig.get('value').toLowerCase());
  450. serviceConfig.configs.filter(function(c) {
  451. if (c.get('category') === category && c.get('name').match(patternConfig.get('dependentConfigPattern')) && c.get('name') != patternConfig.get('name'))
  452. c.set('isVisible', value);
  453. });
  454. }
  455. }
  456. },
  457. /**
  458. * Allow update property if recommendations
  459. * is based on changing property
  460. *
  461. * @param parentProperties
  462. * @returns {boolean}
  463. * @override
  464. */
  465. allowUpdateProperty: function(parentProperties) {
  466. return !!(parentProperties && parentProperties.length);
  467. },
  468. /**
  469. * trigger App.config.createOverride
  470. * @param {Object[]} stepConfig
  471. * @private
  472. * @method checkOverrideProperty
  473. */
  474. checkOverrideProperty: function (stepConfig) {
  475. var overrideToAdd = this.get('overrideToAdd');
  476. var value = !!this.get('overrideToAdd.widget') ? Em.get(overrideToAdd, 'value') : '';
  477. if (overrideToAdd) {
  478. overrideToAdd = stepConfig.configs.filter(function(c){
  479. return c.name == overrideToAdd.name && c.filename == overrideToAdd.filename;
  480. });
  481. if (overrideToAdd[0]) {
  482. App.config.createOverride(overrideToAdd[0], {"isEditable": true, "value": value}, this.get('selectedConfigGroup'));
  483. this.set('overrideToAdd', null);
  484. }
  485. }
  486. },
  487. /**
  488. *
  489. * @param serviceConfig
  490. */
  491. addHostNamesToConfigs: function(serviceConfig) {
  492. serviceConfig.get('configCategories').forEach(function(c) {
  493. if (c.showHost) {
  494. var stackComponent = App.StackServiceComponent.find(c.name);
  495. var component = stackComponent.get('isMaster') ? App.MasterComponent.find(c.name) : App.SlaveComponent.find(c.name);
  496. var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), c.name, component.get('hostNames') || [], stackComponent);
  497. serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
  498. }
  499. }, this);
  500. },
  501. /**
  502. * Trigger loadSelectedVersion
  503. * @method doCancel
  504. */
  505. doCancel: function () {
  506. this.set('preSelectedConfigVersion', null);
  507. this.clearAllRecommendations();
  508. this.loadSelectedVersion(this.get('selectedVersion'), this.get('selectedConfigGroup'));
  509. },
  510. /**
  511. * trigger restartAllServiceHostComponents(batchUtils) if confirmed in popup
  512. * @method restartAllStaleConfigComponents
  513. * @return App.showConfirmationFeedBackPopup
  514. */
  515. restartAllStaleConfigComponents: function () {
  516. var self = this;
  517. var serviceDisplayName = this.get('content.displayName');
  518. var bodyMessage = Em.Object.create({
  519. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  520. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  521. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName) : null
  522. });
  523. var isNNAffected = false;
  524. var restartRequiredHostsAndComponents = this.get('content.restartRequiredHostsAndComponents');
  525. for (var hostName in restartRequiredHostsAndComponents) {
  526. restartRequiredHostsAndComponents[hostName].forEach(function (hostComponent) {
  527. if (hostComponent == 'NameNode')
  528. isNNAffected = true;
  529. })
  530. }
  531. if (this.get('content.serviceName') == 'HDFS' && isNNAffected &&
  532. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  533. App.router.get('mainServiceItemController').checkNnLastCheckpointTime(function () {
  534. return App.showConfirmationFeedBackPopup(function (query) {
  535. var selectedService = self.get('content.id');
  536. batchUtils.restartAllServiceHostComponents(serviceDisplayName, selectedService, true, query);
  537. }, bodyMessage);
  538. });
  539. } else {
  540. return App.showConfirmationFeedBackPopup(function (query) {
  541. var selectedService = self.get('content.id');
  542. batchUtils.restartAllServiceHostComponents(serviceDisplayName, selectedService, true, query);
  543. }, bodyMessage);
  544. }
  545. },
  546. /**
  547. * trigger launchHostComponentRollingRestart(batchUtils)
  548. * @method rollingRestartStaleConfigSlaveComponents
  549. */
  550. rollingRestartStaleConfigSlaveComponents: function (componentName) {
  551. batchUtils.launchHostComponentRollingRestart(componentName.context, this.get('content.displayName'), this.get('content.passiveState') === "ON", true);
  552. },
  553. /**
  554. * trigger showItemsShouldBeRestarted popup with hosts that requires restart
  555. * @param {{context: object}} event
  556. * @method showHostsShouldBeRestarted
  557. */
  558. showHostsShouldBeRestarted: function (event) {
  559. var restartRequiredHostsAndComponents = event.context.restartRequiredHostsAndComponents;
  560. var hosts = [];
  561. for (var hostName in restartRequiredHostsAndComponents) {
  562. hosts.push(hostName);
  563. }
  564. var hostsText = hosts.length == 1 ? Em.I18n.t('common.host') : Em.I18n.t('common.hosts');
  565. hosts = hosts.join(', ');
  566. this.showItemsShouldBeRestarted(hosts, Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(hostsText));
  567. },
  568. /**
  569. * trigger showItemsShouldBeRestarted popup with components that requires restart
  570. * @param {{context: object}} event
  571. * @method showComponentsShouldBeRestarted
  572. */
  573. showComponentsShouldBeRestarted: function (event) {
  574. var restartRequiredHostsAndComponents = event.context.restartRequiredHostsAndComponents;
  575. var hostsComponets = [];
  576. var componentsObject = {};
  577. for (var hostName in restartRequiredHostsAndComponents) {
  578. restartRequiredHostsAndComponents[hostName].forEach(function (hostComponent) {
  579. hostsComponets.push(hostComponent);
  580. if (componentsObject[hostComponent] != undefined) {
  581. componentsObject[hostComponent]++;
  582. } else {
  583. componentsObject[hostComponent] = 1;
  584. }
  585. })
  586. }
  587. var componentsList = [];
  588. for (var obj in componentsObject) {
  589. var componentDisplayName = (componentsObject[obj] > 1) ? obj + 's' : obj;
  590. componentsList.push(componentsObject[obj] + ' ' + componentDisplayName);
  591. }
  592. var componentsText = componentsList.length == 1 ? Em.I18n.t('common.component') : Em.I18n.t('common.components');
  593. hostsComponets = componentsList.join(', ');
  594. this.showItemsShouldBeRestarted(hostsComponets, Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(componentsText));
  595. },
  596. /**
  597. * Show popup with selectable (@see App.SelectablePopupBodyView) list of items
  598. * @param {string} content string with comma-separated list of hostNames or componentNames
  599. * @param {string} header popup header
  600. * @returns {App.ModalPopup}
  601. * @method showItemsShouldBeRestarted
  602. */
  603. showItemsShouldBeRestarted: function (content, header) {
  604. return App.ModalPopup.show({
  605. content: content,
  606. header: header,
  607. bodyClass: App.SelectablePopupBodyView,
  608. secondary: null
  609. });
  610. },
  611. /**
  612. * trigger manageConfigurationGroups
  613. * @method manageConfigurationGroup
  614. */
  615. manageConfigurationGroup: function () {
  616. App.router.get('manageConfigGroupsController').manageConfigurationGroups(null, this.get('content'));
  617. },
  618. /**
  619. * If user changes cfg group if some configs was changed popup with propose to save changes must be shown
  620. * @param {object} event - triggered event for selecting another config-group
  621. * @method selectConfigGroup
  622. */
  623. selectConfigGroup: function (event) {
  624. var self = this;
  625. function callback() {
  626. self.doSelectConfigGroup(event);
  627. }
  628. if (!this.get('isInit')) {
  629. if (this.hasUnsavedChanges()) {
  630. this.showSavePopup(null, callback);
  631. return;
  632. }
  633. }
  634. callback();
  635. },
  636. /**
  637. * switch view to selected group
  638. * @param event
  639. * @method selectConfigGroup
  640. */
  641. doSelectConfigGroup: function (event) {
  642. App.loadTimer.start('Service Configs Page');
  643. var configGroupVersions = App.ServiceConfigVersion.find().filterProperty('groupId', event.context.get('configGroupId'));
  644. //check whether config group has config versions
  645. if (event.context.get('configGroupId') == -1) {
  646. this.loadCurrentVersions();
  647. } else if (configGroupVersions.length > 0) {
  648. this.loadSelectedVersion(configGroupVersions.findProperty('isCurrent').get('version'), event.context);
  649. } else {
  650. this.loadSelectedVersion(null, event.context);
  651. }
  652. }
  653. });