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.

job.go 1.9 kB

7 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package hpc
  2. import (
  3. "fmt"
  4. schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler"
  5. "gitlink.org.cn/cloudream/common/utils/http2"
  6. "gitlink.org.cn/cloudream/common/utils/serder"
  7. "net/url"
  8. "strings"
  9. )
  10. type CreateHPCJobReq struct {
  11. Name string `json:"name"`
  12. ClusterID schsdk.ClusterID `json:"clusterId"`
  13. Backend string `json:"backend"`
  14. App string `json:"app"`
  15. OperateType string `json:"operateType"`
  16. //Parameters HPCParameter `json:"parameters"`
  17. Parameters map[string]string `json:"parameters"`
  18. }
  19. //type HPCParameter struct {
  20. // JobName string `json:"jobName"`
  21. // Partition string `json:"partition"`
  22. // Ntasks string `json:"ntasks"`
  23. // Nodes string `json:"nodes"`
  24. // BamFile string `json:"bamFile"`
  25. // InputFile string `json:"inputFile"`
  26. //}
  27. type CreateJobResp struct {
  28. Backend string `json:"backend"`
  29. JobInfo HPCJobInfo `json:"jobInfo"`
  30. }
  31. type HPCJobInfo struct {
  32. JobDir string `json:"jobDir"`
  33. JobID string `json:"jobId"`
  34. TaskID string `json:"taskId"`
  35. }
  36. func (c *Client) CreateJob(req CreateHPCJobReq, token string) (*CreateJobResp, error) {
  37. targetUrl, err := url.JoinPath(c.baseURL, "/hpc/commitHpcTask")
  38. if err != nil {
  39. return nil, err
  40. }
  41. resp, err := http2.PostJSON(targetUrl, http2.RequestParam{
  42. Body: req,
  43. Header: map[string]string{
  44. "Authorization": token,
  45. },
  46. })
  47. if err != nil {
  48. return nil, err
  49. }
  50. contType := resp.Header.Get("Content-Type")
  51. if strings.Contains(contType, http2.ContentTypeJSON) {
  52. var codeResp respons2[CreateJobResp]
  53. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  54. return nil, fmt.Errorf("parsing response: %w", err)
  55. }
  56. if codeResp.Code == ResponseCodeOK {
  57. return &codeResp.Data, nil
  58. }
  59. return nil, fmt.Errorf("error: %s", codeResp.Message)
  60. }
  61. return nil, fmt.Errorf("unknow response content type: %s", contType)
  62. }