stack_service_mapper.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.stackServiceMapper = App.QuickDataMapper.create({
  20. model: App.StackService,
  21. component_model: App.StackServiceComponent,
  22. config: {
  23. id: 'service_name',
  24. service_name: 'service_name',
  25. display_name: 'display_name',
  26. config_types: 'config_types',
  27. comments: 'comments',
  28. service_version: 'service_version',
  29. stack_name: 'stack_name',
  30. stack_version: 'stack_version',
  31. is_selected: 'is_selected',
  32. is_installed: 'is_installed',
  33. required_services: 'required_services',
  34. service_check_supported: 'service_check_supported',
  35. service_components_key: 'service_components',
  36. service_components_type: 'array',
  37. service_components: {
  38. item: 'id'
  39. }
  40. },
  41. component_config: {
  42. id: 'component_name',
  43. component_name: 'component_name',
  44. display_name: 'display_name',
  45. cardinality: 'cardinality',
  46. custom_commands: 'custom_commands',
  47. service_name: 'service_name',
  48. component_category: 'component_category',
  49. is_master: 'is_master',
  50. is_client: 'is_client',
  51. stack_name: 'stack_name',
  52. stack_version: 'stack_version',
  53. stack_service_id: 'service_name',
  54. dependencies_key: 'dependencies',
  55. dependencies_type: 'array',
  56. dependencies: {
  57. item: 'Dependencies.component_name'
  58. }
  59. },
  60. mapStackServices: function(json) {
  61. this.clearStackModels();
  62. App.resetDsStoreTypeMap(App.StackServiceComponent);
  63. App.resetDsStoreTypeMap(App.StackService);
  64. this.map(json);
  65. },
  66. map: function (json) {
  67. var model = this.get('model');
  68. var result = [];
  69. var stackServiceComponents = [];
  70. this.rearrangeServicesForDisplayOrder(json.items, App.StackService.displayOrder);
  71. json.items.forEach(function (item) {
  72. //@TODO: Remove the condition when Flume becomes supported service in any stack
  73. if (item.StackServices.service_name !== 'FLUME' || App.supports.flume) {
  74. var stackService = item.StackServices;
  75. var serviceComponents = [];
  76. item.serviceComponents.forEach(function (serviceComponent) {
  77. serviceComponent.StackServiceComponents.id = serviceComponent.StackServiceComponents.component_name;
  78. serviceComponent.StackServiceComponents.dependencies = serviceComponent.dependencies;
  79. serviceComponents.push(serviceComponent.StackServiceComponents);
  80. stackServiceComponents.push(this.parseIt(serviceComponent.StackServiceComponents, this.get('component_config')));
  81. }, this);
  82. stackService.service_components = serviceComponents;
  83. result.push(this.parseIt(stackService, this.get('config')));
  84. }
  85. }, this);
  86. App.store.loadMany(this.get('component_model'), stackServiceComponents);
  87. App.store.loadMany(model, result);
  88. },
  89. /**
  90. * Clean store from already loaded data.
  91. **/
  92. clearStackModels: function () {
  93. var models = [App.StackServiceComponent, App.StackService];
  94. models.forEach(function (model) {
  95. var records = App.get('store').findAll(model).filterProperty('id');
  96. records.forEach(function (rec) {
  97. Ember.run(this, function () {
  98. rec.deleteRecord();
  99. App.store.commit();
  100. });
  101. }, this);
  102. }, this);
  103. },
  104. rearrangeServicesForDisplayOrder: function (array, displayOrderArray) {
  105. return array.sort(function (a, b) {
  106. var aValue = displayOrderArray.indexOf(a.StackServices.service_name) != -1 ? displayOrderArray.indexOf(a.StackServices.service_name) : array.length;
  107. var bValue = displayOrderArray.indexOf(b.StackServices.service_name) != -1 ? displayOrderArray.indexOf(b.StackServices.service_name) : array.length;
  108. return aValue - bValue;
  109. });
  110. }
  111. });