Merge branch 'master' of https://gitlink.org.cn/JointCloud/pcm-coordinator
# Conflicts: # desc/core/pcm-core.api # go.mod # go.sum # internal/handler/routes.go # internal/logic/hpc/commithpctasklogic.go # internal/types/types.go # pkg/models/taskaiasynchronousmodel_gen.go Former-commit-id: 1adf77da8a7f4a2903a69c839ea8f1e6d6697c60
This commit is contained in:
commit
f0cd6d5769
|
@ -1,4 +1,4 @@
|
|||
FROM --platform=$BUILDPLATFORM golang:1.22.4-alpine3.20 AS builder
|
||||
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<img src="https://www.gitlink.org.cn/images/avatars/Organization/123822?t=1689062058" alt="PCM" style="float:center" />
|
||||
|
||||
<div style="text-align:center">
|
||||
<img src="https://www.gitlink.org.cn/images/avatars/Organization/123822?t=1689062058" alt="PCM" style="float:center" />
|
||||
</div>
|
||||
<p align="center">
|
||||
<a href="https://www.gitlink.org.cn/JointCloud/pcm-coordinator/tree/master/docs">Docs</a> |
|
||||
<a href="https://www.gitlink.org.cn/JointCloud/pcm-coordinator/tree/master/docs">简体中文</a> |
|
||||
|
|
|
@ -222,7 +222,7 @@ type (
|
|||
ImageRef int64 `json:"imageRef,optional"`
|
||||
FlavorRef int64 `json:"flavorRef,optional"`
|
||||
Uuid int64 `json:"uuid,optional"`
|
||||
Replicas int64 `json:"replicas,string"`
|
||||
Replicas int64 `json:"replicas,optional"`
|
||||
VmName string `json:"vm_name,optional"`
|
||||
}
|
||||
TaskVm {
|
||||
|
@ -317,6 +317,30 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
type(
|
||||
asynCommitAiTaskReq{
|
||||
Name string `json:"name,optional"`
|
||||
AdapterIds []string `json:"adapterIds,optional"`
|
||||
ClusterIds []string `json:"clusterIds,optional"`
|
||||
Strategy string `json:"strategy,optional"`
|
||||
StaticWeightMap map[string]int32 `json:"staticWeightMap,optional"`
|
||||
Replicas int64 `json:"replicas,optional"`
|
||||
ImageId string `json:"imageId,optional"`
|
||||
Command string `json:"command,optional"`
|
||||
FlavorId string `json:"flavorId,optional"`
|
||||
Status string `json:"status,optional"`
|
||||
ClusterId int64 `json:"clusterId,optional"`
|
||||
AdapterId string `json:"adapterId,optional"`
|
||||
|
||||
}
|
||||
|
||||
asynCommitAiTaskResp{
|
||||
Code int32 `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
TaskId int64 `json:"taskId"`
|
||||
}
|
||||
)
|
||||
|
||||
type (
|
||||
scheduleTaskByYamlResp {
|
||||
TaskId int64 `json:"taskId"`
|
||||
|
@ -804,6 +828,7 @@ type (
|
|||
Version string `json:"version,omitempty" db:"version"`
|
||||
Server string `json:"server,omitempty" db:"server"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
|
||||
InfoName string `json:"info_name,omitempty"`
|
||||
}
|
||||
AdapterListResp {
|
||||
List []AdapterInfo `json:"list,omitempty"`
|
||||
|
@ -956,6 +981,24 @@ type ClusterRelationInfo {
|
|||
CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
type adapterInfoNameReq {
|
||||
AdapterId string `form:"adapterId,optional"`
|
||||
}
|
||||
|
||||
type adapterInfoNameReqResp {
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||
InfoList InfoList `json:"infoList,omitempty"`
|
||||
}
|
||||
|
||||
type InfoList {
|
||||
Type string `json:"type,omitempty"`
|
||||
ResourceType string `json:"resource_type,omitempty"`
|
||||
TName string `json:"name,omitempty"`
|
||||
InfoName string `json:"info_name,omitempty"`
|
||||
}
|
||||
|
||||
type (
|
||||
DictInfo {
|
||||
Id string `json:"id,omitempty"`
|
||||
|
|
|
@ -43,6 +43,10 @@ service pcm {
|
|||
@handler commitVmTaskHandler
|
||||
post /core/commitVmTask (commitVmTaskReq) returns (commitVmTaskResp)
|
||||
|
||||
@doc "异步提交智算任务"
|
||||
@handler asynCommitAiTaskHandler
|
||||
post /core/asynCommitAiTask (asynCommitAiTaskReq) returns (asynCommitAiTaskResp)
|
||||
|
||||
@doc "删除任务"
|
||||
@handler deleteTaskHandler
|
||||
delete /core/deleteTask/:id (deleteTaskReq)
|
||||
|
@ -884,6 +888,9 @@ service pcm {
|
|||
|
||||
@handler GetClusterSumHandler
|
||||
get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp)
|
||||
|
||||
@handler GetAdapterInfoHandler
|
||||
get /adapter/getAdapterInfo (adapterInfoNameReq) returns (adapterInfoNameReqResp)
|
||||
}
|
||||
|
||||
@server(
|
||||
|
|
2
go.mod
2
go.mod
|
@ -118,6 +118,8 @@ require (
|
|||
github.com/prometheus/exporter-toolkit v0.11.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/redis/go-redis/v9 v9.7.0 // indirect
|
||||
github.com/robfig/cron v1.2.0 // indirect
|
||||
github.com/rs/zerolog v1.33.0 // indirect
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
|
||||
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
|
||||
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
|
||||
|
|
12
go.sum
12
go.sum
|
@ -239,6 +239,7 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
|||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I=
|
||||
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
|
||||
|
@ -328,6 +329,7 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
|
|||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI=
|
||||
|
@ -421,11 +423,16 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
|
|||
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
|
||||
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
|
||||
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
|
||||
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
|
||||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
|
||||
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c h1:aqg5Vm5dwtvL+YgDpBcK1ITf3o96N/K7/wsRXQnUTEs=
|
||||
|
@ -467,6 +474,10 @@ github.com/zeromicro/go-zero v1.7.3 h1:yDUQF2DXDhUHc77/NZF6mzsoRPMBfldjPmG2O/ZSz
|
|||
github.com/zeromicro/go-zero v1.7.3/go.mod h1:9JIW3gHBGuc9LzvjZnNwINIq9QdiKu3AigajLtkJamQ=
|
||||
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240920093406-601f283f0185 h1:B+YBB5xHlIAS6ILuaCGQwbOpr/L6LOHAlj9PeFUCetM=
|
||||
gitlink.org.cn/JointCloud/pcm-ac v0.0.0-20240920093406-601f283f0185/go.mod h1:3eECiw9O2bIFkkePlloKyLNXiqBAhOxNrDoGaaGseGY=
|
||||
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241026031230-3aa955d47f8b h1:VsS+4OnW6iTB7OFzAQ4Pm1c7iYPgprO+jvhEEresgrQ=
|
||||
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241026031230-3aa955d47f8b/go.mod h1:0tMb2cfE73vdFC3AZmPdfH7NwQYhpwsjdFyh2ZdOfY0=
|
||||
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241026032032-93358313f083 h1:yX66OOXOamj0U/NyTLUDMxqTjpR5jo/HYs2rLhEP4Ps=
|
||||
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241026032032-93358313f083/go.mod h1:0tMb2cfE73vdFC3AZmPdfH7NwQYhpwsjdFyh2ZdOfY0=
|
||||
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241026041404-af824802cfc8 h1:74Sgm3izTWGiENLQQKf/DUCHUds9vU4OigXvYi4d9Pc=
|
||||
gitlink.org.cn/JointCloud/pcm-hpc v0.0.0-20241026041404-af824802cfc8/go.mod h1:0tMb2cfE73vdFC3AZmPdfH7NwQYhpwsjdFyh2ZdOfY0=
|
||||
gitlink.org.cn/JointCloud/pcm-modelarts v0.0.0-20240918011543-482dcd609877 h1:a+1FpxqLPRojlAkJlAeRhKRbxajymXYgrM+s9bfQx0E=
|
||||
|
@ -665,6 +676,7 @@ golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/adapters"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
)
|
||||
|
||||
func GetAdapterInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterInfoNameReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewGetAdapterInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAdapterInfo(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/core"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
)
|
||||
|
||||
// 异步提交智算任务
|
||||
func AsynCommitAiTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AsynCommitAiTaskReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := core.NewAsynCommitAiTaskLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AsynCommitAiTask(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -6,8 +6,10 @@ import (
|
|||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -68,5 +70,33 @@ func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *t
|
|||
|
||||
_ = l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&existAdapter).Error
|
||||
resp = &existAdapter
|
||||
Tadapter := models.TAdapterInfo{}
|
||||
if req.Type == "0" {
|
||||
if req.ResourceType == "01" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "CloudInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "CloudInfoList"
|
||||
} else if req.ResourceType == "02" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "VmInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "VmInfoList"
|
||||
}
|
||||
} else if req.Type == "1" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "AiInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "AiInfoList"
|
||||
} else if req.Type == "2" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "HpcInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "HpcInfoList"
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetAdapterInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetAdapterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterInfoLogic {
|
||||
return &GetAdapterInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetAdapterInfoLogic) GetAdapterInfo(req *types.AdapterInfoNameReq) (resp *types.AdapterInfoNameReqResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
resp = &types.AdapterInfoNameReqResp{}
|
||||
var infoNameReqResp types.AdapterInfoNameReqResp
|
||||
sql := `SELECT ta.type AS Type,ta.resource_type AS ResourceType,ta.name AS TName,tai.info_name AS InfoName FROM t_adapter ta LEFT JOIN t_adapter_info tai ON ta.id = tai.adapter_id WHERE ta.id = ?`
|
||||
tx := l.svcCtx.DbEngin.Raw(sql, req.AdapterId).Scan(&infoNameReqResp.InfoList)
|
||||
if tx.Error != nil {
|
||||
logx.Error(err)
|
||||
return nil, tx.Error
|
||||
}
|
||||
resp.Code = 200
|
||||
resp.Msg = "success"
|
||||
resp.InfoList = infoNameReqResp.InfoList
|
||||
return resp, nil
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
clientCore "gitlink.org.cn/JointCloud/pcm-coordinator/client"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"time"
|
||||
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AsynCommitAiTaskLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
// 异步提交智算任务
|
||||
func NewAsynCommitAiTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AsynCommitAiTaskLogic {
|
||||
return &AsynCommitAiTaskLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AsynCommitAiTaskLogic) AsynCommitAiTask(req *types.AsynCommitAiTaskReq) (resp *types.AsynCommitAiTaskResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
resp = &types.AsynCommitAiTaskResp{}
|
||||
var adapterName string
|
||||
var clusterName string
|
||||
var adapterId int64
|
||||
|
||||
//TODO adapter
|
||||
//adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64)
|
||||
//taskAiAsynchronous := models.TaskAiAsynchronous{}
|
||||
|
||||
// 构建主任务结构体
|
||||
taskModel := models.Task{
|
||||
Name: req.Name,
|
||||
Description: "ai asynchronous task",
|
||||
CommitTime: time.Now(),
|
||||
Status: "Saved",
|
||||
AdapterTypeDict: "1",
|
||||
}
|
||||
// 保存任务数据到数据库
|
||||
tx := l.svcCtx.DbEngin.Create(&taskModel)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
l.svcCtx.DbEngin.Raw("SELECT nickname FROM `t_cluster` where id = ?", req.ClusterId).Scan(&clusterName)
|
||||
l.svcCtx.DbEngin.Raw("SELECT adapter_id FROM `t_cluster` where id = ?", req.ClusterId).Scan(&adapterId)
|
||||
l.svcCtx.DbEngin.Raw("SELECT name FROM `t_adapter` where id = ?", adapterId).Scan(&adapterName)
|
||||
if len(adapterName) == 0 || adapterName == "" {
|
||||
return nil, errors.New("no corresponding adapter found")
|
||||
}
|
||||
|
||||
AiAsynchronousInfo := models.TaskAiAsynchronous{
|
||||
TaskId: taskModel.Id,
|
||||
AdapterId: adapterId,
|
||||
AdapterName: adapterName,
|
||||
ClusterId: req.ClusterId,
|
||||
ClusterName: clusterName,
|
||||
Name: "trainJob" + utils.RandomString(10),
|
||||
StartTime: time.Now().String(),
|
||||
Status: "Saved",
|
||||
ImageId: req.ImageId,
|
||||
Command: req.Command,
|
||||
FlavorId: req.FlavorId,
|
||||
}
|
||||
tx = l.svcCtx.DbEngin.Create(&AiAsynchronousInfo)
|
||||
if tx.Error != nil {
|
||||
return nil, tx.Error
|
||||
}
|
||||
|
||||
noticeInfo := clientCore.NoticeInfo{
|
||||
AdapterId: adapterId,
|
||||
AdapterName: adapterName,
|
||||
ClusterId: req.ClusterId,
|
||||
ClusterName: clusterName,
|
||||
NoticeType: "create",
|
||||
TaskName: req.Name,
|
||||
Incident: "任务创建中",
|
||||
}
|
||||
result := l.svcCtx.DbEngin.Table("t_notice").Create(¬iceInfo)
|
||||
if result.Error != nil {
|
||||
logx.Errorf("Task creation failure, err: %v", result.Error)
|
||||
}
|
||||
resp = &types.AsynCommitAiTaskResp{
|
||||
Code: 200,
|
||||
Msg: "success",
|
||||
TaskId: taskModel.Id,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
12528
internal/types/types.go
12528
internal/types/types.go
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,29 @@
|
|||
package models
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ TAdapterInfoModel = (*customTAdapterInfoModel)(nil)
|
||||
|
||||
type (
|
||||
// TAdapterInfoModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customTAdapterInfoModel.
|
||||
TAdapterInfoModel interface {
|
||||
tAdapterInfoModel
|
||||
withSession(session sqlx.Session) TAdapterInfoModel
|
||||
}
|
||||
|
||||
customTAdapterInfoModel struct {
|
||||
*defaultTAdapterInfoModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewTAdapterInfoModel returns a model for the database table.
|
||||
func NewTAdapterInfoModel(conn sqlx.SqlConn) TAdapterInfoModel {
|
||||
return &customTAdapterInfoModel{
|
||||
defaultTAdapterInfoModel: newTAdapterInfoModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customTAdapterInfoModel) withSession(session sqlx.Session) TAdapterInfoModel {
|
||||
return NewTAdapterInfoModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
tAdapterInfoFieldNames = builder.RawFieldNames(&TAdapterInfo{})
|
||||
tAdapterInfoRows = strings.Join(tAdapterInfoFieldNames, ",")
|
||||
tAdapterInfoRowsExpectAutoSet = strings.Join(stringx.Remove(tAdapterInfoFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
tAdapterInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(tAdapterInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
tAdapterInfoModel interface {
|
||||
Insert(ctx context.Context, data *TAdapterInfo) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*TAdapterInfo, error)
|
||||
Update(ctx context.Context, data *TAdapterInfo) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultTAdapterInfoModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
TAdapterInfo struct {
|
||||
Id int64 `db:"id"` // 主键
|
||||
AdapterId int64 `db:"adapter_id"` // 适配器id
|
||||
InfoName string `db:"info_name"` // 对象类型名称
|
||||
}
|
||||
)
|
||||
|
||||
func newTAdapterInfoModel(conn sqlx.SqlConn) *defaultTAdapterInfoModel {
|
||||
return &defaultTAdapterInfoModel{
|
||||
conn: conn,
|
||||
table: "`t_adapter_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) Delete(ctx context.Context, id int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) FindOne(ctx context.Context, id int64) (*TAdapterInfo, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", tAdapterInfoRows, m.table)
|
||||
var resp TAdapterInfo
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) Insert(ctx context.Context, data *TAdapterInfo) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, tAdapterInfoRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.AdapterId, data.InfoName)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) Update(ctx context.Context, data *TAdapterInfo) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, tAdapterInfoRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.AdapterId, data.InfoName, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) tableName() string {
|
||||
return m.table
|
||||
}
|
|
@ -16,7 +16,7 @@ import (
|
|||
var (
|
||||
taskAiAsynchronousFieldNames = builder.RawFieldNames(&TaskAiAsynchronous{})
|
||||
taskAiAsynchronousRows = strings.Join(taskAiAsynchronousFieldNames, ",")
|
||||
taskAiAsynchronousRowsExpectAutoSet = strings.Join(stringx.Remove(taskAiAsynchronousFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
taskAiAsynchronousRowsExpectAutoSet = strings.Join(stringx.Remove(taskAiAsynchronousFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
taskAiAsynchronousRowsWithPlaceHolder = strings.Join(stringx.Remove(taskAiAsynchronousFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
|
@ -82,8 +82,8 @@ func (m *defaultTaskAiAsynchronousModel) FindOne(ctx context.Context, id int64)
|
|||
}
|
||||
|
||||
func (m *defaultTaskAiAsynchronousModel) Insert(ctx context.Context, data *TaskAiAsynchronous) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskAiAsynchronousRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.TaskId, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.Name, data.Replica, data.JobId, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.ImageId, data.Command, data.FlavorId, data.Status)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, taskAiAsynchronousRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.TaskId, data.AdapterId, data.AdapterName, data.ClusterId, data.ClusterName, data.Name, data.Replica, data.JobId, data.StartTime, data.RunningTime, data.Result, data.DeletedAt, data.ImageId, data.Command, data.FlavorId, data.Status)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue