adapter info

Former-commit-id: c717f0f1d0eabd7121ed7d43a8e22e82603b8d64
This commit is contained in:
zhangwei 2024-04-26 16:27:26 +08:00
parent 8fd635b4a7
commit 2210db4d3c
6 changed files with 83 additions and 0 deletions

View File

@ -70,4 +70,14 @@ type (
history int `json:"history"`
failed int `json:"failed"`
}
)
type (
adapterInfoReq{
clusterId string `form:"clusterId"`
}
adapterInfoResp{
name string `json:"name"`
version string `json:"version"`
}
)

View File

@ -995,4 +995,7 @@ service pcm {
@handler taskNumHandler
get /monitoring/task/num (taskNumReq) returns (taskNumResp)
@handler adapterInfoHandler
get /monitoring/adapter/info (adapterInfoReq) returns (adapterInfoResp)
}

View File

@ -0,0 +1,25 @@
package monitoring
import (
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/monitoring"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
)
func AdapterInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AdapterInfoReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := monitoring.NewAdapterInfoLogic(r.Context(), svcCtx)
resp, err := l.AdapterInfo(&req)
result.HttpResult(r, w, resp, err)
}
}

View File

@ -1252,6 +1252,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/monitoring/task/num",
Handler: monitoring.TaskNumHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/monitoring/adapter/info",
Handler: monitoring.AdapterInfoHandler(serverCtx),
},
},
rest.WithPrefix("/pcm/v1"),
)

View File

@ -0,0 +1,31 @@
package monitoring
import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AdapterInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAdapterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdapterInfoLogic {
return &AdapterInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AdapterInfoLogic) AdapterInfo(req *types.AdapterInfoReq) (resp *types.AdapterInfoResp, err error) {
// todo: add your logic here and delete this line
resp = &types.AdapterInfoResp{}
l.svcCtx.DbEngin.Raw("select ta.name , ta.version from t_adapter ta,t_cluster tc where tc.id = ? and tc.adapter_id = ta.id", req.ClusterId).Scan(resp)
return resp, nil
}

View File

@ -5602,3 +5602,12 @@ type TaskNumResp struct {
History int `json:"history"`
Failed int `json:"failed"`
}
type AdapterInfoReq struct {
ClusterId string `form:"clusterId"`
}
type AdapterInfoResp struct {
Name string `json:"name"`
Version string `json:"version"`
}