stack_config_properties_mapper.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. var service = App.StackService.find(config.StackConfigurations.service_name);
  72. var dependentService = App.config.getServiceByConfigType(dep.StackConfigurationDependency.dependency_type);
  73. if (dependentService && service && dependentService.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentService.get('serviceName'))) {
  74. service.set('dependentServiceNames', service.get('dependentServiceNames').concat(dependentService.get('serviceName')));
  75. }
  76. });
  77. }
  78. if (Em.get(config, 'config.StackConfigurations.property_depends_on.length') > 0) {
  79. config.StackConfigurations.property_depends_on.forEach(function(dep) {
  80. var service = App.StackService.find(config.StackConfigurations.service_name);
  81. var dependentService = App.config.getServiceByConfigType(dep.type);
  82. if (dependentService && service && dependentService.get('serviceName') != service.get('serviceName') && !service.get('dependentServiceNames').contains(dependentService.get('serviceName'))) {
  83. service.set('dependentServiceNames', service.get('dependentServiceNames').concat(dependentService.get('serviceName')));
  84. }
  85. });
  86. }
  87. /**
  88. * merging stack info with that is stored on UI
  89. * for now is not used; uncomment in will be needed
  90. * this.mergeWithUI(config);
  91. */
  92. this.mergeWithUI(config);
  93. configs.push(this.parseIt(config, this.get('config')));
  94. }, this);
  95. }, this);
  96. App.store.loadMany(this.get('model'), configs);
  97. }
  98. console.timeEnd('stackConfigPropertiesMapper execution time');
  99. },
  100. /******************* METHODS TO MERGE STACK PROPERTIES WITH STORED ON UI *********************************/
  101. /**
  102. * find UI config with current name and fileName
  103. * if there is such property - adds some info to config object
  104. * @param {Object} config
  105. * @method mergeWithUI
  106. */
  107. mergeWithUI: function(config) {
  108. var c = config.StackConfigurations;
  109. var uiConfigProperty = this.getUIConfig(c.property_name, c.type);
  110. var advancedData = App.config.advancedConfigIdentityData(c);
  111. if (!c.property_display_name) {
  112. c.property_display_name = App.config.getPropertyIfExists('displayName', App.config.getDefaultDisplayName(c.property_name, c.type), advancedData, uiConfigProperty);
  113. }
  114. c.service_name = App.config.getPropertyIfExists('serviceName', c.service_name, advancedData, uiConfigProperty);
  115. config.category = App.config.getPropertyIfExists('category', App.config.getDefaultCategory(true, c.type), advancedData, uiConfigProperty);
  116. config.display_type = App.config.getPropertyIfExists('displayType', Em.get(c, 'property_value_attributes.type') || App.config.getDefaultDisplayType(c.property_name, c.type, c.property_value), advancedData, uiConfigProperty);
  117. config.index = App.config.getPropertyIfExists('index', null, advancedData, uiConfigProperty);
  118. },
  119. /**
  120. * returns config with such name and fileName if there is such on UI
  121. * otherwise returns null
  122. * @param propertyName
  123. * @param siteName
  124. * @returns {Object|null}
  125. * @method getUIConfig
  126. */
  127. getUIConfig: function(propertyName, siteName) {
  128. return App.config.get('preDefinedSitePropertiesMap')[App.config.configId(propertyName, siteName)];
  129. }
  130. });