数算列表接口

Former-commit-id: 1086a71a5fc77ce13f8c143218d7985985ef85f2
This commit is contained in:
zhangwei 2023-08-31 17:32:44 +08:00
parent 8dc3c3b51a
commit 13fad5ec21
10 changed files with 158 additions and 115 deletions

View File

@ -34,3 +34,24 @@ type DataSet{
Name string `json:"name,omitempty"`
NameSpace string `json:"nameSpace,omitempty"`
}
type cloudListResp {
Clouds []Cloud `json:"clouds"`
}
type Cloud{
Id int64 `json:"id"` // id
TaskId int64 `json:"taskId"` // 任务id
ParticipantId int64 `json:"participantId"` // 集群静态信息id
ApiVersion string `json:"apiVersion"`
Name string `json:"name"` // 名称
Namespace string `json:"namespace"` // 命名空间
Kind string `json:"kind"` // 种类
Status string `json:"status"` // 状态
StartTime string `json:"startTime"` // 开始时间
RunningTime int64 `json:"runningTime"` // 运行时长
CreatedBy int64 `json:"createdBy"` // 创建人
CreatedTime string `json:"createdTime"` // 创建时间
YamlString string `json:"yamlString"`
Result string `json:"result"`
}

View File

@ -92,8 +92,8 @@ service pcm {
group : cloud
)
service pcm {
@handler applyYamlHandler
get /cloud/ApplyYaml (ApplyReq) returns (ApplyResp)
@handler cloudListHandler
get /task/list () returns (cloudListResp)
@handler deleteYamlHandler
get /cloud/DeleteYaml (ApplyReq) returns (DeleteResp)

View File

@ -1,28 +0,0 @@
package cloud
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
)
func ApplyYamlHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ApplyReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := cloud.NewApplyYamlLogic(r.Context(), svcCtx)
resp, err := l.ApplyYaml(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -0,0 +1,17 @@
package cloud
import (
"gitlink.org.cn/jcce-pcm/utils/result"
"net/http"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
)
func CloudListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := cloud.NewCloudListLogic(r.Context(), svcCtx)
resp, err := l.CloudList()
result.HttpResult(r, w, resp, err)
}
}

View File

@ -123,8 +123,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodGet,
Path: "/cloud/ApplyYaml",
Handler: cloud.ApplyYamlHandler(serverCtx),
Path: "/task/list",
Handler: cloud.CloudListHandler(serverCtx),
},
{
Method: http.MethodGet,

View File

@ -1,30 +0,0 @@
package cloud
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ApplyYamlLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewApplyYamlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyYamlLogic {
return &ApplyYamlLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ApplyYamlLogic) ApplyYaml(req *types.ApplyReq) (resp *types.ApplyResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -0,0 +1,38 @@
package cloud
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/model"
"gitlink.org.cn/jcce-pcm/utils/tool"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type CloudListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCloudListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CloudListLogic {
return &CloudListLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CloudListLogic) CloudList() (resp *types.CloudListResp, err error) {
// 查询数据库中数算任务列表
var clouds []*model.Cloud
tx := l.svcCtx.DbEngin.Find(&clouds)
if tx.Error != nil {
return nil, tx.Error
}
result := types.CloudListResp{}
tool.Convert(clouds, &result.Clouds)
return &result, nil
}

View File

@ -17,6 +17,7 @@ func NewHpcScheduler(val string) *hpcScheduler {
func (h *hpcScheduler) getNewStructForDb(task *types.TaskInfo, participantId int64) (interface{}, error) {
hpc := model.Hpc{
Id: tool.GenSnowflakeID(),
TaskId: task.TaskId,
Status: "Saved",
ParticipantId: participantId,

View File

@ -2592,3 +2592,24 @@ type DataSet struct {
Name string `json:"name,omitempty"`
NameSpace string `json:"nameSpace,omitempty"`
}
type CloudListResp struct {
Clouds []Cloud `json:"clouds"`
}
type Cloud struct {
Id int64 `json:"id"` // id
TaskId int64 `json:"taskId"` // 任务id
ParticipantId int64 `json:"participantId"` // 集群静态信息id
ApiVersion string `json:"apiVersion"`
Name string `json:"name"` // 名称
Namespace string `json:"namespace"` // 命名空间
Kind string `json:"kind"` // 种类
Status string `json:"status"` // 状态
StartTime string `json:"startTime"` // 开始时间
RunningTime int64 `json:"runningTime"` // 运行时长
CreatedBy int64 `json:"createdBy"` // 创建人
CreatedTime string `json:"createdTime"` // 创建时间
YamlString string `json:"yamlString"`
Result string `json:"result"`
}

View File

@ -45,8 +45,11 @@ func (l *SyncInfoLogic) SyncInfo(in *pcmCore.SyncInfoReq) (*pcmCore.SyncInfoResp
}
case "hpc":
for _, hpcInfo := range in.HpcInfoList {
tx := db.Exec("update hpc set status = ?,derived_es = ?,assoc_id = ?,exit_code = ?,version = ?,alloc_cpu = ?,alloc_nodes = ?,cluster = ?,block_id = ?,start_time = ?,running_time = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?",
hpcInfo.Status, hpcInfo.DerivedEs, hpcInfo.AssocId, hpcInfo.ExitCode, hpcInfo.Version, hpcInfo.AllocCpu, hpcInfo.AllocNodes, hpcInfo.Cluster, hpcInfo.BlockId, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, in.ParticipantId, hpcInfo.TaskId, hpcInfo.Name)
//tx := db.Exec("update hpc set status = ?,derived_es = ?,assoc_id = ?,exit_code = ?,version = ?,alloc_cpu = ?,alloc_nodes = ?,cluster = ?,block_id = ?,start_time = ?,running_time = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?",
// hpcInfo.Status, hpcInfo.DerivedEs, hpcInfo.AssocId, hpcInfo.ExitCode, hpcInfo.Version, hpcInfo.AllocCpu, hpcInfo.AllocNodes, hpcInfo.Cluster, hpcInfo.BlockId, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, in.ParticipantId, hpcInfo.TaskId, hpcInfo.Name)
//print(tx.Error)
tx := db.Exec("update hpc set status = ?,start_time = ?,running_time = ?,job_id = ? where participant_id = ? and task_id = ? and name = ?",
hpcInfo.Status, hpcInfo.StartTime, hpcInfo.RunningTime, hpcInfo.JobId, in.ParticipantId, hpcInfo.TaskId, hpcInfo.Name)
print(tx.Error)
}
case "ai":