Skip to content

Commit 3b577af

Browse files
author
Bogdan Tsechoev
committed
Merge branch '601-dblab-api-endpoints' into 'dle-4-0'
Refactor API endpoints See merge request postgres-ai/database-lab!994
2 parents 90cfc42 + a672f4b commit 3b577af

File tree

14 files changed

+481
-310
lines changed

14 files changed

+481
-310
lines changed

engine/api/postman/dblab_api.postman_collection.json

+303-176
Large diffs are not rendered by default.

engine/api/swagger-spec/dblab_openapi.yaml

+106-36
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ info:
1616
license:
1717
name: Apache 2.0
1818
url: https://github.com/postgres-ai/database-lab-engine/blob/dle-4-0/LICENSE
19-
version: 4.0.0-alpha.5
19+
version: 4.0.0
2020
externalDocs:
2121
description: DBLab Docs
2222
url: https://gitlab.com/postgres-ai/docs/tree/master/docs/database-lab
@@ -224,6 +224,84 @@ paths:
224224
example:
225225
code: "UNAUTHORIZED"
226226
message: "Check your verification token."
227+
/snapshot:
228+
post:
229+
tags:
230+
- Snapshots
231+
summary: Create a snapshot
232+
description: "Create a new snapshot from the current state of the selected pool.
233+
This snapshot can later be used to create clones or new branches."
234+
parameters:
235+
- name: Verification-Token
236+
in: header
237+
required: true
238+
schema:
239+
type: string
240+
requestBody:
241+
description: "Optional parameters for snapshot creation.
242+
If no pool name is provided, the first available pool is used."
243+
content:
244+
'*/*':
245+
schema:
246+
type: object
247+
properties:
248+
poolName:
249+
type: string
250+
description: Name of the pool to create snapshot in.
251+
required: false
252+
responses:
253+
200:
254+
description: OK
255+
content:
256+
'*/*':
257+
schema:
258+
$ref: '#/components/schemas/Snapshot'
259+
400:
260+
description: Bad request
261+
content:
262+
'*/*':
263+
schema:
264+
$ref: '#/components/schemas/Error'
265+
x-codegen-request-body-name: body
266+
/snapshot/{id}:
267+
delete:
268+
tags:
269+
- Snapshots
270+
summary: Delete a snapshot
271+
description: "Permanently delete the specified snapshot.
272+
If the snapshot has dependent clones or datasets, `force=true` can be provided as a query parameter."
273+
parameters:
274+
- name: id
275+
in: path
276+
required: true
277+
description: The ID of the snapshot to delete.
278+
schema:
279+
type: string
280+
pattern: '.*'
281+
- name: force
282+
in: query
283+
required: false
284+
description: Force deletion even if dependent clones or datasets exist.
285+
schema:
286+
type: boolean
287+
- name: Verification-Token
288+
in: header
289+
required: true
290+
schema:
291+
type: string
292+
responses:
293+
200:
294+
description: OK
295+
content:
296+
'*/*':
297+
schema:
298+
$ref: '#/components/schemas/ResponseStatus'
299+
400:
300+
description: Bad request
301+
content:
302+
'*/*':
303+
schema:
304+
$ref: '#/components/schemas/Error'
227305
/clones:
228306
get:
229307
tags:
@@ -715,7 +793,7 @@ paths:
715793
'*/*':
716794
schema:
717795
$ref: '#/components/schemas/Error'
718-
/branch/create:
796+
/branch:
719797
post:
720798
tags:
721799
- Branches
@@ -805,28 +883,24 @@ paths:
805883
schema:
806884
$ref: '#/components/schemas/Error'
807885
x-codegen-request-body-name: body
808-
/branch/delete:
809-
post:
886+
/branch/{branchName}:
887+
delete:
810888
tags:
811889
- Branches
812890
summary: Delete a branch
813891
description: "Permanently delete the specified branch. It cannot be undone."
814892
parameters:
815-
- name: Verification-Token
816-
in: header
817-
required: true
818-
schema:
819-
type: string
820-
requestBody:
821-
content:
822-
'*/*':
823-
schema:
824-
type: object
825-
properties:
826-
branchName:
827-
type: string
828-
description: "The name of the branch to be deleted."
829-
required: true
893+
- name: branchName
894+
in: path
895+
required: true
896+
schema:
897+
type: string
898+
description: "The name of the branch to be deleted."
899+
- name: Verification-Token
900+
in: header
901+
required: true
902+
schema:
903+
type: string
830904
responses:
831905
200:
832906
description: OK
@@ -841,28 +915,24 @@ paths:
841915
schema:
842916
$ref: '#/components/schemas/Error'
843917
x-codegen-request-body-name: body
844-
/branch/log:
845-
post:
918+
/branch/{branchName}/log:
919+
get:
846920
tags:
847921
- Branches
848922
summary: Retrieve a branch log
849923
description: Retrieve a log of the specified branch (history of snapshots).
850924
parameters:
851-
- name: Verification-Token
852-
in: header
853-
required: true
854-
schema:
855-
type: string
856-
requestBody:
857-
content:
858-
'*/*':
859-
schema:
860-
type: object
861-
properties:
862-
branchName:
863-
type: string
864-
description: The name of the branch.
865-
required: false
925+
- name: branchName
926+
in: path
927+
required: true
928+
schema:
929+
type: string
930+
description: The name of the branch.
931+
- name: Verification-Token
932+
in: header
933+
required: true
934+
schema:
935+
type: string
866936
responses:
867937
200:
868938
description: OK

engine/internal/srv/branch.go

+11-19
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,9 @@ func filterSnapshotsByBranch(pool *resources.Pool, branch string, snapshots []mo
458458
}
459459

460460
func (s *Server) log(w http.ResponseWriter, r *http.Request) {
461-
var logRequest types.LogRequest
462-
if err := api.ReadJSON(r, &logRequest); err != nil {
463-
api.SendBadRequestError(w, r, err.Error())
464-
return
465-
}
461+
branchName := mux.Vars(r)["branchName"]
466462

467-
fsm, err := s.getFSManagerForBranch(logRequest.BranchName)
463+
fsm, err := s.getFSManagerForBranch(branchName)
468464
if err != nil {
469465
api.SendBadRequestError(w, r, err.Error())
470466
return
@@ -481,9 +477,9 @@ func (s *Server) log(w http.ResponseWriter, r *http.Request) {
481477
return
482478
}
483479

484-
snapshotID, ok := repo.Branches[logRequest.BranchName]
480+
snapshotID, ok := repo.Branches[branchName]
485481
if !ok {
486-
api.SendBadRequestError(w, r, "branch not found: "+logRequest.BranchName)
482+
api.SendBadRequestError(w, r, "branch not found: "+branchName)
487483
return
488484
}
489485

@@ -508,13 +504,9 @@ func (s *Server) log(w http.ResponseWriter, r *http.Request) {
508504
}
509505

510506
func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
511-
var deleteRequest types.BranchDeleteRequest
512-
if err := api.ReadJSON(r, &deleteRequest); err != nil {
513-
api.SendBadRequestError(w, r, err.Error())
514-
return
515-
}
507+
branchName := mux.Vars(r)["branchName"]
516508

517-
fsm, err := s.getFSManagerForBranch(deleteRequest.BranchName)
509+
fsm, err := s.getFSManagerForBranch(branchName)
518510
if err != nil {
519511
api.SendBadRequestError(w, r, err.Error())
520512
return
@@ -531,13 +523,13 @@ func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
531523
return
532524
}
533525

534-
snapshotID, ok := repo.Branches[deleteRequest.BranchName]
526+
snapshotID, ok := repo.Branches[branchName]
535527
if !ok {
536-
api.SendBadRequestError(w, r, "branch not found: "+deleteRequest.BranchName)
528+
api.SendBadRequestError(w, r, "branch not found: "+branchName)
537529
return
538530
}
539531

540-
toRemove := snapshotsToRemove(repo, snapshotID, deleteRequest.BranchName)
532+
toRemove := snapshotsToRemove(repo, snapshotID, branchName)
541533

542534
if len(toRemove) > 0 {
543535
// Pre-check.
@@ -550,7 +542,7 @@ func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
550542
}
551543

552544
if len(preCheckList) > 0 {
553-
errMsg := fmt.Sprintf("cannot delete branch %q because", deleteRequest.BranchName)
545+
errMsg := fmt.Sprintf("cannot delete branch %q because", branchName)
554546

555547
for snapID, cloneNum := range preCheckList {
556548
errMsg += fmt.Sprintf(" snapshot %q contains %d clone(s)", snapID, cloneNum)
@@ -563,7 +555,7 @@ func (s *Server) deleteBranch(w http.ResponseWriter, r *http.Request) {
563555
}
564556
}
565557

566-
if err := s.destroyBranchDataset(fsm, deleteRequest.BranchName); err != nil {
558+
if err := s.destroyBranchDataset(fsm, branchName); err != nil {
567559
api.SendBadRequestError(w, r, err.Error())
568560
return
569561
}

0 commit comments

Comments
 (0)