MigrationActions.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. // @flow
  15. import alt from '../alt'
  16. import MigrationSource from '../sources/MigrationSource'
  17. class MigrationActions {
  18. getMigrations(options) {
  19. return {
  20. ...options,
  21. promise: MigrationSource.getMigrations().then(
  22. response => { this.getMigrationsSuccess(response) },
  23. response => { this.getMigrationsFailed(response) },
  24. ),
  25. }
  26. }
  27. getMigrationsSuccess(migrations) {
  28. return migrations || true
  29. }
  30. getMigrationsFailed(response) {
  31. return response || true
  32. }
  33. getMigration(migrationId, showLoading) {
  34. MigrationSource.getMigration(migrationId).then(
  35. migration => { this.getMigrationSuccess(migration) },
  36. response => { this.getMigrationFailed(response) },
  37. )
  38. return { migrationId, showLoading }
  39. }
  40. getMigrationSuccess(migration) {
  41. return migration
  42. }
  43. getMigrationFailed(response) {
  44. return response || true
  45. }
  46. cancel(migrationId) {
  47. return {
  48. migrationId,
  49. promise: MigrationSource.cancel(migrationId).then(
  50. () => { this.cancelSuccess(migrationId) },
  51. response => { this.cancelFailed(response) },
  52. ),
  53. }
  54. }
  55. cancelSuccess(migrationId) {
  56. return { migrationId }
  57. }
  58. cancelFailed(response) {
  59. return response || true
  60. }
  61. delete(migrationId) {
  62. MigrationSource.delete(migrationId).then(
  63. () => { this.deleteSuccess(migrationId) },
  64. response => { this.deleteFailed(response) },
  65. )
  66. return migrationId
  67. }
  68. deleteSuccess(migrationId) {
  69. return migrationId
  70. }
  71. deleteFailed(response) {
  72. return response || true
  73. }
  74. migrateReplica(replicaId, options) {
  75. MigrationSource.migrateReplica(replicaId, options).then(
  76. migration => { this.migrateReplicaSuccess(migration) },
  77. response => { this.migrateReplicaFailed(response) },
  78. )
  79. return { replicaId, options }
  80. }
  81. migrateReplicaSuccess(migration) {
  82. return migration
  83. }
  84. migrateReplicaFailed(response) {
  85. return response || true
  86. }
  87. clearDetails() {
  88. return true
  89. }
  90. }
  91. export default alt.createActions(MigrationActions)