stack_version_mapper.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.stackVersionMapper = App.QuickDataMapper.create({
  20. modelStackVerion: App.StackVersion,
  21. modelRepositories: App.Repositories,
  22. modelOperatingSystems: App.OS,
  23. modelStack: {
  24. id: 'id',
  25. name: 'name',
  26. version: 'version',
  27. operating_systems_key: 'operating_systems',
  28. operating_systems_type: 'array',
  29. operating_systems: {
  30. item: 'id'
  31. },
  32. installed_hosts_count: 'installed_hosts',
  33. current_hosts_count: 'current_hosts'
  34. },
  35. modelOS: {
  36. id: 'id',
  37. name: 'os',
  38. stack_version_id: 'stack_version_id',
  39. repositories_key: 'repositories',
  40. repositories_type: 'array',
  41. repositories: {
  42. item: 'id'
  43. }
  44. },
  45. modelRepository: {
  46. id: 'id',
  47. type: 'type',
  48. baseurl: 'baseurl',
  49. os_id: 'os_id'
  50. },
  51. map: function (json) {
  52. var modelStackVerion = this.get('modelStackVerion');
  53. var modelOperatingSystems = this.get('modelOperatingSystems');
  54. var modelRepositories = this.get('modelRepositories');
  55. var resultStack = [];
  56. var resultOS = [];
  57. var resultRepo = [];
  58. if (json && json.items) {
  59. json.items.forEach(function (item) {
  60. var stack = item.StackVersion;
  61. stack.id = item.StackVersion.name + item.StackVersion.version;
  62. var osArray = [];
  63. if (Em.get(item, 'StackVersion.repositories')) {
  64. item.StackVersion.repositories.forEach(function (os) {
  65. os.id = item.StackVersion.version + os.os;
  66. os.stack_version_id = stack.id;
  67. os.name = os.os;
  68. var repoArray = [];
  69. if (Em.get(os, 'baseurls')) {
  70. os.baseurls.forEach(function (repo) {
  71. repo.os_id = os.id;
  72. resultRepo.push(this.parseIt(repo, this.get('modelRepository')));
  73. repoArray.pushObject(repo);
  74. }, this);
  75. }
  76. os.repositories = repoArray;
  77. resultOS.push(this.parseIt(os, this.get('modelOS')));
  78. osArray.pushObject(os);
  79. }, this);
  80. }
  81. stack.operating_systems = osArray;
  82. resultStack.push(this.parseIt(stack, this.get('modelStack')));
  83. }, this);
  84. }
  85. App.store.commit();
  86. App.store.loadMany(modelRepositories, resultRepo);
  87. App.store.loadMany(modelOperatingSystems, resultOS);
  88. App.store.loadMany(modelStackVerion, resultStack);
  89. }
  90. });