stack_service_mapper.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. stack_id: 'stack_id',
  25. service_name: 'service_name',
  26. display_name: 'display_name',
  27. config_types: 'config_types',
  28. comments: 'comments',
  29. service_version: 'service_version',
  30. stack_name: 'stack_name',
  31. stack_version: 'stack_version',
  32. is_selected: 'is_selected',
  33. is_installed: 'is_installed',
  34. is_installable: 'is_installable',
  35. required_services: 'required_services',
  36. service_check_supported: 'service_check_supported',
  37. service_components_key: 'service_components',
  38. service_components_type: 'array',
  39. service_components: {
  40. item: 'id'
  41. }
  42. },
  43. component_config: {
  44. id: 'component_name',
  45. component_name: 'component_name',
  46. display_name: 'display_name',
  47. cardinality: 'cardinality',
  48. custom_commands: 'custom_commands',
  49. service_name: 'service_name',
  50. component_category: 'component_category',
  51. is_master: 'is_master',
  52. is_client: 'is_client',
  53. stack_name: 'stack_name',
  54. stack_version: 'stack_version',
  55. stack_service_id: 'service_name',
  56. dependencies_key: 'dependencies',
  57. dependencies_type: 'array',
  58. dependencies: {
  59. item: 'Dependencies'
  60. }
  61. },
  62. mapStackServices: function(json) {
  63. App.set('isStackServicesLoaded',false);
  64. this.clearStackModels();
  65. App.resetDsStoreTypeMap(App.StackServiceComponent);
  66. App.resetDsStoreTypeMap(App.StackService);
  67. this.map(json);
  68. App.set('isStackServicesLoaded',true);
  69. },
  70. map: function (json) {
  71. var model = this.get('model');
  72. var result = [];
  73. var stackServiceComponents = [];
  74. var nonInstallableServices = ['KERBEROS'];
  75. this.rearrangeServicesForDisplayOrder(json.items, App.StackService.displayOrder);
  76. json.items.forEach(function (item) {
  77. var stackService = item.StackServices;
  78. var serviceComponents = [];
  79. //TODO iterate over item.components after API is fixed
  80. var components = Em.get(item, 'components') || Em.get(item, 'serviceComponents');
  81. components.forEach(function (serviceComponent) {
  82. var dependencies = serviceComponent.dependencies.map(function (dependecy) {
  83. return { Dependencies: App.keysUnderscoreToCamelCase(App.permit(dependecy.Dependencies, ['component_name', 'scope'])) };
  84. });
  85. serviceComponent.StackServiceComponents.id = serviceComponent.StackServiceComponents.component_name;
  86. serviceComponent.StackServiceComponents.dependencies = dependencies;
  87. serviceComponents.push(serviceComponent.StackServiceComponents);
  88. var parsedResult = this.parseIt(serviceComponent.StackServiceComponents, this.get('component_config'));
  89. if (parsedResult.id == 'MYSQL_SERVER') {
  90. parsedResult.custom_commands = parsedResult.custom_commands.without('CLEAN');
  91. }
  92. stackServiceComponents.push(parsedResult);
  93. }, this);
  94. stackService.stack_id = stackService.stack_name + '-' + stackService.stack_version;
  95. stackService.service_components = serviceComponents;
  96. // @todo: replace with server response value after API implementation
  97. if (nonInstallableServices.contains(stackService.service_name)) {
  98. stackService.is_installable = false;
  99. stackService.is_selected = false;
  100. }
  101. result.push(this.parseIt(stackService, this.get('config')));
  102. }, this);
  103. App.store.loadMany(this.get('component_model'), stackServiceComponents);
  104. App.store.loadMany(model, result);
  105. },
  106. /**
  107. * Clean store from already loaded data.
  108. **/
  109. clearStackModels: function () {
  110. var models = [App.StackServiceComponent, App.StackService];
  111. models.forEach(function (model) {
  112. var records = App.get('store').findAll(model).filterProperty('id');
  113. records.forEach(function (rec) {
  114. Ember.run(this, function () {
  115. rec.deleteRecord();
  116. App.store.commit();
  117. });
  118. }, this);
  119. }, this);
  120. },
  121. rearrangeServicesForDisplayOrder: function (array, displayOrderArray) {
  122. return array.sort(function (a, b) {
  123. var aValue = displayOrderArray.indexOf(a.StackServices.service_name) != -1 ? displayOrderArray.indexOf(a.StackServices.service_name) : array.length;
  124. var bValue = displayOrderArray.indexOf(b.StackServices.service_name) != -1 ? displayOrderArray.indexOf(b.StackServices.service_name) : array.length;
  125. return aValue - bValue;
  126. });
  127. }
  128. });