feat: add getAdapterInfo interface for Operator encapsulation
This commit is contained in:
parent
6847b5f8f4
commit
ae66df1119
|
@ -804,6 +804,7 @@ type (
|
|||
Version string `json:"version,omitempty" db:"version"`
|
||||
Server string `json:"server,omitempty" db:"server"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
|
||||
InfoName string `json:"info_name,omitempty"`
|
||||
}
|
||||
AdapterListResp {
|
||||
List []AdapterInfo `json:"list,omitempty"`
|
||||
|
@ -956,6 +957,24 @@ type ClusterRelationInfo {
|
|||
CCreateTime string `json:"cCreateTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
type adapterInfoNameReq {
|
||||
AdapterId string `form:"adapterId,optional"`
|
||||
}
|
||||
|
||||
type adapterInfoNameReqResp {
|
||||
Code int32 `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
ErrorMsg string `json:"errorMsg,omitempty"`
|
||||
InfoList InfoList `json:"infoList,omitempty"`
|
||||
}
|
||||
|
||||
type InfoList {
|
||||
Type string `json:"type,omitempty"`
|
||||
ResourceType string `json:"resource_type,omitempty"`
|
||||
TName string `json:"name,omitempty"`
|
||||
InfoName string `json:"info_name,omitempty"`
|
||||
}
|
||||
|
||||
type (
|
||||
DictInfo {
|
||||
Id string `json:"id,omitempty"`
|
||||
|
|
|
@ -884,6 +884,9 @@ service pcm {
|
|||
|
||||
@handler GetClusterSumHandler
|
||||
get /adapter/clusterSum (clusterSumReq) returns (clusterSumReqResp)
|
||||
|
||||
@handler GetAdapterInfoHandler
|
||||
get /adapter/getAdapterInfo (adapterInfoNameReq) returns (adapterInfoNameReqResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
|
@ -1064,3 +1067,4 @@ service pcm {
|
|||
@handler scheduleSituationHandler
|
||||
get /monitoring/schedule/situation returns (scheduleSituationResp)
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
func GetAdapterInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterInfoNameReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewGetAdapterInfoLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAdapterInfo(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -6,8 +6,10 @@ import (
|
|||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"gorm.io/gorm"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -68,5 +70,33 @@ func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *t
|
|||
|
||||
_ = l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&existAdapter).Error
|
||||
resp = &existAdapter
|
||||
Tadapter := models.TAdapterInfo{}
|
||||
if req.Type == "0" {
|
||||
if req.ResourceType == "01" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "CloudInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "CloudInfoList"
|
||||
} else if req.ResourceType == "02" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "VmInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "VmInfoList"
|
||||
}
|
||||
} else if req.Type == "1" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "AiInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "AiInfoList"
|
||||
} else if req.Type == "2" {
|
||||
Tadapter.Id, _ = strconv.ParseInt(utils.GenSnowflakeIDStr(), 10, 64)
|
||||
Tadapter.AdapterId, _ = strconv.ParseInt(resp.Id, 10, 64)
|
||||
Tadapter.InfoName = "HpcInfoList"
|
||||
l.svcCtx.DbEngin.Table("t_adapter_info").Create(&Tadapter)
|
||||
resp.InfoName = "HpcInfoList"
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
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 GetAdapterInfoLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetAdapterInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterInfoLogic {
|
||||
return &GetAdapterInfoLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetAdapterInfoLogic) GetAdapterInfo(req *types.AdapterInfoNameReq) (resp *types.AdapterInfoNameReqResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
resp = &types.AdapterInfoNameReqResp{}
|
||||
var infoNameReqResp types.AdapterInfoNameReqResp
|
||||
sql := `SELECT ta.type AS Type,ta.resource_type AS ResourceType,ta.name AS TName,tai.info_name AS InfoName FROM t_adapter ta LEFT JOIN t_adapter_info tai ON ta.id = tai.adapter_id WHERE ta.id = ?`
|
||||
tx := l.svcCtx.DbEngin.Raw(sql, req.AdapterId).Scan(&infoNameReqResp.InfoList)
|
||||
if tx.Error != nil {
|
||||
logx.Error(err)
|
||||
return nil, tx.Error
|
||||
}
|
||||
resp.Code = 200
|
||||
resp.Msg = "success"
|
||||
resp.InfoList = infoNameReqResp.InfoList
|
||||
return resp, nil
|
||||
}
|
12077
internal/types/types.go
12077
internal/types/types.go
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,29 @@
|
|||
package models
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ TAdapterInfoModel = (*customTAdapterInfoModel)(nil)
|
||||
|
||||
type (
|
||||
// TAdapterInfoModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customTAdapterInfoModel.
|
||||
TAdapterInfoModel interface {
|
||||
tAdapterInfoModel
|
||||
withSession(session sqlx.Session) TAdapterInfoModel
|
||||
}
|
||||
|
||||
customTAdapterInfoModel struct {
|
||||
*defaultTAdapterInfoModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewTAdapterInfoModel returns a model for the database table.
|
||||
func NewTAdapterInfoModel(conn sqlx.SqlConn) TAdapterInfoModel {
|
||||
return &customTAdapterInfoModel{
|
||||
defaultTAdapterInfoModel: newTAdapterInfoModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customTAdapterInfoModel) withSession(session sqlx.Session) TAdapterInfoModel {
|
||||
return NewTAdapterInfoModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
// Code generated by goctl. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
tAdapterInfoFieldNames = builder.RawFieldNames(&TAdapterInfo{})
|
||||
tAdapterInfoRows = strings.Join(tAdapterInfoFieldNames, ",")
|
||||
tAdapterInfoRowsExpectAutoSet = strings.Join(stringx.Remove(tAdapterInfoFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
tAdapterInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(tAdapterInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
tAdapterInfoModel interface {
|
||||
Insert(ctx context.Context, data *TAdapterInfo) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*TAdapterInfo, error)
|
||||
Update(ctx context.Context, data *TAdapterInfo) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
}
|
||||
|
||||
defaultTAdapterInfoModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
TAdapterInfo struct {
|
||||
Id int64 `db:"id"` // 主键
|
||||
AdapterId int64 `db:"adapter_id"` // 适配器id
|
||||
InfoName string `db:"info_name"` // 对象类型名称
|
||||
}
|
||||
)
|
||||
|
||||
func newTAdapterInfoModel(conn sqlx.SqlConn) *defaultTAdapterInfoModel {
|
||||
return &defaultTAdapterInfoModel{
|
||||
conn: conn,
|
||||
table: "`t_adapter_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) Delete(ctx context.Context, id int64) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) FindOne(ctx context.Context, id int64) (*TAdapterInfo, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", tAdapterInfoRows, m.table)
|
||||
var resp TAdapterInfo
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) Insert(ctx context.Context, data *TAdapterInfo) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, tAdapterInfoRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.AdapterId, data.InfoName)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) Update(ctx context.Context, data *TAdapterInfo) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, tAdapterInfoRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, data.AdapterId, data.InfoName, data.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultTAdapterInfoModel) tableName() string {
|
||||
return m.table
|
||||
}
|
Loading…
Reference in New Issue