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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 CreateJobReq 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. }
  35. func (c *Client) CreateJob(req CreateJobReq, token string) (*CreateJobResp, error) {
  36. targetUrl, err := url.JoinPath(c.baseURL, "/hpc/commitHpcTask")
  37. if err != nil {
  38. return nil, err
  39. }
  40. resp, err := http2.PostJSON(targetUrl, http2.RequestParam{
  41. Body: req,
  42. Header: map[string]string{
  43. "Authorization": token,
  44. },
  45. })
  46. if err != nil {
  47. return nil, err
  48. }
  49. contType := resp.Header.Get("Content-Type")
  50. if strings.Contains(contType, http2.ContentTypeJSON) {
  51. var codeResp respons2[CreateJobResp]
  52. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  53. return nil, fmt.Errorf("parsing response: %w", err)
  54. }
  55. if codeResp.Code == ResponseCodeOK {
  56. return &codeResp.Data, nil
  57. }
  58. return nil, fmt.Errorf("error: %s", codeResp.Message)
  59. }
  60. return nil, fmt.Errorf("unknow response content type: %s", contType)
  61. }