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