| @@ -70,4 +70,14 @@ type ( | |||||
| history int `json:"history"` | history int `json:"history"` | ||||
| failed int `json:"failed"` | failed int `json:"failed"` | ||||
| } | } | ||||
| ) | |||||
| type ( | |||||
| adapterInfoReq{ | |||||
| clusterId string `form:"clusterId"` | |||||
| } | |||||
| adapterInfoResp{ | |||||
| name string `json:"name"` | |||||
| version string `json:"version"` | |||||
| } | |||||
| ) | ) | ||||
| @@ -995,4 +995,7 @@ service pcm { | |||||
| @handler taskNumHandler | @handler taskNumHandler | ||||
| get /monitoring/task/num (taskNumReq) returns (taskNumResp) | get /monitoring/task/num (taskNumReq) returns (taskNumResp) | ||||
| @handler adapterInfoHandler | |||||
| get /monitoring/adapter/info (adapterInfoReq) returns (adapterInfoResp) | |||||
| } | } | ||||
| @@ -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) | |||||
| } | |||||
| } | |||||
| @@ -1252,6 +1252,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | |||||
| Path: "/monitoring/task/num", | Path: "/monitoring/task/num", | ||||
| Handler: monitoring.TaskNumHandler(serverCtx), | Handler: monitoring.TaskNumHandler(serverCtx), | ||||
| }, | }, | ||||
| { | |||||
| Method: http.MethodGet, | |||||
| Path: "/monitoring/adapter/info", | |||||
| Handler: monitoring.AdapterInfoHandler(serverCtx), | |||||
| }, | |||||
| }, | }, | ||||
| rest.WithPrefix("/pcm/v1"), | rest.WithPrefix("/pcm/v1"), | ||||
| ) | ) | ||||
| @@ -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 | |||||
| } | |||||
| @@ -5602,3 +5602,12 @@ type TaskNumResp struct { | |||||
| History int `json:"history"` | History int `json:"history"` | ||||
| Failed int `json:"failed"` | Failed int `json:"failed"` | ||||
| } | } | ||||
| type AdapterInfoReq struct { | |||||
| ClusterId string `form:"clusterId"` | |||||
| } | |||||
| type AdapterInfoResp struct { | |||||
| Name string `json:"name"` | |||||
| Version string `json:"version"` | |||||
| } | |||||