service_config.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. App.ServiceConfig = Ember.Object.extend({
  20. serviceName: '',
  21. configCategories: [],
  22. configs: null,
  23. restartRequired: false,
  24. restartRequiredMessage: '',
  25. restartRequiredHostsAndComponents: {},
  26. configGroups: [],
  27. dependentServiceNames: [],
  28. initConfigsLength: 0, // configs length after initialization in order to watch changes
  29. errorCount: function () {
  30. var overrideErrors = 0,
  31. masterErrors = 0,
  32. slaveErrors = 0,
  33. configs = this.get('configs'),
  34. configCategories = this.get('configCategories'),
  35. enhancedConfigsErrors = 0;
  36. configCategories.forEach(function (_category) {
  37. slaveErrors += _category.get('slaveErrorCount');
  38. _category.set('nonSlaveErrorCount', 0);
  39. });
  40. configs.forEach(function (item) {
  41. if (item.get('isVisible')) {
  42. var options = item.get('options');
  43. if (options && options.someProperty('foreignKeys')) {
  44. var options = options.filterProperty('foreignKeys');
  45. options.forEach(function (opt) {
  46. opt.foreignKeys.forEach(function (key) {
  47. var config = configs.findProperty('name', key);
  48. if (config) {
  49. config.set('isVisible', item.get('value') === opt.displayName);
  50. }
  51. });
  52. });
  53. }
  54. }
  55. });
  56. configs.forEach(function (item) {
  57. var category = configCategories.findProperty('name', item.get('category'));
  58. if (category && !item.get('isValid') && item.get('isVisible') && !item.get('widgetType')) {
  59. category.incrementProperty('nonSlaveErrorCount');
  60. masterErrors++;
  61. }
  62. if (!item.get('isValid') && item.get('widgetType') && item.get('isVisible') && !item.get('hiddenBySection')) {
  63. enhancedConfigsErrors++;
  64. }
  65. if (item.get('overrides')) {
  66. item.get('overrides').forEach(function (e) {
  67. if (e.error) {
  68. if (category && !Em.get(e, 'parentSCP.widget')) {
  69. category.incrementProperty('nonSlaveErrorCount');
  70. }
  71. overrideErrors++;
  72. }
  73. });
  74. }
  75. });
  76. return masterErrors + slaveErrors + overrideErrors + enhancedConfigsErrors;
  77. }.property('configs.@each.isValid', 'configs.@each.isVisible', 'configCategories.@each.slaveErrorCount', 'configs.@each.overrideErrorTrigger'),
  78. /**
  79. * checks if for example for kdc_type, the value isn't just the pretty version of the saved value, for example mit-kdc
  80. * and Existing MIT KDC are the same value, but they are interpreted as being changed. This function fixes that
  81. * @param configs
  82. * @returns {boolean} - checks
  83. */
  84. checkDefaultValues: function (configs) {
  85. var kdcType = configs.findProperty('name', 'kdc_type');
  86. if (!kdcType) {
  87. return configs.someProperty('isNotDefaultValue')
  88. }
  89. // if there is only one value changed and that value is for kdc_type, check if the value has really changed or just
  90. // the string shown to the user is different
  91. if (configs.filterProperty('isNotDefaultValue').length === 1) {
  92. if (configs.findProperty('isNotDefaultValue', true) === kdcType) {
  93. return App.router.get('mainAdminKerberosController.kdcTypesValues')[kdcType.get('savedValue')] !== kdcType.get('value');
  94. }
  95. }
  96. return configs.someProperty('isNotDefaultValue');
  97. },
  98. isPropertiesChanged: function() {
  99. var requiredByAgent = this.get('configs').filterProperty('isRequiredByAgent');
  100. var isNotSaved = requiredByAgent.someProperty('isNotSaved');
  101. var isNotDefaultValue = this.checkDefaultValues(requiredByAgent);
  102. var isOverrideChanged = requiredByAgent.someProperty('isOverrideChanged');
  103. var differentConfigLengths = this.get('configs.length') !== this.get('initConfigsLength');
  104. return isNotSaved || isNotDefaultValue || isOverrideChanged || differentConfigLengths;
  105. }.property('configs.@each.isNotDefaultValue', 'configs.@each.isOverrideChanged', 'configs.length', 'configs.@each.isNotSaved', 'initConfigsLength'),
  106. init: function() {
  107. this._super();
  108. this.set('dependentServiceNames', App.StackService.find(this.get('serviceName')).get('dependentServiceNames') || []);
  109. }
  110. });
  111. App.SlaveConfigs = Ember.Object.extend({
  112. componentName: null,
  113. displayName: null,
  114. hosts: null,
  115. groups: null
  116. });
  117. App.Group = Ember.Object.extend({
  118. name: null,
  119. hostNames: null,
  120. properties: null,
  121. errorCount: function () {
  122. if (this.get('properties')) {
  123. return this.get('properties').filterProperty('isValid', false).filterProperty('isVisible', true).get('length');
  124. }
  125. }.property('properties.@each.isValid', 'properties.@each.isVisible')
  126. });
  127. App.ConfigSiteTag = Ember.Object.extend({
  128. site: DS.attr('string'),
  129. tag: DS.attr('string'),
  130. /**
  131. * Object map of hostname->override-tag for overrides.
  132. * <b>Creators should set new object here.<b>
  133. */
  134. hostOverrides: null
  135. });