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.

middleware.go 2.2 kB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package jcs
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. jsoniter "github.com/json-iterator/go"
  6. "github.com/rs/zerolog/log"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/database"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
  10. "gitlink.org.cn/JointCloud/pcm-openi/common"
  11. )
  12. type JobStatusReportReq struct {
  13. Report interface{} `json:"report"`
  14. }
  15. type TrainReportMessage struct {
  16. Type string `json:"type"`
  17. TaskName string `json:"taskName"`
  18. TaskID string `json:"taskID"`
  19. Status bool `json:"status"`
  20. Message string `json:"message"`
  21. ClusterID string `json:"clusterID"`
  22. Output string `json:"output"`
  23. }
  24. type InferReportMessage struct {
  25. Type string `json:"type"`
  26. TaskName string `json:"taskName"`
  27. TaskID string `json:"taskID"`
  28. Status bool `json:"status"`
  29. Message string `json:"message"`
  30. Url string `json:"url"`
  31. ID string `json:"id"`
  32. AdapterID string `json:"adapterId"`
  33. ClusterID string `json:"clusterId"`
  34. InstanceID string `json:"instanceId"`
  35. }
  36. func StatusReport(url string, report interface{}) error {
  37. resp := struct {
  38. Code string `json:"code"`
  39. Msg string `json:"message"`
  40. Data string `json:"data"`
  41. }{}
  42. req := common.GetRestyRequest(common.TIMEOUT)
  43. rp, err := req.
  44. SetHeader("Content-Type", "application/json").
  45. SetBody(report).
  46. SetResult(&resp).
  47. Post(url)
  48. bodyStr, _ := jsoniter.MarshalToString(report)
  49. log.Debug().Msgf("上报任务状态到中间件,请求url:%s, 请求参数:%s, 响应结果:%s", url, bodyStr, string(rp.Body()))
  50. if err != nil {
  51. logx.Errorf("############ Report Status Message Error %s", err.Error())
  52. return err
  53. }
  54. if resp.Code != "OK" {
  55. logx.Errorf("############ Report Status Message After Sending %s", string(rp.Body()))
  56. return fmt.Errorf("report status message failed: %s", resp.Msg)
  57. }
  58. return nil
  59. }
  60. func TempSaveReportToTask(store *database.AiStorage, task *types.TaskModel, report interface{}) error {
  61. jsonBytes, err := json.Marshal(report)
  62. task.Result = string(jsonBytes)
  63. err = store.UpdateTask(task)
  64. if err != nil {
  65. return err
  66. }
  67. return nil
  68. }

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.