This commit is contained in:
450705171@qq.com 2023-02-15 10:19:25 +08:00
parent 3fb2fc751a
commit 0dde352c0a
12 changed files with 230 additions and 269 deletions

View File

@ -1,28 +0,0 @@
package handler
import (
"net/http"
"PCM/app/slurm/slurmCore/api/internal/logic"
"PCM/app/slurm/slurmCore/api/internal/svc"
"PCM/app/slurm/slurmCore/api/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func GetDomainSummaryHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.GetDomainSummaryReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewGetDomainSummaryLogic(r.Context(), svcCtx)
resp, err := l.GetDomainSummary(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -1,28 +0,0 @@
package handler
import (
"net/http"
"PCM/app/slurm/slurmCore/api/internal/logic"
"PCM/app/slurm/slurmCore/api/internal/svc"
"PCM/app/slurm/slurmCore/api/internal/types"
"github.com/zeromicro/go-zero/rest/httpx"
)
func ListDomainHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ListDomainReq
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := logic.NewListDomainLogic(r.Context(), svcCtx)
resp, err := l.ListDomain(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@ -12,16 +12,6 @@ import (
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodGet,
Path: "/listDomain",
Handler: ListDomainHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/getDomainSummary",
Handler: GetDomainSummaryHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/listHistoryJob",

View File

@ -1,30 +0,0 @@
package logic
import (
"context"
"PCM/app/slurm/slurmCore/api/internal/svc"
"PCM/app/slurm/slurmCore/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type GetDomainSummaryLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetDomainSummaryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDomainSummaryLogic {
return &GetDomainSummaryLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetDomainSummaryLogic) GetDomainSummary(req *types.GetDomainSummaryReq) (resp *types.GetDomainSummaryResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -1,30 +0,0 @@
package logic
import (
"context"
"PCM/app/slurm/slurmCore/api/internal/svc"
"PCM/app/slurm/slurmCore/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ListDomainLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewListDomainLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListDomainLogic {
return &ListDomainLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ListDomainLogic) ListDomain(req *types.ListDomainReq) (resp *types.ListDomainResp, err error) {
// todo: add your logic here and delete this line
return
}

View File

@ -2,6 +2,7 @@ package logic
import (
"PCM/app/slurm/slurmShuguang/rpc/slurmShuguang"
"PCM/common/tool"
"PCM/common/xerr"
"context"
"github.com/jinzhu/copier"
@ -29,11 +30,30 @@ func NewListHistoryJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Li
func (l *ListHistoryJobLogic) ListHistoryJob(req *types.ListHistoryJobReq) (resp *types.ListHistoryJobResp, err error) {
listDbJobsResp, err := l.svcCtx.ShuguangRpc.ListHistoryJob(l.ctx, &slurmShuguang.ListHistoryJobReq{})
shuguangReq := &slurmShuguang.ListHistoryJobReq{}
err = copier.CopyWithOption(shuguangReq, req, copier.Option{Converters: tool.Converters})
if err != nil {
return nil, err
}
//copier.Copy(shuguangReq, req)
listHistoryJobResp, err := l.svcCtx.ShuguangRpc.ListHistoryJob(l.ctx, shuguangReq)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get db job list"), "Failed to get db job list err : %v ,req:%+v", err, req)
}
copier.Copy(resp, &listDbJobsResp)
resp = &types.ListHistoryJobResp{}
for i := 0; i < len(listHistoryJobResp.HistoryJobs); i++ {
historyJob := types.HistoryJob{}
resp.HistoryJobs = append(resp.HistoryJobs, historyJob)
}
err = copier.CopyWithOption(&resp, &listHistoryJobResp, copier.Option{Converters: tool.Converters})
if err != nil {
return nil, err
}
for i := range resp.HistoryJobs {
resp.HistoryJobs[i].SlurmVersion = "shuguang"
}
return resp, nil
}

View File

@ -21,98 +21,76 @@ type DomainSummary {
}
type HistoryJob {
SlurmVersion string `json:"slurmVersion" copier:"SlurmVersion"`
AllocCPU uint32 `json:"allocCPU" copier:"AllocCPU"`
AllocNodes uint32 `json:"allocNodes" copier:"AllocNodes"` //Nodect 分配的节点数 in shuguang
Account string `json:"account" copier:"Account"`
AssocId uint32 `json:"assocId" copier:"AssocId"`
BlockId string `json:"blockId" copier:"BlockId"`
Cluster string `json:"cluster" copier:"Cluster"`
DerivedEc uint32 `json:"derivedEc" copier:"DerivedEc"`
DerivedEs string `json:"derivedEs" copier:"DerivedEs"`
Elapsed uint32 `json:"elapsed" copier:"Elapsed"`
Eligible int64 `json:"eligible" copier:"Eligible"`
End int64 `json:"end" copier:"End"` //JobEndTime 作业结束时间 in shuguang
ExitCode uint32 `json:"exitCode" copier:"ExitCode"` //JobExitStatus 作业退出码 in shuguang
Gid uint32 `json:"gid" copier:"Gid"`
JobId uint32 `json:"jobId" copier:"JobId"` //JobId in shuguang
JobName string `json:"jobName" copier:"JobName"` //JobName in shuguang
Lft uint32 `json:"lft" copier:"Lft"`
Partition string `json:"partition" copier:"Partition"` //Queue 队列名 in shuguang
Nodes string `json:"nodes" copier:"Nodes"` //JobExecHost 作业执行节点 in shuguang
Priority uint32 `json:"priority" copier:"Priority"`
Qosid uint32 `json:"qosid" copier:"Qosid"`
ReqCpus uint32 `json:"reqCpus" copier:"ReqCpus"`
ReqMem uint32 `json:"reqMem" copier:"ReqMem"`
Requid uint32 `json:"requid" copier:"Requid"`
Resvid uint32 `json:"resvid" copier:"Resvid"`
ShowFull uint32 `json:"showFull" copier:"ShowFull"`
Start int64 `json:"start" copier:"Start"` //JobStartTime 作业启动时间 in shuguang
State uint32 `json:"state" copier:"State"` //JobState 作业状态 in shuguang
Submit int64 `json:"submit" copier:"Submit"`
Suspended uint32 `json:"suspended" copier:"Suspended"`
SysCpuSec uint32 `json:"sysCpuSec" copier:"SysCpuSec"`
SysCpuUsec uint32 `json:"sysCpuUsec" copier:"SysCpuUsec"`
Timelimit uint32 `json:"timelimit" copier:"Timelimit"`
TotCpuSec uint32 `json:"totCpuSec" copier:"TotCpuSec"`
TotCpuUsec uint32 `json:"totCpuUsec" copier:"TotCpuUsec"`
TrackSteps uint32 `json:"trackSteps" copier:"TrackSteps"`
Uid uint32 `json:"uid" copier:"Uid"`
User string `json:"user" copier:"User"` //UserName 用户名 in shuguang
UserCpuSec uint32 `json:"userCpuSec" copier:"UserCpuSec"`
UserCpuUsec uint32 `json:"userCpuUsec" copier:"UserCpuUsec"`
Wckey string `json:"wckey" copier:"Wckey"`
Wckeyid uint32 `json:"wckeyid" copier:"Wckeyid"`
WorkDir string `json:"workDir" copier:"WorkDir"` //Workdir 工作空间 in shuguang
SlurmVersion string `json:"slurmVersion"`
AllocCPU uint32 `json:"allocCPU"`
AllocNodes uint32 `json:"allocNodes"` //Nodect 分配的节点数 in shuguang
Account string `json:"account"`
AssocId uint32 `json:"assocId"`
BlockId string `json:"blockId"`
Cluster string `json:"cluster"`
DerivedEc uint32 `json:"derivedEc"`
DerivedEs string `json:"derivedEs"`
Elapsed uint32 `json:"elapsed"`
Eligible int64 `json:"eligible"`
End int64 `json:"end"` //JobEndTime 作业结束时间 in shuguang
ExitCode uint32 `json:"exitCode"` //JobExitStatus 作业退出码 in shuguang
Gid uint32 `json:"gid"`
JobId uint32 `json:"jobId"` //JobId in shuguang
JobName string `json:"jobName"` //JobName in shuguang
Lft uint32 `json:"lft"`
Partition string `json:"partition"` //Queue 队列名 in shuguang
Nodes string `json:"nodes"` //JobExecHost 作业执行节点 in shuguang
Priority uint32 `json:"priority"`
Qosid uint32 `json:"qosid"`
ReqCpus uint32 `json:"reqCpus"`
ReqMem uint32 `json:"reqMem"`
Requid uint32 `json:"requid"`
Resvid uint32 `json:"resvid"`
ShowFull uint32 `json:"showFull"`
Start int64 `json:"start"` //JobStartTime 作业启动时间 in shuguang
State uint32 `json:"state"` //JobState 作业状态 in shuguang
Submit int64 `json:"submit"`
Suspended uint32 `json:"suspended"`
SysCpuSec uint32 `json:"sysCpuSec"`
SysCpuUsec uint32 `json:"sysCpuUsec"`
Timelimit uint32 `json:"timelimit"`
TotCpuSec uint32 `json:"totCpuSec"`
TotCpuUsec uint32 `json:"totCpuUsec"`
TrackSteps uint32 `json:"trackSteps"`
Uid uint32 `json:"uid"`
User string `json:"user"` //UserName 用户名 in shuguang
UserCpuSec uint32 `json:"userCpuSec"`
UserCpuUsec uint32 `json:"userCpuUsec"`
Wckey string `json:"wckey"`
Wckeyid uint32 `json:"wckeyid"`
WorkDir string `json:"workDir"` //Workdir 工作空间 in shuguang
/****************parmas from shuguang********************/
AcctTime string `json:"acctTime" copier:"AcctTime"` // 记账时间
AppType string `json:"appType" copier:"AppType"` // 作业应用类型
JobQueueTime string `json:"jobQueueTime" copier:"JobQueueTime"` //作业入队列时间
JobWalltimeUsed string `json:"jobWalltimeUsed" copier:"JobWalltimeUs"` //作业实际使用的Walltime,单位为秒
JobManagerId int `json:"jobmanagerId" copier:"JobManagerId"` //区域id
AcctTime string `json:"acctTime"` // 记账时间
AppType string `json:"appType"` // 作业应用类型
JobQueueTime string `json:"jobQueueTime"` //作业入队列时间
JobWalltimeUsed string `json:"jobWalltimeUsed"` //作业实际使用的Walltime,单位为秒
JobManagerId int `json:"jobmanagerId"` //区域id
/****************parmas from shuguang********************/
}
type (
listDomainReq {
}
listDomainResp {
Code int32 `json:"code"`
Msg string `json:"msg"`
Domains []Domain `json:"domains"`
}
)
type (
getDomainSummaryReq {
}
getDomainSummaryResp {
Code int32 `json:"code"`
Msg string `json:"msg"`
DomainSummary DomainSummary `json:"domainSummary"`
}
)
type (
listHistoryJobReq {
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
TimeType string `json:"time_type"`
Start int32 `json:"start"`
Limit int32 `json:"limit"`
IsQueryByQueueTime int32 `json:"is_query_by_queue_time"`
}
listHistoryJobResp {
Code int32 `json:"code" copier:"Code"`
Msg string `json:"msg" copier:"Msg"`
RecordCount int32 `json:"record_count" copier:"RecordCount"`
HistoryJobs []HistoryJob `json:"history_jobs" copier:"HistoryJobs"`
Code int32 `json:"code"`
Msg string `json:"msg"`
RecordCount int32 `json:"record_count"`
HistoryJobs []HistoryJob `json:"history_jobs"`
}
)
service slurmcore-api {
@handler ListDomainHandler
get /listDomain (listDomainReq) returns (listDomainResp)
@handler GetDomainSummaryHandler
get /getDomainSummary (getDomainSummaryReq) returns (getDomainSummaryResp)
@handler listHistoryJobHandler
get /listHistoryJob (listHistoryJobReq) returns (listHistoryJobResp)
}

View File

@ -3,7 +3,7 @@ package logic
import (
"PCM/app/slurm/slurmShuguang/rpc/internal/util"
"context"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
@ -45,13 +45,12 @@ func (l *ListHistoryJobLogic) ListHistoryJob(in *slurmShuguang.ListHistoryJobReq
params := url.Values{}
params.Add("strClusterNameList", strconv.FormatInt(int64(ClusterId), 10))
params.Add("startTime", "2022-11-23 01:01:01")
currentTime := time.Now()
params.Add("endTime", currentTime.Format("2006-01-02 15:04:05"))
params.Add("timeType", "CUSTOM")
params.Add("start", strconv.FormatInt(0, 10))
params.Add("limit", strconv.FormatInt(25, 10))
params.Add("isQueryByQueueTime", "false")
params.Add("startTime", in.StartTime)
params.Add("endTime", in.EndTime)
params.Add("timeType", in.TimeType) //"CUSTOM"
params.Add("start", strconv.FormatInt(int64(in.Start), 10))
params.Add("limit", strconv.FormatInt(int64(in.Limit), 10))
params.Add("isQueryByQueueTime", "true") //曙光参数配置问题
params.Add("strUser", l.svcCtx.Config.ShuguangConf.User)
reqUrl, err := http.NewRequest("GET", "https://api01.hpccube.com:65106/"+jobHistoryUrl+params.Encode(), nil)
@ -76,7 +75,7 @@ func (l *ListHistoryJobLogic) ListHistoryJob(in *slurmShuguang.ListHistoryJobReq
log.Fatal(err)
}
body, err := ioutil.ReadAll(respUrl.Body)
body, err := io.ReadAll(respUrl.Body)
jsonResult, err := simplejson.NewJson(body)
jsonData := jsonResult.Get("data")
@ -85,18 +84,33 @@ func (l *ListHistoryJobLogic) ListHistoryJob(in *slurmShuguang.ListHistoryJobReq
if err != nil {
log.Fatal(err)
}
defer respUrl.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
}
}(respUrl.Body)
var historyJobs []*slurmShuguang.HistoryJob
for index, _ := range rows {
for index := range rows {
jobShuguang := jobHistoryList.GetIndex(index)
var job slurmShuguang.HistoryJob
job.JobId = int32(jobShuguang.Get("jobId").MustInt())
job.JobName = jobShuguang.Get("JobName").MustString()
job.Workdir = jobShuguang.Get("workdir").MustString()
job.JobId, _ = strconv.ParseInt(jobShuguang.Get("jobId").MustString(), 10, 8)
job.JobName = jobShuguang.Get("jobName").MustString()
job.Workdir = jobShuguang.Get("workdir").MustString()
job.Queue = jobShuguang.Get("queue").MustString()
job.JobExecHost = jobShuguang.Get("jobExecHost").MustString()
job.JobExitStatus = int32(jobShuguang.Get("jobExitStatus").MustInt())
job.UserName = jobShuguang.Get("userName").MustString()
job.AcctTime = jobShuguang.Get("accTime").MustString()
job.AppType = jobShuguang.Get("appType").MustString()
job.JobQueueTime = jobShuguang.Get("jobQueueTime").MustString()
job.JobWalltimeUsed = jobShuguang.Get("jobWalltimeUsed").MustString()
job.JobManagerId = jobShuguang.Get("jobmanagerId").MustInt64()
job.JobState = jobShuguang.Get("jobState").MustString()
job.NodeCt = int32(jobShuguang.Get("nodect").MustInt64())
startTime, err := time.Parse(l.svcCtx.Config.ShuguangConf.Layout, jobShuguang.Get("jobStartTime").MustString())
if err == nil {

View File

@ -5,60 +5,40 @@ option go_package = "/slurmShuguang";
/******************Job(DB) Start*************************/
message apiHistoryJob{
}
message historyJob{
// @gotags: copier:"AcctTime"
string acct_time = 1 ;
// @gotags: copier:"AppType"
string app_type = 2 ;
// @gotags: copier:"End"
string job_end_time = 3 ;
// @gotags: copier:"Nodes"
string job_exec_host = 4 ;
// @gotags: copier:"ExitCode"
int32 job_exit_status = 5 ;
// @gotags: copier:"JobId"
int32 job_id = 6 ;
// @gotags: copier:"JobName"
string job_name = 7 ;
// @gotags: copier:"JobQueueTime"
string job_queue_time = 8 ;
// @gotags: copier:"Start"
string job_start_time = 9 ;
// @gotags: copier:"State"
string job_state = 10;
// @gotags: copier:"JobWalltimeUsed"
string job_walltime_used = 11;
// @gotags: copier:"JobManagerId"
int32 job_manager_id = 12;
// @gotags: copier:"AllocNodes"
int32 node_ct = 13;
// @gotags: copier:"Partition"
string queue = 14;
// @gotags: copier:"User"
string user_name = 15;
// @gotags: copier:"WorkDir"
string workdir = 16;
string acct_time = 1; // @gotags: copier:"AcctTime"
string app_type = 2; // @gotags: copier:"AppType"
string job_end_time = 3; // @gotags: copier:"End"
string job_exec_host = 4; // @gotags: copier:"Nodes"
int32 job_exit_status = 5; // @gotags: copier:"ExitCode"
int64 job_id = 6; // @gotags: copier:"JobId"
string job_name = 7; // @gotags: copier:"JobName"
string job_queue_time = 8; // @gotags: copier:"JobQueueTime"
string job_start_time = 9; // @gotags: copier:"Start"
string job_state = 10; // @gotags: copier:"State"
string job_walltime_used = 11; // @gotags: copier:"JobWalltimeUsed"
int64 job_manager_id = 12; // @gotags: copier:"JobManagerId"
int32 node_ct = 13; // @gotags: copier:"AllocNodes"
string queue = 14; // @gotags: copier:"Partition"
string user_name = 15; // @gotags: copier:"User"
string workdir = 16; // @gotags: copier:"WorkDir"
}
message ListHistoryJobReq{
string startTime = 1;// @gotags: copier:"StartTime"
string endTime = 2;// @gotags: copier:"EndTime"
string timeType = 3;// @gotags: copier:"TimeType"
int32 start = 4;// @gotags: copier:"Start"
int32 limit = 5;// @gotags: copier:"Limit"
int32 isQueryByQueueTime = 6;// @gotags: copier:"IsQueryByQueueTime"
}
message ListHistoryJobResp{
// @gotags: copier:"Code"
uint32 code = 1;
// @gotags: copier:"Msg"
string msg = 2;
// @gotags: copier:"RecordCount"
uint32 record_count = 3;
// @gotags: copier:"HistoryJobs"
repeated historyJob history_jobs = 4;
uint32 code = 1; // @gotags: copier:"Code"
string msg = 2; // @gotags: copier:"Msg"
uint32 record_count = 3; // @gotags: copier:"RecordCount"
repeated historyJob history_jobs = 4; // @gotags: copier:"HistoryJobs"
}
/******************Job(DB) End*************************/

View File

@ -13,7 +13,6 @@ import (
)
type (
ApiHistoryJob = slurmShuguang.ApiHistoryJob
HistoryJob = slurmShuguang.HistoryJob
ListHistoryJobReq = slurmShuguang.ListHistoryJobReq
ListHistoryJobResp = slurmShuguang.ListHistoryJobResp

View File

@ -0,0 +1,46 @@
syntax = "proto3";
package slurmTianhe;
option go_package = "/slurmTianhe";
/******************Job(DB) Start*************************/
message historyJob{
string acct_time = 1; // @gotags: copier:"AcctTime"
string app_type = 2; // @gotags: copier:"AppType"
string job_end_time = 3; // @gotags: copier:"End"
string job_exec_host = 4; // @gotags: copier:"Nodes"
int32 job_exit_status = 5; // @gotags: copier:"ExitCode"
int32 job_id = 6; // @gotags: copier:"JobId"
string job_name = 7; // @gotags: copier:"JobName"
string job_queue_time = 8; // @gotags: copier:"JobQueueTime"
string job_start_time = 9; // @gotags: copier:"Start"
string job_state = 10; // @gotags: copier:"State"
string job_walltime_used = 11; // @gotags: copier:"JobWalltimeUsed"
int32 job_manager_id = 12; // @gotags: copier:"JobManagerId"
int32 node_ct = 13; // @gotags: copier:"AllocNodes"
string queue = 14; // @gotags: copier:"Partition"
string user_name = 15; // @gotags: copier:"User"
string workdir = 16; // @gotags: copier:"WorkDir"
}
message ListHistoryJobReq{
}
message ListHistoryJobResp{
uint32 code = 1; // @gotags: copier:"Code"
string msg = 2; // @gotags: copier:"Msg"
uint32 record_count = 3; // @gotags: copier:"RecordCount"
repeated historyJob history_jobs = 4; // @gotags: copier:"HistoryJobs"
}
/******************Job(DB) End*************************/
// Slurm Services for Shuguang Branch
service slurmTianhe {
//ListHistoryJob list all jobs from slurmdb
rpc ListHistoryJob(ListHistoryJobReq) returns (ListHistoryJobResp);
}

50
common/tool/copier.go Normal file
View File

@ -0,0 +1,50 @@
package tool
import (
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"strconv"
"time"
)
var Converters = []copier.TypeConverter{
{
SrcType: time.Time{},
DstType: copier.String,
Fn: func(src interface{}) (interface{}, error) {
s, ok := src.(time.Time)
if !ok {
return nil, errors.New("src type not matching")
}
return s.Format(time.RFC3339), nil
},
},
{
SrcType: copier.String,
DstType: copier.Int,
Fn: func(src interface{}) (interface{}, error) {
s, ok := src.(string)
if !ok {
return nil, errors.New("src type not matching")
}
return strconv.Atoi(s)
},
},
{
SrcType: copier.String,
DstType: copier.Bool,
Fn: func(src interface{}) (interface{}, error) {
s, ok := src.(string)
if !ok {
return nil, errors.New("src type not matching")
}
return strconv.ParseBool(s)
},
},
}