|
|
|
@@ -14,31 +14,21 @@ type GetClusterInfoReq struct { |
|
|
|
IDs []schsdk.ClusterID `json:"clusterIDs"` |
|
|
|
} |
|
|
|
|
|
|
|
//type GetClusterInfoResp struct { |
|
|
|
// Data []ClusterDetail `json:"data"` |
|
|
|
// TraceId string `json:"traceId"` |
|
|
|
//} |
|
|
|
|
|
|
|
func (c *Client) GetClusterInfo(req GetClusterInfoReq, token string) ([]ClusterDetail, error) { |
|
|
|
targetUrl, err := url.JoinPath(c.baseURL, "schedule/queryResources") |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
//resp, err := http2.PostJSON(targetUrl, http2.RequestParam{Body: req}) |
|
|
|
header := map[string]string{ |
|
|
|
"Authorization": token, |
|
|
|
} |
|
|
|
resp, err := http2.PostJSON(targetUrl, http2.RequestParam{ |
|
|
|
Header: header, |
|
|
|
Header: map[string]string{ |
|
|
|
"Authorization": token, |
|
|
|
}, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
//all, err := io.ReadAll(resp.Body) |
|
|
|
//println(string(all)) |
|
|
|
|
|
|
|
contType := resp.Header.Get("Content-Type") |
|
|
|
if strings.Contains(contType, http2.ContentTypeJSON) { |
|
|
|
|
|
|
|
@@ -166,7 +156,43 @@ func (c *Client) CreateInferenceJob(req CreateAIJobReq, token string) (*CreateIn |
|
|
|
} |
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknow response content type: %s", contType) |
|
|
|
} |
|
|
|
|
|
|
|
type StopInferenceJobReq struct { |
|
|
|
TaskId string `json:"taskId"` |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) StopInferenceJob(req StopInferenceJobReq, token string) error { |
|
|
|
targetUrl, err := url.JoinPath(c.baseURL, "inference/createTask") |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
resp, err := http2.PostJSON(targetUrl, http2.RequestParam{ |
|
|
|
Body: req, |
|
|
|
Header: map[string]string{ |
|
|
|
"Authorization": token, |
|
|
|
}, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
contType := resp.Header.Get("Content-Type") |
|
|
|
if strings.Contains(contType, http2.ContentTypeJSON) { |
|
|
|
var codeResp respons2[CreateInferenceJobResp] |
|
|
|
if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { |
|
|
|
return fmt.Errorf("parsing response: %w", err) |
|
|
|
} |
|
|
|
|
|
|
|
if codeResp.Code == ResponseCodeOK { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
return fmt.Errorf("error: %s", codeResp.Message) |
|
|
|
} |
|
|
|
|
|
|
|
return fmt.Errorf("unknow response content type: %s", contType) |
|
|
|
} |
|
|
|
|
|
|
|
func (c *Client) CreateJob(req CreateAIJobReq, token string) (*CreateJobResp, error) { |
|
|
|
@@ -175,13 +201,6 @@ func (c *Client) CreateJob(req CreateAIJobReq, token string) (*CreateJobResp, er |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
// 将req转换成json,并打印 |
|
|
|
//req2, err := serder.ObjectToJSONEx(req) |
|
|
|
//if err != nil { |
|
|
|
// return nil, fmt.Errorf("request to json: %w", err) |
|
|
|
//} |
|
|
|
//fmt.Println(string(req2)) |
|
|
|
|
|
|
|
resp, err := http2.PostJSON(targetUrl, http2.RequestParam{ |
|
|
|
Body: req, |
|
|
|
Header: map[string]string{ |
|
|
|
|