forked from TencentBlueKing/blueking-dbm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(other): VM下架atuator close TencentBlueKing#3842
- Loading branch information
1 parent
75a2e8a
commit 87ca9c9
Showing
8 changed files
with
566 additions
and
0 deletions.
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
dbm-services/bigdata/db-tools/dbactuator/internal/subcmd/vmcmd/clean_data.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package vmcmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"dbm-services/bigdata/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/components/victoriametrics" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/rollback" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/util" | ||
"dbm-services/common/go-pubpkg/logger" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// CleanDataAct 是一个结构体,用于清理VictoriaMetrics的数据目录。 | ||
type CleanDataAct struct { | ||
*subcmd.BaseOptions // BaseOptions 是基础选项,可能包含了一些全局设置或配置。 | ||
Service victoriametrics.CleanDataComp // Service 是用于清理数据的组件。 | ||
} | ||
|
||
// CleanDataCommand 是一个函数,返回一个cobra.Command对象,该对象定义了一个命令行命令,用于清理VictoriaMetrics的数据目录。 | ||
func CleanDataCommand() *cobra.Command { | ||
act := CleanDataAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "clean_data", | ||
Short: "清理vm目录", | ||
Example: fmt.Sprintf(`dbactuator vm clean_data %s`, subcmd.CmdBaseExapmleStr), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validate()) // 验证参数 | ||
if act.RollBack { // 如果需要回滚,则执行回滚操作 | ||
util.CheckErr(act.Rollback()) | ||
return | ||
} | ||
util.CheckErr(act.Init()) // 初始化 | ||
util.CheckErr(act.Run()) // 运行 | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Validate 是 CleanDataAct 的验证函数,用于验证参数是否有效。 | ||
func (d *CleanDataAct) Validate() (err error) { | ||
return d.BaseOptions.Validate() | ||
} | ||
|
||
// Init 是 CleanDataAct 的初始化函数,用于初始化操作。 | ||
func (d *CleanDataAct) Init() (err error) { | ||
logger.Info("CleanDataAct Init") | ||
if err = d.Deserialize(&d.Service.Params); err != nil { // 反序列化参数 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
d.Service.GeneralParam = subcmd.GeneralRuntimeParam // 设置通用运行时参数 | ||
return d.Service.Init() // 初始化服务 | ||
} | ||
|
||
// Rollback TODO | ||
// | ||
// @receiver d | ||
// @return err | ||
func (d *CleanDataAct) Rollback() (err error) { | ||
var r rollback.RollBackObjects | ||
if err = d.DeserializeAndValidate(&r); err != nil { | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
err = r.RollBack() | ||
if err != nil { | ||
logger.Error("roll back failed %s", err.Error()) | ||
} | ||
return | ||
} | ||
|
||
// Run 是 CleanDataAct 的运行函数,用于执行清理VictoriaMetrics数据目录的操作。 | ||
func (d *CleanDataAct) Run() (err error) { | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "清理数据目录", | ||
Func: d.Service.CleanData, // 清理数据的函数 | ||
}, | ||
} | ||
|
||
if err := steps.Run(); err != nil { // 执行步骤 | ||
rollbackCtxb, rerr := json.Marshal(d.Service.RollBackContext) // 序列化回滚上下文 | ||
if rerr != nil { | ||
logger.Error("json Marshal %s", err.Error()) | ||
fmt.Printf("<ctx>Can't RollBack<ctx>\n") | ||
} | ||
fmt.Printf("<ctx>%s<ctx>\n", string(rollbackCtxb)) | ||
return err | ||
} | ||
|
||
logger.Info("clean_data successfully") // 打印成功信息 | ||
return nil | ||
} |
95 changes: 95 additions & 0 deletions
95
dbm-services/bigdata/db-tools/dbactuator/internal/subcmd/vmcmd/restart_process.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package vmcmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"dbm-services/bigdata/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/components/victoriametrics" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/rollback" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/util" | ||
"dbm-services/common/go-pubpkg/logger" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// RestartProcessAct 是一个结构体,用于重启VictoriaMetrics进程。 | ||
type RestartProcessAct struct { | ||
*subcmd.BaseOptions // BaseOptions 是基础选项,可能包含了一些全局设置或配置。 | ||
Service victoriametrics.StartStopProcessComp // Service 是用于启动和停止VictoriaMetrics进程的组件。 | ||
} | ||
|
||
// RestartProcessCommand 是一个函数,返回一个cobra.Command对象,该对象定义了一个命令行命令,用于重启VictoriaMetrics进程。 | ||
func RestartProcessCommand() *cobra.Command { | ||
act := RestartProcessAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "restart_process", | ||
Short: "重启vm进程", | ||
Example: fmt.Sprintf(`dbactuator vm restart_process %s`, subcmd.CmdBaseExapmleStr), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validate()) // 验证参数 | ||
if act.RollBack { // 如果需要回滚,则执行回滚操作 | ||
util.CheckErr(act.Rollback()) | ||
return | ||
} | ||
util.CheckErr(act.Init()) // 初始化 | ||
util.CheckErr(act.Run()) // 运行 | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Validate 是 RestartProcessAct 的验证函数,用于验证参数是否有效。 | ||
func (d *RestartProcessAct) Validate() (err error) { | ||
return d.BaseOptions.Validate() | ||
} | ||
|
||
// Init 是 RestartProcessAct 的初始化函数,用于初始化操作。 | ||
func (d *RestartProcessAct) Init() (err error) { | ||
logger.Info("RestartProcessAct Init") | ||
if err = d.Deserialize(&d.Service.Params); err != nil { // 反序列化参数 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
d.Service.GeneralParam = subcmd.GeneralRuntimeParam // 设置通用运行时参数 | ||
return d.Service.Init() // 初始化服务 | ||
} | ||
|
||
// Rollback 是 RestartProcessAct 的回滚函数,用于在操作失败时进行回滚。 | ||
func (d *RestartProcessAct) Rollback() (err error) { | ||
var r rollback.RollBackObjects | ||
if err = d.DeserializeAndValidate(&r); err != nil { // 反序列化并验证回滚对象 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
err = r.RollBack() // 执行回滚 | ||
if err != nil { | ||
logger.Error("roll back failed %s", err.Error()) | ||
} | ||
return | ||
} | ||
|
||
// Run 是 RestartProcessAct 的运行函数,用于执行重启VictoriaMetrics进程的操作。 | ||
func (d *RestartProcessAct) Run() (err error) { | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "重启vm进程", | ||
Func: d.Service.RestartProcess, // 重启进程的函数 | ||
}, | ||
} | ||
|
||
if err := steps.Run(); err != nil { // 执行步骤 | ||
rollbackCtxb, rerr := json.Marshal(d.Service.RollBackContext) // 序列化回滚上下文 | ||
if rerr != nil { | ||
logger.Error("json Marshal %s", err.Error()) | ||
fmt.Printf("<ctx>Can't RollBack<ctx>\n") | ||
} | ||
fmt.Printf("<ctx>%s<ctx>\n", string(rollbackCtxb)) | ||
return err | ||
} | ||
|
||
logger.Info("restart_process successfully") // 打印成功信息 | ||
return nil | ||
} |
95 changes: 95 additions & 0 deletions
95
dbm-services/bigdata/db-tools/dbactuator/internal/subcmd/vmcmd/start_process.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package vmcmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"dbm-services/bigdata/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/components/victoriametrics" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/rollback" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/util" | ||
"dbm-services/common/go-pubpkg/logger" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// StartProcessAct 是一个结构体,用于启动VictoriaMetrics进程。 | ||
type StartProcessAct struct { | ||
*subcmd.BaseOptions // BaseOptions 是基础选项,可能包含了一些全局设置或配置。 | ||
Service victoriametrics.StartStopProcessComp // Service 是用于启动和停止VictoriaMetrics进程的组件。 | ||
} | ||
|
||
// StartProcessCommand 是一个函数,返回一个cobra.Command对象,该对象定义了一个命令行命令,用于启动VictoriaMetrics进程。 | ||
func StartProcessCommand() *cobra.Command { | ||
act := StartProcessAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "start_process", | ||
Short: "启动vm进程", | ||
Example: fmt.Sprintf(`dbactuator vm start_process %s`, subcmd.CmdBaseExapmleStr), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validate()) // 验证参数 | ||
if act.RollBack { // 如果需要回滚,则执行回滚操作 | ||
util.CheckErr(act.Rollback()) | ||
return | ||
} | ||
util.CheckErr(act.Init()) // 初始化 | ||
util.CheckErr(act.Run()) // 运行 | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Validate 是 StartProcessAct 的验证函数,用于验证参数是否有效。 | ||
func (d *StartProcessAct) Validate() (err error) { | ||
return d.BaseOptions.Validate() | ||
} | ||
|
||
// Init 是 StartProcessAct 的初始化函数,用于初始化操作。 | ||
func (d *StartProcessAct) Init() (err error) { | ||
logger.Info("StartProcessAct Init") | ||
if err = d.Deserialize(&d.Service.Params); err != nil { // 反序列化参数 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
d.Service.GeneralParam = subcmd.GeneralRuntimeParam // 设置通用运行时参数 | ||
return d.Service.Init() // 初始化服务 | ||
} | ||
|
||
// Rollback 是 StartProcessAct 的回滚函数,用于在操作失败时进行回滚。 | ||
func (d *StartProcessAct) Rollback() (err error) { | ||
var r rollback.RollBackObjects | ||
if err = d.DeserializeAndValidate(&r); err != nil { // 反序列化并验证回滚对象 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
err = r.RollBack() // 执行回滚 | ||
if err != nil { | ||
logger.Error("roll back failed %s", err.Error()) | ||
} | ||
return | ||
} | ||
|
||
// Run 是 StartProcessAct 的运行函数,用于执行启动VictoriaMetrics进程的操作。 | ||
func (d *StartProcessAct) Run() (err error) { | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "启动vm进程", | ||
Func: d.Service.StartProcess, // 启动进程的函数 | ||
}, | ||
} | ||
|
||
if err := steps.Run(); err != nil { // 执行步骤 | ||
rollbackCtxb, rerr := json.Marshal(d.Service.RollBackContext) // 序列化回滚上下文 | ||
if rerr != nil { | ||
logger.Error("json Marshal %s", err.Error()) | ||
fmt.Printf("<ctx>Can't RollBack<ctx>\n") | ||
} | ||
fmt.Printf("<ctx>%s<ctx>\n", string(rollbackCtxb)) | ||
return err | ||
} | ||
|
||
logger.Info("start_process successfully") // 打印成功信息 | ||
return nil | ||
} |
95 changes: 95 additions & 0 deletions
95
dbm-services/bigdata/db-tools/dbactuator/internal/subcmd/vmcmd/stop_process.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package vmcmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"dbm-services/bigdata/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/components/victoriametrics" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/rollback" | ||
"dbm-services/bigdata/db-tools/dbactuator/pkg/util" | ||
"dbm-services/common/go-pubpkg/logger" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// StopProcessAct 是一个结构体,用于停止VictoriaMetrics进程。 | ||
type StopProcessAct struct { | ||
*subcmd.BaseOptions // BaseOptions 是基础选项,可能包含了一些全局设置或配置。 | ||
Service victoriametrics.StartStopProcessComp // Service 是用于启动和停止VictoriaMetrics进程的组件。 | ||
} | ||
|
||
// StopProcessCommand 是一个函数,返回一个cobra.Command对象,该对象定义了一个命令行命令,用于停止VictoriaMetrics进程。 | ||
func StopProcessCommand() *cobra.Command { | ||
act := StopProcessAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "stop_process", | ||
Short: "停止vm进程", | ||
Example: fmt.Sprintf(`dbactuator vm stop_process %s`, subcmd.CmdBaseExapmleStr), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validate()) // 验证参数 | ||
if act.RollBack { // 如果需要回滚,则执行回滚操作 | ||
util.CheckErr(act.Rollback()) | ||
return | ||
} | ||
util.CheckErr(act.Init()) // 初始化 | ||
util.CheckErr(act.Run()) // 运行 | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Validate 是 StopProcessAct 的验证函数,用于验证参数是否有效。 | ||
func (d *StopProcessAct) Validate() (err error) { | ||
return d.BaseOptions.Validate() | ||
} | ||
|
||
// Init 是 StopProcessAct 的初始化函数,用于初始化操作。 | ||
func (d *StopProcessAct) Init() (err error) { | ||
logger.Info("StopProcessAct Init") | ||
if err = d.Deserialize(&d.Service.Params); err != nil { // 反序列化参数 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
d.Service.GeneralParam = subcmd.GeneralRuntimeParam // 设置通用运行时参数 | ||
return d.Service.Init() // 初始化服务 | ||
} | ||
|
||
// Rollback 是 StopProcessAct 的回滚函数,用于在操作失败时进行回滚。 | ||
func (d *StopProcessAct) Rollback() (err error) { | ||
var r rollback.RollBackObjects | ||
if err = d.DeserializeAndValidate(&r); err != nil { // 反序列化并验证回滚对象 | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
err = r.RollBack() // 执行回滚 | ||
if err != nil { | ||
logger.Error("roll back failed %s", err.Error()) | ||
} | ||
return | ||
} | ||
|
||
// Run 是 StopProcessAct 的运行函数,用于执行停止VictoriaMetrics进程的操作。 | ||
func (d *StopProcessAct) Run() (err error) { | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "停止vm进程", | ||
Func: d.Service.StopProcess, // 停止进程的函数 | ||
}, | ||
} | ||
|
||
if err := steps.Run(); err != nil { // 执行步骤 | ||
rollbackCtxb, rerr := json.Marshal(d.Service.RollBackContext) // 序列化回滚上下文 | ||
if rerr != nil { | ||
logger.Error("json Marshal %s", err.Error()) | ||
fmt.Printf("<ctx>Can't RollBack<ctx>\n") | ||
} | ||
fmt.Printf("<ctx>%s<ctx>\n", string(rollbackCtxb)) | ||
return err | ||
} | ||
|
||
logger.Info("stop_process successfully") // 打印成功信息 | ||
return nil | ||
} |
Oops, something went wrong.