MigrationActions.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. import alt from '../alt'
  15. import MigrationSource from '../sources/MigrationSource'
  16. class MigrationActions {
  17. getMigrations(options) {
  18. return {
  19. ...options,
  20. promise: MigrationSource.getMigrations().then(
  21. response => { this.getMigrationsSuccess(response) },
  22. response => { this.getMigrationsFailed(response) },
  23. ),
  24. }
  25. }
  26. getMigrationsSuccess(migrations) {
  27. return migrations || true
  28. }
  29. getMigrationsFailed(response) {
  30. return response || true
  31. }
  32. getMigration(migrationId, showLoading) {
  33. MigrationSource.getMigration(migrationId).then(
  34. migration => { this.getMigrationSuccess(migration) },
  35. response => { this.getMigrationFailed(response) },
  36. )
  37. return { migrationId, showLoading }
  38. }
  39. getMigrationSuccess(migration) {
  40. return migration
  41. }
  42. getMigrationFailed(response) {
  43. return response || true
  44. }
  45. cancel(migrationId) {
  46. return {
  47. migrationId,
  48. promise: MigrationSource.cancel(migrationId).then(
  49. () => { this.cancelSuccess(migrationId) },
  50. response => { this.cancelFailed(response) },
  51. ),
  52. }
  53. }
  54. cancelSuccess(migrationId) {
  55. return { migrationId }
  56. }
  57. cancelFailed(response) {
  58. return response || true
  59. }
  60. delete(migrationId) {
  61. MigrationSource.delete(migrationId).then(
  62. () => { this.deleteSuccess(migrationId) },
  63. response => { this.deleteFailed(response) },
  64. )
  65. return migrationId
  66. }
  67. deleteSuccess(migrationId) {
  68. return migrationId
  69. }
  70. deleteFailed(response) {
  71. return response || true
  72. }
  73. migrateReplica(replicaId, options) {
  74. MigrationSource.migrateReplica(replicaId, options).then(
  75. migration => { this.migrateReplicaSuccess(migration) },
  76. response => { this.migrateReplicaFailed(response) },
  77. )
  78. return { replicaId, options }
  79. }
  80. migrateReplicaSuccess(migration) {
  81. return migration
  82. }
  83. migrateReplicaFailed(response) {
  84. return response || true
  85. }
  86. clearDetails() {
  87. return true
  88. }
  89. }
  90. export default alt.createActions(MigrationActions)