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.

listjoblogic.go 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 hpc
  13. import (
  14. "context"
  15. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/helper/enum"
  16. "strings"
  17. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
  18. "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
  19. "github.com/zeromicro/go-zero/core/logx"
  20. )
  21. type ListJobLogic struct {
  22. logx.Logger
  23. ctx context.Context
  24. svcCtx *svc.ServiceContext
  25. }
  26. func NewListJobLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListJobLogic {
  27. return &ListJobLogic{
  28. Logger: logx.WithContext(ctx),
  29. ctx: ctx,
  30. svcCtx: svcCtx,
  31. }
  32. }
  33. func (l *ListJobLogic) ListJob(req *types.ListJobReq) (resp *types.ListJobResp, err error) {
  34. resp = &types.ListJobResp{}
  35. var tasks []types.Job
  36. // 查询任务数据
  37. tx := l.svcCtx.DbEngin.Raw("SELECT h.service_name as SlurmVersion,h.name,h.start_time as JobStartTime,h.running_time as JobRunTime,t.status as StateofJob from hpc h join task t on t.id = h.task_id and t.status != 'Completed'").Scan(&tasks)
  38. if tx.Error != nil {
  39. logx.Error(err)
  40. return nil, tx.Error
  41. }
  42. for _, task := range tasks {
  43. // 承接方转义
  44. if task.SlurmVersion != "" {
  45. var names []string
  46. servicesName := strings.Split(task.SlurmVersion, ",")
  47. for _, name := range servicesName {
  48. names = append(names, enum.Partner(name).String())
  49. }
  50. task.SlurmVersion = strings.Join(names, ",")
  51. }
  52. resp.Jobs = append(resp.Jobs, types.Job{
  53. SlurmVersion: task.SlurmVersion,
  54. Name: task.Name,
  55. JobStartTime: task.JobStartTime,
  56. JobRunTime: task.JobRunTime + "s",
  57. StateofJob: task.StateofJob,
  58. })
  59. }
  60. resp.Code = 200
  61. resp.Msg = "success"
  62. resp.RecordCount = int32(len(resp.Jobs))
  63. return resp, nil
  64. }

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.