创建任务返回任务id

This commit is contained in:
zhangwei 2025-06-18 19:12:17 +08:00
parent a32cd79157
commit 3e9d9efcd7
6 changed files with 7062 additions and 7255 deletions

View File

@ -170,6 +170,10 @@ type (
UserIp string `json:"userIp,optional"` UserIp string `json:"userIp,optional"`
} }
GeneralTaskResp {
TaskId int64 `json:"taskId"`
}
PodLogsReq { PodLogsReq {
TaskId string `json:"taskId"` TaskId string `json:"taskId"`
TaskName string `json:"taskName"` TaskName string `json:"taskName"`

View File

@ -211,7 +211,7 @@ service pcm {
@doc "获取资源规格范围" @doc "获取资源规格范围"
@handler resourceRange @handler resourceRange
get /core/ai/resourceSpec/range (ResourceSpecReq) returns (ListResult) get /core/ai/resourceSpec/range (ResourceSpecReq) returns (ListResult)
//集群资源规格----- 结束 //集群资源规格----- 结束
} }
//hpc二级接口 //hpc二级接口
@ -297,7 +297,7 @@ service pcm {
@doc "Create cloud computing common tasks" @doc "Create cloud computing common tasks"
@handler commitGeneralTask @handler commitGeneralTask
post /cloud/task/create (GeneralTaskReq) post /cloud/task/create (GeneralTaskReq) returns (GeneralTaskResp)
@handler podLogs @handler podLogs
post /cloud/pod/logs (PodLogsReq) returns (string) post /cloud/pod/logs (PodLogsReq) returns (string)
@ -456,7 +456,7 @@ service pcm {
@doc "文本识别" @doc "文本识别"
@handler ChatHandler @handler ChatHandler
post /ai/chat (ChatReq) returns (ChatResult) post /ai/chat (ChatReq) returns (ChatResult)
/******chat end***********/ /******chat end***********/
} }
//screen接口 //screen接口
@ -1145,5 +1145,4 @@ service pcm {
@handler scheduleSituationHandler @handler scheduleSituationHandler
get /monitoring/schedule/situation returns (scheduleSituationResp) get /monitoring/schedule/situation returns (scheduleSituationResp)
} }

View File

@ -1,15 +1,16 @@
package cloud package cloud
import ( import (
"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"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"net/http" "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 CommitGeneralTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { func CommitGeneralTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@ -32,7 +33,7 @@ func CommitGeneralTaskHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
json.Unmarshal([]byte(userStr), user) json.Unmarshal([]byte(userStr), user)
req.UserId = user.Id req.UserId = user.Id
l := cloud.NewCommitGeneralTaskLogic(r.Context(), svcCtx) l := cloud.NewCommitGeneralTaskLogic(r.Context(), svcCtx)
err := l.CommitGeneralTask(&req) resp, err := l.CommitGeneralTask(&req)
result.HttpResult(r, w, nil, err) result.HttpResult(r, w, resp, err)
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,9 @@ func NewCommitGeneralTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext)
} }
} }
func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) error { func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) (resp *types.GeneralTaskResp, err error) {
// todo: add your logic here and delete this line
resp = &types.GeneralTaskResp{}
tx := l.svcCtx.DbEngin.Begin() tx := l.svcCtx.DbEngin.Begin()
// 执行回滚或者提交操作 // 执行回滚或者提交操作
defer func() { defer func() {
@ -60,10 +62,10 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
}() }()
adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64) adapterId, _ := strconv.ParseUint(req.AdapterIds[0], 10, 64)
var clusters []*models.CloudModel var clusters []*models.CloudModel
err := tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error err = tx.Raw("SELECT * FROM `t_cluster` where adapter_id in ? and id in ?", req.AdapterIds, req.ClusterIds).Scan(&clusters).Error
if err != nil { if err != nil {
logx.Errorf("CommitGeneralTask() => sql execution error: %v", err) logx.Errorf("CommitGeneralTask() => sql execution error: %v", err)
return errors.Errorf("the cluster does not match the drive resources. Check the data") return nil, errors.Errorf("the cluster does not match the drive resources. Check the data")
} }
taskCloud := cloud.TaskCloudModel{} taskCloud := cloud.TaskCloudModel{}
opt := &option.CloudOption{} opt := &option.CloudOption{}
@ -73,7 +75,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
results, err := l.svcCtx.Scheduler.AssignAndSchedule(sc, executor.SUBMIT_MODE_JOINT_CLOUD, nil) results, err := l.svcCtx.Scheduler.AssignAndSchedule(sc, executor.SUBMIT_MODE_JOINT_CLOUD, nil)
if err != nil { if err != nil {
logx.Errorf("AssignAndSchedule() => execution error: %v", err) logx.Errorf("AssignAndSchedule() => execution error: %v", err)
return err return nil, err
} }
rs := (results).([]*schedulers.CloudResult) rs := (results).([]*schedulers.CloudResult)
@ -101,6 +103,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
Strategy: strategy, Strategy: strategy,
UserId: req.UserId, UserId: req.UserId,
} }
resp.TaskId = taskModel.Id
var taskClouds []cloud.TaskCloudModel var taskClouds []cloud.TaskCloudModel
adapterName := "" adapterName := ""
tx.Table("t_adapter").Select("name").Where("id=?", adapterId).Find(&adapterName) tx.Table("t_adapter").Select("name").Where("id=?", adapterId).Find(&adapterName)
@ -138,12 +141,12 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
if db.Error != nil { if db.Error != nil {
logx.Errorf("Task creation failure, err: %v", db.Error) logx.Errorf("Task creation failure, err: %v", db.Error)
return errors.New("task creation failure") return nil, errors.New("task creation failure")
} }
// 数据上链 // 数据上链
bytes, _ := json.Marshal(taskModel) bytes, _ := json.Marshal(taskModel)
if err != nil { if err != nil {
return err return nil, err
} }
// 查询资源价格 // 查询资源价格
var price int64 var price int64
@ -163,7 +166,7 @@ func (l *CommitGeneralTaskLogic) CommitGeneralTask(req *types.GeneralTaskReq) er
Amount: price, Amount: price,
Args: []string{strconv.FormatInt(taskModel.Id, 10), string(bytes)}, Args: []string{strconv.FormatInt(taskModel.Id, 10), string(bytes)},
}) })
return nil return resp, nil
} }
func UnMarshalK8sStruct(yamlString string, replica int64) *unstructured.Unstructured { func UnMarshalK8sStruct(yamlString string, replica int64) *unstructured.Unstructured {

File diff suppressed because it is too large Load Diff