You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

jobtotallogic.go 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package core
  13. import (
  14. "context"
  15. "github.com/zeromicro/go-zero/core/logx"
  16. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
  17. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  18. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/enum"
  19. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
  20. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/httputils"
  21. "k8s.io/apimachinery/pkg/util/json"
  22. )
  23. type JobTotalLogic struct {
  24. logx.Logger
  25. ctx context.Context
  26. svcCtx *svc.ServiceContext
  27. }
  28. type Job struct {
  29. TotalSize int `json:"totalSize"`
  30. OtJobs []OtJob `json:"otJobs"`
  31. }
  32. type OtJob struct {
  33. Name string `json:"name"`
  34. Status string `json:"status"`
  35. Tasks []Task `json:"tasks"`
  36. }
  37. type Task struct {
  38. CenterName []string `json:"centerName"`
  39. }
  40. func NewJobTotalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JobTotalLogic {
  41. return &JobTotalLogic{
  42. Logger: logx.WithContext(ctx),
  43. ctx: ctx,
  44. svcCtx: svcCtx,
  45. }
  46. }
  47. func (l *JobTotalLogic) JobTotal() (resp *types.JobTotalResp, err error) {
  48. // 获取任务时间信息
  49. resp = &types.JobTotalResp{}
  50. bytes, err := httputils.HttpGet("GET", "http://grampus.openi.org.cn/openapi/v1/sharescreen/computepower/alljobinfo")
  51. if err != nil {
  52. return nil, err
  53. }
  54. json.Unmarshal(bytes, resp)
  55. // 获取其他任务信息
  56. jobs := &Job{}
  57. jobBytes, err := httputils.HttpGet("GET", "http://grampus.openi.org.cn/openapi/v1/sharescreen/trainjob?pageIndex=1&pageSize=10")
  58. if err != nil {
  59. return nil, err
  60. }
  61. json.Unmarshal(jobBytes, jobs)
  62. for _, job := range jobs.OtJobs {
  63. trainJob := types.TrainJob{
  64. Name: job.Name,
  65. Status: enum.ExternalStatus(job.Status).String(),
  66. Strategy: 0,
  67. SynergyStatus: "未协同",
  68. }
  69. if job.Tasks[0].CenterName != nil {
  70. trainJob.ParticipantName = job.Tasks[0].CenterName[0]
  71. }
  72. resp.TrainJobs = append(resp.TrainJobs, trainJob)
  73. }
  74. var tasks []models.Task
  75. tx := l.svcCtx.DbEngin.Find(&tasks)
  76. if tx.Error != nil {
  77. logx.Error(err)
  78. return nil, tx.Error
  79. }
  80. if len(tasks) == 0 {
  81. return nil, nil
  82. }
  83. for _, task := range tasks {
  84. var participantName string
  85. tx := l.svcCtx.DbEngin.Raw("SELECT name from sc_participant_phy_info where id in (SELECT CONCAT_WS(',',GROUP_CONCAT(DISTINCT h.participant_id) ,GROUP_CONCAT(DISTINCT a.participant_id) ,GROUP_CONCAT(DISTINCT c.participant_id))as service_name from task t left join hpc h on t.id = h.task_id left join cloud c on t.id = c.task_id left join ai a on t.id = a.task_id where t.id = ?)", task.Id).Scan(&participantName)
  86. if tx.Error != nil {
  87. logx.Error(err)
  88. return nil, tx.Error
  89. }
  90. // 承接方转义
  91. resp.TrainJobs = append(resp.TrainJobs, types.TrainJob{
  92. ParticipantName: participantName,
  93. Name: task.Name,
  94. Strategy: int(task.Strategy),
  95. SynergyStatus: enum.SynergyStatus(task.SynergyStatus).String(),
  96. Status: task.Status,
  97. })
  98. }
  99. return resp, nil
  100. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.