stack_config_properties_mapper.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. model: App.StackConfigProperty,
  20. config: {
  21. id: 'id',
  22. name: 'StackConfigurations.property_name',
  23. display_name: 'StackConfigurations.property_display_name',
  24. file_name: 'StackConfigurations.type',
  25. description: 'StackConfigurations.property_description',
  26. value: 'StackConfigurations.property_value',
  27. recommended_value: 'StackConfigurations.property_value',
  28. type: 'StackConfigurations.property_type',
  29. service_name: 'StackConfigurations.service_name',
  30. stack_name: 'StackConfigurations.stack_name',
  31. stack_version: 'StackConfigurations.stack_version',
  32. property_depended_by: 'StackConfigurations.property_depended_by',
  33. property_depends_on: 'StackConfigurations.property_depends_on',
  34. value_attributes: 'StackConfigurations.property_value_attributes',
  35. is_final: 'recommended_is_final',
  36. recommended_is_final: 'recommended_is_final',
  37. supports_final: 'supports_final',
  38. widget: 'widget',
  39. /**** ui properties ***/
  40. display_type: 'display_type',
  41. category: 'category',
  42. index: 'index'
  43. },
  44. map: function (json) {
  45. console.time('stackConfigPropertiesMapper execution time');
  46. if (json && json.Versions) {
  47. //hack for cluster versions
  48. json = {items: [json]};
  49. var clusterConfigs = true;
  50. }
  51. if (json && json.items) {
  52. var configs = [];
  53. json.items.forEach(function(stackItem) {
  54. var configTypeInfo = clusterConfigs ? Em.get(stackItem, 'Versions.config_types') : Em.get(stackItem, 'StackServices.config_types');
  55. stackItem.configurations.forEach(function(config) {
  56. if (clusterConfigs) {
  57. config.StackConfigurations = config.StackLevelConfigurations;
  58. }
  59. var configType = App.config.getConfigTagFromFileName(config.StackConfigurations.type);
  60. config.id = App.config.configId(config.StackConfigurations.property_name, configType);
  61. config.recommended_is_final = config.StackConfigurations.final === "true";
  62. config.supports_final = !!configTypeInfo[configType] && configTypeInfo[configType].supports.final === "true";
  63. // Map from /dependencies to property_depended_by
  64. config.StackConfigurations.property_depended_by = [];
  65. if (config.dependencies && config.dependencies.length > 0) {
  66. config.dependencies.forEach(function(dep) {
  67. config.StackConfigurations.property_depended_by.push({
  68. type : dep.StackConfigurationDependency.dependency_type,
  69. name : dep.StackConfigurationDependency.dependency_name
  70. });
  71. });
  72. }
  73. /**
  74. * merging stack info with that is stored on UI
  75. * for now is not used; uncomment in will be needed
  76. * this.mergeWithUI(config);
  77. */
  78. this.mergeWithUI(config);
  79. configs.push(this.parseIt(config, this.get('config')));
  80. }, this);
  81. }, this);
  82. App.store.loadMany(this.get('model'), configs);
  83. App.StackService.find().filterProperty('id').forEach(function(service) {
  84. this.setDependentServices(service);
  85. }, this);
  86. }
  87. console.timeEnd('stackConfigPropertiesMapper execution time');
  88. },
  89. /******************* METHODS TO MERGE STACK PROPERTIES WITH STORED ON UI *********************************/
  90. /**
  91. * find UI config with current name and fileName
  92. * if there is such property - adds some info to config object
  93. * @param {Object} config
  94. * @method mergeWithUI
  95. */
  96. mergeWithUI: function(config) {
  97. var c = config.StackConfigurations;
  98. var uiConfigProperty = this.getUIConfig(c.property_name, c.type);
  99. var advancedData = App.config.advancedConfigIdentityData(c);
  100. if (!c.property_display_name) {
  101. c.property_display_name = App.config.getPropertyIfExists('displayName', App.config.getDefaultDisplayName(c.property_name, c.type), advancedData, uiConfigProperty);
  102. }
  103. c.service_name = App.config.getPropertyIfExists('serviceName', c.service_name, advancedData, uiConfigProperty);
  104. config.category = App.config.getPropertyIfExists('category', App.config.getDefaultCategory(true, c.type), advancedData, uiConfigProperty);
  105. config.display_type = App.config.getPropertyIfExists('displayType', App.config.getDefaultDisplayType(c.property_name, c.type, c.property_value), advancedData, uiConfigProperty);
  106. config.index = App.config.getPropertyIfExists('index', null, advancedData, uiConfigProperty);
  107. },
  108. /**
  109. * returns config with such name and fileName if there is such on UI
  110. * otherwise returns null
  111. * @param propertyName
  112. * @param siteName
  113. * @returns {Object|null}
  114. * @method getUIConfig
  115. */
  116. getUIConfig: function(propertyName, siteName) {
  117. return App.config.get('preDefinedSitePropertiesMap')[App.config.configId(propertyName, siteName)];
  118. },
  119. /**
  120. * runs <code>setDependentServicesAndFileNames<code>
  121. * for stack properties for current service
  122. * @method loadDependentConfigs
  123. */
  124. setDependentServices: function(service) {
  125. App.StackConfigProperty.find().filterProperty('serviceName', service.get('serviceName')).forEach(function(stackProperty) {
  126. if (stackProperty.get('propertyDependedBy.length')) {
  127. this._setDependentServices(stackProperty, 'propertyDependedBy', service);
  128. }
  129. if (stackProperty.get('propertyDependsOn.length')) {
  130. this._setDependentServices(stackProperty, 'propertyDependsOn', service);
  131. }
  132. }, this);
  133. },
  134. /**
  135. * defines service names for configs and set them to <code>dependentServiceNames<code>
  136. * @param {App.StackConfigProperty} stackProperty
  137. * @param {String} [key='propertyDependedBy'] - attribute to check dependent configs
  138. * @param service
  139. * @private
  140. */
  141. _setDependentServices: function(stackProperty, key, service) {
  142. key = key || 'propertyDependedBy';
  143. if (stackProperty.get(key + '.length') > 0) {
  144. stackProperty.get(key).forEach(function(dependent) {
  145. var tag = App.config.getConfigTagFromFileName(dependent.type);
  146. /** setting dependent serviceNames (without current serviceName) **/
  147. var dependentProperty = App.StackConfigProperty.find(App.config.configId(dependent.name, tag));
  148. if (dependentProperty) {
  149. if (dependentProperty.get('serviceName') && dependentProperty.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentProperty.get('serviceName'))) {
  150. service.set('dependentServiceNames', service.get('dependentServiceNames').concat([dependentProperty.get('serviceName')]));
  151. }
  152. this._setDependentServices(dependentProperty, key, service);
  153. }
  154. }, this);
  155. }
  156. }
  157. });