forked from JointCloud/pcm-coordinator
add GetClusterBaseInfo handler and logic; implement API for retrieving cluster base information
Signed-off-by: jagger <cossjie@foxmail.com>
This commit is contained in:
parent
a7f90f139a
commit
b574a80516
|
@ -947,6 +947,16 @@ type (
|
||||||
ProxyEnable string `json:"proxyEnable,omitempty" db:"proxy_enable"`
|
ProxyEnable string `json:"proxyEnable,omitempty" db:"proxy_enable"`
|
||||||
Driver string `json:"driver,omitempty" db:"driver"`
|
Driver string `json:"driver,omitempty" db:"driver"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClusterBaseInfo {
|
||||||
|
Id string `json:"id,omitempty" db:"id"`
|
||||||
|
AdapterId int64 `json:"adapterId,omitempty,string" db:"adapter_id"`
|
||||||
|
Name string `json:"name,omitempty" db:"name"`
|
||||||
|
Nickname string `json:"nickname,omitempty" db:"nickname"`
|
||||||
|
Description string `json:"description,omitempty" db:"description"`
|
||||||
|
Server string `json:"server,omitempty" db:"server"`
|
||||||
|
Driver string `json:"driver,omitempty" db:"driver"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
type ClusterDelReq {
|
type ClusterDelReq {
|
||||||
|
|
|
@ -948,6 +948,9 @@ service pcm {
|
||||||
|
|
||||||
@handler GetAdapterInfoHandler
|
@handler GetAdapterInfoHandler
|
||||||
get /adapter/getAdapterInfo (adapterInfoNameReq) returns (adapterInfoNameReqResp)
|
get /adapter/getAdapterInfo (adapterInfoNameReq) returns (adapterInfoNameReqResp)
|
||||||
|
|
||||||
|
@handler GetClusterBaseInfoHandler
|
||||||
|
get /adapter/cluster/getClusterBaseInfo (ClusterReq) returns (PageResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
@server (
|
@server (
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package adapters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/logic/adapters"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetClusterBaseInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.ClusterReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
result.ParamErrorResult(r, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
l := adapters.NewGetClusterBaseInfoLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.GetClusterBaseInfo(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -39,6 +39,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/adapter/cluster/get",
|
Path: "/adapter/cluster/get",
|
||||||
Handler: adapters.GetClusterHandler(serverCtx),
|
Handler: adapters.GetClusterHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodGet,
|
||||||
|
Path: "/adapter/cluster/getClusterBaseInfo",
|
||||||
|
Handler: adapters.GetClusterBaseInfoHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/adapter/cluster/list",
|
Path: "/adapter/cluster/list",
|
||||||
|
@ -98,7 +103,7 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
{
|
{
|
||||||
// 创建算法
|
// 创建算法
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/ai/createAlgorithm",
|
Path: "/ai/CreateAlgorithm/:projectId",
|
||||||
Handler: ai.CreateAlgorithmHandler(serverCtx),
|
Handler: ai.CreateAlgorithmHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -218,22 +223,9 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
{
|
{
|
||||||
// 创建数据集
|
// 创建数据集
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/ai/createDataSet",
|
Path: "/ai/createDataSet/:projectId",
|
||||||
Handler: ai.CreateDataSetHandler(serverCtx),
|
Handler: ai.CreateDataSetHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
// 创建模型
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/ai/createModel",
|
|
||||||
Handler: ai.CreateModelHandler(serverCtx),
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
// 创建模型
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/ai/task/sync",
|
|
||||||
Handler: ai.TaskResultSyncHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
// 创建notebook
|
// 创建notebook
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
|
@ -376,24 +368,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
Path: "/task/list",
|
Path: "/task/list",
|
||||||
Handler: cloud.CloudListHandler(serverCtx),
|
Handler: cloud.CloudListHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
// 创建容器
|
|
||||||
Method: http.MethodPost,
|
|
||||||
Path: "/cloud/container/create",
|
|
||||||
Handler: cloud.ContainerCreateHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 删除容器
|
|
||||||
Method: http.MethodDelete,
|
|
||||||
Path: "/cloud/container/delete",
|
|
||||||
Handler: cloud.ContainerDeleteHandler(serverCtx),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// 获取容器
|
|
||||||
Method: http.MethodGet,
|
|
||||||
Path: "/cloud/container/get",
|
|
||||||
Handler: cloud.ContainerGetHandler(serverCtx),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
rest.WithPrefix("/pcm/v1"),
|
rest.WithPrefix("/pcm/v1"),
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
package adapters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetClusterBaseInfoLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewGetClusterBaseInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClusterBaseInfoLogic {
|
||||||
|
return &GetClusterBaseInfoLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *GetClusterBaseInfoLogic) GetClusterBaseInfo(req *types.ClusterReq) (resp *types.PageResult, err error) {
|
||||||
|
limit := req.PageSize
|
||||||
|
offset := req.PageSize * (req.PageNum - 1)
|
||||||
|
resp = &types.PageResult{}
|
||||||
|
var list []types.ClusterBaseInfo
|
||||||
|
db := l.svcCtx.DbEngin.Model(&types.AdapterInfo{}).Table("t_cluster")
|
||||||
|
|
||||||
|
db = db.Joins("left join t_adapter on t_adapter.id = t_cluster.adapter_id").
|
||||||
|
Where("t_cluster.deleted_at is null")
|
||||||
|
if req.Name != "" {
|
||||||
|
db = db.Where("t_cluster.name LIKE ?", "%"+req.Name+"%")
|
||||||
|
}
|
||||||
|
if req.AdapterId != "" {
|
||||||
|
db = db.Where("t_cluster.adapter_id = ?", req.AdapterId)
|
||||||
|
}
|
||||||
|
if req.Nickname != "" {
|
||||||
|
db = db.Where("t_cluster.nickname LIKE ?", "%"+req.Nickname+"%")
|
||||||
|
}
|
||||||
|
if req.Label != "" {
|
||||||
|
db = db.Where("t_cluster.label = ?", req.Label)
|
||||||
|
}
|
||||||
|
if req.Version != "" {
|
||||||
|
db = db.Where("t_cluster.version = ?", req.Version)
|
||||||
|
}
|
||||||
|
if req.ProducerDict != "" {
|
||||||
|
db = db.Where("t_cluster.producer_dict = ?", req.ProducerDict)
|
||||||
|
}
|
||||||
|
if req.RegionDict != "" {
|
||||||
|
db = db.Where("t_cluster.region_dict = ?", req.RegionDict)
|
||||||
|
}
|
||||||
|
if req.Type != "" {
|
||||||
|
db = db.Where("t_adapter.type = ?", req.Type)
|
||||||
|
}
|
||||||
|
if req.ResourceType != "" {
|
||||||
|
db = db.Where("t_adapter.resource_type = ?", req.ResourceType)
|
||||||
|
}
|
||||||
|
if req.StorageSchedule != "" {
|
||||||
|
db = db.Where("t_cluster.storage_schedule = ?", req.StorageSchedule)
|
||||||
|
}
|
||||||
|
|
||||||
|
//count total
|
||||||
|
var total int64
|
||||||
|
err = db.Select("*").Count(&total).Error
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
db = db.Limit(limit).Offset(offset)
|
||||||
|
err = db.Select("t_cluster.*").Order("t_cluster.create_time desc").Scan(&list).Error
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
resp.List = list
|
||||||
|
resp.PageSize = req.PageSize
|
||||||
|
resp.PageNum = req.PageNum
|
||||||
|
resp.Total = total
|
||||||
|
|
||||||
|
return resp, nil
|
||||||
|
}
|
|
@ -700,6 +700,16 @@ type ClusterAvail struct {
|
||||||
ClusterName string `json:"clusterName"`
|
ClusterName string `json:"clusterName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ClusterBaseInfo struct {
|
||||||
|
Id string `json:"id,omitempty" db:"id"`
|
||||||
|
AdapterId int64 `json:"adapterId,omitempty,string" db:"adapter_id"`
|
||||||
|
Name string `json:"name,omitempty" db:"name"`
|
||||||
|
Nickname string `json:"nickname,omitempty" db:"nickname"`
|
||||||
|
Description string `json:"description,omitempty" db:"description"`
|
||||||
|
Server string `json:"server,omitempty" db:"server"`
|
||||||
|
Driver string `json:"driver,omitempty" db:"driver"`
|
||||||
|
}
|
||||||
|
|
||||||
type ClusterCreateReq struct {
|
type ClusterCreateReq struct {
|
||||||
Id string `json:"id,optional"`
|
Id string `json:"id,optional"`
|
||||||
AdapterId string `json:"adapterId,optional"`
|
AdapterId string `json:"adapterId,optional"`
|
||||||
|
@ -718,14 +728,13 @@ type ClusterCreateReq struct {
|
||||||
Version string `json:"version,optional"`
|
Version string `json:"version,optional"`
|
||||||
Label string `json:"label,optional"`
|
Label string `json:"label,optional"`
|
||||||
OwnerId string `json:"ownerId,omitempty,optional"`
|
OwnerId string `json:"ownerId,omitempty,optional"`
|
||||||
AuthType int32 `json:"authType,optional"`
|
AuthType string `json:"authType,optional"`
|
||||||
ProducerDict string `json:"producerDict,optional"`
|
ProducerDict string `json:"producerDict,optional"`
|
||||||
RegionDict string `json:"regionDict,optional"`
|
RegionDict string `json:"regionDict,optional"`
|
||||||
RegionName string `json:"regionName,optional"`
|
RegionName string `json:"regionName,optional"`
|
||||||
Environment map[string]string `json:"environment,optional"`
|
Environment map[string]string `json:"environment,optional"`
|
||||||
CostType string `json:"costType,optional"`
|
CostType string `json:"costType,optional"`
|
||||||
Price int `json:"price,optional"`
|
Price int `json:"price,optional"`
|
||||||
Status string `json:"status,optional"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClusterData struct {
|
type ClusterData struct {
|
||||||
|
@ -757,7 +766,7 @@ type ClusterInfo struct {
|
||||||
Version string `json:"version,omitempty" db:"version"`
|
Version string `json:"version,omitempty" db:"version"`
|
||||||
Label string `json:"label,omitempty" db:"label"`
|
Label string `json:"label,omitempty" db:"label"`
|
||||||
OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
|
OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
|
||||||
AuthType int32 `json:"authType,omitempty" db:"auth_type"`
|
AuthType string `json:"authType,omitempty" db:"auth_type"`
|
||||||
ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"`
|
ProducerDict string `json:"producerDict,omitempty" db:"producer_dict"`
|
||||||
RegionDict string `json:"regionDict,omitempty" db:"region_dict"`
|
RegionDict string `json:"regionDict,omitempty" db:"region_dict"`
|
||||||
Location string `json:"location,omitempty" db:"location"`
|
Location string `json:"location,omitempty" db:"location"`
|
||||||
|
@ -769,7 +778,6 @@ type ClusterInfo struct {
|
||||||
ProxyAddress string `json:"proxyAddress,omitempty" db:"proxy_address"`
|
ProxyAddress string `json:"proxyAddress,omitempty" db:"proxy_address"`
|
||||||
ProxyEnable string `json:"proxyEnable,omitempty" db:"proxy_enable"`
|
ProxyEnable string `json:"proxyEnable,omitempty" db:"proxy_enable"`
|
||||||
Driver string `json:"driver,omitempty" db:"driver"`
|
Driver string `json:"driver,omitempty" db:"driver"`
|
||||||
Status string `json:"status,omitempty" db:"status"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClusterListResp struct {
|
type ClusterListResp struct {
|
||||||
|
@ -825,7 +833,7 @@ type ClusterRelationInfo struct {
|
||||||
CVersion string `json:"cVersion,omitempty" db:"version"`
|
CVersion string `json:"cVersion,omitempty" db:"version"`
|
||||||
CLabel string `json:"cLabel,omitempty" db:"label"`
|
CLabel string `json:"cLabel,omitempty" db:"label"`
|
||||||
COwnerId string `json:"cOwnerId,omitempty" db:"owner_id"`
|
COwnerId string `json:"cOwnerId,omitempty" db:"owner_id"`
|
||||||
CAuthType int32 `json:"cAuthType,omitempty" db:"auth_type"`
|
CAuthType string `json:"cAuthType,omitempty" db:"auth_type"`
|
||||||
CRegionDict string `json:"cRegionDict,omitempty" db:"-"`
|
CRegionDict string `json:"cRegionDict,omitempty" db:"-"`
|
||||||
CProducerDict string `json:"cProducerDict,omitempty" db:"-"`
|
CProducerDict string `json:"cProducerDict,omitempty" db:"-"`
|
||||||
CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||||
|
@ -2145,8 +2153,7 @@ type EditResourceReq struct {
|
||||||
CpuUnit string `json:"cpuUnit,optional"`
|
CpuUnit string `json:"cpuUnit,optional"`
|
||||||
MemoryValue string `json:"memoryValue,optional"`
|
MemoryValue string `json:"memoryValue,optional"`
|
||||||
MemoryUnit string `json:"memoryUnit,optional"`
|
MemoryUnit string `json:"memoryUnit,optional"`
|
||||||
|
UserId int64 `json:"userId,optional"`
|
||||||
UserId int64 `json:"userId,optional"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EndpointsReq struct {
|
type EndpointsReq struct {
|
||||||
|
|
Loading…
Reference in New Issue