Skip to content

Commit

Permalink
feat(backend): 增加从backend导出表结构到中控 TencentBlueKing#7501
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq committed Oct 24, 2024
1 parent 50fc2f0 commit b16a9d2
Show file tree
Hide file tree
Showing 7 changed files with 574 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ import (
"dbm-services/mysql/db-tools/dbactuator/pkg/util"
)

// ImportSchemaFromLocalSpiderAct 从本地Spider导入表结构到中控节点
type ImportSchemaFromLocalSpiderAct struct {
*subcmd.BaseOptions
Service spiderctl.ImportSchemaFromLocalSpiderComp
}

// NewImportSchemaToTdbctlCommand create new subcommand
func NewImportSchemaToTdbctlCommand() *cobra.Command {
act := ImportSchemaFromLocalSpiderAct{
act := ImportSchemaFromBackendAct{
BaseOptions: subcmd.GBaseOptions,
}
cmd := &cobra.Command{
Use: "import-schema-to-tdbctl",
Short: "从spider节点导入表结构到中控节点",
Short: "从backend分片0导入表结构到中控节点",
Example: fmt.Sprintf(
`dbactuator spiderctl import-schema-to-tdbctl %s %s`,
subcmd.CmdBaseExampleStr, subcmd.ToPrettyJson(act.Service.Example()),
Expand All @@ -48,6 +42,12 @@ func NewImportSchemaToTdbctlCommand() *cobra.Command {
return cmd
}

// ImportSchemaFromLocalSpiderAct 从本地Spider导入表结构到中控节点
type ImportSchemaFromLocalSpiderAct struct {
*subcmd.BaseOptions
Service spiderctl.ImportSchemaFromLocalSpiderComp
}

// Init 初始化
func (d *ImportSchemaFromLocalSpiderAct) Init() (err error) {
logger.Info("InitCLusterRoutingAct Init")
Expand Down Expand Up @@ -79,3 +79,45 @@ func (d *ImportSchemaFromLocalSpiderAct) Run() (err error) {
logger.Info("import schema to empty tdbctl succcess ~")
return nil
}

// ImportSchemaFromBackendAct 从backend导入表结构到中控节点
type ImportSchemaFromBackendAct struct {
*subcmd.BaseOptions
Service spiderctl.ImportSchemaFromBackendComp
}

// Init prepare run env
func (d *ImportSchemaFromBackendAct) Init() (err error) {
logger.Info("InitCLusterRoutingAct Init")
if err = d.Deserialize(&d.Service.Params); err != nil {
logger.Error("DeserializeAndValidate failed, %v", err)
return err
}
d.Service.GeneralParam = subcmd.GeneralRuntimeParam
return
}

// Run 执行
func (d *ImportSchemaFromBackendAct) Run() (err error) {
steps := subcmd.Steps{
{
FunName: "初始化",
Func: d.Service.Init,
},
{
FunName: "从本地spider导出表结构至tdbctl",
Func: d.Service.Migrate,
},
{
FunName: "从本地spider导出存储过程、触发器等dbctl",
Func: d.Service.MigrateRoutinesAndTriger,
},
}

if err = steps.Run(); err != nil {
return err
}

logger.Info("import schema to tdbctl succcess ~")
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package spiderctlcmd
import (
"fmt"

"github.com/spf13/cobra"

"dbm-services/common/go-pubpkg/logger"
"dbm-services/mysql/db-tools/dbactuator/internal/subcmd"
"dbm-services/mysql/db-tools/dbactuator/pkg/components/spiderctl"
"dbm-services/mysql/db-tools/dbactuator/pkg/util"

"github.com/spf13/cobra"
)

// InitCLusterRoutingAct 初始化tendb cluster 集群的路由关系
Expand Down
Loading

0 comments on commit b16a9d2

Please sign in to comment.