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 2.2 kB

7 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. "io"
  8. "net/url"
  9. "strings"
  10. )
  11. type CreateHPCJobReq struct {
  12. Name string `json:"name"`
  13. Description string `json:"description"`
  14. ClusterID schsdk.ClusterID `json:"clusterId"`
  15. Backend string `json:"backend"`
  16. App string `json:"app"`
  17. OperateType string `json:"operateType"`
  18. ScriptContent string `json:"scriptContent"`
  19. //Parameters HPCParameter `json:"parameters"`
  20. Parameters map[string]string `json:"parameters"`
  21. }
  22. //type HPCParameter struct {
  23. // JobName string `json:"jobName"`
  24. // Partition string `json:"partition"`
  25. // Ntasks string `json:"ntasks"`
  26. // Nodes string `json:"nodes"`
  27. // BamFile string `json:"bamFile"`
  28. // InputFile string `json:"inputFile"`
  29. //}
  30. type CreateJobResp struct {
  31. Backend string `json:"backend"`
  32. JobInfo HPCJobInfo `json:"jobInfo"`
  33. }
  34. type HPCJobInfo struct {
  35. JobDir string `json:"jobDir"`
  36. JobID string `json:"jobId"`
  37. TaskID string `json:"taskId"`
  38. }
  39. func (c *Client) CreateJob(req CreateHPCJobReq, token string) (*CreateJobResp, error) {
  40. targetUrl, err := url.JoinPath(c.baseURL, "/hpc/commitHpcTask")
  41. if err != nil {
  42. return nil, err
  43. }
  44. resp, err := http2.PostJSON(targetUrl, http2.RequestParam{
  45. Body: req,
  46. Header: map[string]string{
  47. "Authorization": token,
  48. },
  49. })
  50. if err != nil {
  51. return nil, err
  52. }
  53. // 打印resp.Body内容
  54. body, err := io.ReadAll(resp.Body)
  55. if err != nil {
  56. println("Error reading response body:", err)
  57. }
  58. // Print the response body as a string
  59. println("Response Body:", string(body))
  60. contType := resp.Header.Get("Content-Type")
  61. if strings.Contains(contType, http2.ContentTypeJSON) {
  62. var codeResp respons2[CreateJobResp]
  63. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  64. return nil, fmt.Errorf("parsing response: %w", err)
  65. }
  66. if codeResp.Code == ResponseCodeOK {
  67. return &codeResp.Data, nil
  68. }
  69. return nil, fmt.Errorf("error: %s", codeResp.Message)
  70. }
  71. return nil, fmt.Errorf("unknow response content type: %s", contType)
  72. }