forked from JointCloud/pcm-ac
107 lines
3.3 KiB
Go
107 lines
3.3 KiB
Go
package cron
|
|
|
|
import (
|
|
"context"
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/rpc/pcmCore"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcAC"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/hpcacclient"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/logic"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/pkg/utils"
|
|
"gitlink.org.cn/jcce-pcm/pcm-ac/internal/svc"
|
|
)
|
|
|
|
func SyncTask(svc *svc.ServiceContext) {
|
|
|
|
submitJobLogic := logic.NewSubmitJobLogic(context.Background(), svc)
|
|
listLogic := logic.NewListJobLogic(context.Background(), svc)
|
|
|
|
participantId, err := utils.GetParticipantId("etc/hpcac.yaml")
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
// 查询core端分发下来的任务列表
|
|
infoReq := pcmCore.InfoListReq{
|
|
ParticipantId: participantId,
|
|
}
|
|
infoList, err := svc.PcmCoreRpc.InfoList(context.Background(), &infoReq)
|
|
if err != nil {
|
|
logx.Error(err)
|
|
return
|
|
}
|
|
|
|
if len(infoList.HpcInfoList) != 0 {
|
|
|
|
for index := range infoList.HpcInfoList {
|
|
if infoList.HpcInfoList[index].Status == "Saved" {
|
|
subReq := hpcAC.SubmitJobReq{
|
|
Apptype: infoList.HpcInfoList[index].AppType,
|
|
Appname: infoList.HpcInfoList[index].AppName,
|
|
StrJobManagerID: 1637920656,
|
|
MapAppJobInfo: &hpcAC.MapAppJobInfo{
|
|
GAP_CMD_FILE: infoList.HpcInfoList[index].CmdScript,
|
|
GAP_NNODE: infoList.HpcInfoList[index].NNode,
|
|
GAP_NODE_STRING: "",
|
|
GAP_SUBMIT_TYPE: infoList.HpcInfoList[index].SubmitType,
|
|
GAP_JOB_NAME: infoList.HpcInfoList[index].Name,
|
|
GAP_WORK_DIR: infoList.HpcInfoList[index].WorkDir,
|
|
GAP_QUEUE: infoList.HpcInfoList[index].Queue,
|
|
GAP_NPROC: "1",
|
|
GAP_NDCU: "1",
|
|
GAP_WALL_TIME: infoList.HpcInfoList[index].WallTime,
|
|
GAP_APPNAME: infoList.HpcInfoList[index].AppName,
|
|
GAP_STD_OUT_FILE: infoList.HpcInfoList[index].StdOutFile,
|
|
GAP_STD_ERR_FILE: infoList.HpcInfoList[index].StdErrFile,
|
|
},
|
|
}
|
|
jobResult, err := submitJobLogic.SubmitJob(&subReq)
|
|
if jobResult.Code == "0" {
|
|
infoList.HpcInfoList[index].Status = "Pending"
|
|
infoList.HpcInfoList[index].JobId = jobResult.Data
|
|
} else {
|
|
infoList.HpcInfoList[index].Status = "Failed"
|
|
infoList.HpcInfoList[index].Result = jobResult.Msg
|
|
}
|
|
// 同步信息到core端
|
|
SyncInfoReq := pcmCore.SyncInfoReq{
|
|
ParticipantId: participantId,
|
|
HpcInfoList: infoList.HpcInfoList,
|
|
}
|
|
_, err = svc.PcmCoreRpc.SyncInfo(context.Background(), &SyncInfoReq)
|
|
if err != nil {
|
|
return
|
|
}
|
|
} else if infoList.HpcInfoList[index].Status == "Pending" || infoList.HpcInfoList[index].Status == "Running" {
|
|
// 查询P端实际的任务列表
|
|
listReq := hpcacclient.ListJobReq{}
|
|
resp, _ := listLogic.ListJob(&listReq)
|
|
for _, job := range resp.Jobs {
|
|
if job.JobId == infoList.HpcInfoList[index].JobId {
|
|
var pcmState = svc.Config.AcStatus[job.JobStatus]
|
|
if pcmState == "" {
|
|
infoList.HpcInfoList[index].Status = "Other"
|
|
} else {
|
|
infoList.HpcInfoList[index].Status = pcmState
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// 同步信息到core端
|
|
SyncInfoReq := pcmCore.SyncInfoReq{
|
|
ParticipantId: participantId,
|
|
HpcInfoList: infoList.HpcInfoList,
|
|
}
|
|
_, err := svc.PcmCoreRpc.SyncInfo(context.Background(), &SyncInfoReq)
|
|
if err != nil {
|
|
return
|
|
}
|
|
} else {
|
|
return
|
|
}
|
|
|
|
// 提交任务
|
|
|
|
}
|