modelarts返回参数调整

This commit is contained in:
lee 2023-03-28 17:13:33 +08:00
parent 1c33117950
commit ebfca654ce
7 changed files with 31 additions and 42 deletions

View File

@ -43,9 +43,13 @@ func (l *GetImportTaskListLogic) GetImportTaskList(in *modelarts.ListImportTasks
log.Fatal(err)
}
if statusCode == 200 {
json.Unmarshal(body, &resp.Resp200)
} else if statusCode == 400 {
json.Unmarshal(body, &resp.Resp400)
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
}

View File

@ -39,9 +39,13 @@ func (l *GetListTrainingJobsLogic) GetListTrainingJobs(in *modelarts.ListTrainin
return nil, err
}
if statusCode == 200 {
json.Unmarshal(body, &resp.Resp200)
} else if statusCode == 400 {
json.Unmarshal(body, &resp.Resp400)
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
}

View File

@ -102,19 +102,14 @@ message ListImportTasksReq{
}
message ListImportTasksResp{
ListImportTasksResp200 resp200 = 1; //@gotags: copier:"Resp200"
ListImportTasksResp400 resp400 =2; //@gotags: copier:"Resp400"
}
message ListImportTasksResp200{
uint32 total_count = 1; //@gotags: copier:"TotalCount"
repeated Import_tasks import_tasks = 2; //@gotags: copier:"ImportTasks"
int32 code =3; //@gotags: copier:"Code"
string msg =4; //@gotags: copier:"Msg"
}
message ListImportTasksResp400{
string error_msg = 1; //@gotags: copier:"ErrorMsg"
string error_code = 2; //@gotags: copier:"ErrorCode"
string error_solution = 3; //@gotags: copier:"ErrorSolution"
}
message Import_tasks{
uint32 annotated_sample_count = 1; //@gotags: copier:"AnnotatedSampleCount"
@ -189,15 +184,6 @@ message ListTrainingJobsreq{
}
message ListTrainingJobsresp{
ListTrainingJobsresp200 resp200 =1;
ListTrainingJobsresp400 resp400 =2;
}
message ListTrainingJobsresp400{
string error_msg = 1;
string error_code = 2;
string error_solution = 3;
}
message ListTrainingJobsresp200{
int32 total = 1; //@gotags: copier:"Total"
int32 count = 2; //@gotags: copier:"Count"
int32 limit = 3; //@gotags: copier:"Limit"
@ -208,6 +194,8 @@ message ListTrainingJobsresp200{
string workspace_id = 8; //@gotags: copier:"WorkspaceID"
string ai_project = 9; //@gotags: copier:"AiProject"
repeated JobResponse items =10; //@gotags: copier:"Items"
int32 code =11; //@gotags: copier:"Code"
string msg =12; //@gotags: copier:"Msg"
}
message JobResponse{

View File

@ -303,12 +303,10 @@ type (
Offset int32 `json:"offset,optional"`
}
ListImportTasksResp {
Resp200 *ListImportTasksResp200 `json:"resp200,omitempty"`
Resp400 *ListImportTasksResp400 `json:"resp400,omitempty"`
}
ListImportTasksResp200 {
TotalCount uint32 `json:"totalCount,omitempty"`
ImportTasks []ImportTasks `json:"importTasks,omitempty"`
Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
}
ListImportTasksResp400 {
ErrorMsg string `json:"errorMsg,omitempty"`
@ -519,10 +517,6 @@ type (
ProjectId string `json:"projectId"`
}
ListTrainingJobsresp {
Resp200 *ListTrainingJobsresp200 `json:"resp200,omitempty"`
Resp400 *ListTrainingJobsresp400 `json:"resp400,omitempty"`
}
ListTrainingJobsresp200 {
Total int32 `json:"total"`
Count int32 `json:"count"`
Limit int32 `json:"limit"`
@ -533,11 +527,8 @@ type (
WorkspaceID string `json:"workspace_id"`
AiProject string `json:"ai_project"`
Items []Items `json:"items"`
}
ListTrainingJobsresp400 {
ErrorMsg string `json:"errorMsg,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
ErrorSolution string `json:"errorSolution,omitempty"`
Code int32 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
}
)
/******************ListTrainingJobs end*************************/

View File

@ -3,8 +3,10 @@ package ai
import (
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
"PCM/common/tool"
"PCM/common/xerr"
"context"
"github.com/jinzhu/copier"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/json"
"PCM/adaptor/PCM-CORE/api/internal/svc"
@ -31,9 +33,9 @@ func (l *GetListTrainingJobsLogic) GetListTrainingJobs(req *types.ListTrainingJo
modelartsReq := &modelarts.ListTrainingJobsreq{}
err = copier.CopyWithOption(modelartsReq, req, copier.Option{Converters: tool.Converters})
listDataSetResp, err := l.svcCtx.ModelArtsRpc.GetListTrainingJobs(l.ctx, modelartsReq)
//if err != nil {
// return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get db DataSet list"), "Failed to get db DataSet list err : %v ,req:%+v", err, req)
//}
if err != nil {
return nil, errors.Wrapf(xerr.NewErrMsg("Failed to get db DataSet list"), "Failed to get db DataSet list err : %v ,req:%+v", err, req)
}
marshal, err := json.Marshal(&listDataSetResp)
if err != nil {
return nil, err

View File

@ -36,6 +36,6 @@ func (l *ListImportLogic) ListImport(req *types.ListImportTasksReq) (resp *types
return nil, err
}
json.Unmarshal(marshal, &resp)
err = copier.CopyWithOption(&resp, &listDataSetResp, copier.Option{Converters: tool.Converters})
err = copier.CopyWithOption(&resp, &listDataSetResp, copier.Option{IgnoreEmpty: true, DeepCopy: true, Converters: tool.Converters})
return resp, nil
}

View File

@ -211,7 +211,7 @@ func initTaskCron(svc *svc.ServiceContext) {
if err != nil {
return
}
for _, trainingJob := range trainingJobs.Resp200.Items {
for _, trainingJob := range trainingJobs.Items {
_, err := svc.Db.Exec("update ai set status = ?,running_time = ?,start_time = ? where project_id = ? and name = ?", trainingJob.Status.Phase, trainingJob.Status.Duration/1000, tool.DurationToDateTime(trainingJob.Status.StartTime/1000), projectId, trainingJob.Metadata.Name)
if err != nil {
return