fix:创建接口修改

Former-commit-id: 80349a101566d63deeaecf56589ce4ab49ce028c
This commit is contained in:
qiwang 2023-05-18 16:51:02 +08:00
parent 8fc3939653
commit 1efe5406e5
5 changed files with 276 additions and 73 deletions

View File

@ -6,10 +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/common/tool" "PCM/common/tool"
"bytes"
"context" "context"
"fmt"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"net/http"
"strings" "strings"
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
@ -36,7 +41,11 @@ func NewCreateProcessorTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext
func (l *CreateProcessorTaskLogic) CreateProcessorTask(in *modelarts.CreateProcessorTaskReq) (*modelarts.CreateProcessorTaskResp, error) { func (l *CreateProcessorTaskLogic) CreateProcessorTask(in *modelarts.CreateProcessorTaskReq) (*modelarts.CreateProcessorTaskResp, error) {
// todo: add your logic here and delete this line // todo: add your logic here and delete this line
var resp modelarts.CreateProcessorTaskResp var resp modelarts.CreateProcessorTaskResp
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v2/" + in.ProjectId + "/processor-tasks/" //根据智算类型判断走华为智算还是南京智算
modelArtsType := in.ModelArtsType
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
url := modelArtsUrl + "v2/" + in.ProjectId + "/processor-tasks/"
reqByte, err := json.Marshal(in) reqByte, err := json.Marshal(in)
if err != nil { if err != nil {
return nil, err return nil, err
@ -48,5 +57,36 @@ func (l *CreateProcessorTaskLogic) CreateProcessorTask(in *modelarts.CreateProce
return nil, err return nil, err
} }
json.Unmarshal(body, &resp) json.Unmarshal(body, &resp)
} 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,
}
reqByte, err := json.Marshal(in)
r, err := http.NewRequest("POST", NanjingModelArtsUrl+"v2/"+in.ProjectId+"/processor-tasks/",
bytes.NewBuffer(reqByte))
if err != nil {
fmt.Println(err)
}
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)
}
return &resp, nil return &resp, nil
} }

View File

@ -6,12 +6,17 @@ 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/internal/svc" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/modelarts"
"PCM/common/tool" "PCM/common/tool"
"bytes"
"fmt"
"github.com/zeromicro/go-zero/core/logx" "github.com/zeromicro/go-zero/core/logx"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"net/http"
"strings" "strings"
) )
@ -37,7 +42,11 @@ func NewCreateServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
func (l *CreateServiceLogic) CreateService(in *modelarts.CreateServiceReq) (*modelarts.CreateServiceResp, error) { func (l *CreateServiceLogic) CreateService(in *modelarts.CreateServiceReq) (*modelarts.CreateServiceResp, error) {
// todo: add your logic here and delete this line // todo: add your logic here and delete this line
var resp modelarts.CreateServiceResp var resp modelarts.CreateServiceResp
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/" + in.ProjectId + "/services" //根据智算类型判断走华为智算还是南京智算
modelArtsType := in.ModelArtsType
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
url := modelArtsUrl + "v1/" + in.ProjectId + "/services"
reqByte, err := json.Marshal(in) reqByte, err := json.Marshal(in)
if err != nil { if err != nil {
return nil, err return nil, err
@ -57,5 +66,37 @@ func (l *CreateServiceLogic) CreateService(in *modelarts.CreateServiceReq) (*mod
resp.Code = 400 resp.Code = 400
resp.Msg = "Failure" 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,
}
reqByte, err := json.Marshal(in)
r, err := http.NewRequest("POST", NanjingModelArtsUrl+"v1/"+in.ProjectId+"/services",
bytes.NewBuffer(reqByte))
if err != nil {
fmt.Println(err)
}
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)
}
return &resp, nil return &resp, nil
} }

View File

@ -1,10 +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"
"bytes"
"context" "context"
"fmt"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"net/http"
"strings" "strings"
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
@ -30,7 +35,11 @@ func NewCreateTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Create
// creat task 创建导入任务 // creat task 创建导入任务
func (l *CreateTaskLogic) CreateTask(in *modelarts.ImportTaskDataReq) (*modelarts.ImportTaskDataResp, error) { func (l *CreateTaskLogic) CreateTask(in *modelarts.ImportTaskDataReq) (*modelarts.ImportTaskDataResp, error) {
var resp modelarts.ImportTaskDataResp var resp modelarts.ImportTaskDataResp
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v2/" + in.ProjectId + "/datasets/" + in.DatasetId + "/import-tasks" //根据智算类型判断走华为智算还是南京智算
modelArtsType := in.ModelArtsType
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
url := modelArtsUrl + "v2/" + in.ProjectId + "/datasets/" + in.DatasetId + "/import-tasks"
reqByte, err := json.Marshal(in) reqByte, err := json.Marshal(in)
if err != nil { if err != nil {
return nil, err return nil, err
@ -50,5 +59,37 @@ func (l *CreateTaskLogic) CreateTask(in *modelarts.ImportTaskDataReq) (*modelart
resp.Code = 400 resp.Code = 400
resp.Msg = "Failure" 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,
}
reqByte, err := json.Marshal(in)
r, err := http.NewRequest("POST", NanjingModelArtsUrl+"v2/"+in.ProjectId+"/datasets"+in.DatasetId+"/import-tasks",
bytes.NewBuffer(reqByte))
if err != nil {
fmt.Println(err)
}
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)
}
return &resp, nil return &resp, nil
} }

View File

@ -1,10 +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"
"bytes"
"context" "context"
"fmt"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/json"
"net/http"
"strings" "strings"
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
@ -30,7 +35,11 @@ func NewCreateTrainingJobConfigLogic(ctx context.Context, svcCtx *svc.ServiceCon
// CreateTrainingJobConfig 创建训练作业参数 // CreateTrainingJobConfig 创建训练作业参数
func (l *CreateTrainingJobConfigLogic) CreateTrainingJobConfig(in *modelarts.CreateTrainingJobConfigReq) (*modelarts.CreateTrainingJobConfigResp, error) { func (l *CreateTrainingJobConfigLogic) CreateTrainingJobConfig(in *modelarts.CreateTrainingJobConfigReq) (*modelarts.CreateTrainingJobConfigResp, error) {
var resp modelarts.CreateTrainingJobConfigResp var resp modelarts.CreateTrainingJobConfigResp
url := "https://modelarts.cn-north-4.myhuaweicloud.com/v1/" + in.ProjectId + "/training-job-configs" //根据智算类型判断走华为智算还是南京智算
modelArtsType := in.ModelArtsType
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
url := modelArtsUrl + "v1/" + in.ProjectId + "/training-job-configs"
reqByte, err := json.Marshal(in) reqByte, err := json.Marshal(in)
if err != nil { if err != nil {
return nil, err return nil, err
@ -45,5 +54,36 @@ func (l *CreateTrainingJobConfigLogic) CreateTrainingJobConfig(in *modelarts.Cre
if &resp == nil { if &resp == nil {
return nil, err return nil, err
} }
} 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,
}
reqByte, err := json.Marshal(in)
r, err := http.NewRequest("POST", NanjingModelArtsUrl+"v1/"+in.ProjectId+"/training-job-configs",
bytes.NewBuffer(reqByte))
if err != nil {
fmt.Println(err)
}
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)
}
return &resp, nil return &resp, nil
} }

View File

@ -1,10 +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"
"bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strings" "strings"
"PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc" "PCM/adaptor/PCM-AI/PCM-MODELARTS/rpc/internal/svc"
@ -29,7 +34,11 @@ func NewCreateVisualizationJobLogic(ctx context.Context, svcCtx *svc.ServiceCont
func (l *CreateVisualizationJobLogic) CreateVisualizationJob(in *modelarts.CreateVisualizationJobReq) (*modelarts.CreateVisualizationJobResp, error) { func (l *CreateVisualizationJobLogic) CreateVisualizationJob(in *modelarts.CreateVisualizationJobReq) (*modelarts.CreateVisualizationJobResp, error) {
var resp modelarts.CreateVisualizationJobResp var resp modelarts.CreateVisualizationJobResp
createVisualJobUrl := "https://modelarts.cn-east-3.myhuaweicloud.com/v1/{project_id}/visualization-jobs" //根据智算类型判断走华为智算还是南京智算
modelArtsType := in.ModelArtsType
if modelArtsType == l.svcCtx.Config.HaweiModelArtsType {
modelArtsUrl := l.svcCtx.Config.ModelArtsUrl
createVisualJobUrl := modelArtsUrl + "/v1/{project_id}/visualization-jobs"
createVisualJobUrl = strings.Replace(createVisualJobUrl, "{project_id}", in.ProjectId, -1) createVisualJobUrl = strings.Replace(createVisualJobUrl, "{project_id}", in.ProjectId, -1)
reqByte, err := json.Marshal(in.Param) reqByte, err := json.Marshal(in.Param)
@ -43,5 +52,37 @@ func (l *CreateVisualizationJobLogic) CreateVisualizationJob(in *modelarts.Creat
return nil, err return nil, err
} }
json.Unmarshal(body, &resp) json.Unmarshal(body, &resp)
} 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,
}
reqByte, err := json.Marshal(in)
r, err := http.NewRequest("POST", NanjingModelArtsUrl+"v1/"+in.ProjectId+"/visualization-jobs",
bytes.NewBuffer(reqByte))
if err != nil {
fmt.Println(err)
}
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)
}
return &resp, nil return &resp, nil
} }