configs.js 27 KB

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