diff --git a/sdks/hpc/job.go b/sdks/hpc/job.go index 8c9acad..4aba8da 100644 --- a/sdks/hpc/job.go +++ b/sdks/hpc/job.go @@ -2,11 +2,12 @@ package hpc import ( "fmt" + "net/url" + "strings" + schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler" "gitlink.org.cn/cloudream/common/utils/http2" "gitlink.org.cn/cloudream/common/utils/serder" - "net/url" - "strings" ) 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) } + +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) + +} diff --git a/sdks/hpc/models.go b/sdks/hpc/models.go index d3a0522..ba78238 100644 --- a/sdks/hpc/models.go +++ b/sdks/hpc/models.go @@ -1,11 +1,12 @@ package hpc import ( + "time" + "gitlink.org.cn/cloudream/common/pkgs/types" schsdk "gitlink.org.cn/cloudream/common/sdks/scheduler" cdssdk "gitlink.org.cn/cloudream/common/sdks/storage" "gitlink.org.cn/cloudream/common/utils/serder" - "time" ) type ResourceType string @@ -523,3 +524,12 @@ type PublicLevel struct { Type string `json:"type" binding:"required"` Info DataBinding `json:"info"` // 可选,用于精细筛选,功能暂未实现 } + +type AppClusterResp struct { + List []struct { + Id string `json:"id"` + Name string `json:"name"` + Nickname string `json:"nickname"` + Region string `json:"region"` + } `json:"list"` +}