Merge remote-tracking branch 'origin/master'

This commit is contained in:
zhouqunjie 2023-10-27 10:04:23 +08:00
commit 0ad85477e4
14 changed files with 448 additions and 174 deletions

View File

@ -337,7 +337,7 @@ service pcm {
@handler DeleteNodeHandler
delete /vm/deleteNode (DeleteNodeReq) returns (DeleteNodeResp)
@handler ShowNodeDetailsHandler
delete /vm/showNodeDetails (ShowNodeDetailsReq) returns (ShowNodeDetailsResp)
get /vm/showNodeDetails (ShowNodeDetailsReq) returns (ShowNodeDetailsResp)
}
//存算联动 接口

View File

@ -15,7 +15,7 @@ type (
UploadLinkImageResp {
Success bool `json:"success"`
Image ImageSl `json:"image"`
Image *ImageSl `json:"image"`
ErrorMsg string `json:"errorMsg"`
}
@ -31,7 +31,7 @@ type (
GetLinkImageListResp {
Success bool `json:"success"`
Images []ImageSl `json:"images"`
Images []*ImageSl `json:"images"`
ErrorMsg string `json:"errorMsg"`
}
@ -49,7 +49,7 @@ type (
PartId int64 `json:"partId"`
ImageId string `json:"imageId"`
Cmd string `json:"cmd"`
Params []ParamSl `json:"params"`
Params []*ParamSl `json:"params"`
ResourceId string `json:"resourceId"`
}
@ -71,7 +71,7 @@ type (
GetLinkTaskResp {
Success bool `json:"success"`
Task TaskSl `json:"task"`
Task *TaskSl `json:"task"`
ErrorMsg string `json:"errorMsg"`
}
@ -99,7 +99,7 @@ type (
GetParticipantsResp {
Success bool `json:"success"`
Participants []ParticipantSl `json:"participant"`
Participants []*ParticipantSl `json:"participant"`
}
GetResourceSpecsReq {
@ -108,7 +108,7 @@ type (
GetResourceSpecsResp {
Success bool `json:"success"`
ResourceSpecs []ResourceSpecSl `json:"resourceSpecs"`
ResourceSpecs []*ResourceSpecSl `json:"resourceSpecs"`
}
ResourceSpecSl {

View File

@ -236,7 +236,7 @@ type(
type (
StartServerReq {
ServerId string `json:"server_id" copier:"ServerId"`
Action []map[string]string `json:"Action,optional" copier:"Action"`
Action []map[string]string `json:"action,optional" copier:"Action"`
start_action string `json:"start_action" copier:"start_action"`
}
@ -250,7 +250,7 @@ type (
type(
StopServerReq{
ServerId string `json:"server_id" copier:"ServerId"`
Action []map[string]string `json:"Action,optional" copier:"Action"`
Action []map[string]string `json:"action,optional" copier:"Action"`
stop_action string `json:"stop_action" copier:"stop_action"`
}
StopServerResp {
@ -742,7 +742,7 @@ type (
type(
UpdateVolumeReq {
Volume Volume `json:"volume" copier:"Volume"`
VolumeTypeId string `json:"volume_type_id" copier:"VolumeTypeId"`
VolumeId string `json:"volume_id" copier:"VolumeId"`
}
UpdateVolumeResp {
Volume Volume `json:"volume" copier:"Volume"`
@ -794,7 +794,7 @@ type(
ErrorMsg string `json:"errorMsg,omitempty" copier:"ErrorMsg"`
}
VolumeType {
VolumeType string `json:"Volume_type" copier:"VolumeType"`
Name string `json:"name" copier:"Name"`
Description string `json:"description" copier:"Description"`
ExtraSpecs ExtraSpecs `json:"extra_specs" copier:"ExtraSpecs"`
Id string `json:"id" copier:"Id"`

View File

@ -552,7 +552,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Handler: vm.DeleteNodeHandler(serverCtx),
},
{
Method: http.MethodDelete,
Method: http.MethodGet,
Path: "/vm/showNodeDetails",
Handler: vm.ShowNodeDetailsHandler(serverCtx),
},

View File

@ -2,13 +2,10 @@ package storelink
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/storeLink"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
type GetAISpecsLogic struct {
@ -26,41 +23,13 @@ func NewGetAISpecsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAIS
}
func (l *GetAISpecsLogic) GetAISpecs(req *types.GetResourceSpecsReq) (resp *types.GetResourceSpecsResp, err error) {
var res types.GetResourceSpecsResp
participants := storeLink.GetParticipants(l.svcCtx.DbEngin)
for _, participant := range participants {
switch participant.Type {
case storeLink.TYPE_OCTOPUS:
req := &octopus.GetResourceSpecsReq{
Platform: participant.Name,
ResourcePool: "common-pool",
}
specs, err := l.svcCtx.OctopusRpc.GetResourceSpecs(l.ctx, req)
if err != nil || !specs.Success {
continue
}
for _, spec := range specs.TrainResourceSpecs {
var respec types.ResourceSpecSl
respec.SpecId = spec.Id
respec.SpecName = spec.Name
respec.ParticipantId = strconv.FormatInt(participant.Id, 10)
respec.ParticipantName = participant.Name
respec.SpecPrice = spec.Price
res.ResourceSpecs = append(res.ResourceSpecs, respec)
}
}
participant := storeLink.GetParticipantById(req.PartId, l.svcCtx.DbEngin)
storelink := storeLink.NewStoreLink(l.ctx, l.svcCtx, participant)
specs, err := storelink.ILinkage.QuerySpecs()
if err != nil {
return nil, err
}
if len(res.ResourceSpecs) == 0 {
res.Success = false
return &res, nil
}
res.Success = true
return &res, nil
specsResp := specs.(types.GetResourceSpecsResp)
return &specsResp, nil
}

View File

@ -38,7 +38,7 @@ func (l *GetParticipantsLogic) GetParticipants(req *types.GetParticipantsReq) (r
p.ParticipantId = strconv.FormatInt(participant.Id, 10)
p.ParticipantType = storeLink.AITYPE[participant.Type]
p.ParticipantName = participant.Name
res.Participants = append(res.Participants, p)
res.Participants = append(res.Participants, &p)
}
res.Success = true

View File

@ -3,6 +3,7 @@ package storeLink
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts"
"strings"
@ -23,8 +24,8 @@ type ModelArtsLink struct {
// RESOURCE_POOL = "common-pool"
//)
func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, platform string) *ModelArtsLink {
return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, platform: platform, pageIndex: 1, pageSize: 100}
func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *ModelArtsLink {
return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, platform: participant.Name, pageIndex: 1, pageSize: 100}
}
func (o *ModelArtsLink) UploadImage(path string) (interface{}, error) {
@ -50,7 +51,7 @@ func (o *ModelArtsLink) QueryImageList() (interface{}, error) {
}
//转换成统一返回类型
imgListResp, err := ConvertType[modelarts.ListReposDetailsResp](resp)
imgListResp, err := ConvertType[modelarts.ListReposDetailsResp](resp, nil)
if err != nil {
return nil, err
}
@ -93,7 +94,7 @@ func (o *ModelArtsLink) SubmitTask(imageId string, cmd string, params []string,
}
//转换成统一返回类型
submitResp, err := ConvertType[modelarts.CreateTrainingJobResp](resp)
submitResp, err := ConvertType[modelarts.CreateTrainingJobResp](resp, nil)
if err != nil {
return nil, err
}
@ -112,7 +113,7 @@ func (o *ModelArtsLink) QueryTask(taskId string) (interface{}, error) {
}
//转换成统一返回类型
taskResp, err := ConvertType[modelarts.JobResponse](resp)
taskResp, err := ConvertType[modelarts.JobResponse](resp, nil)
if err != nil {
return nil, err
}
@ -131,10 +132,14 @@ func (o *ModelArtsLink) DeleteTask(taskId string) (interface{}, error) {
}
//转换成统一返回类型
deleteResp, err := ConvertType[modelarts.DeleteTrainingJobResp](resp)
deleteResp, err := ConvertType[modelarts.DeleteTrainingJobResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
}
func (o *ModelArtsLink) QuerySpecs() (interface{}, error) {
return nil, nil
}

View File

@ -3,17 +3,18 @@ package storeLink
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
"strings"
)
type OctopusLink struct {
ctx context.Context
svcCtx *svc.ServiceContext
platform string
pageIndex int32
pageSize int32
ctx context.Context
svcCtx *svc.ServiceContext
pageIndex int32
pageSize int32
participant *models.ScParticipantPhyInfo
}
const (
@ -23,17 +24,17 @@ const (
RESOURCE_POOL = "common-pool"
)
func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, platform string) *OctopusLink {
return &OctopusLink{ctx: ctx, svcCtx: svcCtx, platform: platform, pageIndex: 1, pageSize: 100}
func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *OctopusLink {
return &OctopusLink{ctx: ctx, svcCtx: svcCtx, participant: participant, pageIndex: 1, pageSize: 100}
}
func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
// octopus创建镜像
createReq := &octopus.CreateImageReq{
Platform: o.platform,
Platform: o.participant.Name,
CreateImage: &octopus.CreateImage{
SourceType: 1,
ImageName: IMG_NAME_PREFIX + utils.RandomString(5),
ImageName: IMG_NAME_PREFIX + utils.RandomString(7),
ImageVersion: IMG_VERSION_PREFIX + utils.RandomString(7),
},
}
@ -44,7 +45,7 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
// octopus上传镜像
uploadReq := &octopus.UploadImageReq{
Platform: o.platform,
Platform: o.participant.Name,
ImageId: createResp.Payload.ImageId,
Params: &octopus.UploadImageParam{
Domain: "",
@ -59,7 +60,7 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
// Todo 实际上传
//转换成统一返回类型
resp, err := ConvertType[octopus.UploadImageResp](uploadResp)
resp, err := ConvertType[octopus.UploadImageResp](uploadResp, nil)
if err != nil {
return nil, err
}
@ -70,7 +71,7 @@ func (o *OctopusLink) UploadImage(path string) (interface{}, error) {
func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
// octopus删除镜像
req := &octopus.DeleteImageReq{
Platform: o.platform,
Platform: o.participant.Name,
ImageId: imageId,
}
resp, err := o.svcCtx.OctopusRpc.DeleteImage(o.ctx, req)
@ -79,7 +80,7 @@ func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
}
//转换成统一返回类型
deleteResp, err := ConvertType[octopus.DeleteImageResp](resp)
deleteResp, err := ConvertType[octopus.DeleteImageResp](resp, nil)
if err != nil {
return nil, err
}
@ -90,7 +91,7 @@ func (o *OctopusLink) DeleteImage(imageId string) (interface{}, error) {
func (o *OctopusLink) QueryImageList() (interface{}, error) {
// octopus获取镜像列表
req := &octopus.GetUserImageListReq{
Platform: o.platform,
Platform: o.participant.Name,
PageIndex: o.pageIndex,
PageSize: o.pageSize,
}
@ -100,7 +101,7 @@ func (o *OctopusLink) QueryImageList() (interface{}, error) {
}
//转换成统一返回类型
imgListResp, err := ConvertType[octopus.GetUserImageListResp](resp)
imgListResp, err := ConvertType[octopus.GetUserImageListResp](resp, nil)
if err != nil {
return nil, err
}
@ -120,7 +121,7 @@ func (o *OctopusLink) SubmitTask(imageId string, cmd string, params []string, re
}
req := &octopus.CreateTrainJobReq{
Platform: o.platform,
Platform: o.participant.Name,
Params: &octopus.CreateTrainJobParam{
ImageId: imageId,
Name: TASK_NAME_PREFIX + utils.RandomString(7),
@ -143,7 +144,7 @@ func (o *OctopusLink) SubmitTask(imageId string, cmd string, params []string, re
}
//转换成统一返回类型
submitResp, err := ConvertType[octopus.CreateTrainJobResp](resp)
submitResp, err := ConvertType[octopus.CreateTrainJobResp](resp, nil)
if err != nil {
return nil, err
}
@ -154,7 +155,7 @@ func (o *OctopusLink) SubmitTask(imageId string, cmd string, params []string, re
func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
// octopus获取任务
req := &octopus.GetTrainJobReq{
Platform: o.platform,
Platform: o.participant.Name,
Id: taskId,
}
resp, err := o.svcCtx.OctopusRpc.GetTrainJob(o.ctx, req)
@ -163,7 +164,7 @@ func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
}
//转换成统一返回类型
taskResp, err := ConvertType[octopus.GetTrainJobResp](resp)
taskResp, err := ConvertType[octopus.GetTrainJobResp](resp, nil)
if err != nil {
return nil, err
}
@ -174,7 +175,7 @@ func (o *OctopusLink) QueryTask(taskId string) (interface{}, error) {
func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) {
// octopus删除任务
req := &octopus.DeleteTrainJobReq{
Platform: o.platform,
Platform: o.participant.Name,
JobIds: []string{taskId},
}
resp, err := o.svcCtx.OctopusRpc.DeleteTrainJob(o.ctx, req)
@ -183,10 +184,30 @@ func (o *OctopusLink) DeleteTask(taskId string) (interface{}, error) {
}
//转换成统一返回类型
deleteResp, err := ConvertType[octopus.DeleteTrainJobResp](resp)
deleteResp, err := ConvertType[octopus.DeleteTrainJobResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
}
func (o *OctopusLink) QuerySpecs() (interface{}, error) {
// octopus查询资源规格
req := &octopus.GetResourceSpecsReq{
Platform: o.participant.Name,
ResourcePool: "common-pool",
}
resp, err := o.svcCtx.OctopusRpc.GetResourceSpecs(o.ctx, req)
if err != nil {
return nil, err
}
//转换成统一返回类型
specsResp, err := ConvertType[octopus.GetResourceSpecsResp](resp, o.participant)
if err != nil {
return nil, err
}
return specsResp, nil
}

View File

@ -0,0 +1,152 @@
package storeLink
import (
"context"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils/timeutils"
"gitlink.org.cn/jcce-pcm/pcm-participant-ac/hpcAC"
"time"
)
type ShuguangAi struct {
ctx context.Context
svcCtx *svc.ServiceContext
participant *models.ScParticipantPhyInfo
}
func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *ShuguangAi {
return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, participant: participant}
}
func (s *ShuguangAi) UploadImage(path string) (interface{}, error) {
return nil, nil
}
func (s *ShuguangAi) DeleteImage(imageId string) (interface{}, error) {
return nil, nil
}
func (s *ShuguangAi) QueryImageList() (interface{}, error) {
// shuguangAi获取镜像列表
req := &hpcAC.GetImageListAiReq{
AcceleratorType: DCU,
TaskType: PYTORCH,
}
resp, err := s.svcCtx.ACRpc.GetImageListAi(s.ctx, req)
if err != nil {
return nil, err
}
//转换成统一返回类型
imgListResp, err := ConvertType[hpcAC.GetImageListAiResp](resp, nil)
if err != nil {
return nil, err
}
return imgListResp, nil
}
func (s *ShuguangAi) SubmitTask(imageId string, cmd string, params []string, resourceId string) (interface{}, error) {
// shuguangAi提交任务
//根据imageId获取imagePath, version
imageReq := &hpcAC.GetImageAiByIdReq{ImageId: imageId}
imageResp, err := s.svcCtx.ACRpc.GetImageAiById(s.ctx, imageReq)
if err != nil {
return nil, err
}
dateStr := timeutils.UnixTimeToString(time.Now().Unix())
req := &hpcAC.SubmitPytorchTaskReq{
Params: &hpcAC.SubmitPytorchTaskParams{
TaskName: TASK_PYTORCH_PREFIX + "_" + utils.RandomString(7) + dateStr,
WorkPath: WorkPath,
IsDistributed: false,
IsHvd: false,
//Env:
AcceleratorType: DCU,
Version: imageResp.Image.Version,
ImagePath: imageResp.Image.Path,
WorkerNumber: 1,
WorkerCpuNumber: "1",
WorkerGpuNumber: 1,
WorkerRamSize: 1024,
ResourceGroup: RESOURCE_GROUP,
TimeoutLimit: TimeoutLimit,
PythonCodePath: PythonCodePath,
},
}
resp, err := s.svcCtx.ACRpc.SubmitPytorchTask(s.ctx, req)
if err != nil {
return nil, err
}
//转换成统一返回类型
submitResp, err := ConvertType[hpcAC.SubmitTaskAiResp](resp, nil)
if err != nil {
return nil, err
}
return submitResp, nil
}
func (s *ShuguangAi) QueryTask(taskId string) (interface{}, error) {
// shuguangAi获取任务
req := &hpcAC.GetPytorchTaskReq{
Id: taskId,
}
resp, err := s.svcCtx.ACRpc.GetPytorchTask(s.ctx, req)
if err != nil {
return nil, err
}
//转换成统一返回类型
taskResp, err := ConvertType[hpcAC.GetPytorchTaskResp](resp, nil)
if err != nil {
return nil, err
}
return taskResp, nil
}
func (s *ShuguangAi) DeleteTask(taskId string) (interface{}, error) {
// shuguangAi删除任务
req := &hpcAC.DeleteTaskAiReq{
Ids: taskId,
}
resp, err := s.svcCtx.ACRpc.DeleteTaskAi(s.ctx, req)
if err != nil {
return nil, err
}
//转换成统一返回类型
deleteResp, err := ConvertType[hpcAC.DeleteTaskAiResp](resp, nil)
if err != nil {
return nil, err
}
return deleteResp, nil
}
func (o *ShuguangAi) QuerySpecs() (interface{}, error) {
// ShuguangAi查询资源规格
req := &hpcAC.GetResourceSpecReq{
AcceleratorType: DCU,
ResourceGroup: RESOURCE_GROUP,
}
specs, err := o.svcCtx.ACRpc.GetResourceSpec(o.ctx, req)
if err != nil {
return nil, err
}
//转换成统一返回类型
specsResp, err := ConvertType[hpcAC.GetResourceSpecResp](specs, o.participant)
if err != nil {
return nil, err
}
return specsResp, nil
}

View File

@ -6,9 +6,12 @@ import (
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils/timeutils"
"gitlink.org.cn/jcce-pcm/pcm-participant-ac/hpcAC"
"gitlink.org.cn/jcce-pcm/pcm-participant-modelarts/modelarts"
"gitlink.org.cn/jcce-pcm/pcm-participant-octopus/octopus"
"gorm.io/gorm"
"strconv"
)
type Linkage interface {
@ -17,15 +20,25 @@ type Linkage interface {
QueryImageList() (interface{}, error)
SubmitTask(imageId string, cmd string, params []string, resourceId string) (interface{}, error)
QueryTask(taskId string) (interface{}, error)
QuerySpecs() (interface{}, error)
DeleteTask(taskId string) (interface{}, error)
}
const (
COMMA = ","
TYPE_OCTOPUS = "1"
TYPE_MODELARTS = "2"
OCTOPUS = "Octopus"
MODELARTS = "Modelarts"
COMMA = ","
TYPE_OCTOPUS = "1"
TYPE_MODELARTS = "2"
TYPE_SHUGUANGAI = "3"
OCTOPUS = "Octopus"
MODELARTS = "Modelarts"
DCU = "dcu"
PYTORCH = "Pytorch"
TASK_PYTORCH_PREFIX = "PytorchTask"
TENSORFLOW = "Tensorflow"
RESOURCE_GROUP = "wzhdtest"
WorkPath = "/work/home/acgnnmfbwo/111111/py/"
TimeoutLimit = "10:00:00"
PythonCodePath = "/work/home/acgnnmfbwo/111111/py/test.py"
)
var (
@ -44,25 +57,35 @@ type StoreLink struct {
ILinkage Linkage
}
func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant models.ScParticipantPhyInfo) *StoreLink {
//todo 创建modelarts client
linkStruct := NewOctopusLink(ctx, svcCtx, participant.Name)
return &StoreLink{ILinkage: linkStruct}
func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *StoreLink {
switch participant.Type {
case TYPE_OCTOPUS:
linkStruct := NewOctopusLink(ctx, svcCtx, participant)
return &StoreLink{ILinkage: linkStruct}
case TYPE_MODELARTS:
linkStruct := NewModelArtsLink(ctx, svcCtx, participant)
return &StoreLink{ILinkage: linkStruct}
case TYPE_SHUGUANGAI:
linkStruct := NewShuguangAi(ctx, svcCtx, participant)
return &StoreLink{ILinkage: linkStruct}
default:
return nil
}
}
func GetParticipants(dbEngin *gorm.DB) []models.ScParticipantPhyInfo {
var participants []models.ScParticipantPhyInfo
func GetParticipants(dbEngin *gorm.DB) []*models.ScParticipantPhyInfo {
var participants []*models.ScParticipantPhyInfo
dbEngin.Raw("select * from sc_participant_phy_info where type = 1").Scan(&participants)
return participants
}
func GetParticipantById(partId int64, dbEngin *gorm.DB) models.ScParticipantPhyInfo {
func GetParticipantById(partId int64, dbEngin *gorm.DB) *models.ScParticipantPhyInfo {
var participant models.ScParticipantPhyInfo
dbEngin.Raw("select * from sc_participant_phy_info where id = ?", partId).Scan(&participant)
return participant
return &participant
}
func ConvertType[T any](in *T) (interface{}, error) {
func ConvertType[T any](in *T, participant *models.ScParticipantPhyInfo) (interface{}, error) {
switch (interface{})(in).(type) {
case *octopus.UploadImageResp:
@ -74,6 +97,16 @@ func ConvertType[T any](in *T) (interface{}, error) {
return resp, nil
}
return resp, nil
case *octopus.DeleteImageResp:
var resp types.DeleteLinkImageResp
inresp := (interface{})(in).(*octopus.DeleteImageResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
case *octopus.GetUserImageListResp:
@ -91,61 +124,9 @@ func ConvertType[T any](in *T) (interface{}, error) {
image.ImageId = v.Image.Id
image.ImageName = v.Image.ImageName
image.ImageStatus = OctImgStatus[v.Image.ImageStatus]
resp.Images = append(resp.Images, image)
resp.Images = append(resp.Images, &image)
}
return resp, nil
case *octopus.DeleteImageResp:
var resp types.DeleteLinkImageResp
inresp := (interface{})(in).(*octopus.DeleteImageResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
case *octopus.CreateTrainJobResp:
var resp types.SubmitLinkTaskResp
inresp := (interface{})(in).(*octopus.CreateTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
resp.TaskId = inresp.Payload.JobId
return resp, nil
case *octopus.GetTrainJobResp:
var resp types.GetLinkTaskResp
inresp := (interface{})(in).(*octopus.GetTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
resp.Task.TaskId = inresp.Payload.TrainJob.Id
resp.Task.TaskName = inresp.Payload.TrainJob.Name
resp.Task.StartedAt = inresp.Payload.TrainJob.StartedAt
resp.Task.CompletedAt = inresp.Payload.TrainJob.CompletedAt
resp.Task.TaskStatus = inresp.Payload.TrainJob.Status
return resp, nil
case *octopus.DeleteTrainJobResp:
var resp types.DeleteLinkTaskResp
inresp := (interface{})(in).(*octopus.DeleteTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
case *modelarts.ListReposDetailsResp:
var resp types.GetLinkImageListResp
inresp := (interface{})(in).(*modelarts.ListReposDetailsResp)
@ -162,10 +143,42 @@ func ConvertType[T any](in *T) (interface{}, error) {
var image types.ImageSl
image.ImageId = v.Namespace + "/" + v.Name + ":" + r
image.ImageName = v.Name
image.ImageStatus = "succeed"
resp.Images = append(resp.Images, image)
image.ImageStatus = "created"
resp.Images = append(resp.Images, &image)
}
}
return resp, nil
case *hpcAC.GetImageListAiResp:
var resp types.GetLinkImageListResp
inresp := (interface{})(in).(*hpcAC.GetImageListAiResp)
if inresp.Code == "0" {
resp.Success = true
for _, img := range inresp.Data {
var image types.ImageSl
image.ImageId = img.ImageId
image.ImageName = img.Name
image.ImageStatus = "created"
resp.Images = append(resp.Images, &image)
}
} else {
resp.Success = false
resp.ErrorMsg = inresp.Msg
resp.Images = nil
}
return resp, nil
case *octopus.CreateTrainJobResp:
var resp types.SubmitLinkTaskResp
inresp := (interface{})(in).(*octopus.CreateTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
resp.TaskId = inresp.Payload.JobId
return resp, nil
case *modelarts.CreateTrainingJobResp:
var resp types.SubmitLinkTaskResp
@ -179,6 +192,34 @@ func ConvertType[T any](in *T) (interface{}, error) {
resp.TaskId = inresp.Metadata.Id
return resp, nil
case *hpcAC.SubmitTaskAiResp:
var resp types.SubmitLinkTaskResp
inresp := (interface{})(in).(*hpcAC.SubmitTaskAiResp)
if inresp.Code == "0" {
resp.Success = true
resp.TaskId = inresp.Data
} else {
resp.Success = false
resp.ErrorMsg = inresp.Msg
}
return resp, nil
case *octopus.GetTrainJobResp:
var resp types.GetLinkTaskResp
inresp := (interface{})(in).(*octopus.GetTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
resp.Task.TaskId = inresp.Payload.TrainJob.Id
resp.Task.TaskName = inresp.Payload.TrainJob.Name
resp.Task.StartedAt = inresp.Payload.TrainJob.StartedAt
resp.Task.CompletedAt = inresp.Payload.TrainJob.CompletedAt
resp.Task.TaskStatus = inresp.Payload.TrainJob.Status
return resp, nil
case *modelarts.JobResponse:
var resp types.GetLinkTaskResp
@ -195,6 +236,33 @@ func ConvertType[T any](in *T) (interface{}, error) {
resp.Task.CompletedAt = int64(inresp.Status.Duration)
resp.Task.TaskStatus = inresp.Status.Phase
return resp, nil
case *hpcAC.GetPytorchTaskResp:
var resp types.GetLinkTaskResp
inresp := (interface{})(in).(*hpcAC.GetPytorchTaskResp)
if inresp.Code == "0" {
resp.Success = true
resp.Task.TaskId = inresp.Data.Id
resp.Task.TaskName = inresp.Data.TaskName
resp.Task.TaskStatus = inresp.Data.Status
resp.Task.StartedAt = timeutils.StringToUnixTime(inresp.Data.StartTime)
resp.Task.CompletedAt = timeutils.StringToUnixTime(inresp.Data.EndTime)
} else {
resp.Success = false
resp.ErrorMsg = inresp.Msg
resp.Task = nil
}
return resp, nil
case *octopus.DeleteTrainJobResp:
var resp types.DeleteLinkTaskResp
inresp := (interface{})(in).(*octopus.DeleteTrainJobResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ErrorMsg = inresp.Error.Message
return resp, nil
}
return resp, nil
case *modelarts.DeleteTrainingJobResp:
var resp types.DeleteLinkTaskResp
@ -205,6 +273,51 @@ func ConvertType[T any](in *T) (interface{}, error) {
return resp, nil
}
return resp, nil
case *hpcAC.DeleteTaskAiResp:
var resp types.DeleteLinkTaskResp
inresp := (interface{})(in).(*hpcAC.DeleteTaskAiResp)
if inresp.Code == "0" {
resp.Success = true
} else {
resp.Success = false
resp.ErrorMsg = inresp.Msg
}
return resp, nil
case *octopus.GetResourceSpecsResp:
var resp types.GetResourceSpecsResp
inresp := (interface{})(in).(*octopus.GetResourceSpecsResp)
resp.Success = inresp.Success
if !resp.Success {
resp.ResourceSpecs = nil
return resp, nil
}
for _, spec := range inresp.TrainResourceSpecs {
var respec types.ResourceSpecSl
respec.SpecId = spec.Id
respec.SpecName = spec.Name
respec.ParticipantId = strconv.FormatInt(participant.Id, 10)
respec.ParticipantName = participant.Name
respec.SpecPrice = spec.Price
resp.ResourceSpecs = append(resp.ResourceSpecs, &respec)
}
return resp, nil
case *hpcAC.GetResourceSpecResp:
var resp types.GetResourceSpecsResp
inresp := (interface{})(in).(*hpcAC.GetResourceSpecResp)
if inresp.Code != "0" {
resp.Success = false
resp.ResourceSpecs = nil
} else {
var spec types.ResourceSpecSl
resp.Success = true
spec.ParticipantName = participant.Name
spec.ParticipantId = strconv.FormatInt(participant.Id, 10)
resp.ResourceSpecs = append(resp.ResourceSpecs, &spec)
}
return resp, nil
default:
return nil, errors.New("type convert fail")
}

View File

@ -2416,7 +2416,7 @@ type UpdateServerResp struct {
type StartServerReq struct {
ServerId string `json:"server_id" copier:"ServerId"`
Action []map[string]string `json:"Action,optional" copier:"Action"`
Action []map[string]string `json:"action,optional" copier:"Action"`
Start_action string `json:"start_action" copier:"start_action"`
}
@ -2428,7 +2428,7 @@ type StartServerResp struct {
type StopServerReq struct {
ServerId string `json:"server_id" copier:"ServerId"`
Action []map[string]string `json:"Action,optional" copier:"Action"`
Action []map[string]string `json:"action,optional" copier:"Action"`
Stop_action string `json:"stop_action" copier:"stop_action"`
}
@ -2891,8 +2891,8 @@ type Extra_specs struct {
}
type UpdateVolumeReq struct {
Volume Volume `json:"volume" copier:"Volume"`
VolumeTypeId string `json:"volume_type_id" copier:"VolumeTypeId"`
Volume Volume `json:"volume" copier:"Volume"`
VolumeId string `json:"volume_id" copier:"VolumeId"`
}
type UpdateVolumeResp struct {
@ -2945,7 +2945,7 @@ type CreateVolumeTypeResp struct {
}
type VolumeType struct {
VolumeType string `json:"Volume_type" copier:"VolumeType"`
Name string `json:"name" copier:"Name"`
Description string `json:"description" copier:"Description"`
ExtraSpecs ExtraSpecs `json:"extra_specs" copier:"ExtraSpecs"`
Id string `json:"id" copier:"Id"`
@ -3344,9 +3344,9 @@ type UploadLinkImageReq struct {
}
type UploadLinkImageResp struct {
Success bool `json:"success"`
Image ImageSl `json:"image"`
ErrorMsg string `json:"errorMsg"`
Success bool `json:"success"`
Image *ImageSl `json:"image"`
ErrorMsg string `json:"errorMsg"`
}
type ImageSl struct {
@ -3360,9 +3360,9 @@ type GetLinkImageListReq struct {
}
type GetLinkImageListResp struct {
Success bool `json:"success"`
Images []ImageSl `json:"images"`
ErrorMsg string `json:"errorMsg"`
Success bool `json:"success"`
Images []*ImageSl `json:"images"`
ErrorMsg string `json:"errorMsg"`
}
type DeleteLinkImageReq struct {
@ -3376,11 +3376,11 @@ type DeleteLinkImageResp struct {
}
type SubmitLinkTaskReq struct {
PartId int64 `json:"partId"`
ImageId string `json:"imageId"`
Cmd string `json:"cmd"`
Params []ParamSl `json:"params"`
ResourceId string `json:"resourceId"`
PartId int64 `json:"partId"`
ImageId string `json:"imageId"`
Cmd string `json:"cmd"`
Params []*ParamSl `json:"params"`
ResourceId string `json:"resourceId"`
}
type ParamSl struct {
@ -3400,9 +3400,9 @@ type GetLinkTaskReq struct {
}
type GetLinkTaskResp struct {
Success bool `json:"success"`
Task TaskSl `json:"task"`
ErrorMsg string `json:"errorMsg"`
Success bool `json:"success"`
Task *TaskSl `json:"task"`
ErrorMsg string `json:"errorMsg"`
}
type DeleteLinkTaskReq struct {
@ -3427,8 +3427,8 @@ type GetParticipantsReq struct {
}
type GetParticipantsResp struct {
Success bool `json:"success"`
Participants []ParticipantSl `json:"participant"`
Success bool `json:"success"`
Participants []*ParticipantSl `json:"participant"`
}
type GetResourceSpecsReq struct {
@ -3436,8 +3436,8 @@ type GetResourceSpecsReq struct {
}
type GetResourceSpecsResp struct {
Success bool `json:"success"`
ResourceSpecs []ResourceSpecSl `json:"resourceSpecs"`
Success bool `json:"success"`
ResourceSpecs []*ResourceSpecSl `json:"resourceSpecs"`
}
type ResourceSpecSl struct {

2
go.mod
View File

@ -21,7 +21,7 @@ require (
github.com/shopspring/decimal v1.3.1
github.com/zeromicro/go-queue v1.1.8
github.com/zeromicro/go-zero v1.5.5
gitlink.org.cn/jcce-pcm/pcm-participant-ac v0.0.0-20230814074259-99e24e1194d1
gitlink.org.cn/jcce-pcm/pcm-participant-ac v0.0.0-20231026084523-f76f3da5525d
gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230817103341-2459e5bfc835
gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes v0.0.0-20230830120334-bf6d99c715ef
gitlink.org.cn/jcce-pcm/pcm-participant-modelarts v0.0.0-20231024115530-f6fd0505d2a1

4
go.sum
View File

@ -1033,8 +1033,8 @@ github.com/zeromicro/go-zero v1.4.3/go.mod h1:UmDjuW7LHd9j7+nnnPBcXF0HLNmjJw6OjH
github.com/zeromicro/go-zero v1.5.1/go.mod h1:bGYm4XWsGN9GhDsO2O2BngpVoWjf3Eog2a5hUOMhlXs=
github.com/zeromicro/go-zero v1.5.3 h1:9poyd+raeL7gSMUu6P19N7bssTppieR2j7Oos2j1yFQ=
github.com/zeromicro/go-zero v1.5.3/go.mod h1:dmoBpgJTxt9KWmgrNGpv06XxZRPXMakrxUVgROFAR3g=
gitlink.org.cn/jcce-pcm/pcm-participant-ac v0.0.0-20230814074259-99e24e1194d1 h1:eh5H8d2+YsvN6uhkwMg6UbihPEDZcU2yKpXVYE8hDE0=
gitlink.org.cn/jcce-pcm/pcm-participant-ac v0.0.0-20230814074259-99e24e1194d1/go.mod h1:OflOWySJqYAygcwL7vT2yVtfcUs9TM3kmoD+89Tbu7c=
gitlink.org.cn/jcce-pcm/pcm-participant-ac v0.0.0-20231026084523-f76f3da5525d h1:CY4pWM8JVRXBtD5CdVZC0fe4xUxjHmQegdwpHBaOBes=
gitlink.org.cn/jcce-pcm/pcm-participant-ac v0.0.0-20231026084523-f76f3da5525d/go.mod h1:DY45tXlPBWBptj9YjCHWnAK5LshvJ33PjFkE5/vtd4o=
gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230817103341-2459e5bfc835 h1:WDCPqD8IrepGJXankkpG14Ny6inh9AldB0RX9WWa+ck=
gitlink.org.cn/jcce-pcm/pcm-participant-ceph v0.0.0-20230817103341-2459e5bfc835/go.mod h1:r/KLzUpupCV5jdxSfgDhc2pVjP0fBi3VhAWRttsBn30=
gitlink.org.cn/jcce-pcm/pcm-participant-kubernetes v0.0.0-20230830120334-bf6d99c715ef h1:s7JfXjka2MhGaDjKMJ57fj0k3XuDB6w+UlYHFLyJlUY=

View File

@ -47,3 +47,17 @@ func TimeRemoveZone(tm time.Time) time.Time {
}
return parse
}
func StringToUnixTime(str string) int64 {
dt, err := time.ParseInLocation("2006-01-02 15:04:05", str, time.Local)
if err != nil {
return 0
}
return dt.Unix()
}
func UnixTimeToString(ut int64) string {
t := time.Unix(ut, 0)
return t.Format("2006-01-02 15:04:05")
}