configs.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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, App.ComponentActionsByConfigs, {
  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', 'groupsStore.@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');
  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. } else {
  264. this.loadCurrentVersions();
  265. }
  266. this.loadServiceConfigVersions();
  267. },
  268. /**
  269. * Generate "finger-print" for current <code>stepConfigs[0]</code>
  270. * Used to determine, if user has some unsaved changes (comparing with <code>hash</code>)
  271. * @returns {string|null}
  272. * @method getHash
  273. */
  274. getHash: function () {
  275. if (!this.get('selectedService.configs.length')) {
  276. return null;
  277. }
  278. var hash = {};
  279. this.get('selectedService.configs').forEach(function (config) {
  280. hash[config.get('name')] = {value: App.config.formatPropertyValue(config), overrides: [], isFinal: config.get('isFinal')};
  281. if (!config.get('overrides')) return;
  282. if (!config.get('overrides.length')) return;
  283. config.get('overrides').forEach(function (override) {
  284. hash[config.get('name')].overrides.push(App.config.formatPropertyValue(override));
  285. });
  286. });
  287. return JSON.stringify(hash);
  288. },
  289. parseConfigData: function(data) {
  290. this.prepareConfigObjects(data, this.get('content.serviceName'));
  291. var self = this;
  292. this.loadCompareVersionConfigs(this.get('allConfigs')).done(function() {
  293. self.addOverrides(data, self.get('allConfigs'));
  294. self.onLoadOverrides(self.get('allConfigs'));
  295. });
  296. },
  297. prepareConfigObjects: function(data, serviceName) {
  298. this.get('stepConfigs').clear();
  299. var configs = [];
  300. data.items.forEach(function (version) {
  301. if (version.group_name == 'default') {
  302. version.configurations.forEach(function (configObject) {
  303. configs = configs.concat(App.config.getConfigsFromJSON(configObject, true));
  304. });
  305. }
  306. });
  307. configs = App.config.sortConfigs(configs);
  308. /**
  309. * if property defined in stack but somehow it missed from cluster properties (can be after stack upgrade)
  310. * ui should add this properties to step configs
  311. */
  312. configs = this.mergeWithStackProperties(configs);
  313. //put properties from capacity-scheduler.xml into one config with textarea view
  314. if (this.get('content.serviceName') === 'YARN') {
  315. configs = App.config.addYarnCapacityScheduler(configs);
  316. }
  317. if (this.get('content.serviceName') === 'KERBEROS') {
  318. var kdc_type = configs.findProperty('name', 'kdc_type');
  319. if (kdc_type.get('value') === 'none') {
  320. configs.findProperty('name', 'kdc_host').set('isVisible', false);
  321. configs.findProperty('name', 'admin_server_host').set('isVisible', false);
  322. configs.findProperty('name', 'domains').set('isVisible', false);
  323. } else if (kdc_type.get('value') === 'active-directory') {
  324. configs.findProperty('name', 'container_dn').set('isVisible', true);
  325. configs.findProperty('name', 'ldap_url').set('isVisible', true);
  326. } else if (kdc_type.get('value') === 'ipa') {
  327. configs.findProperty('name', 'group').set('isVisible', true);
  328. configs.findProperty('name', 'manage_krb5_conf').set('value', false);
  329. configs.findProperty('name', 'install_packages').set('value', false);
  330. configs.findProperty('name', 'admin_server_host').set('isVisible', false);
  331. configs.findProperty('name', 'domains').set('isVisible', false);
  332. }
  333. }
  334. this.setPropertyIsEditable(configs);
  335. this.set('allConfigs', configs);
  336. },
  337. /**
  338. * Set <code>isEditable<code> proeperty based on selected group, security
  339. * and controller restriction
  340. * @param configs
  341. */
  342. setPropertyIsEditable: function(configs) {
  343. if (!this.get('selectedConfigGroup.isDefault') || !this.get('canEdit')) {
  344. configs.setEach('isEditable', false);
  345. } else if (App.get('isKerberosEnabled')) {
  346. configs.filterProperty('isSecureConfig').setEach('isEditable', false);
  347. }
  348. },
  349. /**
  350. * adds properties form stack that doesn't belong to cluster
  351. * to step configs
  352. * also set recommended value if isn't exists
  353. *
  354. * @return {App.ServiceConfigProperty[]}
  355. * @method mergeWithStackProperties
  356. */
  357. mergeWithStackProperties: function (configs) {
  358. App.config.getPropertiesFromTheme(this.get('content.serviceName')).forEach(function (advanced_id) {
  359. if (!configs.someProperty('id', advanced_id)) {
  360. var advanced = App.configsCollection.getConfig(advanced_id);
  361. if (advanced) {
  362. advanced.savedValue = null;
  363. advanced.isNotSaved = true;
  364. configs.pushObject(App.ServiceConfigProperty.create(advanced));
  365. }
  366. }
  367. });
  368. return configs;
  369. },
  370. addOverrides: function(data, allConfigs) {
  371. var self = this;
  372. data.items.forEach(function(group) {
  373. if (group.group_name != 'default') {
  374. var configGroup = App.ServiceConfigGroup.find().filterProperty('serviceName', group.service_name).findProperty('name', group.group_name);
  375. group.configurations.forEach(function(config) {
  376. for (var prop in config.properties) {
  377. var fileName = App.config.getOriginalFileName(config.type);
  378. var serviceConfig = allConfigs.filterProperty('name', prop).findProperty('filename', fileName);
  379. if (serviceConfig) {
  380. var value = App.config.formatPropertyValue(serviceConfig, config.properties[prop]);
  381. var isFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]);
  382. if (self.get('selectedConfigGroup.isDefault') || configGroup.get('name') == self.get('selectedConfigGroup.name')) {
  383. var overridePlainObject = {
  384. "value": value,
  385. "savedValue": value,
  386. "isFinal": isFinal,
  387. "savedIsFinal": isFinal,
  388. "isEditable": self.get('canEdit') && configGroup.get('name') == self.get('selectedConfigGroup.name')
  389. };
  390. App.config.createOverride(serviceConfig, overridePlainObject, configGroup);
  391. }
  392. } else {
  393. var isEditable = self.get('canEdit') && configGroup.get('name') == self.get('selectedConfigGroup.name');
  394. allConfigs.push(App.config.createCustomGroupConfig(prop, fileName, config.properties[prop], configGroup, isEditable));
  395. }
  396. }
  397. });
  398. }
  399. });
  400. },
  401. /**
  402. * @param allConfigs
  403. * @private
  404. * @method onLoadOverrides
  405. */
  406. onLoadOverrides: function (allConfigs) {
  407. this.get('servicesToLoad').forEach(function(serviceName) {
  408. var configGroups = serviceName == this.get('content.serviceName') ? this.get('configGroups') : this.get('dependentConfigGroups').filterProperty('serviceName', serviceName);
  409. var configTypes = App.StackService.find(serviceName).get('configTypeList');
  410. var configsByService = this.get('allConfigs').filter(function (c) {
  411. return configTypes.contains(App.config.getConfigTagFromFileName(c.get('filename')));
  412. });
  413. var serviceConfig = App.config.createServiceConfig(serviceName, configGroups, configsByService, configsByService.length);
  414. this.addHostNamesToConfigs(serviceConfig);
  415. this.get('stepConfigs').pushObject(serviceConfig);
  416. }, this);
  417. var selectedService = this.get('stepConfigs').findProperty('serviceName', this.get('content.serviceName'));
  418. this.set('selectedService', selectedService);
  419. this.checkOverrideProperty(selectedService);
  420. if (App.Service.find().someProperty('serviceName', 'RANGER')) {
  421. this.setVisibilityForRangerProperties(selectedService);
  422. } else {
  423. App.config.removeRangerConfigs(this.get('stepConfigs'));
  424. }
  425. this.loadConfigRecommendations(null, this._onLoadComplete.bind(this));
  426. App.loadTimer.finish('Service Configs Page');
  427. },
  428. /**
  429. * @method _getRecommendationsForDependenciesCallback
  430. */
  431. _onLoadComplete: function () {
  432. this.get('stepConfigs').forEach(function(serviceConfig){
  433. serviceConfig.set('initConfigsLength', serviceConfig.get('configs.length'));
  434. });
  435. this.setProperties({
  436. dataIsLoaded: true,
  437. versionLoaded: true,
  438. isInit: false,
  439. hash: this.getHash()
  440. });
  441. },
  442. /**
  443. * hide properties from Advanced ranger category that match pattern
  444. * if property with dependentConfigPattern is false otherwise don't hide
  445. * @param serviceConfig
  446. * @private
  447. * @method setVisibilityForRangerProperties
  448. */
  449. setVisibilityForRangerProperties: function(serviceConfig) {
  450. var category = "Advanced ranger-{0}-plugin-properties".format(this.get('content.serviceName').toLowerCase());
  451. if (serviceConfig.configCategories.findProperty('name', category)) {
  452. var patternConfig = serviceConfig.configs.findProperty('dependentConfigPattern');
  453. if (patternConfig) {
  454. var value = patternConfig.get('value') === true || ["yes", "true"].contains(patternConfig.get('value').toLowerCase());
  455. serviceConfig.configs.filter(function(c) {
  456. if (c.get('category') === category && c.get('name').match(patternConfig.get('dependentConfigPattern')) && c.get('name') != patternConfig.get('name'))
  457. c.set('isVisible', value);
  458. });
  459. }
  460. }
  461. },
  462. /**
  463. * Allow update property if recommendations
  464. * is based on changing property
  465. *
  466. * @param parentProperties
  467. * @returns {boolean}
  468. * @override
  469. */
  470. allowUpdateProperty: function(parentProperties) {
  471. return !!(parentProperties && parentProperties.length);
  472. },
  473. /**
  474. * trigger App.config.createOverride
  475. * @param {Object[]} stepConfig
  476. * @private
  477. * @method checkOverrideProperty
  478. */
  479. checkOverrideProperty: function (stepConfig) {
  480. var overrideToAdd = this.get('overrideToAdd');
  481. var value = !!this.get('overrideToAdd.widget') ? Em.get(overrideToAdd, 'value') : '';
  482. if (overrideToAdd) {
  483. overrideToAdd = stepConfig.configs.filter(function(c){
  484. return c.name == overrideToAdd.name && c.filename == overrideToAdd.filename;
  485. });
  486. if (overrideToAdd[0]) {
  487. App.config.createOverride(overrideToAdd[0], {"isEditable": true, "value": value}, this.get('selectedConfigGroup'));
  488. this.set('overrideToAdd', null);
  489. }
  490. }
  491. },
  492. /**
  493. *
  494. * @param serviceConfig
  495. */
  496. addHostNamesToConfigs: function(serviceConfig) {
  497. serviceConfig.get('configCategories').forEach(function(c) {
  498. if (c.showHost) {
  499. var stackComponent = App.StackServiceComponent.find(c.name);
  500. var component = stackComponent.get('isMaster') ? App.MasterComponent.find(c.name) : App.SlaveComponent.find(c.name);
  501. var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), c.name, component.get('hostNames') || [], stackComponent);
  502. serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
  503. }
  504. }, this);
  505. App.ConfigAction.find().forEach(function(item){
  506. var hostComponentConfig = item.get('hostComponentConfig');
  507. var config = serviceConfig.get('configs').filterProperty('filename', hostComponentConfig.fileName).findProperty('name', hostComponentConfig.configName);
  508. if (config){
  509. var componentHostName = App.HostComponent.find().findProperty('componentName', item.get('componentName')) ;
  510. if (componentHostName) {
  511. var setConfigValue = !config.get('value');
  512. if (setConfigValue) {
  513. config.set('value', componentHostName.get('hostName'));
  514. config.set('recommendedValue', componentHostName.get('hostName'));
  515. }
  516. }
  517. }
  518. }, this);
  519. },
  520. /**
  521. * Trigger loadSelectedVersion
  522. * @method doCancel
  523. */
  524. doCancel: function () {
  525. this.set('preSelectedConfigVersion', null);
  526. this.clearAllRecommendations();
  527. this.loadSelectedVersion(this.get('selectedVersion'), this.get('selectedConfigGroup'));
  528. },
  529. /**
  530. * trigger restartAllServiceHostComponents(batchUtils) if confirmed in popup
  531. * @method restartAllStaleConfigComponents
  532. * @return App.showConfirmationFeedBackPopup
  533. */
  534. restartAllStaleConfigComponents: function () {
  535. var self = this;
  536. var serviceDisplayName = this.get('content.displayName');
  537. var bodyMessage = Em.Object.create({
  538. confirmMsg: Em.I18n.t('services.service.restartAll.confirmMsg').format(serviceDisplayName),
  539. confirmButton: Em.I18n.t('services.service.restartAll.confirmButton'),
  540. additionalWarningMsg: this.get('content.passiveState') === 'OFF' ? Em.I18n.t('services.service.restartAll.warningMsg.turnOnMM').format(serviceDisplayName) : null
  541. });
  542. var isNNAffected = false;
  543. var restartRequiredHostsAndComponents = this.get('content.restartRequiredHostsAndComponents');
  544. for (var hostName in restartRequiredHostsAndComponents) {
  545. restartRequiredHostsAndComponents[hostName].forEach(function (hostComponent) {
  546. if (hostComponent == 'NameNode')
  547. isNNAffected = true;
  548. })
  549. }
  550. if (this.get('content.serviceName') == 'HDFS' && isNNAffected &&
  551. this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) {
  552. App.router.get('mainServiceItemController').checkNnLastCheckpointTime(function () {
  553. return App.showConfirmationFeedBackPopup(function (query) {
  554. var selectedService = self.get('content.id');
  555. batchUtils.restartAllServiceHostComponents(serviceDisplayName, selectedService, true, query);
  556. }, bodyMessage);
  557. });
  558. } else {
  559. return App.showConfirmationFeedBackPopup(function (query) {
  560. var selectedService = self.get('content.id');
  561. batchUtils.restartAllServiceHostComponents(serviceDisplayName, selectedService, true, query);
  562. }, bodyMessage);
  563. }
  564. },
  565. /**
  566. * trigger launchHostComponentRollingRestart(batchUtils)
  567. * @method rollingRestartStaleConfigSlaveComponents
  568. */
  569. rollingRestartStaleConfigSlaveComponents: function (componentName) {
  570. batchUtils.launchHostComponentRollingRestart(componentName.context, this.get('content.displayName'), this.get('content.passiveState') === "ON", true);
  571. },
  572. /**
  573. * trigger showItemsShouldBeRestarted popup with hosts that requires restart
  574. * @param {{context: object}} event
  575. * @method showHostsShouldBeRestarted
  576. */
  577. showHostsShouldBeRestarted: function (event) {
  578. var restartRequiredHostsAndComponents = event.context.restartRequiredHostsAndComponents;
  579. var hosts = [];
  580. for (var hostName in restartRequiredHostsAndComponents) {
  581. hosts.push(hostName);
  582. }
  583. var hostsText = hosts.length == 1 ? Em.I18n.t('common.host') : Em.I18n.t('common.hosts');
  584. hosts = hosts.join(', ');
  585. this.showItemsShouldBeRestarted(hosts, Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(hostsText));
  586. },
  587. /**
  588. * trigger showItemsShouldBeRestarted popup with components that requires restart
  589. * @param {{context: object}} event
  590. * @method showComponentsShouldBeRestarted
  591. */
  592. showComponentsShouldBeRestarted: function (event) {
  593. var restartRequiredHostsAndComponents = event.context.restartRequiredHostsAndComponents;
  594. var hostsComponets = [];
  595. var componentsObject = {};
  596. for (var hostName in restartRequiredHostsAndComponents) {
  597. restartRequiredHostsAndComponents[hostName].forEach(function (hostComponent) {
  598. hostsComponets.push(hostComponent);
  599. if (componentsObject[hostComponent] != undefined) {
  600. componentsObject[hostComponent]++;
  601. } else {
  602. componentsObject[hostComponent] = 1;
  603. }
  604. })
  605. }
  606. var componentsList = [];
  607. for (var obj in componentsObject) {
  608. var componentDisplayName = (componentsObject[obj] > 1) ? obj + 's' : obj;
  609. componentsList.push(componentsObject[obj] + ' ' + componentDisplayName);
  610. }
  611. var componentsText = componentsList.length == 1 ? Em.I18n.t('common.component') : Em.I18n.t('common.components');
  612. hostsComponets = componentsList.join(', ');
  613. this.showItemsShouldBeRestarted(hostsComponets, Em.I18n.t('service.service.config.restartService.shouldBeRestarted').format(componentsText));
  614. },
  615. /**
  616. * Show popup with selectable (@see App.SelectablePopupBodyView) list of items
  617. * @param {string} content string with comma-separated list of hostNames or componentNames
  618. * @param {string} header popup header
  619. * @returns {App.ModalPopup}
  620. * @method showItemsShouldBeRestarted
  621. */
  622. showItemsShouldBeRestarted: function (content, header) {
  623. return App.ModalPopup.show({
  624. content: content,
  625. header: header,
  626. bodyClass: App.SelectablePopupBodyView,
  627. secondary: null
  628. });
  629. },
  630. /**
  631. * trigger manageConfigurationGroups
  632. * @method manageConfigurationGroup
  633. */
  634. manageConfigurationGroup: function () {
  635. App.router.get('manageConfigGroupsController').manageConfigurationGroups(null, this.get('content'));
  636. },
  637. /**
  638. * If user changes cfg group if some configs was changed popup with propose to save changes must be shown
  639. * @param {object} event - triggered event for selecting another config-group
  640. * @method selectConfigGroup
  641. */
  642. selectConfigGroup: function (event) {
  643. var self = this;
  644. function callback() {
  645. self.doSelectConfigGroup(event);
  646. }
  647. if (!this.get('isInit')) {
  648. if (this.hasUnsavedChanges()) {
  649. this.showSavePopup(null, callback);
  650. return;
  651. }
  652. }
  653. callback();
  654. },
  655. /**
  656. * switch view to selected group
  657. * @param event
  658. * @method selectConfigGroup
  659. */
  660. doSelectConfigGroup: function (event) {
  661. App.loadTimer.start('Service Configs Page');
  662. var configGroupVersions = App.ServiceConfigVersion.find().filterProperty('groupId', event.context.get('configGroupId'));
  663. //check whether config group has config versions
  664. if (event.context.get('configGroupId') == -1) {
  665. this.loadCurrentVersions();
  666. } else if (configGroupVersions.length > 0) {
  667. this.loadSelectedVersion(configGroupVersions.findProperty('isCurrent').get('version'), event.context);
  668. } else {
  669. this.loadSelectedVersion(null, event.context);
  670. }
  671. }
  672. });