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): cluster扩缩容容接入层 TencentBlueKing#3364
- Loading branch information
yyhenryyy
committed
Mar 1, 2024
1 parent
7006381
commit 887d79d
Showing
13 changed files
with
380 additions
and
21 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
60 changes: 60 additions & 0 deletions
60
dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_cluster_scale_mongos.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,60 @@ | ||
# -*- 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 import increase_mongos, reduce_mongos | ||
from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs | ||
|
||
logger = logging.getLogger("flow") | ||
|
||
|
||
class ScaleMongoSFlow(object): | ||
"""cluster增加或减少mongos的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 = ActKwargs() | ||
self.get_kwargs.payload = data | ||
self.get_kwargs.get_file_path() | ||
|
||
def multi_cluster_mongos_flow(self, increase: bool): | ||
""" | ||
增加或减少mongos流程 | ||
""" | ||
|
||
# 创建流程实例 | ||
pipeline = Builder(root_id=self.root_id, data=self.data) | ||
|
||
# 根据不同的cluster进行增加mongos——子流程并行 | ||
sub_pipelines = [] | ||
for cluster in self.data["infos"]: | ||
if increase: | ||
sub_pipline = increase_mongos( | ||
root_id=self.root_id, ticket_data=self.data, sub_kwargs=self.get_kwargs, info=cluster | ||
) | ||
else: | ||
sub_pipline = reduce_mongos( | ||
root_id=self.root_id, ticket_data=self.data, sub_kwargs=self.get_kwargs, info=cluster | ||
) | ||
sub_pipelines.append(sub_pipline) | ||
pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_pipelines) | ||
|
||
# 运行流程 | ||
pipeline.run_pipeline() |
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
104 changes: 104 additions & 0 deletions
104
dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.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,104 @@ | ||
# -*- 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.plugins.components.collections.mongodb.add_domain_to_dns import ExecAddDomainToDnsOperationComponent | ||
from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent | ||
from backend.flow.plugins.components.collections.mongodb.mongos_scale_4_meta import MongosScaleMetaComponent | ||
from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent | ||
from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs | ||
|
||
from .mongos_install import mongos_install | ||
|
||
|
||
def increase_mongos(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKwargs, info: dict) -> SubBuilder: | ||
""" | ||
cluster 增加mongos流程 | ||
info 表示cluster信息 | ||
""" | ||
|
||
# 获取变量 | ||
sub_get_kwargs = deepcopy(sub_kwargs) | ||
|
||
# 创建子流程 | ||
sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data) | ||
|
||
# 设置参数 | ||
sub_get_kwargs.payload["db_version"] = info["db_version"] | ||
|
||
# 获取机器 | ||
sub_get_kwargs.get_host_scale_mongos(info=info, increase=True) | ||
|
||
# 介质下发 | ||
kwargs = sub_get_kwargs.get_send_media_kwargs() | ||
sub_pipeline.add_act( | ||
act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs | ||
) | ||
|
||
# 创建原子任务执行目录 | ||
kwargs = sub_get_kwargs.get_create_dir_kwargs() | ||
sub_pipeline.add_act( | ||
act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs | ||
) | ||
|
||
# 获取信息 | ||
sub_get_kwargs.get_cluster_info_deinstall(cluster_id=info["cluster_id"]) | ||
sub_get_kwargs.payload["cluster_id"] = info["cluster_id"] | ||
sub_get_kwargs.cluster_type = sub_get_kwargs.payload["cluster_type"] | ||
sub_get_kwargs.mongos_info = info | ||
sub_get_kwargs.mongos_info["nodes"] = info["mongos"] | ||
sub_get_kwargs.mongos_info["port"] = sub_get_kwargs.payload["mongos_nodes"][0]["port"] | ||
sub_get_kwargs.payload["config"] = {} | ||
sub_get_kwargs.payload["config"]["nodes"] = sub_get_kwargs.payload["config_nodes"] | ||
sub_get_kwargs.payload["config"]["port"] = sub_get_kwargs.payload["config_nodes"][0]["port"] | ||
sub_get_kwargs.payload["app"] = sub_get_kwargs.payload["db_app_abbr"] | ||
cluster_name = info["cluster_name"] | ||
sub_get_kwargs.mongos_info["set_id"] = cluster_name | ||
sub_get_kwargs.db_main_version = str(info["db_version"].split(".")[0]) | ||
sub_get_kwargs.payload["key_file"] = sub_get_kwargs.get_key_file(cluster_name=cluster_name) | ||
sub_get_kwargs.payload["nodes"] = [] | ||
sub_get_kwargs.payload["nodes"].append(sub_get_kwargs.payload["mongos_nodes"][0]) | ||
sub_get_kwargs.payload["mongos"] = {} | ||
sub_get_kwargs.payload["mongos"]["nodes"] = info["mongos"] | ||
sub_get_kwargs.payload["mongos"]["domain"] = sub_get_kwargs.payload["mongos_nodes"][0]["domain"] | ||
sub_get_kwargs.payload["mongos"]["port"] = sub_get_kwargs.payload["mongos_nodes"][0]["port"] | ||
|
||
# 进行mongos安装——子流程 | ||
sub_sub_pipeline = mongos_install( | ||
root_id=root_id, | ||
ticket_data=ticket_data, | ||
sub_kwargs=sub_get_kwargs, | ||
increase_mongos=True, | ||
) | ||
sub_pipeline.add_sub_pipeline(sub_sub_pipeline) | ||
|
||
# dns新增实例 | ||
kwargs = sub_get_kwargs.get_add_domain_to_dns_kwargs(cluster=True) | ||
sub_pipeline.add_act( | ||
act_name=_("MongoDB--添加domain到dns"), | ||
act_component_code=ExecAddDomainToDnsOperationComponent.code, | ||
kwargs=kwargs, | ||
) | ||
|
||
# 修改db_meta数据 | ||
kwargs = sub_get_kwargs.get_change_meta_mongos_kwargs(increase=True) | ||
sub_pipeline.add_act( | ||
act_name=_("MongoDB--修改meta"), | ||
act_component_code=MongosScaleMetaComponent.code, | ||
kwargs=kwargs, | ||
) | ||
|
||
return sub_pipeline.build_sub_process(sub_name=_("MongoDB--{}增加mongos".format(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
Oops, something went wrong.