Skip to content

Commit 93bd485

Browse files
feat(restapi): plug backup cleanup into handled endpoints
Refs #4648
1 parent f5445cb commit 93bd485

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pkg/restapi/backup.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"encoding/json"
88
"net/http"
9+
"strconv"
910

1011
"github.com/go-chi/chi/v5"
1112
"github.com/go-chi/render"
@@ -42,6 +43,7 @@ func newBackupHandler(services Services) *chi.Mux {
4243
m.Get("/files", h.listFiles)
4344
})
4445
m.Get("/schema", h.describeSchema)
46+
m.Delete("/cleanup", h.cleanup)
4547

4648
return m
4749
}
@@ -250,6 +252,32 @@ func (h backupHandler) describeSchema(w http.ResponseWriter, r *http.Request) {
250252
render.Respond(w, r, convertSchema(cqlSchema))
251253
}
252254

255+
func (h backupHandler) cleanup(w http.ResponseWriter, r *http.Request) {
256+
cluster := mustClusterFromCtx(r)
257+
258+
var (
259+
deleteDiskSnapshots bool
260+
err error
261+
)
262+
if v := r.URL.Query().Get("delete_disk_snapshots"); v != "" {
263+
deleteDiskSnapshots, err = strconv.ParseBool(v)
264+
if err != nil {
265+
respondBadRequest(w, r, util.ErrValidate(errors.Wrap(err, "parse delete_disk_snapshots")))
266+
return
267+
}
268+
}
269+
if !deleteDiskSnapshots {
270+
respondBadRequest(w, r, util.ErrValidate(errors.New("no cleanup specified")))
271+
return
272+
}
273+
274+
if err := h.svc.Cleanup(r.Context(), cluster.ID); err != nil {
275+
respondError(w, r, errors.Wrap(err, "perform cleanup"))
276+
return
277+
}
278+
w.WriteHeader(http.StatusOK)
279+
}
280+
253281
func parseOptionalUUID(v string) (uuid.UUID, error) {
254282
if v == "" {
255283
return uuid.Nil, nil

pkg/restapi/services.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type BackupService interface {
6969
// GetProgress must work even when the cluster is no longer available.
7070
GetProgress(ctx context.Context, clusterID, taskID, runID uuid.UUID) (backup.Progress, error)
7171
DeleteSnapshot(ctx context.Context, clusterID uuid.UUID, locations []backupspec.Location, snapshotTags []string) error
72+
Cleanup(ctx context.Context, clusterID uuid.UUID) error
7273
GetValidationTarget(_ context.Context, clusterID uuid.UUID, properties json.RawMessage) (backup.ValidationTarget, error)
7374
// GetValidationProgress must work even when the cluster is no longer available.
7475
GetValidationProgress(ctx context.Context, clusterID, taskID, runID uuid.UUID) ([]backup.ValidationHostProgress, error)

0 commit comments

Comments
 (0)