add adapter impl
Signed-off-by: jagger <cossjie@foxmail.com> Former-commit-id: a6090b9e548b1e708441d4e8524186927500b57c
This commit is contained in:
parent
75543eacae
commit
3d3e2e80bc
|
@ -704,4 +704,96 @@ type (
|
|||
Msg string `json:"msg,omitempty"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
type (
|
||||
AdapterReq {
|
||||
Id string `json:"id,optional" db:"id"`
|
||||
Name string `json:"name,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
Nickname string `json:"nickname,optional"`
|
||||
Version string `json:"version,optional"`
|
||||
Server string `json:"server,optional"`
|
||||
}
|
||||
AdapterDelReq {
|
||||
Id string `form:"id,optional" db:"id"`
|
||||
}
|
||||
AdapterInfo {
|
||||
Id string `json:"id,omitempty" db:"id"`
|
||||
Name string `json:"name,omitempty" db:"name"`
|
||||
Type string `json:"type,omitempty" db:"type"`
|
||||
Nickname string `json:"nickname,omitempty" db:"nickname"`
|
||||
Version string `json:"version,omitempty" db:"version"`
|
||||
Server string `json:"server,omitempty" db:"server"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
|
||||
}
|
||||
AdapterResp {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data AdapterInfo `json:"data,omitempty"`
|
||||
}
|
||||
AdapterListResp {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data []AdapterInfo `json:"data,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
type ClusterReq {
|
||||
Id string `json:"id,optional"`
|
||||
AdapterId string `json:"adapterId,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Nickname string `json:"nickname,optional"`
|
||||
Description string `json:"description,optional"`
|
||||
Server string `json:"server,optional"`
|
||||
MonitorServer string `json:"monitorServer,optional"`
|
||||
Username string `json:"username,optional"`
|
||||
Password string `json:"password,optional"`
|
||||
Token string `json:"token,optional"`
|
||||
Ak string `json:"ak,optional"`
|
||||
Sk string `json:"sk,optional"`
|
||||
Region string `json:"region,optional"`
|
||||
ProjectId string `json:"projectId,optional"`
|
||||
Version string `json:"version,optional"`
|
||||
Label string `json:"label,optional"`
|
||||
OwnerId string `json:"ownerId,omitempty,optional"`
|
||||
AuthType string `json:"authType,optional"`
|
||||
}
|
||||
|
||||
type ClusterDelReq {
|
||||
Id string `form:"id,optional"`
|
||||
}
|
||||
|
||||
type ClusterInfo {
|
||||
Id string `json:"id,omitempty" db:"id"`
|
||||
AdapterId string `json:"adapterId,omitempty" 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"`
|
||||
MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"`
|
||||
Username string `json:"username,omitempty" db:"username"`
|
||||
Password string `json:"password,omitempty" db:"password"`
|
||||
Token string `json:"token,omitempty" db:"token"`
|
||||
Ak string `json:"ak,omitempty" db:"ak"`
|
||||
Sk string `json:"sk,omitempty" db:"sk"`
|
||||
Region string `json:"region,omitempty" db:"region"`
|
||||
ProjectId string `json:"projectId,omitempty" db:"project_id"`
|
||||
Version string `json:"version,omitempty" db:"version"`
|
||||
Label string `json:"label,omitempty" db:"label"`
|
||||
OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
|
||||
AuthType string `json:"authType,omitempty" db:"auth_type"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
type ClusterResp {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data ClusterInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type ClusterListResp {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data []ClusterInfo `json:"data,omitempty"`
|
||||
}
|
|
@ -570,4 +570,42 @@ service pcm {
|
|||
@doc "启动应用"
|
||||
@handler StartAppByAppName
|
||||
put /apps/startApp (DeleteAppReq) returns (AppResp)
|
||||
}
|
||||
|
||||
// 接口
|
||||
@server(
|
||||
prefix: pcm/v1
|
||||
group : adapters
|
||||
)
|
||||
|
||||
service pcm {
|
||||
@handler AdaptersListHandler
|
||||
get /adapter/list (AdapterReq) returns (AdapterListResp)
|
||||
|
||||
@handler CreateAdapterHandler
|
||||
post /adapter/create (AdapterReq) returns (AdapterResp)
|
||||
|
||||
@handler UpdateAdapterHandler
|
||||
put /adapter/update (AdapterReq) returns (AdapterResp)
|
||||
|
||||
@handler DeleteAdapterHandler
|
||||
delete /adapter/delete (AdapterDelReq) returns (AdapterResp)
|
||||
|
||||
@handler GetAdapterHandler
|
||||
get /adapter/get (AdapterDelReq) returns (AdapterResp)
|
||||
|
||||
@handler ClusterListHandler
|
||||
get /adapter/cluster/list (ClusterReq) returns (ClusterListResp)
|
||||
|
||||
@handler CreateClusterHandler
|
||||
post /adapter/cluster/create (ClusterReq) returns (ClusterResp)
|
||||
|
||||
@handler UpdateClusterHandler
|
||||
put /adapter/cluster/update (ClusterReq) returns (ClusterResp)
|
||||
|
||||
@handler DeleteClusterHandler
|
||||
delete /adapter/cluster/delete (ClusterDelReq) returns (ClusterResp)
|
||||
|
||||
@handler GetClusterHandler
|
||||
get /adapter/cluster/get (ClusterDelReq) returns (ClusterResp)
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func AdaptersListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewAdaptersListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.AdaptersList(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func ClusterListHandler(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.NewClusterListLogic(r.Context(), svcCtx)
|
||||
resp, err := l.ClusterList(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func CreateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewCreateAdapterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateAdapter(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func CreateClusterHandler(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.NewCreateClusterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.CreateCluster(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DeleteAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterDelReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewDeleteAdapterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DeleteAdapter(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func DeleteClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ClusterDelReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewDeleteClusterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.DeleteCluster(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterDelReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewGetAdapterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetAdapter(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func GetClusterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.ClusterDelReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewGetClusterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetCluster(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func UpdateAdapterHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.AdapterReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := adapters.NewUpdateAdapterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateAdapter(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/adapters"
|
||||
"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/repository/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func UpdateClusterHandler(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.NewUpdateClusterLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateCluster(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ package handler
|
|||
import (
|
||||
"net/http"
|
||||
|
||||
adapters "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/adapters"
|
||||
ai "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/ai"
|
||||
apps "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/apps"
|
||||
cloud "gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/handler/cloud"
|
||||
|
@ -692,4 +693,60 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/adapter/list",
|
||||
Handler: adapters.AdaptersListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/adapter/create",
|
||||
Handler: adapters.CreateAdapterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/adapter/update",
|
||||
Handler: adapters.UpdateAdapterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Path: "/adapter/delete",
|
||||
Handler: adapters.DeleteAdapterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/adapter/get",
|
||||
Handler: adapters.GetAdapterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/adapter/cluster/list",
|
||||
Handler: adapters.ClusterListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/adapter/cluster/create",
|
||||
Handler: adapters.CreateClusterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPut,
|
||||
Path: "/adapter/cluster/update",
|
||||
Handler: adapters.UpdateClusterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodDelete,
|
||||
Path: "/adapter/cluster/delete",
|
||||
Handler: adapters.DeleteClusterHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/adapter/cluster/get",
|
||||
Handler: adapters.GetClusterHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type AdaptersListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewAdaptersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdaptersListLogic {
|
||||
return &AdaptersListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *AdaptersListLogic) AdaptersList(req *types.AdapterReq) (resp *types.AdapterListResp, err error) {
|
||||
resp = &types.AdapterListResp{}
|
||||
tx := l.svcCtx.DbEngin.Raw("select * from t_adapter where `deleted_at` IS NULL ORDER BY create_time Desc").Scan(&resp.Data)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf(tx.Error.Error())
|
||||
return nil, tx.Error
|
||||
}
|
||||
return resp, nil
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ClusterListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewClusterListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClusterListLogic {
|
||||
return &ClusterListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.ClusterListResp, err error) {
|
||||
resp = &types.ClusterListResp{}
|
||||
tx := l.svcCtx.DbEngin.Raw("select * from t_cluster where `deleted_at` IS NULL ORDER BY create_time Desc").Scan(&resp.Data)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf(tx.Error.Error())
|
||||
return nil, tx.Error
|
||||
}
|
||||
return resp, nil
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"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/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CreateAdapterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAdapterLogic {
|
||||
return &CreateAdapterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterReq) (resp *types.AdapterResp, err error) {
|
||||
adapter := types.AdapterInfo{}
|
||||
utils.Convert(req, &adapter)
|
||||
adapter.Id = utils.GenSnowflakeIDStr()
|
||||
adapter.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
||||
tx := l.svcCtx.DbEngin.Table("t_adapter").Create(&adapter)
|
||||
fmt.Print(tx.Error)
|
||||
return
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
||||
"time"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateClusterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewCreateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateClusterLogic {
|
||||
return &CreateClusterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateClusterLogic) CreateCluster(req *types.ClusterReq) (resp *types.ClusterResp, err error) {
|
||||
cluster := types.ClusterInfo{}
|
||||
utils.Convert(req, &cluster)
|
||||
cluster.Id = utils.GenSnowflakeIDStr()
|
||||
cluster.CreateTime = time.Now().Format("2006-01-02 15:04:05")
|
||||
cluster.OwnerId = "0"
|
||||
tx := l.svcCtx.DbEngin.Table("t_cluster").Create(&cluster)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf(tx.Error.Error())
|
||||
return nil, errors.New("cluster create failed")
|
||||
}
|
||||
return
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteAdapterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteAdapterLogic {
|
||||
return &DeleteAdapterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteAdapterLogic) DeleteAdapter(req *types.AdapterDelReq) (resp *types.AdapterResp, err error) {
|
||||
var sId int64
|
||||
l.svcCtx.DbEngin.Table("t_adapter").Raw("select a.id from t_cluster c left join t_adapter a on c.adapter_id=a.id where a.id = ? ", req.Id).Scan(&sId)
|
||||
if sId != 0 {
|
||||
return nil, errors.New("Delete failed,The adapter is associated with a cluster")
|
||||
}
|
||||
db := l.svcCtx.DbEngin.Table("t_adapter").Where("id = ?", req.Id).First(&types.AdapterInfo{})
|
||||
if db.Error != nil {
|
||||
logx.Errorf("err %v", db.Error.Error())
|
||||
return nil, errors.New("Adapter does not exist")
|
||||
}
|
||||
tx := l.svcCtx.DbEngin.Table("t_adapter").Delete(types.AdapterInfo{}, req.Id)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf("err %v", db.Error.Error())
|
||||
return nil, errors.New("Delete adapter failed")
|
||||
}
|
||||
return
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type DeleteClusterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewDeleteClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteClusterLogic {
|
||||
return &DeleteClusterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *DeleteClusterLogic) DeleteCluster(req *types.ClusterDelReq) (resp *types.ClusterResp, err error) {
|
||||
db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&types.ClusterInfo{})
|
||||
if db.Error != nil {
|
||||
logx.Errorf("err %v", db.Error.Error())
|
||||
return nil, errors.New("Cluster does not exist")
|
||||
}
|
||||
tx := l.svcCtx.DbEngin.Table("t_cluster").Delete(types.AdapterInfo{}, req.Id)
|
||||
if tx.Error != nil {
|
||||
logx.Errorf("err %v", db.Error.Error())
|
||||
return nil, errors.New("Delete Cluster failed")
|
||||
}
|
||||
return
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetAdapterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAdapterLogic {
|
||||
return &GetAdapterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetAdapterLogic) GetAdapter(req *types.AdapterDelReq) (resp *types.AdapterResp, err error) {
|
||||
resp = &types.AdapterResp{}
|
||||
db := l.svcCtx.DbEngin.Table("t_adapter").Where("id = ?", req.Id).First(&resp.Data)
|
||||
if db.Error != nil {
|
||||
logx.Errorf("err %v", db.Error.Error())
|
||||
return nil, errors.New("Adapter does not exist")
|
||||
}
|
||||
return
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetClusterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetClusterLogic {
|
||||
return &GetClusterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetClusterLogic) GetCluster(req *types.ClusterDelReq) (resp *types.ClusterResp, err error) {
|
||||
resp = &types.ClusterResp{}
|
||||
db := l.svcCtx.DbEngin.Table("t_cluster").Where("id = ?", req.Id).First(&resp.Data)
|
||||
if db.Error != nil {
|
||||
logx.Errorf("err %v", db.Error.Error())
|
||||
return nil, errors.New("Adapter does not exist")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateAdapterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateAdapterLogic {
|
||||
return &UpdateAdapterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateAdapterLogic) UpdateAdapter(req *types.AdapterReq) (resp *types.AdapterResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package adapters
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UpdateClusterLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUpdateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClusterLogic {
|
||||
return &UpdateClusterLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterReq) (resp *types.ClusterResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
|
@ -668,6 +668,100 @@ type AppResp struct {
|
|||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type AdapterReq struct {
|
||||
Id string `json:"id,optional" db:"id"`
|
||||
Name string `json:"name,optional"`
|
||||
Type string `json:"type,optional"`
|
||||
Nickname string `json:"nickname,optional"`
|
||||
Version string `json:"version,optional"`
|
||||
Server string `json:"server,optional"`
|
||||
}
|
||||
|
||||
type AdapterDelReq struct {
|
||||
Id string `form:"id,optional" db:"id"`
|
||||
}
|
||||
|
||||
type AdapterInfo struct {
|
||||
Id string `json:"id,omitempty" db:"id"`
|
||||
Name string `json:"name,omitempty" db:"name"`
|
||||
Type string `json:"type,omitempty" db:"type"`
|
||||
Nickname string `json:"nickname,omitempty" db:"nickname"`
|
||||
Version string `json:"version,omitempty" db:"version"`
|
||||
Server string `json:"server,omitempty" db:"server"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
type AdapterResp struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data AdapterInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type AdapterListResp struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data []AdapterInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type ClusterReq struct {
|
||||
Id string `json:"id,optional"`
|
||||
AdapterId string `json:"adapterId,optional"`
|
||||
Name string `json:"name,optional"`
|
||||
Nickname string `json:"nickname,optional"`
|
||||
Description string `json:"description,optional"`
|
||||
Server string `json:"server,optional"`
|
||||
MonitorServer string `json:"monitorServer,optional"`
|
||||
Username string `json:"username,optional"`
|
||||
Password string `json:"password,optional"`
|
||||
Token string `json:"token,optional"`
|
||||
Ak string `json:"ak,optional"`
|
||||
Sk string `json:"sk,optional"`
|
||||
Region string `json:"region,optional"`
|
||||
ProjectId string `json:"projectId,optional"`
|
||||
Version string `json:"version,optional"`
|
||||
Label string `json:"label,optional"`
|
||||
OwnerId string `json:"ownerId,omitempty,optional"`
|
||||
AuthType string `json:"authType,optional"`
|
||||
}
|
||||
|
||||
type ClusterDelReq struct {
|
||||
Id string `form:"id,optional"`
|
||||
}
|
||||
|
||||
type ClusterInfo struct {
|
||||
Id string `json:"id,omitempty" db:"id"`
|
||||
AdapterId string `json:"adapterId,omitempty" 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"`
|
||||
MonitorServer string `json:"monitorServer,omitempty" db:"monitor_server"`
|
||||
Username string `json:"username,omitempty" db:"username"`
|
||||
Password string `json:"password,omitempty" db:"password"`
|
||||
Token string `json:"token,omitempty" db:"token"`
|
||||
Ak string `json:"ak,omitempty" db:"ak"`
|
||||
Sk string `json:"sk,omitempty" db:"sk"`
|
||||
Region string `json:"region,omitempty" db:"region"`
|
||||
ProjectId string `json:"projectId,omitempty" db:"project_id"`
|
||||
Version string `json:"version,omitempty" db:"version"`
|
||||
Label string `json:"label,omitempty" db:"label"`
|
||||
OwnerId string `json:"ownerId,omitempty" db:"owner_id"`
|
||||
AuthType string `json:"authType,omitempty" db:"auth_type"`
|
||||
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
|
||||
}
|
||||
|
||||
type ClusterResp struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data ClusterInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type ClusterListResp struct {
|
||||
Code int `json:"code,omitempty"`
|
||||
Msg string `json:"msg,omitempty"`
|
||||
Data []ClusterInfo `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
SlurmVersion string `json:"slurmVersion"`
|
||||
Name string `json:"name"`
|
||||
|
|
|
@ -36,3 +36,8 @@ func InitSnowflake(machineID int64) (err error) {
|
|||
func GenSnowflakeID() int64 {
|
||||
return node.Generate().Int64()
|
||||
}
|
||||
|
||||
// machineId 工作id
|
||||
func GenSnowflakeIDStr() string {
|
||||
return node.Generate().String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue