configs.js 27 KB

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