stack_version_mapper.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. /**
  44. * this property contains array of hosts on which repoversion was installed
  45. * but state of repoveriosn for this hosts can be any postinstalled state
  46. * possible states:
  47. * <code>INSTALLED<code>
  48. * <code>UPGRADING<code>
  49. * <code>UPGRADED<code>
  50. * <code>UPGRADE_FAILED<code>
  51. * <code>CURRENT<code>
  52. */
  53. stack.host_states.INSTALLED = item.ClusterStackVersions.host_states.INSTALLED
  54. .concat(item.ClusterStackVersions.host_states.UPGRADING)
  55. .concat(item.ClusterStackVersions.host_states.UPGRADED)
  56. .concat(item.ClusterStackVersions.host_states.UPGRADE_FAILED)
  57. .concat(item.ClusterStackVersions.host_states.CURRENT);
  58. if (item.repository_versions && item.repository_versions[0]) {
  59. item.repository_versions[0].RepositoryVersions.stackVersionId = item.ClusterStackVersions.id;
  60. App.repoVersionMapper.map({"items": item.repository_versions }, true);
  61. }
  62. resultStack.push(this.parseIt(stack, this.get('modelStack')));
  63. }, this);
  64. }
  65. App.store.commit();
  66. App.store.loadMany(modelStackVerion, resultStack);
  67. }
  68. });