Skip to content

Commit

Permalink
APPS-1342 Add REST endpoint for cancelling restore jobs (#282)
Browse files Browse the repository at this point in the history
* initial commit for cancel jobs

* add comment

* add update api

* update test

* extractJobID

* tests

* add cancel status

* clean tests

* use waitgroup

* inrtoduce finished function

* regenerate

* misprint

* rename back to handlers

* rename handler

* return nil

* set handler

* use int for restore

* add error message

* Update internal/server/handlers/restore.go

Co-authored-by: Eugene R. <[email protected]>

* update handler

* failed to extract job id

* add constructor

* add comments

---------

Co-authored-by: Eugene R. <[email protected]>
  • Loading branch information
korotkov-aerospike and reugn authored Dec 11, 2024
1 parent d118935 commit f89de90
Show file tree
Hide file tree
Showing 15 changed files with 524 additions and 264 deletions.
68 changes: 52 additions & 16 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,50 @@ const docTemplate = `{
}
}
},
"/v1/restore/cancel/{jobID}": {
"post": {
"tags": [
"Restore"
],
"summary": "Cancel a running restore operation.",
"operationId": "cancelRestore",
"parameters": [
{
"type": "integer",
"description": "Restore job ID",
"name": "jobID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Restore job canceled successfully",
"schema": {
"type": "string"
}
},
"400": {
"description": "Invalid job ID",
"schema": {
"type": "string"
}
},
"404": {
"description": "Job not found",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal server error",
"schema": {
"type": "string"
}
}
}
}
},
"/v1/restore/full": {
"post": {
"consumes": [
Expand All @@ -1244,7 +1288,7 @@ const docTemplate = `{
"202": {
"description": "Restore operation job id",
"schema": {
"type": "int64"
"type": "integer"
}
},
"400": {
Expand Down Expand Up @@ -1287,7 +1331,7 @@ const docTemplate = `{
"202": {
"description": "Restore operation job id",
"schema": {
"type": "int64"
"type": "integer"
}
},
"400": {
Expand Down Expand Up @@ -1318,7 +1362,6 @@ const docTemplate = `{
"parameters": [
{
"type": "integer",
"format": "int64",
"description": "Job ID to retrieve the status",
"name": "jobId",
"in": "path",
Expand Down Expand Up @@ -1367,7 +1410,7 @@ const docTemplate = `{
"202": {
"description": "Restore operation job id",
"schema": {
"type": "int64"
"type": "integer"
}
},
"400": {
Expand Down Expand Up @@ -2088,12 +2131,14 @@ const docTemplate = `{
"enum": [
"Running",
"Done",
"Failed"
"Failed",
"Cancelled"
],
"x-enum-varnames": [
"JobStatusRunning",
"JobStatusDone",
"JobStatusFailed"
"JobStatusFailed",
"JobStatusCancelled"
]
},
"dto.LocalStorage": {
Expand Down Expand Up @@ -2240,16 +2285,7 @@ const docTemplate = `{
"example": 4
},
"status": {
"enum": [
"Running",
"Done",
"Failed"
],
"allOf": [
{
"$ref": "#/definitions/dto.JobStatus"
}
]
"$ref": "#/definitions/dto.JobStatus"
},
"total-bytes": {
"type": "integer",
Expand Down
71 changes: 61 additions & 10 deletions docs/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,64 @@
"x-codegen-request-body-name" : "storage"
}
},
"/v1/restore/cancel/{jobID}" : {
"post" : {
"operationId" : "cancelRestore",
"parameters" : [ {
"description" : "Restore job ID",
"in" : "path",
"name" : "jobID",
"required" : true,
"schema" : {
"type" : "integer"
}
} ],
"responses" : {
"200" : {
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
},
"description" : "Restore job canceled successfully"
},
"400" : {
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
},
"description" : "Invalid job ID"
},
"404" : {
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
},
"description" : "Job not found"
},
"500" : {
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
},
"description" : "Internal server error"
}
},
"summary" : "Cancel a running restore operation.",
"tags" : [ "Restore" ]
}
},
"/v1/restore/full" : {
"post" : {
"operationId" : "restoreFull",
Expand All @@ -1385,7 +1443,6 @@
"content" : {
"*/*" : {
"schema" : {
"format" : "int64",
"type" : "integer"
}
}
Expand Down Expand Up @@ -1437,7 +1494,6 @@
"content" : {
"*/*" : {
"schema" : {
"format" : "int64",
"type" : "integer"
}
}
Expand Down Expand Up @@ -1479,7 +1535,6 @@
"name" : "jobId",
"required" : true,
"schema" : {
"format" : "int64",
"type" : "integer"
}
} ],
Expand Down Expand Up @@ -1529,7 +1584,6 @@
"content" : {
"*/*" : {
"schema" : {
"format" : "int64",
"type" : "integer"
}
}
Expand Down Expand Up @@ -2215,9 +2269,9 @@
"type" : "object"
},
"dto.JobStatus" : {
"enum" : [ "Running", "Done", "Failed" ],
"enum" : [ "Running", "Done", "Failed", "Cancelled" ],
"type" : "string",
"x-enum-varnames" : [ "JobStatusRunning", "JobStatusDone", "JobStatusFailed" ]
"x-enum-varnames" : [ "JobStatusRunning", "JobStatusDone", "JobStatusFailed", "JobStatusCancelled" ]
},
"dto.LocalStorage" : {
"properties" : {
Expand Down Expand Up @@ -2339,10 +2393,7 @@
"type" : "integer"
},
"status" : {
"allOf" : [ {
"$ref" : "#/components/schemas/dto.JobStatus"
} ],
"type" : "object"
"$ref" : "#/components/schemas/dto.JobStatus"
},
"total-bytes" : {
"example" : 2000,
Expand Down
50 changes: 42 additions & 8 deletions docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,44 @@ paths:
tags:
- Configuration
x-codegen-request-body-name: storage
/v1/restore/cancel/{jobID}:
post:
operationId: cancelRestore
parameters:
- description: Restore job ID
in: path
name: jobID
required: true
schema:
type: integer
responses:
"200":
content:
'*/*':
schema:
type: string
description: Restore job canceled successfully
"400":
content:
'*/*':
schema:
type: string
description: Invalid job ID
"404":
content:
'*/*':
schema:
type: string
description: Job not found
"500":
content:
'*/*':
schema:
type: string
description: Internal server error
summary: Cancel a running restore operation.
tags:
- Restore
/v1/restore/full:
post:
operationId: restoreFull
Expand All @@ -959,7 +997,6 @@ paths:
content:
'*/*':
schema:
format: int64
type: integer
description: Restore operation job id
"400":
Expand Down Expand Up @@ -993,7 +1030,6 @@ paths:
content:
'*/*':
schema:
format: int64
type: integer
description: Restore operation job id
"400":
Expand Down Expand Up @@ -1021,7 +1057,6 @@ paths:
name: jobId
required: true
schema:
format: int64
type: integer
responses:
"200":
Expand Down Expand Up @@ -1055,7 +1090,6 @@ paths:
content:
'*/*':
schema:
format: int64
type: integer
description: Restore operation job id
"400":
Expand Down Expand Up @@ -1796,11 +1830,13 @@ components:
- Running
- Done
- Failed
- Cancelled
type: string
x-enum-varnames:
- JobStatusRunning
- JobStatusDone
- JobStatusFailed
- JobStatusCancelled
dto.LocalStorage:
properties:
path:
Expand Down Expand Up @@ -1889,7 +1925,7 @@ components:
fresher-records: 5
skipped-records: 4
index-count: 3
status: "{}"
status: Running
properties:
current-job:
$ref: '#/components/schemas/dto.RunningJob'
Expand Down Expand Up @@ -1928,9 +1964,7 @@ components:
format: int64
type: integer
status:
allOf:
- $ref: '#/components/schemas/dto.JobStatus'
type: object
$ref: '#/components/schemas/dto.JobStatus'
total-bytes:
example: 2000
format: int64
Expand Down
8 changes: 8 additions & 0 deletions internal/server/handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ func (mock restoreManagerMock) RetrieveConfiguration(routine string, _ time.Time
return []byte(fmt.Sprintf(`{ "dir": "%s" }`, testDir)), nil
}

func (mock restoreManagerMock) CancelRestore(jobID model.RestoreJobID) error {
if jobID != model.RestoreJobID(testJobID) {
return errTest
}

return nil
}

type backupListReaderMock struct{}

func (mock backupListReaderMock) FullBackupList(_ context.Context, timebounds model.TimeBounds,
Expand Down
Loading

0 comments on commit f89de90

Please sign in to comment.