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.
fix(sqlserver): 优化slave重建的逻辑 TencentBlueKing#8306
- Loading branch information
Showing
17 changed files
with
779 additions
and
60 deletions.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
dbm-services/sqlserver/db-tools/dbactuator/internal/subcmd/checkcmd/check_mssql_service.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,83 @@ | ||
/* | ||
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package checkcmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"dbm-services/common/go-pubpkg/logger" | ||
"dbm-services/sqlserver/db-tools/dbactuator/internal/subcmd" | ||
"dbm-services/sqlserver/db-tools/dbactuator/pkg/components/check" | ||
"dbm-services/sqlserver/db-tools/dbactuator/pkg/util" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// MssqlServiceAct sqlserver 检查实例连接情况 | ||
type MssqlServiceAct struct { | ||
*subcmd.BaseOptions | ||
BaseService check.MssqlServiceComp | ||
} | ||
|
||
// MssqlServiceCommand godoc | ||
// | ||
// @Summary sqlserver 检查实例连接情况 | ||
// @Description - | ||
// @Tags sqlserver | ||
// @Accept json | ||
// @Param body body MssqlServiceComp true "short description" | ||
func MssqlServiceCommand() *cobra.Command { | ||
act := MssqlServiceAct{ | ||
BaseOptions: subcmd.GBaseOptions, | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "MssqlServiceCheck", | ||
Short: "检查机器注册Sqlserver进程情况", | ||
Example: fmt.Sprintf(`dbactuator check MssqlServiceCheck %s `, subcmd.CmdBaseExampleStr), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(act.Validate()) | ||
if act.RollBack { | ||
return | ||
} | ||
util.CheckErr(act.Init()) | ||
util.CheckErr(act.Run()) | ||
}, | ||
} | ||
return cmd | ||
} | ||
|
||
// Init 初始化 | ||
func (u *MssqlServiceAct) Init() (err error) { | ||
logger.Info("MssqlServiceAct Init") | ||
if err = u.Deserialize(&u.BaseService.Params); err != nil { | ||
logger.Error("DeserializeAndValidate failed, %v", err) | ||
return err | ||
} | ||
u.BaseService.GeneralParam = subcmd.GeneralRuntimeParam | ||
|
||
return nil | ||
} | ||
|
||
// Run 执行 | ||
func (u *MssqlServiceAct) Run() (err error) { | ||
steps := subcmd.Steps{ | ||
{ | ||
FunName: "检查机器注册Sqlserver进程情况", | ||
Func: u.BaseService.CheckMssqlService, | ||
}, | ||
} | ||
|
||
if err := steps.Run(); err != nil { | ||
return err | ||
} | ||
logger.Info("check-inst-processlists successfully") | ||
return nil | ||
} |
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
53 changes: 53 additions & 0 deletions
53
dbm-services/sqlserver/db-tools/dbactuator/pkg/components/check/check_mssql_service.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,53 @@ | ||
/* | ||
* TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. | ||
* Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. | ||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at https://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package check | ||
|
||
import ( | ||
"bk-dbconfig/pkg/core/logger" | ||
"fmt" | ||
|
||
"dbm-services/sqlserver/db-tools/dbactuator/pkg/components" | ||
"dbm-services/sqlserver/db-tools/dbactuator/pkg/util/osutil" | ||
"dbm-services/sqlserver/db-tools/dbactuator/pkg/util/sqlserver" | ||
) | ||
|
||
// MssqlServiceComp 检查db连接情况 | ||
type MssqlServiceComp struct { | ||
GeneralParam *components.GeneralParam | ||
Params *MssqlServiceParam | ||
DB *sqlserver.DbWorker | ||
} | ||
|
||
// MssqlServiceParam 参数 | ||
type MssqlServiceParam struct { | ||
Host string `json:"host" validate:"ip" ` // 本地hostip | ||
} | ||
|
||
// CheckMssqlService 检查机器注册Sqlserver进程情况 | ||
func (c *MssqlServiceComp) CheckMssqlService() error { | ||
var checkresult string | ||
ret, err := osutil.StandardPowerShellCommand( | ||
"GET-SERVICE -NAME MSSQL* | WHERE-OBJECT {$_.NAME -NOTLIKE \"*#*\"}", | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if ret != "" { | ||
// 输出不为空则表示有部署进程 | ||
logger.Info("there is a mssql process has been registered [%s]", osutil.CleanExecOutput(ret)) | ||
checkresult = "1" | ||
} | ||
logger.Info("no mssql service registered") | ||
checkresult = "0" | ||
components.WrapperOutputString(fmt.Sprintf("{\"checkresult\": \"%s\"}", checkresult)) | ||
return nil | ||
|
||
} |
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
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
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
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
Oops, something went wrong.