forked from JointCloud/pcm-coordinator
监控接口修改
This commit is contained in:
parent
c0c11e7d01
commit
cbfa00c5d4
|
@ -0,0 +1,25 @@
|
||||||
|
package cloud
|
||||||
|
|
||||||
|
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/internal/logic/cloud"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func PodsListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.PodsListReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := cloud.NewPodsListLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.PodsList(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
package cloud
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
|
||||||
|
v1 "k8s.io/api/core/v1"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PodsListLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
type ParticipantResp struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"message"`
|
||||||
|
Data *v1.PodList `json:"data"` // 改成结构体
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PodsListLogic {
|
||||||
|
return &PodsListLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *PodsListLogic) PodsList(req *types.PodsListReq) (resp *types.PodsListResp, err error) {
|
||||||
|
resp = &types.PodsListResp{}
|
||||||
|
// query cluster http url.
|
||||||
|
var apiServerList []string
|
||||||
|
l.svcCtx.DbEngin.Raw("select server from t_adapter where resource_type = '01'").Scan(&apiServerList)
|
||||||
|
for _, server := range apiServerList {
|
||||||
|
participantResp := ParticipantResp{}
|
||||||
|
param := map[string]string{
|
||||||
|
"clusterName": req.ClusterName,
|
||||||
|
}
|
||||||
|
httputils.HttpGetWithResult(param, server+"/api/v1/pod/list", &participantResp)
|
||||||
|
|
||||||
|
resp.Data = append(resp.Data, participantResp.Data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
Loading…
Reference in New Issue