Skip to content

Commit

Permalink
feat(bak): add test bak interface
Browse files Browse the repository at this point in the history
  • Loading branch information
noovertime7 committed Oct 24, 2022
1 parent 4770ede commit f09257f
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 109 deletions.
16 changes: 16 additions & 0 deletions agent/agentcontroller/bak.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func BakRegister(group *gin.RouterGroup) {
bakService: agentservice.GetClusterBakService(),
}
group.PUT("/bakstart", bak.StartBak)
group.PUT("/bak_test", bak.TestBak)
group.PUT("/bakstop", bak.StopBak)
group.PUT("/bakhoststart", bak.StartBakByHost)
group.PUT("/bakhoststop", bak.StopBakByHost)
Expand All @@ -35,6 +36,21 @@ func (b *BakController) StartBak(ctx *gin.Context) {
}
middleware.ResponseSuccess(ctx, "任务启动成功")
}

func (b *BakController) TestBak(ctx *gin.Context) {
params := &agentdto.StartBakInput{}
if err := params.BindValidParams(ctx); err != nil {
middleware.ResponseError(ctx, globalError.NewGlobalError(globalError.ParamBindError, err))
return
}
data, err := b.bakService.TestBak(ctx, params)
if err != nil || !data.OK {
middleware.ResponseError(ctx, globalError.NewGlobalError(globalError.BakStartError, err))
return
}
middleware.ResponseSuccess(ctx, "测试任务启动成功")
}

func (b *BakController) StopBak(ctx *gin.Context) {
params := &agentdto.StopBakInput{}
if err := params.BindValidParams(ctx); err != nil {
Expand Down
16 changes: 16 additions & 0 deletions agent/agentservice/bak.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func (b *BakService) StartBak(ctx *gin.Context, params *agentdto.StartBakInput)
return bakService.StartBak(ctx, bakStartInput, ops)
}

func (b *BakService) TestBak(ctx *gin.Context, params *agentdto.StartBakInput) (*bak.BakOneMessage, error) {
bakService, addr, err := pkg.GetBakService(params.ServiceName)
if err != nil {
return nil, err
}
var ops client.CallOption = func(options *client.CallOptions) {
options.Address = []string{addr}
}
bakStartInput := &bak.StartBakInput{
TaskID: params.TaskID,
ServiceName: params.ServiceName,
}
log.Logger.Info("agent开始启动测试任务", bakStartInput)
return bakService.TestBak(ctx, bakStartInput, ops)
}

func (b *BakService) StopBak(ctx *gin.Context, params *agentdto.StopBakInput) (*bak.BakOneMessage, error) {
bakService, addr, err := pkg.GetBakService(params.ServiceName)
if err != nil {
Expand Down
Loading

0 comments on commit f09257f

Please sign in to comment.