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.

octopusHttp.go 5.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package octopusHttp
  2. import (
  3. "bytes"
  4. "context"
  5. "encoding/json"
  6. "errors"
  7. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
  8. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
  9. "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
  10. omodel "gitlink.org.cn/JointCloud/pcm-octopus/http/model"
  11. "gitlink.org.cn/JointCloud/pcm-openi/common"
  12. "mime/multipart"
  13. "net/http"
  14. )
  15. const (
  16. RESOURCE_POOL = "common-pool"
  17. Param_Token = "token"
  18. Param_Addr = "addr"
  19. Octopus = "octopus"
  20. Forward_Slash = "/"
  21. )
  22. const (
  23. NotImplementError = "not implemented"
  24. )
  25. const (
  26. MyAlgorithmListUrl = "/api/v1/algorithm/myAlgorithmList"
  27. ResourcespecsUrl = "/api/v1/resource/specs"
  28. )
  29. type OctopusHttp struct {
  30. server string
  31. host string
  32. platform string
  33. participantId int64
  34. token *Token
  35. }
  36. func NewOctopusHttp(id int64, name, server, host string, user string, pwd string) *OctopusHttp {
  37. token, _ := NewToken(host, user, pwd)
  38. return &OctopusHttp{platform: name, participantId: id, server: server, host: host, token: token}
  39. }
  40. // executor
  41. func (o *OctopusHttp) Execute(ctx context.Context, option *option.AiOption, mode int) (interface{}, error) {
  42. //TODO implement me
  43. panic("implement me")
  44. }
  45. func (o *OctopusHttp) Stop(ctx context.Context, id string) error {
  46. //TODO implement me
  47. panic("implement me")
  48. }
  49. // collector
  50. func (o *OctopusHttp) GetResourceStats(ctx context.Context) (*collector.ResourceStats, error) {
  51. resourcespecsUrl := o.server + Forward_Slash + ResourcespecsUrl
  52. token, err := o.token.Get()
  53. if err != nil {
  54. return nil, err
  55. }
  56. param := omodel.ResourceSpecParam{
  57. ResourcePool: RESOURCE_POOL,
  58. }
  59. b, _ := json.Marshal(param)
  60. byt := bytes.NewBuffer(b)
  61. resp := struct {
  62. Code int `json:"code"`
  63. Msg string `json:"msg"`
  64. Data interface{} `json:"data"`
  65. }{}
  66. req := common.GetRestyRequest(common.TIMEOUT)
  67. r, _ := http.NewRequest("GET", resourcespecsUrl, byt)
  68. req.RawRequest = r
  69. req.URL = resourcespecsUrl
  70. _, err = req.
  71. SetHeader("Content-Type", "application/json").
  72. SetQueryParam(Param_Token, token).
  73. SetQueryParam(Param_Addr, o.host).
  74. SetBody(byt).
  75. SetResult(&resp).
  76. Send()
  77. if err != nil {
  78. return nil, err
  79. }
  80. if resp.Code != http.StatusOK {
  81. if resp.Data != nil {
  82. marshal, err := json.Marshal(resp.Data)
  83. if err != nil {
  84. return nil, err
  85. }
  86. errormdl := &omodel.Error{}
  87. err = json.Unmarshal(marshal, errormdl)
  88. if err != nil {
  89. return nil, err
  90. }
  91. return nil, errors.New(errormdl.Message)
  92. }
  93. } else {
  94. if resp.Data != nil {
  95. spec := omodel.ResourceSpec{}
  96. marshal, err := json.Marshal(resp.Data)
  97. if err != nil {
  98. return nil, err
  99. }
  100. err = json.Unmarshal(marshal, &spec.Payload)
  101. if err != nil {
  102. return nil, err
  103. }
  104. }
  105. }
  106. return nil, nil
  107. }
  108. func (o *OctopusHttp) GetDatasetsSpecs(ctx context.Context) ([]*collector.DatasetsSpecs, error) {
  109. //TODO implement me
  110. panic("implement me")
  111. }
  112. func (o *OctopusHttp) GetAlgorithms(ctx context.Context) ([]*collector.Algorithm, error) {
  113. //TODO implement me
  114. panic("implement me")
  115. }
  116. func (o *OctopusHttp) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) {
  117. //TODO implement me
  118. panic("implement me")
  119. }
  120. func (o *OctopusHttp) GetTrainingTask(ctx context.Context, taskId string) (*collector.Task, error) {
  121. //TODO implement me
  122. panic("implement me")
  123. }
  124. func (o *OctopusHttp) DownloadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string) (string, error) {
  125. //TODO implement me
  126. panic("implement me")
  127. }
  128. func (o *OctopusHttp) UploadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string, code string) error {
  129. //TODO implement me
  130. panic("implement me")
  131. }
  132. func (o OctopusHttp) GetComputeCards(ctx context.Context) ([]string, error) {
  133. //TODO implement me
  134. panic("implement me")
  135. }
  136. func (o *OctopusHttp) GetUserBalance(ctx context.Context) (float64, error) {
  137. //TODO implement me
  138. panic("implement me")
  139. }
  140. func (o *OctopusHttp) GetResourceSpecs(ctx context.Context, resrcType string) (*collector.ResourceSpec, error) {
  141. //TODO implement me
  142. panic("implement me")
  143. }
  144. // inference
  145. func (o *OctopusHttp) GetClusterInferUrl(ctx context.Context, option *option.InferOption) (*inference.ClusterInferUrl, error) {
  146. return nil, errors.New(NotImplementError)
  147. }
  148. func (o *OctopusHttp) GetInferDeployInstanceList(ctx context.Context) ([]*inference.DeployInstance, error) {
  149. return nil, errors.New(NotImplementError)
  150. }
  151. func (o *OctopusHttp) StartInferDeployInstance(ctx context.Context, id string) bool {
  152. return false
  153. }
  154. func (o *OctopusHttp) StopInferDeployInstance(ctx context.Context, id string) bool {
  155. return false
  156. }
  157. func (o *OctopusHttp) GetInferDeployInstance(ctx context.Context, id string) (*inference.DeployInstance, error) {
  158. return nil, errors.New(NotImplementError)
  159. }
  160. func (o *OctopusHttp) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) {
  161. return "", errors.New(NotImplementError)
  162. }
  163. func (o *OctopusHttp) CheckModelExistence(ctx context.Context, modelName string, modelType string) bool {
  164. return false
  165. }
  166. func (o *OctopusHttp) GetImageInferResult(ctx context.Context, url string, file multipart.File, fileName string) (string, error) {
  167. return "", errors.New(NotImplementError)
  168. }

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.