Skip to content

Commit

Permalink
fix(dbm-services): 修复上架多实例参数过长问题 close #3755
Browse files Browse the repository at this point in the history
  • Loading branch information
ymakedaq authored and zhangzhw8 committed Apr 2, 2024
1 parent 6e6f1a9 commit 2538421
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 27 deletions.
4 changes: 4 additions & 0 deletions dbm-services/mysql/db-tools/dbactuator/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ Buildstamp:%s`, version, githash, strings.ToUpper(external), buildstamp,
&subcmd.GBaseOptions.PayloadFormat, "payload-format", "m",
subcmd.GBaseOptions.PayloadFormat, "command payload format, default base64, value_allowed: base64|raw",
)
cmds.PersistentFlags().StringVarP(
&subcmd.GBaseOptions.NotSensitivePayload, "non-sensitive-paylod", "c",
subcmd.GBaseOptions.NotSensitivePayload, "commandn not sensitive payload <base64>",
)
cmds.PersistentFlags().StringVarP(&subcmd.GBaseOptions.Uid, "uid", "U", subcmd.GBaseOptions.Uid, "bill id")
cmds.PersistentFlags().StringVarP(&subcmd.GBaseOptions.RootId, "root_id", "R", subcmd.GBaseOptions.NodeId,
"process id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func (d *DeployMySQLAct) Init() (err error) {
logger.Error("DeserializeAndValidate failed, %v", err)
return err
}
if err = d.DeserializeNonSensitivePayload(&d.Service.MySQLConfigParams); err != nil {
logger.Error("DeserializeAndValidate failed, %v", err)
return err
}
d.Service.GeneralParam = subcmd.GeneralRuntimeParam
return d.Service.InitDefaultParam()
}
Expand Down
43 changes: 32 additions & 11 deletions dbm-services/mysql/db-tools/dbactuator/internal/subcmd/subcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"path/filepath"
"strings"

"dbm-services/common/go-pubpkg/cmutil"
"dbm-services/common/go-pubpkg/logger"
"dbm-services/common/go-pubpkg/validate"
"dbm-services/mysql/db-tools/dbactuator/pkg/components"
Expand Down Expand Up @@ -53,14 +54,15 @@ func init() {
此参数是json字符串的base64编码之后的字符串
*/
type BaseOptions struct {
Uid string
RootId string
NodeId string
VersionId string
Payload string
PayloadFormat string
RollBack bool
Helper bool
Uid string
RootId string
NodeId string
VersionId string
Payload string
PayloadFormat string
NotSensitivePayload string
RollBack bool
Helper bool
// 是否为外部版本
// on ON
External string
Expand Down Expand Up @@ -191,6 +193,25 @@ func Deserialize(s interface{}) (p *BaseOptions, err error) {
return GBaseOptions, nil
}

// DeserializeNonSensitivePayload 反序列化非敏感payload,不校验参数
func (b *BaseOptions) DeserializeNonSensitivePayload(s interface{}) (err error) {
var bp []byte
if cmutil.IsEmpty(b.NotSensitivePayload) {
return errors.New("non-sensitive payload need input")
}
bp, err = base64.StdEncoding.DecodeString(b.NotSensitivePayload)
if err != nil {
return err
}
logger.Local("DeserializeSimple not sensitive payload body: %s", b.NotSensitivePayload)
if err = json.Unmarshal(bp, &s); err != nil {
logger.Error("json.Unmarshal failed, %v", s, err)
err = errors.WithMessage(err, "error in resolving parameter")
return err
}
return nil
}

// Deserialize 反序列化payload,并校验参数
//
// ps: 参数校验 from golang validate v10
Expand Down Expand Up @@ -266,15 +287,15 @@ func (b *BaseOptions) DeserializeSimple(s interface{}) (err error) {
return nil
}

// Validate TODO
// Validate validate payload
func (b *BaseOptions) Validate() (err error) {
if len(b.Payload) == 0 {
return fmt.Errorf("payload need input")
}
return nil
}

// OutputCtx TODO
// OutputCtx output ctx
//
// @receiver b
func (b *BaseOptions) OutputCtx(ctx string) {
Expand Down Expand Up @@ -326,7 +347,7 @@ func SetLogger(cmd *cobra.Command, opt *BaseOptions) {
defer logger.Sync()
}

// ValidateSubCommand TODO
// ValidateSubCommand validate sub command
func ValidateSubCommand() func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
if len(args) <= 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
type InstallMySQLComp struct {
GeneralParam *components.GeneralParam `json:"general"`
Params *InstallMySQLParams `json:"extend"`
MySQLConfigParams *MySQLConfigParams
installMySQLConfig `json:"-"`
RollBackContext rollback.RollBackObjects `json:"-"`
TimeZone string
Expand All @@ -52,11 +53,16 @@ type InstallMySQLComp struct {
AvoidReset bool `json:"-"` // 迁移单据复用了这个 actor, 需要不做reset
}

// MySQLConfigParams TODO
type MySQLConfigParams struct {
MyCnfConfigs json.RawMessage `json:"mycnf_configs" validate:"required" `
}

// InstallMySQLParams TODO
type InstallMySQLParams struct {
components.Medium
// map[port]my.cnf
MyCnfConfigs json.RawMessage `json:"mycnf_configs" validate:"required" `
MyCnfConfigs json.RawMessage
// MySQLVerion 只需5.6 5.7 这样的大版本号
MysqlVersion string `json:"mysql_version" validate:"required"`
// 字符集参数
Expand All @@ -72,14 +78,14 @@ type InstallMySQLParams struct {
AllowDiskFileSystemTypes []string
}

// InitDirs TODO
// InitDirs init dirs
type InitDirs = []string

// Port TODO
// Port port
type Port = int
type socket = string

// SpiderAutoIncrModeValue TODO
// SpiderAutoIncrModeValue spider au
type SpiderAutoIncrModeValue int

type installMySQLConfig struct {
Expand Down Expand Up @@ -131,15 +137,6 @@ func (i *InstallMySQLComp) Example() interface{} {
CharSet: "utf8",
Ports: []int{20000, 20001},
InstMem: 0,
MyCnfConfigs: []byte(`{
"20000":{
"client":{"port": "{{mysqld.port}}" },
"mysql":{"socket": "{{mysqld.datadir}}/mysql.sock" },
"mysqld":{"binlog_format": "ROW","innodb_io_capacity": "1000","innodb_read_io_threads": "8"}},
"20001":{
"client":{"port": "{{mysqld.port}}"},
"mysql":{"socket": "{{mysqld.datadir}}/mysql.sock"},
"mysqld":{"binlog_format": "ROW","innodb_io_capacity": "2000","innodb_read_io_threads": "10"}}}`),
SuperAccount: AdditionalAccount{
User: "user",
Pwd: "xxx",
Expand All @@ -161,6 +158,7 @@ func (i *InstallMySQLComp) InitDefaultParam() (err error) {
i.WorkPassword = ""
i.AvoidReset = false

i.Params.MyCnfConfigs = i.MySQLConfigParams.MyCnfConfigs
var mountpoint string
i.InstallDir = cst.UsrLocal
i.MysqlInstallDir = cst.MysqldInstallPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,18 @@ def _execute(self, data, parent_data) -> bool:
db_act_template["node_id"] = node_id
db_act_template["version_id"] = self._runtime_attrs.get("version")
db_act_template["uid"] = global_data["uid"]

# 拼接mysql系统账号固定参数
if "general" in db_act_template["payload"]:
db_act_template["payload"]["general"].update(
{"runtime_extend": {"mysql_sys_users": get_mysql_sys_users(kwargs["bk_cloud_id"])}}
)

# mycnf_configs 参数很多,放到非敏感参数去处理
if "mycnf_configs" in db_act_template["payload"]["extend"]:
db_act_template["non_sensitive_payload"] = base64_encode(
json.dumps({"mycnf_configs": db_act_template["payload"]["extend"].get("mycnf_configs", "")})
)
del db_act_template["payload"]["extend"]["mycnf_configs"]

# payload参数转换base64格式
db_act_template["payload"] = base64_encode(json.dumps(db_act_template["payload"]))

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/flow/utils/script_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
cd /data/install/dbactuator-{{uid}}
chmod +x dbactuator
./dbactuator {{db_type}} {{action}} --uid {{uid}} --root_id {{root_id}} --node_id {{node_id}} --version_id {{version_id}} --payload $1
./dbactuator {{db_type}} {{action}} --uid {{uid}} --root_id {{root_id}} --node_id {{node_id}} --version_id {{version_id}} -c {{non_sensitive_payload}} --payload $1
""" # noqa

# 运行dba_toolkit的命令
Expand Down

0 comments on commit 2538421

Please sign in to comment.