|
|
@@ -2,11 +2,12 @@ package hpc |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
|
|
|
"net/url" |
|
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler" |
|
|
schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler" |
|
|
"gitlink.org.cn/cloudream/common/utils/http2" |
|
|
"gitlink.org.cn/cloudream/common/utils/http2" |
|
|
"gitlink.org.cn/cloudream/common/utils/serder" |
|
|
"gitlink.org.cn/cloudream/common/utils/serder" |
|
|
"net/url" |
|
|
|
|
|
"strings" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
type CreateHPCJobReq struct { |
|
|
type CreateHPCJobReq struct { |
|
|
@@ -81,3 +82,39 @@ func (c *Client) CreateJob(req CreateHPCJobReq, token string) (*CreateJobResp, e |
|
|
return nil, fmt.Errorf("unknow response content type: %s", contType) |
|
|
return nil, fmt.Errorf("unknow response content type: %s", contType) |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Client) GetHPCAppClusters(app string, token string) (*AppClusterResp, error) { |
|
|
|
|
|
targetUrl, err := url.JoinPath(c.baseURL, "/hpc/getHpcAppCluster") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resp, err := http2.GetForm(targetUrl, http2.RequestParam{ |
|
|
|
|
|
Query: map[string]string{ |
|
|
|
|
|
"app": app, |
|
|
|
|
|
}, |
|
|
|
|
|
Header: map[string]string{ |
|
|
|
|
|
"Authorization": token, |
|
|
|
|
|
}, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
contType := resp.Header.Get("Content-Type") |
|
|
|
|
|
if strings.Contains(contType, http2.ContentTypeJSON) { |
|
|
|
|
|
var codeResp respons2[AppClusterResp] |
|
|
|
|
|
if err := serder.JSONToObjectStream(resp.Body, &codeResp); err != nil { |
|
|
|
|
|
return nil, fmt.Errorf("parsing response: %w", err) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if codeResp.Code == ResponseCodeOK { |
|
|
|
|
|
return &codeResp.Data, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("error: %s", codeResp.Message) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unknow response content type: %s", contType) |
|
|
|
|
|
|
|
|
|
|
|
} |