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.

slurm.go 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package hpcservice
  2. import (
  3. "context"
  4. "github.com/go-resty/resty/v2"
  5. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  6. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
  8. )
  9. type ParticipantHpc struct {
  10. participantId int64
  11. platform string
  12. host string
  13. userName string
  14. accessToken string
  15. }
  16. const (
  17. JobDetailUrl = "/api/v1/jobs/detail/{backend}/{jobId}"
  18. SubmitTaskUrl = "/api/v1/jobs"
  19. )
  20. func NewHpc(host string, id int64, platform string) *ParticipantHpc {
  21. return &ParticipantHpc{
  22. host: host,
  23. participantId: id,
  24. platform: platform,
  25. }
  26. }
  27. func (c *ParticipantHpc) GetTask(ctx context.Context, taskId string) (*collector.Task, error) {
  28. reqUrl := c.host + JobDetailUrl
  29. hpcResp := &collector.HpcJobDetailResp{}
  30. httpClient := resty.New().R()
  31. _, err := httpClient.SetHeader("Content-Type", "application/json").
  32. SetPathParam("jobId", taskId).
  33. SetPathParam("backend", "slurm").
  34. SetResult(&hpcResp).
  35. Get(reqUrl)
  36. if err != nil {
  37. return nil, err
  38. }
  39. var resp collector.Task
  40. resp.Id = hpcResp.Data.ID
  41. if !hpcResp.Data.StartTime.IsZero() {
  42. resp.Start = hpcResp.Data.StartTime.Format(constants.Layout)
  43. }
  44. if !hpcResp.Data.EndTime.IsZero() {
  45. resp.End = hpcResp.Data.EndTime.Format(constants.Layout)
  46. }
  47. switch hpcResp.Data.StatusText {
  48. case "COMPLETED":
  49. resp.Status = constants.Completed
  50. case "FAILED":
  51. resp.Status = constants.Failed
  52. case "CREATED_FAILED":
  53. resp.Status = constants.Failed
  54. case "RUNNING":
  55. resp.Status = constants.Running
  56. case "STOPPED":
  57. resp.Status = constants.Stopped
  58. case "PENDING":
  59. resp.Status = constants.Pending
  60. case "WAITING":
  61. resp.Status = constants.Waiting
  62. default:
  63. resp.Status = "undefined"
  64. }
  65. return &resp, nil
  66. }
  67. func (c *ParticipantHpc) SubmitTask(ctx context.Context, req types.CommitHpcTaskReq) (*types.CommitHpcTaskResp, error) {
  68. reqUrl := c.host + SubmitTaskUrl
  69. resp := types.CommitHpcTaskResp{}
  70. httpClient := resty.New().R()
  71. _, err := httpClient.SetHeader("Content-Type", "application/json").
  72. SetBody(req).
  73. SetResult(&resp).
  74. Post(reqUrl)
  75. if err != nil {
  76. return nil, err
  77. }
  78. return &resp, nil
  79. }

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.