stack_version_mapper.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. modelStack: {
  22. "id": "id",
  23. "cluster_name": "cluster_name",
  24. "stack": "stack",
  25. "version": "version",
  26. "repository_version_id": "repository_version_id",
  27. "state": "state",
  28. "installing_hosts": "host_states.INSTALLING",
  29. "installed_hosts": "host_states.INSTALLED",
  30. "install_failed_hosts": "host_states.INSTALL_FAILED",
  31. "upgrading_hosts": "host_states.UPGRADING",
  32. "upgraded_hosts": "host_states.UPGRADED",
  33. "upgrade_failed_hosts": "host_states.UPGRADE_FAILED",
  34. "current_hosts": "host_states.CURRENT"
  35. },
  36. map: function (json) {
  37. var modelStackVerion = this.get('modelStackVerion');
  38. var resultStack = [];
  39. if (json && json.items) {
  40. json.items.forEach(function (item) {
  41. var stack = item.ClusterStackVersions;
  42. stack.repository_version_id = item.ClusterStackVersions.repository_version;
  43. if (item.repository_versions && item.repository_versions[0]) {
  44. item.repository_versions[0].RepositoryVersions.stackVersionId = item.ClusterStackVersions.id;
  45. App.repoVersionMapper.map({"items": item.repository_versions }, true);
  46. }
  47. resultStack.push(this.parseIt(stack, this.get('modelStack')));
  48. }, this);
  49. }
  50. App.store.commit();
  51. App.store.loadMany(modelStackVerion, resultStack);
  52. }
  53. });