Merge remote-tracking branch 'origin/master'
Former-commit-id: 458812fca278897b6c0c75e5228cde772601287a
This commit is contained in:
commit
7f6b9cf0ca
|
@ -9,5 +9,5 @@ type TaskOptions struct {
|
||||||
type Task interface {
|
type Task interface {
|
||||||
PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, error)
|
PullTaskInfo(pullTaskInfoReq PullTaskInfoReq) (*PullTaskInfoResp, error)
|
||||||
PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp, error)
|
PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp, error)
|
||||||
PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) error
|
PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) (*PushResourceInfoResp, error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,8 @@ func (t *task) PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp,
|
||||||
|
|
||||||
url := t.client.url + "/pcm/v1/core/pushTaskInfo"
|
url := t.client.url + "/pcm/v1/core/pushTaskInfo"
|
||||||
method := "POST"
|
method := "POST"
|
||||||
infoReq := PullTaskInfoReq{AdapterId: pushTaskInfoReq.AdapterId}
|
//infoReq := PullTaskInfoReq{AdapterId: pushTaskInfoReq.AdapterId}
|
||||||
jsonStr, _ := json.Marshal(infoReq)
|
jsonStr, _ := json.Marshal(pushTaskInfoReq)
|
||||||
payload := strings.NewReader(string(jsonStr))
|
payload := strings.NewReader(string(jsonStr))
|
||||||
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
|
@ -66,7 +66,22 @@ func (t *task) PushTaskInfo(pushTaskInfoReq PushTaskInfoReq) (*PushTaskInfoResp,
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) error {
|
func (t *task) PushResourceInfo(pushResourceInfoReq PushResourceInfoReq) (*PushResourceInfoResp, error) {
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
url := t.client.url + "/pcm/v1/core/pushResourceInfo"
|
||||||
|
method := "POST"
|
||||||
|
//infoReq := PushResourceInfoReq{AdapterId: pushResourceInfoReq.AdapterId}
|
||||||
|
jsonStr, _ := json.Marshal(pushResourceInfoReq)
|
||||||
|
payload := strings.NewReader(string(jsonStr))
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
req, _ := http.NewRequest(method, url, payload)
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
res, _ := client.Do(req)
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
body, _ := ioutil.ReadAll(res.Body)
|
||||||
|
var resp PushResourceInfoResp
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,14 @@ type PushTaskInfoResp struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PushResourceInfoReq struct {
|
type PushResourceInfoReq struct {
|
||||||
AdapterId int64 `json:"adapterId"`
|
AdapterId int64 `json:"adapterId"`
|
||||||
|
ResourceStats []ResourceStats `json:"resourceStats"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PushResourceInfoResp struct {
|
||||||
|
Code int64
|
||||||
|
Msg string
|
||||||
|
}
|
||||||
type HpcInfo struct {
|
type HpcInfo struct {
|
||||||
Id int64 `json:"id"` // id
|
Id int64 `json:"id"` // id
|
||||||
TaskId int64 `json:"task_id"` // 任务id
|
TaskId int64 `json:"task_id"` // 任务id
|
||||||
|
@ -121,3 +126,27 @@ type VmInfo struct {
|
||||||
DeleteOnTermination bool `json:"delete_on_termination,omitempty"`
|
DeleteOnTermination bool `json:"delete_on_termination,omitempty"`
|
||||||
State string `json:"state,omitempty"`
|
State string `json:"state,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResourceStats struct {
|
||||||
|
ClusterId int64
|
||||||
|
Name string
|
||||||
|
CpuCoreAvail int64
|
||||||
|
CpuCoreTotal int64
|
||||||
|
MemAvail float64
|
||||||
|
MemTotal float64
|
||||||
|
DiskAvail float64
|
||||||
|
DiskTotal float64
|
||||||
|
GpuAvail int64
|
||||||
|
CardsAvail []*Card
|
||||||
|
CpuCoreHours float64
|
||||||
|
Balance float64
|
||||||
|
}
|
||||||
|
|
||||||
|
type Card struct {
|
||||||
|
Platform string
|
||||||
|
Type string
|
||||||
|
Name string
|
||||||
|
TOpsAtFp16 float64
|
||||||
|
CardHours float64
|
||||||
|
CardNum int32
|
||||||
|
}
|
||||||
|
|
|
@ -146,6 +146,10 @@ service pcm {
|
||||||
@handler jobHandler
|
@handler jobHandler
|
||||||
get /hpc/job (hpcJobReq) returns (hpcJobResp)
|
get /hpc/job (hpcJobReq) returns (hpcJobResp)
|
||||||
|
|
||||||
|
@doc "超算资源总览"
|
||||||
|
@handler resourceHandler
|
||||||
|
get /hpc/resource (hpcResourceReq) returns (hpcResourceResp)
|
||||||
|
|
||||||
@doc "超算查询资产列表"
|
@doc "超算查询资产列表"
|
||||||
@handler queueAssetsHandler
|
@handler queueAssetsHandler
|
||||||
get /hpc/queueAssets returns (QueueAssetsResp)
|
get /hpc/queueAssets returns (QueueAssetsResp)
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package hpc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/hpc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ResourceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.HpcResourceReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := hpc.NewResourceLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.Resource(&req)
|
||||||
|
if err != nil {
|
||||||
|
httpx.ErrorCtx(r.Context(), w, err)
|
||||||
|
} else {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -171,6 +171,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/hpc/job",
|
Path: "/hpc/job",
|
||||||
Handler: hpc.JobHandler(serverCtx),
|
Handler: hpc.JobHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/hpc/resource",
|
||||||
|
Handler: hpc.ResourceHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/hpc/queueAssets",
|
Path: "/hpc/queueAssets",
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package hpc
|
||||||
|
|
||||||
|
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 ResourceLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewResourceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResourceLogic {
|
||||||
|
return &ResourceLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ResourceLogic) Resource(req *types.HpcResourceReq) (resp *types.HpcResourceResp, err error) {
|
||||||
|
|
||||||
|
l.svcCtx.DbEngin.Raw("SELECT th.NAME as job_name,t.description as job_desc,t.commit_time as submit_time,th.STATUS as job_status,ta.name as adapter_name,tc.name as cluster_name,tc.label as cluster_type FROM task_hpc th LEFT JOIN task t ON t.id = th.task_id JOIN t_cluster tc on th.cluster_id = tc.id JOIN t_adapter ta on tc.adapter_id = ta.id")
|
||||||
|
|
||||||
|
hpcResource := types.HPCResource{
|
||||||
|
GPUCardsTotal: 0,
|
||||||
|
CPUCoresTotal: 0,
|
||||||
|
RAMTotal: 0,
|
||||||
|
GPUCardsUsed: 0,
|
||||||
|
CPUCoresUsed: 0,
|
||||||
|
RAMUsed: 0,
|
||||||
|
GPURate: 0,
|
||||||
|
CPURate: 0,
|
||||||
|
RAMRate: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp = &types.HpcResourceResp{
|
||||||
|
Code: 200,
|
||||||
|
Msg: "success",
|
||||||
|
HPCResource: hpcResource,
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
Loading…
Reference in New Issue