Skip to content

Commit

Permalink
feat: 调整sqlserver流程,执行时增加随机账号添加 #3527
Browse files Browse the repository at this point in the history
  • Loading branch information
yksitu authored and iSecloud committed Mar 21, 2024
1 parent bc55bf9 commit 97f50af
Show file tree
Hide file tree
Showing 24 changed files with 605 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from backend.db_meta.exceptions import DBMetaException
from backend.db_meta.models import Cluster, ClusterEntry, StorageInstance, StorageInstanceTuple
from backend.db_meta.models.storage_set_dtl import SqlserverClusterSyncMode
from backend.flow.utils.sqlserver.sqlserver_db_function import get_instance_time_zone

logger = logging.getLogger("root")

Expand Down Expand Up @@ -70,7 +71,6 @@ def create(
major_version: str,
db_module_id: int,
bk_cloud_id: int,
time_zone: str,
region: str,
sync_type: str,
slave_domain: Optional[str] = None,
Expand Down Expand Up @@ -104,7 +104,7 @@ def create(
phase=ClusterPhase.ONLINE.value,
status=ClusterStatus.NORMAL.value,
bk_cloud_id=bk_cloud_id,
time_zone=time_zone,
time_zone=get_instance_time_zone(master_storage_obj),
major_version=major_version,
region=region,
)
Expand Down Expand Up @@ -138,6 +138,8 @@ def create(
m = ins.machine
ins.db_module_id = db_module_id
m.db_module_id = db_module_id
# 保存最新的time_zone
ins.time_zone = get_instance_time_zone(ins)
ins.save(update_fields=["db_module_id"])
m.save(update_fields=["db_module_id"])

Expand Down
1 change: 0 additions & 1 deletion dbm-ui/backend/db_meta/api/cluster/sqlserverha/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def create(
storages=storages,
creator=creator,
bk_cloud_id=bk_cloud_id,
time_zone=time_zone,
major_version=major_version,
region=region,
sync_type=sync_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from backend.db_meta.enums import ClusterEntryType, ClusterPhase, ClusterStatus, ClusterType
from backend.db_meta.exceptions import DBMetaException
from backend.db_meta.models import Cluster, ClusterEntry, StorageInstance
from backend.flow.utils.sqlserver.sqlserver_db_function import get_instance_time_zone

logger = logging.getLogger("root")

Expand Down Expand Up @@ -48,7 +49,6 @@ def create(
db_module_id: int,
storage: Dict,
bk_cloud_id: int,
time_zone: str,
region: str,
creator: str = "",
) -> Cluster:
Expand All @@ -69,7 +69,7 @@ def create(
phase=ClusterPhase.ONLINE.value,
status=ClusterStatus.NORMAL.value,
bk_cloud_id=bk_cloud_id,
time_zone=time_zone,
time_zone=get_instance_time_zone(storage_objs[0]),
major_version=major_version,
region=region,
)
Expand All @@ -85,7 +85,8 @@ def create(
m = ins.machine
ins.db_module_id = db_module_id
m.db_module_id = db_module_id
# 保存最新的time_zone
ins.time_zone = get_instance_time_zone(ins)
ins.save(update_fields=["db_module_id"])
m.save(update_fields=["db_module_id"])

return cluster
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def create(
storage=storage,
creator=creator,
bk_cloud_id=bk_cloud_id,
time_zone=time_zone,
region=region,
)
)
Expand Down
10 changes: 5 additions & 5 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,11 @@ class SqlserverSysVersion(str, StructuredEnum):
定义Sqlserver支持操作系统版本名称
"""

Windows_Server_2008 = EnumField("Windows Server 2008", _("2008服务器版"))
Windows_Server_2012 = EnumField("Windows Server 2012", _("2012服务器版"))
Windows_Server_2016 = EnumField("Windows Server 2016", _("2016服务器版"))
Windows_Server_2019 = EnumField("Windows Server 2019", _("2019服务器版"))
Windows_Server_2022 = EnumField("Windows Server 2022", _("2022服务器版"))
Windows_Server_2008 = EnumField("WindowsServer2008", _("2008服务器版"))
Windows_Server_2012 = EnumField("WindowsServer2012", _("2012服务器版"))
Windows_Server_2016 = EnumField("WindowsServer2016", _("2016服务器版"))
Windows_Server_2019 = EnumField("WindowsServer2019", _("2019服务器版"))
Windows_Server_2022 = EnumField("WindowsServer2022", _("2022服务器版"))


# mssql各版本的操作系统版本支持
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import logging.config
from dataclasses import asdict

from django.utils.translation import ugettext as _

Expand All @@ -17,6 +18,10 @@
from backend.flow.engine.bamboo.scene.common.builder import Builder, SubBuilder
from backend.flow.engine.bamboo.scene.sqlserver.base_flow import BaseFlow
from backend.flow.engine.bamboo.scene.sqlserver.common_sub_flow import sync_dbs_for_cluster_sub_flow
from backend.flow.plugins.components.collections.sqlserver.create_random_job_user import SqlserverAddJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.drop_random_job_user import SqlserverDropJobUserComponent
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import CreateRandomJobUserKwargs, DropRandomJobUserKwargs
from backend.flow.utils.sqlserver.sqlserver_db_function import create_sqlserver_login_sid
from backend.flow.utils.sqlserver.sqlserver_host import Host

logger = logging.getLogger("flow")
Expand Down Expand Up @@ -50,6 +55,20 @@ def run_flow(self):

# 声明子流程
sub_pipeline = SubBuilder(root_id=self.root_id, data=self.data)

# 创建随机账号
sub_pipeline.add_act(
act_name=_("create job user"),
act_component_code=SqlserverAddJobUserComponent.code,
kwargs=asdict(
CreateRandomJobUserKwargs(
cluster_ids=[cluster.id],
sid=create_sqlserver_login_sid(),
),
),
)

# 数据同步子流程
sub_pipeline.add_sub_pipeline(
sub_flow=sync_dbs_for_cluster_sub_flow(
uid=self.data["uid"],
Expand All @@ -59,6 +78,14 @@ def run_flow(self):
sync_dbs=info["sync_dbs"],
)
)

# 删除随机账号
sub_pipeline.add_act(
act_name=_("drop job user"),
act_component_code=SqlserverDropJobUserComponent.code,
kwargs=asdict(DropRandomJobUserKwargs(cluster_ids=[cluster.id])),
)

sub_pipelines.append(sub_pipeline.build_sub_process(sub_name=_("{}集群建立数据库同步".format(cluster.name))))

main_pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@
install_sqlserver_sub_flow,
sync_dbs_for_cluster_sub_flow,
)
from backend.flow.plugins.components.collections.sqlserver.create_random_job_user import SqlserverAddJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.drop_random_job_user import SqlserverDropJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.sqlserver_db_meta import SqlserverDBMetaComponent
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import DBMetaOPKwargs
from backend.flow.utils.sqlserver.sqlserver_db_function import get_dbs_for_drs, get_group_name
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import (
CreateRandomJobUserKwargs,
DBMetaOPKwargs,
DropRandomJobUserKwargs,
)
from backend.flow.utils.sqlserver.sqlserver_db_function import (
create_sqlserver_login_sid,
get_dbs_for_drs,
get_group_name,
)
from backend.flow.utils.sqlserver.sqlserver_db_meta import SqlserverDBMeta
from backend.flow.utils.sqlserver.sqlserver_host import Host
from backend.flow.utils.sqlserver.validate import SqlserverCluster, SqlserverInstance
Expand Down Expand Up @@ -128,6 +138,19 @@ def run_flow(self):
)
)

# 创建随机账号
cluster_sub_pipeline.add_act(
act_name=_("create job user"),
act_component_code=SqlserverAddJobUserComponent.code,
kwargs=asdict(
CreateRandomJobUserKwargs(
cluster_ids=[cluster.id],
sid=create_sqlserver_login_sid(),
other_instances=[f"{info['new_slave_host']['ip']}:{master_instance.port}"],
),
),
)

# 加入到集群的AlwaysOn可用组
cluster_sub_pipeline.add_sub_pipeline(
sub_flow=build_always_on_sub_flow(
Expand Down Expand Up @@ -156,6 +179,18 @@ def run_flow(self):
)
)

# 删除随机账号
cluster_sub_pipeline.add_act(
act_name=_("drop job user"),
act_component_code=SqlserverDropJobUserComponent.code,
kwargs=asdict(
DropRandomJobUserKwargs(
cluster_ids=[cluster.id],
other_instances=[f"{info['new_slave_host']['ip']}:{master_instance.port}"],
),
),
)

cluster_flows.append(
cluster_sub_pipeline.build_sub_process(sub_name=_("[{}]集群与新slave建立关系".format(cluster.name)))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
from backend.flow.engine.bamboo.scene.common.builder import Builder, SubBuilder
from backend.flow.engine.bamboo.scene.common.get_file_list import GetFileList
from backend.flow.engine.bamboo.scene.sqlserver.base_flow import BaseFlow
from backend.flow.plugins.components.collections.sqlserver.create_random_job_user import SqlserverAddJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.drop_random_job_user import SqlserverDropJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.exec_actuator_script import SqlserverActuatorScriptComponent
from backend.flow.plugins.components.collections.sqlserver.trans_files import TransFileInWindowsComponent
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import DownloadMediaKwargs, ExecActuatorKwargs
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import (
CreateRandomJobUserKwargs,
DownloadMediaKwargs,
DropRandomJobUserKwargs,
ExecActuatorKwargs,
)
from backend.flow.utils.sqlserver.sqlserver_act_payload import SqlserverActPayload
from backend.flow.utils.sqlserver.sqlserver_db_function import create_sqlserver_login_sid
from backend.flow.utils.sqlserver.sqlserver_host import Host

logger = logging.getLogger("flow")
Expand Down Expand Up @@ -63,6 +71,18 @@ def run_flow(self):
# 声明子流程
sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(sub_flow_context))

# 创建随机账号
sub_pipeline.add_act(
act_name=_("create job user"),
act_component_code=SqlserverAddJobUserComponent.code,
kwargs=asdict(
CreateRandomJobUserKwargs(
cluster_ids=[cluster.id],
sid=create_sqlserver_login_sid(),
),
),
)

sub_pipeline.add_act(
act_name=_("下发执行器"),
act_component_code=TransFileInWindowsComponent.code,
Expand All @@ -88,6 +108,13 @@ def run_flow(self):
),
)

# 删除随机账号
sub_pipeline.add_act(
act_name=_("drop job user"),
act_component_code=SqlserverDropJobUserComponent.code,
kwargs=asdict(DropRandomJobUserKwargs(cluster_ids=[cluster.id])),
)

sub_pipelines.append(sub_pipeline.build_sub_process(sub_name=_("{}执行备份".format(cluster.name))))

main_pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@
from backend.flow.engine.bamboo.scene.common.builder import Builder, SubBuilder
from backend.flow.engine.bamboo.scene.common.get_file_list import GetFileList
from backend.flow.engine.bamboo.scene.sqlserver.base_flow import BaseFlow
from backend.flow.plugins.components.collections.sqlserver.create_random_job_user import SqlserverAddJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.drop_random_job_user import SqlserverDropJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.exec_actuator_script import SqlserverActuatorScriptComponent
from backend.flow.plugins.components.collections.sqlserver.trans_files import TransFileInWindowsComponent
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import DownloadMediaKwargs, ExecActuatorKwargs
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import (
CreateRandomJobUserKwargs,
DownloadMediaKwargs,
DropRandomJobUserKwargs,
ExecActuatorKwargs,
)
from backend.flow.utils.sqlserver.sqlserver_act_payload import SqlserverActPayload
from backend.flow.utils.sqlserver.sqlserver_db_function import create_sqlserver_login_sid
from backend.flow.utils.sqlserver.sqlserver_host import Host

logger = logging.getLogger("flow")
Expand Down Expand Up @@ -78,6 +86,18 @@ def run_flow(self):
# 声明子流程
sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(sub_flow_context))

# 创建随机账号
sub_pipeline.add_act(
act_name=_("create job user"),
act_component_code=SqlserverAddJobUserComponent.code,
kwargs=asdict(
CreateRandomJobUserKwargs(
cluster_ids=[cluster.id],
sid=create_sqlserver_login_sid(),
),
),
)

sub_pipeline.add_act(
act_name=_("下发执行器"),
act_component_code=TransFileInWindowsComponent.code,
Expand All @@ -101,6 +121,13 @@ def run_flow(self):
),
)

# 删除随机账号
sub_pipeline.add_act(
act_name=_("drop job user"),
act_component_code=SqlserverDropJobUserComponent.code,
kwargs=asdict(DropRandomJobUserKwargs(cluster_ids=[cluster.id])),
)

sub_pipelines.append(sub_pipeline.build_sub_process(sub_name=_("{}集群执行清档".format(cluster.name))))

main_pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
from backend.flow.engine.bamboo.scene.common.get_file_list import GetFileList
from backend.flow.engine.bamboo.scene.sqlserver.base_flow import BaseFlow
from backend.flow.plugins.components.collections.mysql.dns_manage import MySQLDnsManageComponent
from backend.flow.plugins.components.collections.sqlserver.create_random_job_user import SqlserverAddJobUserComponent
from backend.flow.plugins.components.collections.sqlserver.exec_actuator_script import SqlserverActuatorScriptComponent
from backend.flow.plugins.components.collections.sqlserver.sqlserver_db_meta import SqlserverDBMetaComponent
from backend.flow.plugins.components.collections.sqlserver.trans_files import TransFileInWindowsComponent
from backend.flow.utils.mysql.mysql_act_dataclass import DeleteClusterDnsKwargs
from backend.flow.utils.sqlserver.sqlserver_act_dataclass import (
CreateRandomJobUserKwargs,
DBMetaOPKwargs,
DownloadMediaKwargs,
ExecActuatorKwargs,
)
from backend.flow.utils.sqlserver.sqlserver_act_payload import SqlserverActPayload
from backend.flow.utils.sqlserver.sqlserver_db_function import create_sqlserver_login_sid
from backend.flow.utils.sqlserver.sqlserver_db_meta import SqlserverDBMeta
from backend.flow.utils.sqlserver.sqlserver_host import Host

Expand Down Expand Up @@ -77,6 +80,18 @@ def run_flow(self):
# 声明子流程
sub_pipeline = SubBuilder(root_id=self.root_id, data=copy.deepcopy(sub_flow_context))

# 创建随机账号
sub_pipeline.add_act(
act_name=_("create job user"),
act_component_code=SqlserverAddJobUserComponent.code,
kwargs=asdict(
CreateRandomJobUserKwargs(
cluster_ids=[cluster.id],
sid=create_sqlserver_login_sid(),
),
),
)

# 下发执行器
sub_pipeline.add_act(
act_name=_("下发执行器"),
Expand Down
Loading

0 comments on commit 97f50af

Please sign in to comment.