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(mongodb): 从旧系统迁移元数据到新系统 TencentBlueKing#5994
- Loading branch information
yyhenryyy
committed
Aug 19, 2024
1 parent
6d6f076
commit 080236e
Showing
18 changed files
with
960 additions
and
18 deletions.
There are no files selected for viewing
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
70 changes: 70 additions & 0 deletions
70
dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_migrate.py
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,70 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
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. | ||
""" | ||
import logging.config | ||
from typing import Dict, Optional | ||
|
||
from backend.flow.engine.bamboo.scene.common.builder import Builder | ||
from backend.flow.engine.bamboo.scene.mongodb.sub_task.migrate_meta import cluster_migrate | ||
from backend.flow.engine.bamboo.scene.mongodb.sub_task.multi_replicaset_migrate_meta import multi_replicaset_migrate | ||
from backend.flow.utils.mongodb.mongodb_migrate_dataclass import MigrateActKwargs | ||
|
||
logger = logging.getLogger("flow") | ||
|
||
|
||
class MongoDBMigrateMetaFlow(object): | ||
"""元数据迁移flow""" | ||
|
||
def __init__(self, root_id: str, data: Optional[Dict]): | ||
""" | ||
传入参数 | ||
@param root_id : 任务流程定义的root_id | ||
@param data : 单据传递过来的参数列表,是dict格式 | ||
""" | ||
|
||
self.root_id = root_id | ||
self.data = data | ||
self.get_kwargs = MigrateActKwargs() | ||
self.get_kwargs.payload = data | ||
self.get_kwargs.bk_biz_id = data.get("bk_biz_id") | ||
|
||
def multi_cluster_migrate_flow(self): | ||
""" | ||
cluster migrate流程 | ||
""" | ||
|
||
# 创建流程实例 | ||
pipeline = Builder(root_id=self.root_id, data=self.data) | ||
|
||
# 副本集与分片集群并行 | ||
# 副本集子流程串行 | ||
sub_pipelines = [] | ||
if self.data["MongoReplicaSet"]: | ||
self.get_kwargs.multi_replicaset_info = self.data["MongoReplicaSet"] | ||
sub_pipline = multi_replicaset_migrate( | ||
root_id=self.root_id, | ||
ticket_data=self.data, | ||
sub_kwargs=self.get_kwargs, | ||
) | ||
sub_pipelines.append(sub_pipline) | ||
# 分片集群并行 | ||
for cluster_info in self.data["MongoShardedCluster"]: | ||
self.get_kwargs.source_cluster_info = cluster_info | ||
sub_pipline = cluster_migrate( | ||
root_id=self.root_id, | ||
ticket_data=self.data, | ||
sub_kwargs=self.get_kwargs, | ||
cluster=True, | ||
) | ||
sub_pipelines.append(sub_pipline) | ||
pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines) | ||
|
||
# 运行流程 | ||
pipeline.run_pipeline() |
103 changes: 103 additions & 0 deletions
103
dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/migrate_meta.py
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,103 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
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. | ||
""" | ||
|
||
from copy import deepcopy | ||
from typing import Dict, Optional | ||
|
||
from django.utils.translation import ugettext as _ | ||
|
||
from backend.db_meta.enums.cluster_type import ClusterType | ||
from backend.flow.engine.bamboo.scene.common.builder import SubBuilder | ||
from backend.flow.plugins.components.collections.mongodb.add_relationship_to_meta import ( | ||
ExecAddRelationshipOperationComponent, | ||
) | ||
from backend.flow.plugins.components.collections.mongodb.migrate_meta import MongoDBMigrateMetaComponent | ||
from backend.flow.utils.mongodb.mongodb_migrate_dataclass import MigrateActKwargs | ||
|
||
|
||
def cluster_migrate( | ||
root_id: str, ticket_data: Optional[Dict], sub_kwargs: MigrateActKwargs, cluster: bool | ||
) -> SubBuilder: | ||
""" | ||
单个replicaset迁移元数 | ||
""" | ||
|
||
# 获取变量 | ||
sub_get_kwargs = deepcopy(sub_kwargs) | ||
# 创建子流程 | ||
sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data) | ||
|
||
# 获取副本集机器是否复用 | ||
sub_get_kwargs.skip_machine() | ||
|
||
# 检查 是否已经迁移 从目标环境检查迁移ip是否复用 | ||
kwargs = sub_get_kwargs.get_check_dest_cluster_info( | ||
cluster_name=sub_get_kwargs.source_cluster_info.get("replsetname") | ||
) | ||
sub_pipeline.add_act( | ||
act_name=_("检查cluster目标端是否存在"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs | ||
) | ||
|
||
# 检查机器规格是否在目标端存在 | ||
kwargs = sub_get_kwargs.get_check_spec_info() | ||
sub_pipeline.add_act(act_name=_("检查目标端机器规格"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs) | ||
|
||
# dbconfig保存oplogsize cachesize | ||
if cluster: | ||
namespace = ClusterType.MongoShardedCluster.value | ||
else: | ||
namespace = ClusterType.MongoReplicaSet.value | ||
kwargs = sub_get_kwargs.get_save_conf_info(namespace=namespace) | ||
sub_pipeline.add_act(act_name=_("保存配置"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs) | ||
|
||
# 目标业务更新dba 检查目标业务的dba,不一致则更新 | ||
kwargs = sub_get_kwargs.get_dba_info() | ||
sub_pipeline.add_act(act_name=_("更新dba"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs) | ||
|
||
# 迁移数据 | ||
kwargs = sub_get_kwargs.get_migrate_info() | ||
sub_pipeline.add_act( | ||
act_name=_("迁移meta"), | ||
act_component_code=ExecAddRelationshipOperationComponent.code, | ||
kwargs=kwargs, | ||
) | ||
|
||
# node保存密码到密码服务 | ||
kwargs = sub_get_kwargs.get_save_password_info() | ||
sub_pipeline.add_act(act_name=_("保存密码"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs) | ||
|
||
# 修改dns的app字段 | ||
kwargs = sub_get_kwargs.get_change_dns_app_info() | ||
sub_pipeline.add_act(act_name=_("更新dns的app"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs) | ||
|
||
if cluster: | ||
name = "cluster" | ||
# cluster删除shard的域名 迁移完,运行无误后再删 | ||
# kwargs = sub_get_kwargs.get_shard_delete_doamin_info() | ||
# sub_pipeline.add_act( | ||
# act_name=_("删除shard的domain"), | ||
# act_component_code=MongoDBMigrateMetaComponent.code, | ||
# kwargs=kwargs | ||
# ) | ||
cluster_name = sub_get_kwargs.source_cluster_info["cluster_id"] | ||
# 添加clb | ||
if sub_get_kwargs.source_cluster_info["clb"]: | ||
kwargs = sub_get_kwargs.get_clb_info() | ||
sub_pipeline.add_act( | ||
act_name=_("添加clb到meta"), act_component_code=MongoDBMigrateMetaComponent.code, kwargs=kwargs | ||
) | ||
else: | ||
name = "replicaset" | ||
cluster_name = sub_get_kwargs.source_cluster_info["replsetname"] | ||
|
||
return sub_pipeline.build_sub_process( | ||
sub_name=_("MongoDB--{}-meta迁移-{}-{}".format(name, sub_get_kwargs.payload["app"], cluster_name)) | ||
) |
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
47 changes: 47 additions & 0 deletions
47
dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/multi_replicaset_migrate_meta.py
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,47 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
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. | ||
""" | ||
|
||
from copy import deepcopy | ||
from typing import Dict, Optional | ||
|
||
from django.utils.translation import ugettext as _ | ||
|
||
from backend.flow.engine.bamboo.scene.common.builder import SubBuilder | ||
from backend.flow.engine.bamboo.scene.mongodb.sub_task.migrate_meta import cluster_migrate | ||
from backend.flow.utils.mongodb.mongodb_migrate_dataclass import MigrateActKwargs | ||
|
||
|
||
def multi_replicaset_migrate( | ||
root_id: str, | ||
ticket_data: Optional[Dict], | ||
sub_kwargs: MigrateActKwargs, | ||
) -> SubBuilder: | ||
""" | ||
多个replicaset迁移元数据 | ||
""" | ||
|
||
# 获取变量 | ||
sub_get_kwargs = deepcopy(sub_kwargs) | ||
# 创建子流程 | ||
sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data) | ||
|
||
# 多个replicaset迁移元数据——串行 | ||
for replicaset_info in sub_get_kwargs.multi_replicaset_info: | ||
sub_get_kwargs.source_cluster_info = replicaset_info | ||
flow = cluster_migrate( | ||
root_id=root_id, | ||
ticket_data=ticket_data, | ||
sub_kwargs=sub_get_kwargs, | ||
cluster=False, | ||
) | ||
sub_pipeline.add_sub_pipeline(sub_flow=flow) | ||
|
||
return sub_pipeline.build_sub_process(sub_name=_("MongoDB--复制集迁移元数据")) |
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.