Skip to content

Commit

Permalink
Merge pull request #2837 from actiontech/optimize_plugin_configuratio…
Browse files Browse the repository at this point in the history
…n_ce

Optimize plugin configuration ce
  • Loading branch information
LordofAvernus authored Dec 27, 2024
2 parents e19aa34 + 0886482 commit 56742af
Show file tree
Hide file tree
Showing 17 changed files with 3,025 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/Masterminds/semver/v3 v3.1.1
github.com/actiontech/dms v0.0.0-20241205071755-3b81d30f71c3
github.com/actiontech/dms v0.0.0-20241223063204-661bd1bf229b
github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62
github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20240806065717-29cde7000ef5
github.com/agiledragon/gomonkey v2.0.2+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/actiontech/dms v0.0.0-20241205071755-3b81d30f71c3 h1:96fKxlsA2ZOqRlfB1oseZsuu6HedEBf2yHRme+M4644=
github.com/actiontech/dms v0.0.0-20241205071755-3b81d30f71c3/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA=
github.com/actiontech/dms v0.0.0-20241223063204-661bd1bf229b h1:ROmTjEcA8/yVI2ohKfkuPyIz/MpJ39qpTg5pHfVdRGY=
github.com/actiontech/dms v0.0.0-20241223063204-661bd1bf229b/go.mod h1:Jm+tDoBYmX8R8zqgPJRq1NwZXdxO/F+HxVRJVF65WXA=
github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62 h1:JM7WnLzlvXOGE90KKd+aigi+qUDS+U5dLwQMNpTKZxE=
github.com/actiontech/java-sql-extractor v0.0.0-20231103015812-cdd5fc040f62/go.mod h1:adDZHhAf2LRMx2h0JzofPXn12x2XlyQjVE116KXquwo=
github.com/actiontech/mybatis-mapper-2-sql v0.5.1-0.20240806065717-29cde7000ef5 h1:vyQVrkYPzUV9d7gSvOWoezwWMTiC4jc3f3Hpianefq0=
Expand Down
1 change: 1 addition & 0 deletions sqle/api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,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)
}

// project admin and global manage router
Expand Down
54 changes: 54 additions & 0 deletions sqle/api/controller/v1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/actiontech/sqle/sqle/errors"
"github.com/actiontech/sqle/sqle/log"
"github.com/actiontech/sqle/sqle/model"
"github.com/actiontech/sqle/sqle/pkg/params"
"github.com/actiontech/sqle/sqle/server"
opt "github.com/actiontech/sqle/sqle/server/optimization/rule"
"github.com/actiontech/sqle/sqle/utils"
Expand Down Expand Up @@ -579,3 +580,56 @@ type GetTableMetadataResV1 struct {
func GetTableMetadata(c echo.Context) error {
return getTableMetadata(c)
}

type GetDatabaseDriverOptionsResV1 struct {
controller.BaseRes
Metas []*DatabaseDriverOptionsV1 `json:"data"`
}

type DatabaseDriverOptionsV1 struct {
DBType string `json:"db_type"`
Params []*InstanceAdditionalParamResV1 `json:"params"`
Logo []byte `json:"logo"`
}

// GetDatabaseDriverOptions get database driver options
// @Summary 获取实例的额外属性列表
// @Description get database driver options
// @Id getDatabaseDriverOptions
// @Tags instance
// @Security ApiKeyAuth
// @Success 200 {object} v1.GetDatabaseDriverOptionsResV1
// @router /v1/database_driver_options [get]
func GetDatabaseDriverOptions(c echo.Context) error {
pluginMgr := driver.GetPluginManager()
additionalParams := pluginMgr.AllAdditionalParams()
allLogos := pluginMgr.AllLogo()
res := &GetDatabaseDriverOptionsResV1{
BaseRes: controller.NewBaseReq(nil),
Metas: []*DatabaseDriverOptionsV1{},
}
for name, params := range additionalParams {

meta := &DatabaseDriverOptionsV1{
DBType: name,
Params: convertParamsToInstanceAdditionalParamRes(params),
Logo: allLogos[name],
}

res.Metas = append(res.Metas, meta)
}
return c.JSON(http.StatusOK, res)
}

func convertParamsToInstanceAdditionalParamRes(params params.Params) []*InstanceAdditionalParamResV1 {
res := make([]*InstanceAdditionalParamResV1, len(params))
for i, param := range params {
res[i] = &InstanceAdditionalParamResV1{
Name: param.Key,
Description: param.Desc,
Type: string(param.Type),
Value: param.Value,
}
}
return res
}
1 change: 1 addition & 0 deletions sqle/dms/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func RegisterAsDMSTarget(sqleConfig *config.SqleOptions) error {
if err := dmsRegister.RegisterDMSPlugin(ctx, controller.GetDMSServerAddress(), &dmsV1.Plugin{
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"),
}); err != nil {
return fmt.Errorf("failed to register dms plugin for operation data source handle")
}
Expand Down
62 changes: 62 additions & 0 deletions sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,29 @@ var doc = `{
}
}
},
"/v1/database_driver_options": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get database driver options",
"tags": [
"instance"
],
"summary": "获取实例的额外属性列表",
"operationId": "getDatabaseDriverOptions",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.GetDatabaseDriverOptionsResV1"
}
}
}
}
},
"/v1/import_rule_template": {
"get": {
"security": [
Expand Down Expand Up @@ -13033,6 +13056,26 @@ var doc = `{
}
}
},
"v1.DatabaseDriverOptionsV1": {
"type": "object",
"properties": {
"db_type": {
"type": "string"
},
"logo": {
"type": "array",
"items": {
"type": "integer"
}
},
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.InstanceAdditionalParamResV1"
}
}
}
},
"v1.DatabaseObject": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -13935,6 +13978,25 @@ var doc = `{
}
}
},
"v1.GetDatabaseDriverOptionsResV1": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.DatabaseDriverOptionsV1"
}
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.GetDepBetweenStageInstanceResV1": {
"type": "object",
"properties": {
Expand Down
62 changes: 62 additions & 0 deletions sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,29 @@
}
}
},
"/v1/database_driver_options": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "get database driver options",
"tags": [
"instance"
],
"summary": "获取实例的额外属性列表",
"operationId": "getDatabaseDriverOptions",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/v1.GetDatabaseDriverOptionsResV1"
}
}
}
}
},
"/v1/import_rule_template": {
"get": {
"security": [
Expand Down Expand Up @@ -13017,6 +13040,26 @@
}
}
},
"v1.DatabaseDriverOptionsV1": {
"type": "object",
"properties": {
"db_type": {
"type": "string"
},
"logo": {
"type": "array",
"items": {
"type": "integer"
}
},
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.InstanceAdditionalParamResV1"
}
}
}
},
"v1.DatabaseObject": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -13919,6 +13962,25 @@
}
}
},
"v1.GetDatabaseDriverOptionsResV1": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 0
},
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/v1.DatabaseDriverOptionsV1"
}
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"v1.GetDepBetweenStageInstanceResV1": {
"type": "object",
"properties": {
Expand Down
40 changes: 40 additions & 0 deletions sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,19 @@ definitions:
$ref: '#/definitions/v1.ObjectDiffResult'
type: array
type: object
v1.DatabaseDriverOptionsV1:
properties:
db_type:
type: string
logo:
items:
type: integer
type: array
params:
items:
$ref: '#/definitions/v1.InstanceAdditionalParamResV1'
type: array
type: object
v1.DatabaseObject:
properties:
object_name:
Expand Down Expand Up @@ -1792,6 +1805,19 @@ definitions:
$ref: '#/definitions/v1.DatabaseComparisonObject'
type: object
type: object
v1.GetDatabaseDriverOptionsResV1:
properties:
code:
example: 0
type: integer
data:
items:
$ref: '#/definitions/v1.DatabaseDriverOptionsV1'
type: array
message:
example: ok
type: string
type: object
v1.GetDepBetweenStageInstanceResV1:
properties:
code:
Expand Down Expand Up @@ -7031,6 +7057,20 @@ paths:
summary: 获取全局工单统计数据
tags:
- workflow
/v1/database_driver_options:
get:
description: get database driver options
operationId: getDatabaseDriverOptions
responses:
"200":
description: OK
schema:
$ref: '#/definitions/v1.GetDatabaseDriverOptionsResV1'
security:
- ApiKeyAuth: []
summary: 获取实例的额外属性列表
tags:
- instance
/v1/import_rule_template:
get:
description: get rule template file
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 56742af

Please sign in to comment.