stack_service_mapper.js 4.4 KB

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