Merge branch 'master' of https://gitlink.org.cn/JointCloud/pcm-coordinator
Former-commit-id: 24c55d85e333fa974545a84f855e41bc0e19c854
This commit is contained in:
commit
c3486ec099
|
@ -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"`
|
||||
|
|
|
@ -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二级接口
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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),
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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{
|
||||
|
|
|
@ -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"`
|
||||
|
|
Loading…
Reference in New Issue