fix:查询开发环境接口修改
Former-commit-id: 444b56c4e37e91e03396074d8f51da83ed3be74f
This commit is contained in:
parent
9d0b9b4cae
commit
ac8c4033e4
|
@ -6,11 +6,15 @@ package logic
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"APIGW-go-sdk/core"
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/common"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/common"
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
|
||||||
"PCM/common/tool"
|
"PCM/common/tool"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
|
||||||
|
@ -38,23 +42,65 @@ func NewGetExportTasksOfDatasetLogic(ctx context.Context, svcCtx *svc.ServiceCon
|
||||||
|
|
||||||
func (l *GetExportTasksOfDatasetLogic) GetExportTasksOfDataset(in *modelarts.GetExportTasksOfDatasetReq) (*modelarts.GetExportTasksOfDatasetResp, error) {
|
func (l *GetExportTasksOfDatasetLogic) GetExportTasksOfDataset(in *modelarts.GetExportTasksOfDatasetReq) (*modelarts.GetExportTasksOfDatasetResp, error) {
|
||||||
var resp modelarts.GetExportTasksOfDatasetResp
|
var resp modelarts.GetExportTasksOfDatasetResp
|
||||||
limit := strconv.Itoa(int(in.Limit))
|
|
||||||
offset := strconv.Itoa(int(in.Offset))
|
offset := strconv.Itoa(int(in.Offset))
|
||||||
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v2/" + in.ProjectId + "/datasets/" + in.DatasetId + "/export-tasks?limit=" + limit + "&offset=" + offset
|
judgeLimit := strconv.Itoa(int(in.Limit))
|
||||||
token := common.GetToken()
|
var limit string
|
||||||
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
if judgeLimit != "0" {
|
||||||
if err != nil {
|
limit = strconv.Itoa(int(in.Limit))
|
||||||
return nil, err
|
} else {
|
||||||
|
limit = "10"
|
||||||
}
|
}
|
||||||
if statusCode == 200 {
|
//根据智算类型判断走华为智算还是南京智算
|
||||||
|
modelArtsType := in.ModelArtsType
|
||||||
|
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
|
||||||
|
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
|
||||||
|
url := modelArtsUrl + "v2/" + in.ProjectId + "/datasets/" + in.DatasetId + "/export-tasks?limit=" + limit + "&offset=" + offset
|
||||||
|
token := common.GetToken()
|
||||||
|
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, url, nil, token)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if statusCode == 200 {
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
resp.Code = 200
|
||||||
|
resp.Msg = "Success"
|
||||||
|
} else if statusCode != 202 {
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
resp.Code = 400
|
||||||
|
resp.Msg = "Failure"
|
||||||
|
}
|
||||||
|
} else if modelArtsType == l.svcCtx.Config.NanjingModelArtsType {
|
||||||
|
AK := l.svcCtx.Config.AK
|
||||||
|
SK := l.svcCtx.Config.SK
|
||||||
|
NanjingModelArtsUrl := l.svcCtx.Config.NanjingModelArtsUrl
|
||||||
|
XProjectId := l.svcCtx.Config.XProjectId
|
||||||
|
s := core.Signer{
|
||||||
|
Key: AK,
|
||||||
|
Secret: SK,
|
||||||
|
}
|
||||||
|
r, err := http.NewRequest("GET", NanjingModelArtsUrl+"v2/"+in.ProjectId+"/datasets/"+in.DatasetId+"/export-tasks?limit="+limit+"&offset="+offset,
|
||||||
|
nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
r.Header.Add("content-type", "application/json;charset=UTF-8")
|
||||||
|
r.Header.Add("X-Project-Id", XProjectId)
|
||||||
|
r.Header.Add("x-stage", "RELEASE")
|
||||||
|
s.Sign(r)
|
||||||
|
client := http.DefaultClient
|
||||||
|
res, err := client.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
json.Unmarshal(body, &resp)
|
json.Unmarshal(body, &resp)
|
||||||
resp.Code = 200
|
|
||||||
resp.Msg = "Success"
|
|
||||||
} else if statusCode != 202 {
|
|
||||||
json.Unmarshal(body, &resp)
|
|
||||||
resp.Code = 400
|
|
||||||
resp.Msg = "Failure"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"APIGW-go-sdk/core"
|
||||||
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/common"
|
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/common"
|
||||||
"PCM/common/tool"
|
"PCM/common/tool"
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"k8s.io/apimachinery/pkg/util/json"
|
"k8s.io/apimachinery/pkg/util/json"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -32,22 +36,64 @@ func NewGetImportTaskListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||||
// find taskList 查询数据集导入任务列表
|
// find taskList 查询数据集导入任务列表
|
||||||
func (l *GetImportTaskListLogic) GetImportTaskList(in *modelarts.ListImportTasksReq) (*modelarts.ListImportTasksResp, error) {
|
func (l *GetImportTaskListLogic) GetImportTaskList(in *modelarts.ListImportTasksReq) (*modelarts.ListImportTasksResp, error) {
|
||||||
var resp modelarts.ListImportTasksResp
|
var resp modelarts.ListImportTasksResp
|
||||||
limit := strconv.Itoa(int(in.Limit))
|
judgeLimit := strconv.Itoa(int(in.Limit))
|
||||||
offset := strconv.Itoa(int(in.Offset))
|
offset := strconv.Itoa(int(in.Offset))
|
||||||
token := common.GetToken()
|
token := common.GetToken()
|
||||||
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, "https://modelarts.cn-north-4.myhuaweicloud.com/v2/"+in.ProjectId+"/datasets/"+in.DatasetId+"/import-tasks?limit="+limit+"&offset="+offset, strings.NewReader(``), token)
|
var limit string
|
||||||
|
if judgeLimit != "0" {
|
||||||
|
limit = strconv.Itoa(int(in.Limit))
|
||||||
|
} else {
|
||||||
|
limit = "10"
|
||||||
|
}
|
||||||
|
//根据智算类型判断走华为智算还是南京智算
|
||||||
|
modelArtsType := in.ModelArtsType
|
||||||
|
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
|
||||||
|
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
|
||||||
|
statusCode, body, err := tool.HttpClientWithBodyAndCode(tool.GET, modelArtsUrl+"v2/"+in.ProjectId+"/datasets/"+in.DatasetId+"/import-tasks?limit="+limit+"&offset="+offset, strings.NewReader(``), token)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if statusCode == 200 {
|
if statusCode == 200 {
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
resp.Code = 200
|
||||||
|
resp.Msg = "Success"
|
||||||
|
} else if statusCode != 200 {
|
||||||
|
json.Unmarshal(body, &resp)
|
||||||
|
resp.Code = 400
|
||||||
|
resp.Msg = "Failure"
|
||||||
|
}
|
||||||
|
} else if modelArtsType == l.svcCtx.Config.NanjingModelArtsType {
|
||||||
|
AK := l.svcCtx.Config.AK
|
||||||
|
SK := l.svcCtx.Config.SK
|
||||||
|
NanjingModelArtsUrl := l.svcCtx.Config.NanjingModelArtsUrl
|
||||||
|
XProjectId := l.svcCtx.Config.XProjectId
|
||||||
|
s := core.Signer{
|
||||||
|
Key: AK,
|
||||||
|
Secret: SK,
|
||||||
|
}
|
||||||
|
r, err := http.NewRequest("GET", NanjingModelArtsUrl+"v2/"+in.ProjectId+"/datasets/"+in.DatasetId+"/import-tasks?limit="+limit+"&offset="+offset,
|
||||||
|
nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
//return
|
||||||
|
}
|
||||||
|
r.Header.Add("content-type", "application/json;charset=UTF-8")
|
||||||
|
r.Header.Add("X-Project-Id", XProjectId)
|
||||||
|
r.Header.Add("x-stage", "RELEASE")
|
||||||
|
s.Sign(r)
|
||||||
|
client := http.DefaultClient
|
||||||
|
res, err := client.Do(r)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
json.Unmarshal(body, &resp)
|
json.Unmarshal(body, &resp)
|
||||||
resp.Code = 200
|
|
||||||
resp.Msg = "Success"
|
|
||||||
} else if statusCode != 200 {
|
|
||||||
json.Unmarshal(body, &resp)
|
|
||||||
resp.Code = 400
|
|
||||||
resp.Msg = "Failure"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &resp, nil
|
return &resp, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue