stack_service_mapper.js 5.4 KB

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