Browse Source

调用C端接口传入token

pull/52/head
JeshuaRen 6 months ago
parent
commit
88484e929d
2 changed files with 26 additions and 2 deletions
  1. +11
    -2
      sdks/pcmscheduler/jobset.go
  2. +15
    -0
      sdks/scheduler/models.go

+ 11
- 2
sdks/pcmscheduler/jobset.go View File

@@ -19,17 +19,26 @@ type GetClusterInfoReq struct {
// TraceId string `json:"traceId"` // TraceId string `json:"traceId"`
//} //}


func (c *Client) GetClusterInfo(req GetClusterInfoReq) ([]ClusterDetail, error) {
func (c *Client) GetClusterInfo(req GetClusterInfoReq, token string) ([]ClusterDetail, error) {
targetUrl, err := url.JoinPath(c.baseURL, "schedule/queryResources") targetUrl, err := url.JoinPath(c.baseURL, "schedule/queryResources")
if err != nil { if err != nil {
return nil, err return nil, err
} }


//resp, err := http2.PostJSON(targetUrl, http2.RequestParam{Body: req}) //resp, err := http2.PostJSON(targetUrl, http2.RequestParam{Body: req})
resp, err := http2.PostJSON(targetUrl, http2.RequestParam{})
header := map[string]string{
"Authorization": token,
}
resp, err := http2.PostJSON(targetUrl, http2.RequestParam{
Header: header,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }

//all, err := io.ReadAll(resp.Body)
//println(string(all))

contType := resp.Header.Get("Content-Type") contType := resp.Header.Get("Content-Type")
if strings.Contains(contType, http2.ContentTypeJSON) { if strings.Contains(contType, http2.ContentTypeJSON) {




+ 15
- 0
sdks/scheduler/models.go View File

@@ -26,6 +26,10 @@ const (
MemoryUtilization = "MemoryUtilization" MemoryUtilization = "MemoryUtilization"
GPUUtilization = "GPUUtilization" GPUUtilization = "GPUUtilization"
CPUUtilization = "CPUUtilization" CPUUtilization = "CPUUtilization"

MethodPost = "POST"
MethodGet = "GET"
CodeSuccess = 200
) )


type JobID string type JobID string
@@ -72,6 +76,7 @@ var JobInfoTypeUnion = types.NewTypeUnion[JobInfo](
(*PCMInferenceJobInfo)(nil), (*PCMInferenceJobInfo)(nil),
(*CompleteJobInfo)(nil), (*CompleteJobInfo)(nil),
(*StartJobInfo)(nil), (*StartJobInfo)(nil),
(*NotifyJobInfo)(nil),
) )
var _ = serder.UseTypeUnionInternallyTagged(&JobInfoTypeUnion, "type") var _ = serder.UseTypeUnionInternallyTagged(&JobInfoTypeUnion, "type")


@@ -162,6 +167,16 @@ type StartJobInfo struct {
Type string `json:"type"` Type string `json:"type"`
} }


type NotifyJobInfo struct {
serder.Metadata `union:"Notify"`
JobInfoBase
Type string `json:"type"`
RequestType string `json:"requestType"`
Url string `json:"url"`
Body any `json:"body"`
Headers map[string]string `json:"headers"`
}

type ResourceChoice struct { type ResourceChoice struct {
Type string `json:"type"` Type string `json:"type"`
ResourceScopes []ResourceScope `json:"resourceScopes"` ResourceScopes []ResourceScope `json:"resourceScopes"`


Loading…
Cancel
Save