|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package octopusHttp
-
- import (
- "bytes"
- "context"
- "encoding/json"
- "errors"
- "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/schedulers/option"
- "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/collector"
- "gitlink.org.cn/JointCloud/pcm-coordinator/internal/scheduler/service/inference"
- omodel "gitlink.org.cn/JointCloud/pcm-octopus/http/model"
- "gitlink.org.cn/JointCloud/pcm-openi/common"
- "mime/multipart"
- "net/http"
- )
-
- const (
- RESOURCE_POOL = "common-pool"
- Param_Token = "token"
- Param_Addr = "addr"
- Octopus = "octopus"
- Forward_Slash = "/"
- )
-
- const (
- NotImplementError = "not implemented"
- )
-
- const (
- MyAlgorithmListUrl = "/api/v1/algorithm/myAlgorithmList"
- ResourcespecsUrl = "/api/v1/resource/specs"
- )
-
- type OctopusHttp struct {
- server string
- host string
- platform string
- participantId int64
- token *Token
- }
-
- func NewOctopusHttp(id int64, name, server, host string, user string, pwd string) *OctopusHttp {
- token, _ := NewToken(host, user, pwd)
- return &OctopusHttp{platform: name, participantId: id, server: server, host: host, token: token}
- }
-
- // executor
- func (o *OctopusHttp) Execute(ctx context.Context, option *option.AiOption, mode int) (interface{}, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) Stop(ctx context.Context, id string) error {
- //TODO implement me
- panic("implement me")
- }
-
- // collector
- func (o *OctopusHttp) GetResourceStats(ctx context.Context) (*collector.ResourceStats, error) {
- resourcespecsUrl := o.server + Forward_Slash + ResourcespecsUrl
- token, err := o.token.Get()
- if err != nil {
- return nil, err
- }
-
- param := omodel.ResourceSpecParam{
- ResourcePool: RESOURCE_POOL,
- }
-
- b, _ := json.Marshal(param)
- byt := bytes.NewBuffer(b)
-
- resp := struct {
- Code int `json:"code"`
- Msg string `json:"msg"`
- Data interface{} `json:"data"`
- }{}
-
- req := common.GetRestyRequest(common.TIMEOUT)
- r, _ := http.NewRequest("GET", resourcespecsUrl, byt)
- req.RawRequest = r
- req.URL = resourcespecsUrl
-
- _, err = req.
- SetHeader("Content-Type", "application/json").
- SetQueryParam(Param_Token, token).
- SetQueryParam(Param_Addr, o.host).
- SetBody(byt).
- SetResult(&resp).
- Send()
-
- if err != nil {
- return nil, err
- }
-
- if resp.Code != http.StatusOK {
- if resp.Data != nil {
- marshal, err := json.Marshal(resp.Data)
- if err != nil {
- return nil, err
- }
-
- errormdl := &omodel.Error{}
- err = json.Unmarshal(marshal, errormdl)
- if err != nil {
- return nil, err
- }
- return nil, errors.New(errormdl.Message)
- }
- } else {
- if resp.Data != nil {
- spec := omodel.ResourceSpec{}
-
- marshal, err := json.Marshal(resp.Data)
- if err != nil {
- return nil, err
- }
- err = json.Unmarshal(marshal, &spec.Payload)
- if err != nil {
- return nil, err
- }
- }
- }
-
- return nil, nil
- }
-
- func (o *OctopusHttp) GetDatasetsSpecs(ctx context.Context) ([]*collector.DatasetsSpecs, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) GetAlgorithms(ctx context.Context) ([]*collector.Algorithm, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) GetTrainingTaskLog(ctx context.Context, taskId string, instanceNum string) (string, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) GetTrainingTask(ctx context.Context, taskId string) (*collector.Task, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) DownloadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string) (string, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) UploadAlgorithmCode(ctx context.Context, resourceType string, card string, taskType string, dataset string, algorithm string, code string) error {
- //TODO implement me
- panic("implement me")
- }
-
- func (o OctopusHttp) GetComputeCards(ctx context.Context) ([]string, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) GetUserBalance(ctx context.Context) (float64, error) {
- //TODO implement me
- panic("implement me")
- }
-
- func (o *OctopusHttp) GetResourceSpecs(ctx context.Context, resrcType string) (*collector.ResourceSpec, error) {
- //TODO implement me
- panic("implement me")
- }
-
- // inference
- func (o *OctopusHttp) GetClusterInferUrl(ctx context.Context, option *option.InferOption) (*inference.ClusterInferUrl, error) {
- return nil, errors.New(NotImplementError)
- }
-
- func (o *OctopusHttp) GetInferDeployInstanceList(ctx context.Context) ([]*inference.DeployInstance, error) {
- return nil, errors.New(NotImplementError)
- }
-
- func (o *OctopusHttp) StartInferDeployInstance(ctx context.Context, id string) bool {
- return false
- }
-
- func (o *OctopusHttp) StopInferDeployInstance(ctx context.Context, id string) bool {
- return false
- }
-
- func (o *OctopusHttp) GetInferDeployInstance(ctx context.Context, id string) (*inference.DeployInstance, error) {
- return nil, errors.New(NotImplementError)
- }
-
- func (o *OctopusHttp) CreateInferDeployInstance(ctx context.Context, option *option.InferOption) (string, error) {
- return "", errors.New(NotImplementError)
- }
-
- func (o *OctopusHttp) CheckModelExistence(ctx context.Context, modelName string, modelType string) bool {
- return false
- }
-
- func (o *OctopusHttp) GetImageInferResult(ctx context.Context, url string, file multipart.File, fileName string) (string, error) {
- return "", errors.New(NotImplementError)
- }
|