stack_version_mapper.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. var stringUtils = require('utils/string_utils');
  20. App.stackVersionMapper = App.QuickDataMapper.create({
  21. modelStackVerion: App.StackVersion,
  22. modelStack: {
  23. "id": "id",
  24. "cluster_name": "cluster_name",
  25. "stack": "stack",
  26. "version": "version",
  27. "repository_version_id": "repository_version_id",
  28. "state": "state",
  29. "not_installed_hosts": "host_states.NOT_INSTALLED",
  30. "installing_hosts": "host_states.INSTALLING",
  31. "installed_hosts": "host_states.INSTALLED",
  32. "install_failed_hosts": "host_states.INSTALL_FAILED",
  33. "out_of_sync_hosts": "host_states.OUT_OF_SYNC",
  34. "upgrading_hosts": "host_states.UPGRADING",
  35. "upgraded_hosts": "host_states.UPGRADED",
  36. "upgrade_failed_hosts": "host_states.UPGRADE_FAILED",
  37. "current_hosts": "host_states.CURRENT"
  38. },
  39. map: function (json) {
  40. var modelStackVerion = this.get('modelStackVerion');
  41. var resultStack = [];
  42. if (json && json.items) {
  43. json.items.sort(function (a, b) {
  44. return stringUtils.compareVersions(a.repository_versions[0].RepositoryVersions.repository_version, b.repository_versions[0].RepositoryVersions.repository_version);
  45. });
  46. json.items.forEach(function (item) {
  47. var stack = item.ClusterStackVersions;
  48. stack.repository_version_id = item.ClusterStackVersions.repository_version;
  49. /**
  50. * this property contains array of hosts on which repoversion wasn't installed
  51. * possible states:
  52. * <code>INSTALLING<code>
  53. * <code>INSTALL_FAILED<code>
  54. * <code>OUT_OF_SYNC<code>
  55. */
  56. stack.host_states.NOT_INSTALLED = item.ClusterStackVersions.host_states.INSTALLING
  57. .concat(item.ClusterStackVersions.host_states.INSTALL_FAILED)
  58. .concat(item.ClusterStackVersions.host_states.OUT_OF_SYNC);
  59. /**
  60. * this property contains array of hosts on which repoversion was installed
  61. * but state of repoveriosn for this hosts can be any postinstalled state
  62. * possible states:
  63. * <code>INSTALLED<code>
  64. * <code>UPGRADING<code>
  65. * <code>UPGRADED<code>
  66. * <code>UPGRADE_FAILED<code>
  67. */
  68. stack.host_states.INSTALLED = item.ClusterStackVersions.host_states.INSTALLED
  69. .concat(item.ClusterStackVersions.host_states.UPGRADING)
  70. .concat(item.ClusterStackVersions.host_states.UPGRADED)
  71. .concat(item.ClusterStackVersions.host_states.UPGRADE_FAILED);
  72. if (item.repository_versions && item.repository_versions[0]) {
  73. item.repository_versions[0].RepositoryVersions.stackVersionId = item.ClusterStackVersions.id;
  74. App.repoVersionMapper.map({"items": item.repository_versions }, true, true);
  75. }
  76. resultStack.push(this.parseIt(stack, this.get('modelStack')));
  77. }, this);
  78. }
  79. App.store.commit();
  80. App.store.loadMany(modelStackVerion, resultStack);
  81. }
  82. });