stack_service_mapper.js 5.1 KB

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