stack_config_properties_mapper.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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;
  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_name,
  95. config.StackConfigurations.type, config.StackConfigurations.property_value, config.StackConfigurations.service_name);
  96. }
  97. // Map from /dependencies to property_depended_by
  98. config.StackConfigurations.property_depended_by = [];
  99. if (config.dependencies && config.dependencies.length > 0) {
  100. config.dependencies.forEach(function(dep) {
  101. config.StackConfigurations.property_depended_by.push({
  102. type : dep.StackConfigurationDependency.dependency_type,
  103. name : dep.StackConfigurationDependency.dependency_name
  104. });
  105. var service = App.StackService.find(config.StackConfigurations.service_name);
  106. var dependentService = App.config.getServiceByConfigType(dep.StackConfigurationDependency.dependency_type);
  107. if (dependentService && service && dependentService.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentService.get('serviceName'))) {
  108. service.set('dependentServiceNames', service.get('dependentServiceNames').concat(dependentService.get('serviceName')));
  109. }
  110. });
  111. }
  112. if (Em.get(config, 'StackConfigurations.property_depends_on.length') > 0) {
  113. config.StackConfigurations.property_depends_on.forEach(function(dep) {
  114. var service = App.StackService.find(config.StackConfigurations.service_name);
  115. var dependentService = App.config.getServiceByConfigType(dep.type);
  116. if (dependentService && service && dependentService.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentService.get('serviceName'))) {
  117. service.set('dependentServiceNames', service.get('dependentServiceNames').concat(dependentService.get('serviceName')));
  118. }
  119. });
  120. }
  121. /**
  122. * merging stack info with that is stored on UI
  123. * for now is not used; uncomment in will be needed
  124. * this.mergeWithUI(config);
  125. */
  126. if (this.isMiscService(config.StackConfigurations.property_type)) {
  127. this.handleSpecialProperties(config);
  128. } else {
  129. this.mergeWithUI(config);
  130. }
  131. var staticConfigInfo = this.parseIt(config, this.get('configToPlain'));
  132. var v = Em.isNone(staticConfigInfo.recommendedValue) ? staticConfigInfo.recommendedValue : staticConfigInfo.value;
  133. staticConfigInfo.value = staticConfigInfo.recommendedValue = App.config.formatPropertyValue(staticConfigInfo, v);
  134. staticConfigInfo.isSecure = App.config.getIsSecure(staticConfigInfo.name);
  135. staticConfigInfo.isUserProperty = false;
  136. App.configsCollection.add(staticConfigInfo);
  137. }, this);
  138. }, this);
  139. this.addUIOnlyProperties(configs);
  140. }
  141. console.timeEnd('App.stackConfigPropertiesMapper execution time');
  142. },
  143. /******************* METHODS TO MERGE STACK PROPERTIES WITH STORED ON UI *********************************/
  144. /**
  145. * find UI config with current name and fileName
  146. * if there is such property - adds some info to config object
  147. * @param {Object} config
  148. * @method mergeWithUI
  149. */
  150. mergeWithUI: function(config) {
  151. var c = config.StackConfigurations;
  152. var uiConfigProperty = this.getUIConfig(c.property_name, c.type);
  153. config.category = uiConfigProperty && uiConfigProperty.category ? uiConfigProperty.category : App.config.getDefaultCategory(true, c.type);
  154. if (uiConfigProperty) {
  155. config.index = uiConfigProperty.index || Infinity;
  156. if (uiConfigProperty.displayType) {
  157. c.property_value_attributes.type = uiConfigProperty.displayType;
  158. config.radioName = uiConfigProperty.radioName;
  159. config.options = uiConfigProperty.options;
  160. }
  161. config.dependentConfigPattern = uiConfigProperty.dependentConfigPattern;
  162. }
  163. },
  164. /**
  165. *
  166. * @param config
  167. */
  168. handleSpecialProperties: function(config) {
  169. if (!config.StackConfigurations.property_type.contains('ADDITIONAL_USER_PROPERTY')) {
  170. config.index = App.StackService.displayOrder.indexOf(config.StackConfigurations.service_name) + 1 || 30;
  171. config.StackConfigurations.property_value_attributes.type = 'user';
  172. }
  173. config.StackConfigurations.service_name = 'MISC';
  174. config.category = 'Users and Groups';
  175. },
  176. /**
  177. * defines if property should refer to MISC tab
  178. * @param type
  179. * @returns {Boolean}
  180. */
  181. isMiscService: function(type) {
  182. return type.length && (type.contains('USER') || type.contains('GROUP') || type.contains('ADDITIONAL_USER_PROPERTY'));
  183. },
  184. /**
  185. * add properties that doesn't have any info on stack definition
  186. * @param configs
  187. */
  188. addUIOnlyProperties: function(configs) {
  189. require('data/HDP2/ui_properties').concat(require('data/HDP2/alert_notification')).forEach(function(p) {
  190. configs.push({
  191. id: App.config.configId(p.name, p.filename),
  192. name: p.name,
  193. display_name: p.displayName,
  194. file_name: p.filename,
  195. description: p.description || '',
  196. is_required_by_agent: p.isRequiredByAgent !== false, // by default is_required_by_agent should be true
  197. service_name: p.serviceName,
  198. supports_final: false,
  199. category: p.category,
  200. index: p.index,
  201. stack_name: App.get('currentStackName'),
  202. stack_version: App.get('currentStackVersionNumber')
  203. });
  204. p.id = App.config.configId(p.name, p.filename);
  205. App.configsCollection.add(p);
  206. });
  207. },
  208. /**
  209. * returns config with such name and fileName if there is such on UI
  210. * otherwise returns null
  211. * @param propertyName
  212. * @param siteName
  213. * @returns {Object|null}
  214. * @method getUIConfig
  215. */
  216. getUIConfig: function(propertyName, siteName) {
  217. return App.config.get('preDefinedSitePropertiesMap')[App.config.configId(propertyName, siteName)];
  218. }
  219. });