diff --git a/adaptor/pcm_slurm/service/tianhe.go b/adaptor/pcm_slurm/service/tianhe.go index 5e90747..76a7bb6 100644 --- a/adaptor/pcm_slurm/service/tianhe.go +++ b/adaptor/pcm_slurm/service/tianhe.go @@ -37,38 +37,18 @@ func (slurmStruct SlurmStruct) ListNodes(ctx context.Context, req *pbslurm.ListN func (slurmStruct SlurmStruct) GetAllJobs(ctx context.Context, req *pbslurm.JobInfoMsgReq) (*pbslurm.JobInfoMsgResp, error) { job_info_msg := slurm.Get_all_jobs() - - var resp = pbslurm.JobInfoMsgResp{} - var jobInfoList = getJobList(job_info_msg) - - jobInfoMsg := pbslurm.JobInfoMsg{} - jobInfoMsg.RecordCount = job_info_msg.Record_count - jobInfoMsg.LastUpdate = job_info_msg.Last_update - jobInfoMsg.JobList = jobInfoList - - resp.JobInfoMsg = append(resp.JobInfoMsg, &jobInfoMsg) - - return &resp, nil + return getJobInfoMsgResp(job_info_msg), nil } func (slurmStruct SlurmStruct) GetJob(ctx context.Context, req *pbslurm.JobInfoMsgReq) (*pbslurm.JobInfoMsgResp, error) { job_info_msg := slurm.Get_job(req.JobId) - - var resp = pbslurm.JobInfoMsgResp{} - var jobInfoList = getJobList(job_info_msg) - - jobInfoMsg := pbslurm.JobInfoMsg{} - jobInfoMsg.RecordCount = job_info_msg.Record_count - jobInfoMsg.LastUpdate = job_info_msg.Last_update - jobInfoMsg.JobList = jobInfoList - - resp.JobInfoMsg = append(resp.JobInfoMsg, &jobInfoMsg) - - return &resp, nil + return getJobInfoMsgResp(job_info_msg), nil } -func getJobList(job_info_msg slurm.Job_info_msg) []*pbslurm.JobInfo { +func getJobInfoMsgResp(job_info_msg slurm.Job_info_msg) *pbslurm.JobInfoMsgResp { + var resp = pbslurm.JobInfoMsgResp{} var jobInfoList = []*pbslurm.JobInfo{} + for _, e := range job_info_msg.Job_list { jobInfo := pbslurm.JobInfo{} jobInfo.ArrayJobId = e.Array_job_id @@ -146,5 +126,13 @@ func getJobList(job_info_msg slurm.Job_info_msg) []*pbslurm.JobInfo { jobInfo.Wait4Switch = e.Wait4switch jobInfoList = append(jobInfoList, &jobInfo) } - return jobInfoList + + jobInfoMsg := pbslurm.JobInfoMsg{} + jobInfoMsg.RecordCount = job_info_msg.Record_count + jobInfoMsg.LastUpdate = job_info_msg.Last_update + jobInfoMsg.JobList = jobInfoList + + resp.JobInfoMsg = append(resp.JobInfoMsg, &jobInfoMsg) + + return &resp }