-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#21357] yugabyted: Display the list of backup and restore tasks run …
…in the YugabyteDB cluster. Summary: Created `/backup` and `/restore` APIs for getting the list of previously run backup and restore tasks. Jira: DB-10254 Test Plan: Manual Testing. Reviewers: nikhil, sgarg-yb, djiang Reviewed By: nikhil, djiang Subscribers: djiang, shikhar.sahay Differential Revision: https://phorge.dev.yugabyte.com/D33372
- Loading branch information
1 parent
b4f4b80
commit 5e5b564
Showing
24 changed files
with
925 additions
and
12 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
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
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,70 @@ | ||
package handlers | ||
|
||
import ( | ||
"apiserver/cmd/server/helpers" | ||
"apiserver/cmd/server/models" | ||
"fmt" | ||
"net/http" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (c *Container) GetBackupDetails(ctx echo.Context) error { | ||
var operationType = "backup" | ||
lockfilelistFuture := make(chan helpers.LockFileListFuture, 1) | ||
c.helper.ListLockFilesFuture(helpers.DataDir, operationType, lockfilelistFuture) | ||
lockfilelistResult := <-lockfilelistFuture | ||
if lockfilelistResult.Error != nil { | ||
return ctx.String(http.StatusInternalServerError, | ||
fmt.Sprintf("Failed to list lock files: %v", lockfilelistResult.Error)) | ||
} | ||
if len(lockfilelistResult.Result) == 0 { | ||
return ctx.JSON(http.StatusOK, []interface{}{}) | ||
} | ||
var lockFileDetails helpers.LockFileDetails | ||
lockFileInfoFutures := make([]chan helpers.LockFileInfoFuture, | ||
len(lockfilelistResult.Result)) | ||
taskProgressInfoFutures := make([]chan helpers.TaskProgressInfoFuture, | ||
len(lockfilelistResult.Result)) | ||
|
||
for i, lockFilePath := range lockfilelistResult.Result { | ||
lockFileInfoFutures[i] = make(chan helpers.LockFileInfoFuture) | ||
// Fetch lock file info asynchronously | ||
go c.helper.GetLockFileInfoFuture(lockFilePath, lockFileInfoFutures[i]) | ||
} | ||
// Asynchronously start task progress | ||
for i := range lockfilelistResult.Result { | ||
lockFileInfo := <-lockFileInfoFutures[i] | ||
if lockFileInfo.Error != nil { | ||
return ctx.String(http.StatusInternalServerError, | ||
fmt.Sprintf("Failed to parse lock files: %v", lockFileInfo.Error)) | ||
} | ||
c.logger.Infof("Successfully read lock file for database/keyspace: %s", | ||
lockFileInfo.DatabaseKeyspace) | ||
lockFileDetails.Data = append(lockFileDetails.Data, lockFileInfo) | ||
taskProgressInfoFutures[i] = make(chan helpers.TaskProgressInfoFuture) | ||
go c.helper.GetYBCTaskProgress(lockFileInfo.YbcTaskID, lockFileInfo.TserverIP, | ||
taskProgressInfoFutures[i]) | ||
} | ||
|
||
var response models.BackupResponse | ||
for i, lockFileInfo := range lockFileDetails.Data { | ||
taskProgressInfo := <-taskProgressInfoFutures[i] | ||
if taskProgressInfo.Error != nil { | ||
return ctx.String(http.StatusInternalServerError, | ||
fmt.Sprintf("Failed to get task progress: %v", taskProgressInfo.Error)) | ||
} | ||
response.Backup = append(response.Backup, models.BackupDetails{ | ||
YbcTaskId: lockFileInfo.YbcTaskID, | ||
TserverIp: lockFileInfo.TserverIP, | ||
UserOperation: lockFileInfo.UserOperation, | ||
YbdbApi: lockFileInfo.YbdbAPI, | ||
DatabaseKeyspace: lockFileInfo.DatabaseKeyspace, | ||
TaskStartTime: lockFileInfo.TaskStartTime, | ||
TaskStatus: taskProgressInfo.FinalStatus, | ||
TimeTaken: taskProgressInfo.TimeTaken, | ||
BytesTransferred: taskProgressInfo.BytesTransferred, | ||
ActualSize: taskProgressInfo.ActualSize, | ||
}) | ||
} | ||
return ctx.JSON(http.StatusOK, 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,70 @@ | ||
package handlers | ||
|
||
import ( | ||
"apiserver/cmd/server/helpers" | ||
"apiserver/cmd/server/models" | ||
"fmt" | ||
"net/http" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (c *Container) GetRestoreDetails(ctx echo.Context) error { | ||
var operationType = "restore" | ||
lockfilelistFuture := make(chan helpers.LockFileListFuture, 1) | ||
c.helper.ListLockFilesFuture(helpers.DataDir, operationType, lockfilelistFuture) | ||
lockfilelistResult := <-lockfilelistFuture | ||
if lockfilelistResult.Error != nil { | ||
return ctx.String(http.StatusInternalServerError, | ||
fmt.Sprintf("Failed to list lock files: %v", lockfilelistResult.Error)) | ||
} | ||
if len(lockfilelistResult.Result) == 0 { | ||
return ctx.JSON(http.StatusOK, []interface{}{}) | ||
} | ||
var lockFileDetails helpers.LockFileDetails | ||
lockFileInfoFutures := make([]chan helpers.LockFileInfoFuture, | ||
len(lockfilelistResult.Result)) | ||
taskProgressInfoFutures := make([]chan helpers.TaskProgressInfoFuture, | ||
len(lockfilelistResult.Result)) | ||
|
||
for i, lockFilePath := range lockfilelistResult.Result { | ||
lockFileInfoFutures[i] = make(chan helpers.LockFileInfoFuture) | ||
// Fetch lock file info asynchronously | ||
go c.helper.GetLockFileInfoFuture(lockFilePath, lockFileInfoFutures[i]) | ||
} | ||
// Asynchronously start task progress | ||
for i := range lockfilelistResult.Result { | ||
lockFileInfo := <-lockFileInfoFutures[i] | ||
if lockFileInfo.Error != nil { | ||
return ctx.String(http.StatusInternalServerError, | ||
fmt.Sprintf("Failed to parse lock files: %v", lockFileInfo.Error)) | ||
} | ||
c.logger.Infof("Successfully read lock file for database/keyspace: %s", | ||
lockFileInfo.DatabaseKeyspace) | ||
lockFileDetails.Data = append(lockFileDetails.Data, lockFileInfo) | ||
taskProgressInfoFutures[i] = make(chan helpers.TaskProgressInfoFuture) | ||
go c.helper.GetYBCTaskProgress(lockFileInfo.YbcTaskID, lockFileInfo.TserverIP, | ||
taskProgressInfoFutures[i]) | ||
} | ||
|
||
var response models.RestoreResponse | ||
for i, lockFileInfo := range lockFileDetails.Data { | ||
taskProgressInfo := <-taskProgressInfoFutures[i] | ||
if taskProgressInfo.Error != nil { | ||
return ctx.String(http.StatusInternalServerError, | ||
fmt.Sprintf("Failed to get task progress: %v", taskProgressInfo.Error)) | ||
} | ||
response.Restore = append(response.Restore, models.RestoreDetails{ | ||
YbcTaskId: lockFileInfo.YbcTaskID, | ||
TserverIp: lockFileInfo.TserverIP, | ||
UserOperation: lockFileInfo.UserOperation, | ||
YbdbApi: lockFileInfo.YbdbAPI, | ||
DatabaseKeyspace: lockFileInfo.DatabaseKeyspace, | ||
TaskStartTime: lockFileInfo.TaskStartTime, | ||
TaskStatus: taskProgressInfo.FinalStatus, | ||
TimeTaken: taskProgressInfo.TimeTaken, | ||
BytesTransferred: taskProgressInfo.BytesTransferred, | ||
ActualSize: taskProgressInfo.ActualSize, | ||
}) | ||
} | ||
return ctx.JSON(http.StatusOK, response) | ||
} |
Oops, something went wrong.