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.

modeljob.go 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package schsdk
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strings"
  6. "gitlink.org.cn/cloudream/common/consts/errorcode"
  7. "gitlink.org.cn/cloudream/common/pkgs/mq"
  8. "gitlink.org.cn/cloudream/common/utils/http2"
  9. "gitlink.org.cn/cloudream/common/utils/serder"
  10. )
  11. // 这个结构体无任何字段,但实现了Noop,每种MessageBody都要内嵌这个结构体
  12. type MessageBodyBase struct{}
  13. // 此处的receiver是指针
  14. func (b *MessageBodyBase) Noop() {}
  15. type RunningModelResp struct {
  16. MessageBodyBase
  17. RunningModels map[string]RunningModelInfo `json:"allNode"`
  18. }
  19. type AllModelResp struct {
  20. MessageBodyBase
  21. AllModels []Models `json:"allModels"`
  22. }
  23. type Models struct {
  24. ModelID ModelID `json:"modelID"`
  25. ModelName ModelName `json:"modelName"`
  26. }
  27. type NodeInfo struct {
  28. MessageBodyBase
  29. InstanceID JobID `json:"instanceID"`
  30. //NodeID NodeID `json:"nodeID"`
  31. Address Address `json:"address"`
  32. Status string `json:"status"`
  33. }
  34. type RunningModelInfo struct {
  35. MessageBodyBase
  36. JobSetID JobSetID `json:"jobSetID"`
  37. ModelID ModelID `json:"modelID"`
  38. ModelName ModelName `json:"modelName"`
  39. CustomModelName ModelName `json:"customModelName"`
  40. Nodes []NodeInfo `json:"nodes"`
  41. }
  42. type ECSNodeRunningInfoReq struct {
  43. mq.MessageBodyBase
  44. CustomModelName ModelName `form:"customModelName" json:"customModelName" binding:"required"`
  45. ModelID ModelID `form:"modelID" json:"modelID" binding:"required"`
  46. }
  47. type ECSNodeRunningInfoResp struct {
  48. MessageBodyBase
  49. NodeUsageRateInfos []NodeUsageRateInfo `json:"nodeUsageRateInfos"`
  50. }
  51. func NewECSNodeRunningInfoResp(nodeUsageRateInfos []NodeUsageRateInfo) *ECSNodeRunningInfoResp {
  52. return &ECSNodeRunningInfoResp{
  53. NodeUsageRateInfos: nodeUsageRateInfos,
  54. }
  55. }
  56. type NodeUsageRateInfo struct {
  57. MessageBodyBase
  58. InstanceID JobID `json:"instanceID"`
  59. Address Address `json:"address"`
  60. MemoryUtilization []UsageRate `json:"memoryUtilization"`
  61. GPUUtilization []UsageRate `json:"GPUUtilization"`
  62. CPUUtilization []UsageRate `json:"CPUUtilization"`
  63. }
  64. type UsageRate struct {
  65. Timestamp string `json:"timestamp"`
  66. Number string `json:"number"`
  67. }
  68. const (
  69. FineTuning = "finetuning"
  70. DataPreprocess = "DataPreprocess"
  71. CreateECS = "create"
  72. RunECS = "run"
  73. PauseECS = "pause"
  74. DestroyECS = "destroy"
  75. OperateServer = "operate"
  76. RestartServer = "restartServer"
  77. GPUMonitor = "GPUMonitor"
  78. RcloneMount = "rclone"
  79. Mounted = "mounted"
  80. MountDir = "/mnt/oss"
  81. Deploying = "Deploying"
  82. Waiting = "Waiting"
  83. Failed = "Failed"
  84. Invalid = "Invalid"
  85. )
  86. type QueryRunningModelsReq struct {
  87. UserID int64 `form:"userID" json:"userID"`
  88. }
  89. func (c *Client) QueryRunningModels(req QueryRunningModelsReq) (*RunningModelResp, error) {
  90. url, err := url.JoinPath(c.baseURL, "/job/queryRunningModels")
  91. if err != nil {
  92. return nil, err
  93. }
  94. resp, err := http2.GetJSON(url, http2.RequestParam{
  95. Body: req,
  96. })
  97. if err != nil {
  98. return nil, err
  99. }
  100. contType := resp.Header.Get("Content-Type")
  101. if strings.Contains(contType, http2.ContentTypeJSON) {
  102. var codeResp response[RunningModelResp]
  103. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  104. return nil, fmt.Errorf("parsing response: %w", err)
  105. }
  106. if codeResp.Code == errorcode.OK {
  107. return &codeResp.Data, nil
  108. }
  109. return nil, codeResp.ToError()
  110. }
  111. return nil, fmt.Errorf("unknow response content type: %s", contType)
  112. }
  113. func (c *Client) QueryAllModels(req QueryRunningModelsReq) (*AllModelResp, error) {
  114. url, err := url.JoinPath(c.baseURL, "/job/getAllModels")
  115. if err != nil {
  116. return nil, err
  117. }
  118. resp, err := http2.GetJSON(url, http2.RequestParam{
  119. Body: req,
  120. })
  121. if err != nil {
  122. return nil, err
  123. }
  124. contType := resp.Header.Get("Content-Type")
  125. if strings.Contains(contType, http2.ContentTypeJSON) {
  126. var codeResp response[AllModelResp]
  127. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  128. return nil, fmt.Errorf("parsing response: %w", err)
  129. }
  130. if codeResp.Code == errorcode.OK {
  131. return &codeResp.Data, nil
  132. }
  133. return nil, codeResp.ToError()
  134. }
  135. return nil, fmt.Errorf("unknow response content type: %s", contType)
  136. }
  137. func (c *Client) ECSNodeRunningInfo(req ECSNodeRunningInfoReq) (*ECSNodeRunningInfoResp, error) {
  138. url, err := url.JoinPath(c.baseURL, "/job/getECSNodeRunningInfo")
  139. if err != nil {
  140. return nil, err
  141. }
  142. resp, err := http2.GetJSON(url, http2.RequestParam{
  143. Body: req,
  144. })
  145. if err != nil {
  146. return nil, err
  147. }
  148. contType := resp.Header.Get("Content-Type")
  149. if strings.Contains(contType, http2.ContentTypeJSON) {
  150. var codeResp response[ECSNodeRunningInfoResp]
  151. if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil {
  152. return nil, fmt.Errorf("parsing response: %w", err)
  153. }
  154. if codeResp.Code == errorcode.OK {
  155. return &codeResp.Data, nil
  156. }
  157. return nil, codeResp.ToError()
  158. }
  159. return nil, fmt.Errorf("unknow response content type: %s", contType)
  160. }