stack_config_properties_mapper.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. App.stackConfigPropertiesMapper = App.QuickDataMapper.create({
  19. /**
  20. * this is map for configs that will be stored as plan objects
  21. */
  22. configToPlain: {
  23. id: 'id',
  24. name: 'StackConfigurations.property_name',
  25. displayName: 'StackConfigurations.property_display_name',
  26. fileName: 'StackConfigurations.type',
  27. filename: 'StackConfigurations.type',
  28. description: 'StackConfigurations.property_description',
  29. value: 'StackConfigurations.property_value',
  30. recommendedValue: 'StackConfigurations.property_value',
  31. serviceName: 'StackConfigurations.service_name',
  32. stackName: 'StackConfigurations.stack_name',
  33. stackVersion: 'StackConfigurations.stack_version',
  34. isOverridable: 'StackConfigurations.property_value_attributes.overridable',
  35. isVisible: 'StackConfigurations.property_value_attributes.visible',
  36. showLabel: 'StackConfigurations.property_value_attributes.show_property_name',
  37. displayType: 'StackConfigurations.property_value_attributes.type',
  38. unit: 'StackConfigurations.property_value_attributes.unit',
  39. isRequired: 'is_required',
  40. isReconfigurable: 'is_reconfigurable',
  41. isEditable: 'is_editable',
  42. isRequiredByAgent: 'is_required_by_agent',
  43. isFinal: 'recommended_is_final',
  44. recommendedIsFinal: 'recommended_is_final',
  45. supportsFinal: 'supports_final',
  46. propertyDependedBy: 'StackConfigurations.property_depended_by',
  47. propertyDependsOn: 'StackConfigurations.property_depends_on',
  48. valueAttributes: 'StackConfigurations.property_value_attributes',
  49. /**** ui properties, ib future should be moved to BE ***/
  50. category: 'category',
  51. index: 'index',
  52. /*** temp properties until all radio buttons type will be moved to BE **/
  53. radioName: 'radioName',
  54. options: 'options',
  55. /*** temp property until visibility dependencies will be retrieved from stack **/
  56. dependentConfigPattern: 'dependentConfigPattern'
  57. },
  58. map: function (json) {
  59. console.time('App.stackConfigPropertiesMapper execution time');
  60. if (json && json.Versions) {
  61. //hack for cluster versions
  62. json = {items: [json]};
  63. var clusterConfigs = true;
  64. }
  65. if (json && json.items) {
  66. var configs = [];
  67. json.items.forEach(function(stackItem) {
  68. var configTypeInfo = clusterConfigs ? Em.get(stackItem, 'Versions.config_types') : Em.get(stackItem, 'StackServices.config_types');
  69. stackItem.configurations.forEach(function(config) {
  70. if (clusterConfigs) {
  71. config.StackConfigurations = config.StackLevelConfigurations;
  72. }
  73. var configType = App.config.getConfigTagFromFileName(config.StackConfigurations.type);
  74. config.id = App.config.configId(config.StackConfigurations.property_name, configType);
  75. config.recommended_is_final = config.StackConfigurations.final === "true";
  76. config.supports_final = !!configTypeInfo[configType] && configTypeInfo[configType].supports.final === "true";
  77. var attributes = config.StackConfigurations.property_value_attributes;
  78. if (attributes) {
  79. config.is_required = !attributes.empty_value_valid;
  80. config.is_reconfigurable = !(attributes.editable_only_at_install || config.StackConfigurations.type === 'cluster-env.xml');
  81. config.is_editable = !attributes.read_only;
  82. config.is_required_by_agent = !attributes.ui_only_property;
  83. }
  84. if (!config.StackConfigurations.property_display_name) {
  85. config.StackConfigurations.property_display_name = config.StackConfigurations.property_name;
  86. }
  87. if (!config.StackConfigurations.service_name) {
  88. config.StackConfigurations.service_name = 'MISC';
  89. }
  90. if (!attributes || !attributes.type) {
  91. if (!attributes) {
  92. config.StackConfigurations.property_value_attributes = {};
  93. }
  94. config.StackConfigurations.property_value_attributes.type = App.config.getDefaultDisplayType(config.StackConfigurations.property_value);
  95. }
  96. // Map from /dependencies to property_depended_by
  97. config.StackConfigurations.property_depended_by = [];
  98. if (config.dependencies && config.dependencies.length > 0) {
  99. config.dependencies.forEach(function(dep) {
  100. config.StackConfigurations.property_depended_by.push({
  101. type : dep.StackConfigurationDependency.dependency_type,
  102. name : dep.StackConfigurationDependency.dependency_name
  103. });
  104. var service = App.StackService.find(config.StackConfigurations.service_name);
  105. var dependentService = App.config.get('serviceByConfigTypeMap')[dep.StackConfigurationDependency.dependency_type];
  106. if (dependentService && service && dependentService.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentService.get('serviceName'))) {
  107. service.set('dependentServiceNames', service.get('dependentServiceNames').concat(dependentService.get('serviceName')));
  108. }
  109. });
  110. }
  111. if (Em.get(config, 'StackConfigurations.property_depends_on.length') > 0) {
  112. config.StackConfigurations.property_depends_on.forEach(function(dep) {
  113. var service = App.StackService.find(config.StackConfigurations.service_name);
  114. var dependentService = App.config.get('serviceByConfigTypeMap')[dep.type];
  115. if (dependentService && service && dependentService.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentService.get('serviceName'))) {
  116. service.set('dependentServiceNames', service.get('dependentServiceNames').concat(dependentService.get('serviceName')));
  117. }
  118. });
  119. }
  120. /**
  121. * merging stack info with that is stored on UI
  122. * for now is not used; uncomment in will be needed
  123. * this.mergeWithUI(config);
  124. */
  125. if (this.isMiscService(config.StackConfigurations.property_type)) {
  126. this.handleSpecialProperties(config);
  127. } else {
  128. this.mergeWithUI(config);
  129. }
  130. var staticConfigInfo = this.parseIt(config, this.get('configToPlain'));
  131. var v = Em.isNone(staticConfigInfo.recommendedValue) ? staticConfigInfo.recommendedValue : staticConfigInfo.value;
  132. staticConfigInfo.value = staticConfigInfo.recommendedValue = App.config.formatPropertyValue(staticConfigInfo, v);
  133. staticConfigInfo.isSecureConfig = App.config.getIsSecure(staticConfigInfo.name);
  134. staticConfigInfo.isUserProperty = false;
  135. App.configsCollection.add(staticConfigInfo);
  136. }, this);
  137. }, this);
  138. this.addUIOnlyProperties(configs);
  139. }
  140. console.timeEnd('App.stackConfigPropertiesMapper execution time');
  141. },
  142. /******************* METHODS TO MERGE STACK PROPERTIES WITH STORED ON UI *********************************/
  143. /**
  144. * find UI config with current name and fileName
  145. * if there is such property - adds some info to config object
  146. * @param {Object} config
  147. * @method mergeWithUI
  148. */
  149. mergeWithUI: function(config) {
  150. var c = config.StackConfigurations;
  151. var uiConfigProperty = this.getUIConfig(c.property_name, c.type);
  152. config.category = uiConfigProperty && uiConfigProperty.category ? uiConfigProperty.category : App.config.getDefaultCategory(true, c.type);
  153. if (uiConfigProperty) {
  154. config.index = (uiConfigProperty.index !== undefined) ? uiConfigProperty.index : Infinity;
  155. if (uiConfigProperty.displayType) {
  156. c.property_value_attributes.type = uiConfigProperty.displayType;
  157. config.radioName = uiConfigProperty.radioName;
  158. config.options = uiConfigProperty.options;
  159. }
  160. config.dependentConfigPattern = uiConfigProperty.dependentConfigPattern;
  161. }
  162. },
  163. /**
  164. *
  165. * @param config
  166. */
  167. handleSpecialProperties: function(config) {
  168. if (!config.StackConfigurations.property_type.contains('ADDITIONAL_USER_PROPERTY')) {
  169. config.index = App.StackService.displayOrder.indexOf(config.StackConfigurations.service_name) + 1 || 30;
  170. }
  171. config.StackConfigurations.service_name = 'MISC';
  172. config.category = 'Users and Groups';
  173. },
  174. /**
  175. * defines if property should refer to MISC tab
  176. * @param type
  177. * @returns {Boolean}
  178. */
  179. isMiscService: function(type) {
  180. return type.length && (type.contains('USER') || type.contains('GROUP') || type.contains('ADDITIONAL_USER_PROPERTY'));
  181. },
  182. /**
  183. * add properties that doesn't have any info on stack definition
  184. * @param configs
  185. */
  186. addUIOnlyProperties: function(configs) {
  187. require('data/HDP2/ui_properties').concat(require('data/HDP2/alert_notification')).forEach(function(p) {
  188. configs.push({
  189. id: App.config.configId(p.name, p.filename),
  190. name: p.name,
  191. display_name: p.displayName,
  192. file_name: p.filename,
  193. description: p.description || '',
  194. is_required_by_agent: p.isRequiredByAgent !== false, // by default is_required_by_agent should be true
  195. service_name: p.serviceName,
  196. supports_final: false,
  197. category: p.category,
  198. index: p.index,
  199. stack_name: App.get('currentStackName'),
  200. stack_version: App.get('currentStackVersionNumber')
  201. });
  202. p.id = App.config.configId(p.name, p.filename);
  203. App.configsCollection.add(p);
  204. });
  205. },
  206. /**
  207. * returns config with such name and fileName if there is such on UI
  208. * otherwise returns null
  209. * @param propertyName
  210. * @param siteName
  211. * @returns {Object|null}
  212. * @method getUIConfig
  213. */
  214. getUIConfig: function(propertyName, siteName) {
  215. return App.config.get('preDefinedSitePropertiesMap')[App.config.configId(propertyName, siteName)];
  216. }
  217. });