Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize plugin configuration ce #2843

Merged
merged 4 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func StartApi(net *gracenet.Net, exitChan chan struct{}, config *config.SqleOpti
v1Router.POST("/data_resource/handle", v1.OperateDataResourceHandle, sqleMiddleware.OpGlobalAllowed())
v1Router.POST(fmt.Sprintf("%s/connection", dmsV1.InternalDBServiceRouterGroup), v1.CheckInstanceIsConnectable, sqleMiddleware.OpGlobalAllowed())
v1Router.GET("/database_driver_options", v1.GetDatabaseDriverOptions)
v1Router.GET("/database_driver_logos", v1.GetDatabaseDriverLogos)
}

// project admin and global manage router
Expand Down
48 changes: 45 additions & 3 deletions sqle/api/controller/v1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"strings"

baseV1 "github.com/actiontech/dms/pkg/dms-common/api/base/v1"
dmsV1 "github.com/actiontech/dms/pkg/dms-common/api/dms/v1"
Expand Down Expand Up @@ -589,7 +590,6 @@ type GetDatabaseDriverOptionsResV1 struct {
type DatabaseDriverOptionsV1 struct {
DBType string `json:"db_type"`
Params []*InstanceAdditionalParamResV1 `json:"params"`
Logo []byte `json:"logo"`
}

// GetDatabaseDriverOptions get database driver options
Expand All @@ -603,7 +603,6 @@ type DatabaseDriverOptionsV1 struct {
func GetDatabaseDriverOptions(c echo.Context) error {
pluginMgr := driver.GetPluginManager()
additionalParams := pluginMgr.AllAdditionalParams()
allLogos := pluginMgr.AllLogo()
res := &GetDatabaseDriverOptionsResV1{
BaseRes: controller.NewBaseReq(nil),
Metas: []*DatabaseDriverOptionsV1{},
Expand All @@ -613,7 +612,6 @@ func GetDatabaseDriverOptions(c echo.Context) error {
meta := &DatabaseDriverOptionsV1{
DBType: name,
Params: convertParamsToInstanceAdditionalParamRes(params),
Logo: allLogos[name],
}

res.Metas = append(res.Metas, meta)
Expand All @@ -633,3 +631,47 @@ func convertParamsToInstanceAdditionalParamRes(params params.Params) []*Instance
}
return res
}

type DatabaseDriverLogosReqV1 struct {
FilterDBTypes string `json:"db_types" query:"db_types"`
ColdWaterLW marked this conversation as resolved.
Show resolved Hide resolved
}

type GetDatabaseDriverLogosResV1 struct {
controller.BaseRes
Logos []*DatabaseDriverLogosV1 `json:"data"`
}

type DatabaseDriverLogosV1 struct {
DBType string `json:"db_type"`
Logo []byte `json:"logo"`
}

// GetDatabaseDriverLogos get database driver logos
// @Summary 获取数据库插件的Logo图片
// @Description get database driver logos
// @Id GetDatabaseDriverLogos
// @Tags instance
// @Param db_types query string true "MySQL,Oracle"
// @Security ApiKeyAuth
// @Success 200 {object} v1.GetDatabaseDriverLogosResV1
// @router /v1/database_driver_logos [get]
func GetDatabaseDriverLogos(c echo.Context) error {
req := new(DatabaseDriverLogosReqV1)
if err := controller.BindAndValidateReq(c, req); err != nil {
return controller.JSONBaseErrorReq(c, err)
}
dbTypes := strings.Split(req.FilterDBTypes, ",")
pluginMgr := driver.GetPluginManager()
allLogos := pluginMgr.AllLogo()
logos := make([]*DatabaseDriverLogosV1, len(dbTypes))
for i, dbType := range dbTypes {
logos[i] = &DatabaseDriverLogosV1{
DBType: dbType,
Logo: allLogos[dbType],
}
}
return c.JSON(http.StatusOK, &GetDatabaseDriverLogosResV1{
Logos: logos,
BaseRes: controller.NewBaseReq(nil),
})
}
1 change: 1 addition & 0 deletions sqle/dms/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ func RegisterAsDMSTarget(sqleConfig *config.SqleOptions) error {
Name: "sqle",
OperateDataResourceHandleUrl: fmt.Sprintf("http://%s:%d/%s/%s", sqleConfig.APIServiceOpts.Addr, sqleConfig.APIServiceOpts.Port, "v1", "data_resource/handle"),
GetDatabaseDriverOptionsUrl: fmt.Sprintf("http://%s:%d/%s/%s", sqleConfig.APIServiceOpts.Addr, sqleConfig.APIServiceOpts.Port, "v1", "database_driver_options"),
GetDatabaseDriverLogosUrl: fmt.Sprintf("http://%s:%d/%s/%s", sqleConfig.APIServiceOpts.Addr, sqleConfig.APIServiceOpts.Port, "v1", "database_driver_logos"),
}); err != nil {
return fmt.Errorf("failed to register dms plugin for operation data source handle")
}
Expand Down
61 changes: 60 additions & 1 deletion sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,38 @@ var doc = `{
}
}
},
"/v1/database_driver_logos": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get database driver logos",
"tags": [
"instance"
],
"summary": "获取数据库插件的Logo图片",
"operationId": "GetDatabaseDriverLogos",
"parameters": [
{
"type": "string",
"description": "MySQL,Oracle",
"name": "db_types",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.GetDatabaseDriverLogosResV1"
}
}
}
}
},
"/v1/database_driver_options": {
"get": {
"security": [
Expand Down Expand Up @@ -13056,7 +13088,7 @@ var doc = `{
}
}
},
"v1.DatabaseDriverOptionsV1": {
"v1.DatabaseDriverLogosV1": {
"type": "object",
"properties": {
"db_type": {
Expand All @@ -13067,6 +13099,14 @@ var doc = `{
"items": {
"type": "integer"
}
}
}
},
"v1.DatabaseDriverOptionsV1": {
"type": "object",
"properties": {
"db_type": {
"type": "string"
},
"params": {
"type": "array",
Expand Down Expand Up @@ -13978,6 +14018,25 @@ var doc = `{
}
}
},
"v1.GetDatabaseDriverLogosResV1": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.DatabaseDriverLogosV1"
}
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.GetDatabaseDriverOptionsResV1": {
"type": "object",
"properties": {
Expand Down
61 changes: 60 additions & 1 deletion sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,38 @@
}
}
},
"/v1/database_driver_logos": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get database driver logos",
"tags": [
"instance"
],
"summary": "获取数据库插件的Logo图片",
"operationId": "GetDatabaseDriverLogos",
"parameters": [
{
"type": "string",
"description": "MySQL,Oracle",
"name": "db_types",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.GetDatabaseDriverLogosResV1"
}
}
}
}
},
"/v1/database_driver_options": {
"get": {
"security": [
Expand Down Expand Up @@ -13040,7 +13072,7 @@
}
}
},
"v1.DatabaseDriverOptionsV1": {
"v1.DatabaseDriverLogosV1": {
"type": "object",
"properties": {
"db_type": {
Expand All @@ -13051,6 +13083,14 @@
"items": {
"type": "integer"
}
}
}
},
"v1.DatabaseDriverOptionsV1": {
"type": "object",
"properties": {
"db_type": {
"type": "string"
},
"params": {
"type": "array",
Expand Down Expand Up @@ -13962,6 +14002,25 @@
}
}
},
"v1.GetDatabaseDriverLogosResV1": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.DatabaseDriverLogosV1"
}
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.GetDatabaseDriverOptionsResV1": {
"type": "object",
"properties": {
Expand Down
40 changes: 39 additions & 1 deletion sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,14 +1173,19 @@ definitions:
$ref: '#/definitions/v1.ObjectDiffResult'
type: array
type: object
v1.DatabaseDriverOptionsV1:
v1.DatabaseDriverLogosV1:
properties:
db_type:
type: string
logo:
items:
type: integer
type: array
type: object
v1.DatabaseDriverOptionsV1:
properties:
db_type:
type: string
params:
items:
$ref: '#/definitions/v1.InstanceAdditionalParamResV1'
Expand Down Expand Up @@ -1805,6 +1810,19 @@ definitions:
$ref: '#/definitions/v1.DatabaseComparisonObject'
type: object
type: object
v1.GetDatabaseDriverLogosResV1:
properties:
code:
example: 0
type: integer
data:
items:
$ref: '#/definitions/v1.DatabaseDriverLogosV1'
type: array
message:
example: ok
type: string
type: object
v1.GetDatabaseDriverOptionsResV1:
properties:
code:
Expand Down Expand Up @@ -7057,6 +7075,26 @@ paths:
summary: 获取全局工单统计数据
tags:
- workflow
/v1/database_driver_logos:
get:
description: get database driver logos
operationId: GetDatabaseDriverLogos
parameters:
- description: MySQL,Oracle
in: query
name: db_types
required: true
type: string
responses:
"200":
description: OK
schema:
$ref: '#/definitions/v1.GetDatabaseDriverLogosResV1'
security:
- ApiKeyAuth: []
summary: 获取数据库插件的Logo图片
tags:
- instance
/v1/database_driver_options:
get:
description: get database driver options
Expand Down
Loading