Skip to content

Commit

Permalink
feat(backup): add websocket for backup targets
Browse files Browse the repository at this point in the history
Ref: 5411

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz committed Sep 26, 2024
1 parent 99e9b35 commit 442d9f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions api/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@ func (s *Server) BackupTargetGet(w http.ResponseWriter, req *http.Request) error
func (s *Server) BackupTargetList(w http.ResponseWriter, req *http.Request) error {
apiContext := api.GetApiContext(req)

backupTargets, err := s.m.ListBackupTargetsSorted()
bts, err := s.backupTargetList(apiContext)
if err != nil {
return errors.Wrap(err, "failed to list backup targets")
}
apiContext.Write(toBackupTargetCollection(backupTargets, apiContext))

apiContext.Write(bts)
return nil
}

func (s *Server) backupTargetList(apiContext *api.ApiContext) (*client.GenericCollection, error) {
bts, err := s.m.ListBackupTargetsSorted()
if err != nil {
return nil, errors.Wrap(err, "failed to list backup target")
}
return toBackupTargetCollection(bts, apiContext), nil
}

func (s *Server) BackupTargetCreate(rw http.ResponseWriter, req *http.Request) error {
var input BackupTarget
apiContext := api.GetApiContext(req)
Expand Down
4 changes: 4 additions & 0 deletions api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ func NewRouter(s *Server) *mux.Router {
r.Path("/v1/ws/backupvolumes").Handler(f(schemas, backupVolumeStream))
r.Path("/v1/ws/{period}/backupvolumes").Handler(f(schemas, backupVolumeStream))

backupTargetStream := NewStreamHandlerFunc("backuptargets", s.wsc.NewWatcher("backupTarget"), s.backupTargetList)
r.Path("/v1/ws/backuptargets").Handler(f(schemas, backupTargetStream))
r.Path("/v1/ws/{period}/backuptargets").Handler(f(schemas, backupTargetStream))

// TODO:
// We haven't found a way to allow passing the volume name as a parameter to filter
// per-backup volume's backups change thru. WebSocket endpoint. Either by:
Expand Down

0 comments on commit 442d9f4

Please sign in to comment.