stack_service_mapper.js 4.2 KB

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