diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index da7df371..f433416e 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -49,6 +49,52 @@ type ( } ) +type ( + PublicImageReq { + + } + PublicImageResp { + Code int `json:"code"` + Message string `json:"message"` + ImageDict []ImageDict `json:"imageRDict"` + } + ImageDict { + Id int `json:"id"` + PublicImageName string `json:"public_image_name"` + } +) + +type ( + PublicFlavorReq { + + } + PublicFlavorResp { + Code int `json:"code"` + Message string `json:"message"` + FlavorDict []FlavorDict `json:"flavorDict"` + } + FlavorDict { + Id int `json:"id"` + PublicFlavorName string `json:"public_flavor_name"` + } +) + +type ( + PublicNetworkReq { + + } + PublicNetworkResp { + Code int `json:"code"` + Message string `json:"message"` + NetworkDict []NetworkDict `json:"networkDict"` + } + NetworkDict { + Id int `json:"id"` + PublicImageName string `json:"public_image_name"` + } + +) + type remoteResp { Code int `json:"code"` Message string `json:"message"` diff --git a/api/desc/pcm.api b/api/desc/pcm.api index 2515c1e1..8a3ac032 100644 --- a/api/desc/pcm.api +++ b/api/desc/pcm.api @@ -145,6 +145,18 @@ service pcm { @doc "task details" @handler taskDetails get /core/task/details (FId) returns(TaskDetailsResp) + + @doc "Get Public Image" + @handler getPublicImageHandler + get /core/getPublicImage (PublicImageReq) returns (PublicImageResp) + + @doc "Get Public Flavor" + @handler getPublicFlavorHandler + get /core/getPublicFlavor (PublicFlavorReq) returns (PublicFlavorResp) + + @doc "Get Public Network" + @handler getPublicNetworkHandler + get /core/getPublicNetwork (PublicNetworkReq) returns (PublicNetworkResp) } //hpc二级接口 diff --git a/api/internal/handler/core/getpublicflavorhandler.go b/api/internal/handler/core/getpublicflavorhandler.go new file mode 100644 index 00000000..0fc1942a --- /dev/null +++ b/api/internal/handler/core/getpublicflavorhandler.go @@ -0,0 +1,28 @@ +package core + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func GetPublicFlavorHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.PublicFlavorReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := core.NewGetPublicFlavorLogic(r.Context(), svcCtx) + resp, err := l.GetPublicFlavor(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/api/internal/handler/core/getpublicimagehandler.go b/api/internal/handler/core/getpublicimagehandler.go new file mode 100644 index 00000000..de2b1033 --- /dev/null +++ b/api/internal/handler/core/getpublicimagehandler.go @@ -0,0 +1,28 @@ +package core + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func GetPublicImageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.PublicImageReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := core.NewGetPublicImageLogic(r.Context(), svcCtx) + resp, err := l.GetPublicImage(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/api/internal/handler/core/getpublicnetworkhandler.go b/api/internal/handler/core/getpublicnetworkhandler.go new file mode 100644 index 00000000..7450740d --- /dev/null +++ b/api/internal/handler/core/getpublicnetworkhandler.go @@ -0,0 +1,28 @@ +package core + +import ( + "net/http" + + "github.com/zeromicro/go-zero/rest/httpx" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/logic/core" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" +) + +func GetPublicNetworkHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + var req types.PublicNetworkReq + if err := httpx.Parse(r, &req); err != nil { + httpx.ErrorCtx(r.Context(), w, err) + return + } + + l := core.NewGetPublicNetworkLogic(r.Context(), svcCtx) + resp, err := l.GetPublicNetwork(&req) + if err != nil { + httpx.ErrorCtx(r.Context(), w, err) + } else { + httpx.OkJsonCtx(r.Context(), w, resp) + } + } +} diff --git a/api/internal/handler/routes.go b/api/internal/handler/routes.go index f72ac4f9..bedd9c57 100644 --- a/api/internal/handler/routes.go +++ b/api/internal/handler/routes.go @@ -175,6 +175,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/core/task/details", Handler: core.TaskDetailsHandler(serverCtx), }, + { + Method: http.MethodGet, + Path: "/core/getPublicImage", + Handler: core.GetPublicImageHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/core/getPublicFlavor", + Handler: core.GetPublicFlavorHandler(serverCtx), + }, + { + Method: http.MethodGet, + Path: "/core/getPublicNetwork", + Handler: core.GetPublicNetworkHandler(serverCtx), + }, }, rest.WithPrefix("/pcm/v1"), ) @@ -1175,11 +1190,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/schedule/ai/getAlgorithms/:adapterId/:resourceType/:taskType/:dataset", Handler: schedule.ScheduleGetAlgorithmsHandler(serverCtx), }, - { - Method: http.MethodGet, - Path: "/schedule/ai/getJobLog/:adapterId/:clusterId/:taskId/:instanceNum", - Handler: schedule.ScheduleGetAiJobLogLogHandler(serverCtx), - }, { Method: http.MethodPost, Path: "/schedule/submit", @@ -1284,7 +1294,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { }, { Method: http.MethodPost, - Path: "/monitoring/syncClusterAlert", + Path: "/core/syncClusterAlert", Handler: monitoring.SyncClusterAlertHandler(serverCtx), }, { diff --git a/api/internal/logic/core/commithpctasklogic.go b/api/internal/logic/core/commithpctasklogic.go deleted file mode 100644 index d676a7c9..00000000 --- a/api/internal/logic/core/commithpctasklogic.go +++ /dev/null @@ -1,65 +0,0 @@ -package core - -import ( - "context" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/pkg/response" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" - tool "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" - "k8s.io/apimachinery/pkg/util/json" - "time" - - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" - - "github.com/zeromicro/go-zero/core/logx" -) - -type CommitHpcTaskLogic struct { - logx.Logger - ctx context.Context - svcCtx *svc.ServiceContext -} - -func NewCommitHpcTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommitHpcTaskLogic { - return &CommitHpcTaskLogic{ - Logger: logx.WithContext(ctx), - ctx: ctx, - svcCtx: svcCtx, - } -} - -func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *types.CommitHpcTaskResp, err error) { - // 构建主任务结构体 - taskModel := models.Task{ - Status: constants.Saved, - Description: req.Description, - Name: req.Name, - CommitTime: time.Now(), - } - // 保存任务数据到数据库 - tx := l.svcCtx.DbEngin.Create(&taskModel) - if tx.Error != nil { - return nil, tx.Error - } - hpc := models.Hpc{} - tool.Convert(req, &hpc) - mqInfo := response.TaskInfo{ - TaskId: taskModel.Id, - TaskType: "hpc", - MatchLabels: req.MatchLabels, - //Metadata: hpc, - } - req.TaskId = taskModel.Id - // 将任务数据转换成消息体 - reqMessage, err := json.Marshal(mqInfo) - if err != nil { - logx.Error(err) - return nil, err - } - publish := l.svcCtx.RedisClient.Publish(context.Background(), mqInfo.TaskType, reqMessage) - if publish.Err() != nil { - return nil, publish.Err() - } - return -} diff --git a/api/internal/logic/core/getpublicflavorlogic.go b/api/internal/logic/core/getpublicflavorlogic.go new file mode 100644 index 00000000..14d4be55 --- /dev/null +++ b/api/internal/logic/core/getpublicflavorlogic.go @@ -0,0 +1,40 @@ +package core + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetPublicFlavorLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetPublicFlavorLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPublicFlavorLogic { + return &GetPublicFlavorLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetPublicFlavorLogic) GetPublicFlavor(req *types.PublicFlavorReq) (resp *types.PublicFlavorResp, err error) { + // todo: add your logic here and delete this line + resp = &types.PublicFlavorResp{} + var flavorDict []types.FlavorDict + sqlStrTask := "SELECT * FROM `vm_flavor_dict`" + txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&flavorDict) + if txTask.Error != nil { + logx.Error(err) + return nil, txTask.Error + } + resp.Code = 200 + resp.Message = "success" + resp.FlavorDict = flavorDict + return resp, nil +} diff --git a/api/internal/logic/core/getpublicimagelogic.go b/api/internal/logic/core/getpublicimagelogic.go new file mode 100644 index 00000000..a3dafc16 --- /dev/null +++ b/api/internal/logic/core/getpublicimagelogic.go @@ -0,0 +1,40 @@ +package core + +import ( + "context" + + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetPublicImageLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetPublicImageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPublicImageLogic { + return &GetPublicImageLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetPublicImageLogic) GetPublicImage(req *types.PublicImageReq) (resp *types.PublicImageResp, err error) { + // todo: add your logic here and delete this line + resp = &types.PublicImageResp{} + var iamgeDict []types.ImageDict + sqlStrTask := "SELECT * FROM `vm_image_dict`" + txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&iamgeDict) + if txTask.Error != nil { + logx.Error(err) + return nil, txTask.Error + } + resp.Code = 200 + resp.Message = "success" + resp.ImageDict = iamgeDict + return resp, nil +} diff --git a/api/internal/logic/core/getpublicnetworklogic.go b/api/internal/logic/core/getpublicnetworklogic.go new file mode 100644 index 00000000..b0d38bb0 --- /dev/null +++ b/api/internal/logic/core/getpublicnetworklogic.go @@ -0,0 +1,39 @@ +package core + +import ( + "context" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" + "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + + "github.com/zeromicro/go-zero/core/logx" +) + +type GetPublicNetworkLogic struct { + logx.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +func NewGetPublicNetworkLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPublicNetworkLogic { + return &GetPublicNetworkLogic{ + Logger: logx.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *GetPublicNetworkLogic) GetPublicNetwork(req *types.PublicNetworkReq) (resp *types.PublicNetworkResp, err error) { + // todo: add your logic here and delete this line + resp = &types.PublicNetworkResp{} + var networkDict []types.NetworkDict + sqlStrTask := "SELECT * FROM `vm_network_dict`" + txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&networkDict) + if txTask.Error != nil { + logx.Error(err) + return nil, txTask.Error + } + resp.Code = 200 + resp.Message = "success" + resp.NetworkDict = networkDict + return resp, nil +} diff --git a/api/internal/logic/hpc/commithpctasklogic.go b/api/internal/logic/hpc/commithpctasklogic.go index 6211a13d..636400df 100644 --- a/api/internal/logic/hpc/commithpctasklogic.go +++ b/api/internal/logic/hpc/commithpctasklogic.go @@ -32,11 +32,15 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t // 构建主任务结构体 taskModel := models.Task{ - Status: constants.Saved, - Description: req.Description, - Name: req.Name, - CommitTime: time.Now(), + Name: req.Name, + Description: req.Description, + Status: constants.Saved, + Strategy: 0, + SynergyStatus: 0, + CommitTime: time.Now(), + AdapterTypeDict: 2, } + // 保存任务数据到数据库 tx := l.svcCtx.DbEngin.Create(&taskModel) if tx.Error != nil { @@ -49,7 +53,9 @@ func (l *CommitHpcTaskLogic) CommitHpcTask(req *types.CommitHpcTaskReq) (resp *t env, _ := json.Marshal(req.Environment) if len(clusterIds) == 0 || clusterIds == nil { - return nil, nil + resp.Code = 400 + resp.Msg = "no cluster found" + return resp, nil } hpcInfo := models.TaskHpc{ diff --git a/api/internal/types/types.go b/api/internal/types/types.go index cc217112..0a905601 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -41,6 +41,48 @@ type HomeOverviewData struct { TaskSum int64 `json:"taskSum"` } +type PublicImageReq struct { +} + +type PublicImageResp struct { + Code int `json:"code"` + Message string `json:"message"` + ImageDict []ImageDict `json:"imageRDict"` +} + +type ImageDict struct { + Id int `json:"id"` + PublicImageName string `json:"public_image_name"` +} + +type PublicFlavorReq struct { +} + +type PublicFlavorResp struct { + Code int `json:"code"` + Message string `json:"message"` + FlavorDict []FlavorDict `json:"flavorDict"` +} + +type FlavorDict struct { + Id int `json:"id"` + PublicFlavorName string `json:"public_flavor_name"` +} + +type PublicNetworkReq struct { +} + +type PublicNetworkResp struct { + Code int `json:"code"` + Message string `json:"message"` + NetworkDict []NetworkDict `json:"networkDict"` +} + +type NetworkDict struct { + Id int `json:"id"` + PublicImageName string `json:"public_image_name"` +} + type RemoteResp struct { Code int `json:"code"` Message string `json:"message"`