-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
APPS-937 Group OpenAPI endpoints with tags
- Loading branch information
Showing
5 changed files
with
247 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"log/slog" | ||
) | ||
|
||
// @Summary Get available full backups. | ||
// @Tags Backup | ||
// @Produce plain | ||
// @Param name query string true "Backup policy name" | ||
// @Router /backup/full/list [get] | ||
// @Success 200 {array} model.BackupDetails "Full backups" | ||
// @Failure 404 {string} string "" | ||
func (ws *HTTPServer) getAvailableFullBackups(w http.ResponseWriter, r *http.Request) { | ||
policyName := r.URL.Query().Get("name") | ||
if policyName == "" { | ||
http.Error(w, "Invalid/undefined policy name", http.StatusBadRequest) | ||
} else { | ||
list, err := ws.backupBackends[policyName].FullBackupList() | ||
if err != nil { | ||
slog.Error("Get full backup list", "err", err) | ||
http.Error(w, "", http.StatusNotFound) | ||
} else { | ||
response, err := json.Marshal(list) | ||
if err != nil { | ||
slog.Error("Failed to parse full backup list", "err", err) | ||
http.Error(w, "", http.StatusInternalServerError) | ||
} else { | ||
fmt.Fprint(w, string(response)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// @Summary Get available incremental backups. | ||
// @Tags Backup | ||
// @Produce plain | ||
// @Param name query string true "Backup policy name" | ||
// @Router /backup/incremental/list [get] | ||
// @Success 200 {array} model.BackupDetails "Incremental backups" | ||
// @Failure 404 {string} string "" | ||
func (ws *HTTPServer) getAvailableIncrBackups(w http.ResponseWriter, r *http.Request) { | ||
policyName := r.URL.Query().Get("name") | ||
if policyName == "" { | ||
http.Error(w, "Invalid/undefined policy name", http.StatusBadRequest) | ||
} else { | ||
list, err := ws.backupBackends[policyName].IncrementalBackupList() | ||
if err != nil { | ||
slog.Error("Get incremental backup list", "err", err) | ||
http.Error(w, "", http.StatusNotFound) | ||
} else { | ||
response, err := json.Marshal(list) | ||
if err != nil { | ||
slog.Error("Failed to parse incremental backup list", "err", err) | ||
http.Error(w, "", http.StatusInternalServerError) | ||
} else { | ||
fmt.Fprint(w, string(response)) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strconv" | ||
|
||
"log/slog" | ||
|
||
"github.com/aerospike/backup/pkg/model" | ||
) | ||
|
||
// @Summary Trigger an asynchronous restore operation. | ||
// @Description Specify the directory parameter for the full backup restore. | ||
// @Description Use the file parameter to restore from an incremental backup file. | ||
// @Tags Restore | ||
// @Router /restore [post] | ||
// @Param request body model.RestoreRequest true "query params" | ||
// @Success 200 {integer} int "Job ID (int64)" | ||
func (ws *HTTPServer) restoreHandler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == http.MethodPost { | ||
var request model.RestoreRequest | ||
|
||
err := json.NewDecoder(r.Body).Decode(&request) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
if err = request.Validate(); err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
jobID := ws.restoreService.Restore(&request) | ||
slog.Info("Restore action", "jobID", jobID, "request", request) | ||
fmt.Fprint(w, strconv.Itoa(jobID)) | ||
} else { | ||
http.Error(w, "", http.StatusNotFound) | ||
} | ||
} | ||
|
||
// @Summary Retrieve status for a restore job. | ||
// @Tags Restore | ||
// @Produce plain | ||
// @Param jobId query int true "Job ID to retrieve the status" | ||
// @Router /restore/status [get] | ||
// @Success 200 {string} string "Job status" | ||
func (ws *HTTPServer) restoreStatusHandler(w http.ResponseWriter, r *http.Request) { | ||
jobIDParam := r.URL.Query().Get("jobId") | ||
jobID, err := strconv.Atoi(jobIDParam) | ||
if err != nil { | ||
http.Error(w, "Invalid job id", http.StatusBadRequest) | ||
} else { | ||
fmt.Fprint(w, ws.restoreService.JobStatus(jobID)) | ||
} | ||
} |
Oops, something went wrong.