diff --git a/internal/handler/cloud/podslisthandler.go b/internal/handler/cloud/podslisthandler.go new file mode 100644 index 00000000..000b32ed --- /dev/null +++ b/internal/handler/cloud/podslisthandler.go @@ -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) + } +} diff --git a/internal/logic/cloud/podslistlogic.go b/internal/logic/cloud/podslistlogic.go new file mode 100644 index 00000000..63f576f1 --- /dev/null +++ b/internal/logic/cloud/podslistlogic.go @@ -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 +}