From b779965f9e4228b8760535e36409d7c883248a5f Mon Sep 17 00:00:00 2001 From: yyhenryyy Date: Fri, 21 Jun 2024 17:42:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(mongodb):=20mongodb=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=97=B6=E4=BF=AE=E5=A4=8Ddb=E7=89=88=E6=9C=AC=E5=90=8D?= =?UTF-8?q?=E7=A7=B0bug=EF=BC=8C=E5=A2=9E=E5=8A=A0=E8=93=9D=E9=B2=B8?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E5=AE=89=E8=A3=85=E8=8A=82=E7=82=B9=20#5075?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pkg/atomjobs/atommongodb/add_user.go | 4 +- .../pkg/atomjobs/atommongodb/del_user.go | 4 +- .../bamboo/scene/common/get_file_list.py | 6 ++- .../mongodb/mongodb_cluster_scale_mongos.py | 3 +- .../bamboo/scene/mongodb/mongodb_deinstall.py | 2 +- .../scene/mongodb/mongodb_enable_disable.py | 2 +- .../scene/mongodb/mongodb_exec_script.py | 2 +- .../bamboo/scene/mongodb/mongodb_install.py | 26 ++++++++++- .../scene/mongodb/mongodb_instance_restart.py | 2 +- .../bamboo/scene/mongodb/mongodb_replace.py | 3 +- .../scene/mongodb/mongodb_scale_node.py | 10 ++--- .../scene/mongodb/mongodb_scale_storage.py | 3 +- .../bamboo/scene/mongodb/mongodb_user.py | 2 +- .../mongodb/sub_task/cluster_increase_node.py | 4 ++ .../scene/mongodb/sub_task/cluster_replace.py | 4 ++ .../scene/mongodb/sub_task/cluster_scale.py | 4 ++ .../scene/mongodb/sub_task/increase_mongos.py | 4 ++ .../mongodb/sub_task/replicaset_replace.py | 4 ++ .../mongodb/sub_task/replicaset_scale.py | 4 ++ .../sub_task/replicaset_set_increase_node.py | 4 ++ .../flow/utils/mongodb/mongodb_dataclass.py | 43 +++++++++++++++++-- 21 files changed, 114 insertions(+), 26 deletions(-) diff --git a/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go index 5d0599fb2c..38ce7876bc 100644 --- a/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/add_user.go @@ -203,8 +203,8 @@ func (u *AddUser) execScript() error { return err } if flag == true { - u.runtime.Logger.Info("user:%s has been existed", u.ConfParams.Username) - return nil + u.runtime.Logger.Error("user:%s has been existed", u.ConfParams.Username) + return fmt.Errorf("user:%s has been existed", u.ConfParams.Username) } cmd = fmt.Sprintf( "%s -u %s -p '%s' --host %s --port %d --authenticationDatabase=admin --quiet --eval '%s' %s", diff --git a/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go index 6f1a7937ff..b1779cc6a5 100644 --- a/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go +++ b/dbm-services/mongodb/db-tools/dbactuator/pkg/atomjobs/atommongodb/del_user.go @@ -170,8 +170,8 @@ func (d *DelUser) execScript() error { return err } if flag == false { - d.runtime.Logger.Info(fmt.Sprintf("user:%s is not existed", d.ConfParams.Username)) - return nil + d.runtime.Logger.Error(fmt.Sprintf("user:%s is not existed", d.ConfParams.Username)) + return fmt.Errorf("user:%s is not existed", d.ConfParams.Username) } // 执行脚本 diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/common/get_file_list.py b/dbm-ui/backend/flow/engine/bamboo/scene/common/get_file_list.py index 2dca11c759..e831c4947a 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/common/get_file_list.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/common/get_file_list.py @@ -613,12 +613,14 @@ def get_sqlserver_package(self, db_version: str): f"{env.BKREPO_PROJECT}/{env.BKREPO_BUCKET}/{self.actuator_pkg.path}", ] - def mongodb_pkg(self, db_version: str, release_info: str) -> list: + def mongodb_pkg(self, db_version: str) -> list: """ 部署mongodb,需要的pkg包 """ - mongodb_pkg = Package.get_latest_package(version=db_version, pkg_type=release_info, db_type=DBType.MongoDB) + mongodb_pkg = Package.get_latest_package( + version=db_version, pkg_type=MediumEnum.MongoDB, db_type=DBType.MongoDB + ) # bkdbmon_pkg = Package.get_latest_package( # version=MediumEnum.Latest, pkg_type=MediumEnum.DbMon, db_type=DBType.MongoDB # ) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_cluster_scale_mongos.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_cluster_scale_mongos.py index 855c5672d8..d5e3eabaf3 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_cluster_scale_mongos.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_cluster_scale_mongos.py @@ -12,7 +12,8 @@ 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.engine.bamboo.scene.mongodb.sub_task.increase_mongos import increase_mongos +from backend.flow.engine.bamboo.scene.mongodb.sub_task.reduce_mongos import reduce_mongos from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_deinstall.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_deinstall.py index 6a67b0150e..dfa0052e77 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_deinstall.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_deinstall.py @@ -14,7 +14,7 @@ from django.utils.translation import ugettext as _ from backend.flow.engine.bamboo.scene.common.builder import Builder -from backend.flow.engine.bamboo.scene.mongodb.sub_task import deinstall +from backend.flow.engine.bamboo.scene.mongodb.sub_task.deinstall import deinstall from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_enable_disable.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_enable_disable.py index 1699952f36..82ce4c1ed1 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_enable_disable.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_enable_disable.py @@ -14,7 +14,7 @@ from django.utils.translation import ugettext as _ from backend.flow.engine.bamboo.scene.common.builder import Builder -from backend.flow.engine.bamboo.scene.mongodb.sub_task import cluster_enable_disable +from backend.flow.engine.bamboo.scene.mongodb.sub_task.cluster_enable_disable import cluster_enable_disable from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_exec_script.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_exec_script.py index 9386c2cd2a..02df302641 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_exec_script.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_exec_script.py @@ -12,7 +12,7 @@ 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 exec_script +from backend.flow.engine.bamboo.scene.mongodb.sub_task.exec_script import exec_script from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_install.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_install.py index 6eb08c4853..4eab499280 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_install.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_install.py @@ -14,10 +14,14 @@ from django.utils.translation import ugettext as _ from backend.db_meta.enums.cluster_type import ClusterType -from backend.flow.consts import MongoDBClusterRole +from backend.flow.consts import DEPENDENCIES_PLUGINS, MongoDBClusterRole from backend.flow.engine.bamboo.scene.common.builder import Builder from backend.flow.engine.bamboo.scene.mongodb.mongodb_install_dbmon import add_install_dbmon -from backend.flow.engine.bamboo.scene.mongodb.sub_task import mongos_install, replicaset_install +from backend.flow.engine.bamboo.scene.mongodb.sub_task.mongos_install import mongos_install +from backend.flow.engine.bamboo.scene.mongodb.sub_task.replicaset_install import replicaset_install +from backend.flow.plugins.components.collections.common.install_nodeman_plugin import ( + InstallNodemanPluginServiceComponent, +) from backend.flow.plugins.components.collections.mongodb.add_domain_to_dns import ExecAddDomainToDnsOperationComponent from backend.flow.plugins.components.collections.mongodb.add_relationship_to_meta import ( ExecAddRelationshipOperationComponent, @@ -33,6 +37,21 @@ logger = logging.getLogger("flow") +def install_plugin(pipeline: Builder, get_kwargs: ActKwargs, new_cluster: bool): + """安装蓝鲸插件""" + + acts_list = [] + for plugin_name in DEPENDENCIES_PLUGINS: + acts_list.append( + { + "act_name": _("安装[{}]插件".format(plugin_name)), + "act_component_code": InstallNodemanPluginServiceComponent.code, + "kwargs": get_kwargs.get_install_plugin_kwargs(plugin_name=plugin_name, new_cluster=new_cluster), + } + ) + pipeline.add_parallel_acts(acts_list=acts_list) + + class MongoDBInstallFlow(object): """MongoDB安装flow""" @@ -57,6 +76,9 @@ def prepare_job(self, pipeline: Builder): 准备工作 """ + # 安装蓝鲸插件 + install_plugin(pipeline=pipeline, get_kwargs=self.get_kwargs, new_cluster=True) + # 介质下发——job的api可以多个IP并行执行 kwargs = self.get_kwargs.get_send_media_kwargs(media_type="all") pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_instance_restart.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_instance_restart.py index 4077785985..abed621b7a 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_instance_restart.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_instance_restart.py @@ -12,7 +12,7 @@ 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 instance_restart +from backend.flow.engine.bamboo.scene.mongodb.sub_task.instance_restart import instance_restart from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_replace.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_replace.py index fdfb248118..46fef04929 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_replace.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_replace.py @@ -13,7 +13,8 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.engine.bamboo.scene.common.builder import Builder -from backend.flow.engine.bamboo.scene.mongodb.sub_task import cluster_replace, replicaset_replace +from backend.flow.engine.bamboo.scene.mongodb.sub_task.cluster_replace import cluster_replace +from backend.flow.engine.bamboo.scene.mongodb.sub_task.replicaset_replace import replicaset_replace from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_node.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_node.py index 35e9f9e221..b5e3c50e3c 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_node.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_node.py @@ -13,12 +13,10 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.engine.bamboo.scene.common.builder import Builder -from backend.flow.engine.bamboo.scene.mongodb.sub_task import ( - cluster_increase_node, - cluster_reduce_node, - replicaset_reduce_node, - replicaset_set_increase_node, -) +from backend.flow.engine.bamboo.scene.mongodb.sub_task.cluster_increase_node import cluster_increase_node +from backend.flow.engine.bamboo.scene.mongodb.sub_task.cluster_reduce_node import cluster_reduce_node +from backend.flow.engine.bamboo.scene.mongodb.sub_task.replicaset_reduce_node import replicaset_reduce_node +from backend.flow.engine.bamboo.scene.mongodb.sub_task.replicaset_set_increase_node import replicaset_set_increase_node from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py index 19ddf3e621..c4d99ab8c7 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_scale_storage.py @@ -13,7 +13,8 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.engine.bamboo.scene.common.builder import Builder -from backend.flow.engine.bamboo.scene.mongodb.sub_task import cluster_scale, replicaset_scale +from backend.flow.engine.bamboo.scene.mongodb.sub_task.cluster_scale import cluster_scale +from backend.flow.engine.bamboo.scene.mongodb.sub_task.replicaset_scale import replicaset_scale from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_user.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_user.py index f49f52ae76..72539535d2 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_user.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_user.py @@ -12,7 +12,7 @@ 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 user +from backend.flow.engine.bamboo.scene.mongodb.sub_task.user import user from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_increase_node.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_increase_node.py index af78e8b699..a41cb3308d 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_increase_node.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_increase_node.py @@ -16,6 +16,7 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs @@ -46,6 +47,9 @@ def cluster_increase_node(root_id: str, ticket_data: Optional[Dict], sub_kwargs: # 获取主机信息 sub_get_kwargs.get_host_increase_node(info=info) + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py index 2ac4347acf..7162bc65bb 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_replace.py @@ -17,6 +17,7 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.consts import MongoDBClusterRole, MongoDBInstanceType from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.mongodb_cmr_4_meta import CMRMongoDBMetaComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent @@ -54,6 +55,9 @@ def cluster_replace(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw if info["mongo_config"]: sub_get_kwargs.get_mongos_host_replace() + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py index 1af28f6dd6..f60df574b5 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/cluster_scale.py @@ -17,6 +17,7 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.consts import MongoDBClusterRole from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs @@ -42,6 +43,9 @@ def cluster_scale(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKwar # 获取信息 sub_get_kwargs.get_host_scale(mongodb_type=ClusterType.MongoShardedCluster.value, info=info) + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py index a1a84b7460..3caee476e1 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/increase_mongos.py @@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _ from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin 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 @@ -42,6 +43,9 @@ def increase_mongos(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw # 获取机器 sub_get_kwargs.get_host_scale_mongos(info=info, increase=True) + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py index e568a2c1bc..f046f073df 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_replace.py @@ -17,6 +17,7 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.consts import MongoDBClusterRole from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.mongodb_cmr_4_meta import CMRMongoDBMetaComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent @@ -43,6 +44,9 @@ def replicaset_replace( # 获取信息 sub_get_kwargs.get_host_replace(mongodb_type=ClusterType.MongoReplicaSet.value, info=info) + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py index eabf734c71..063345b678 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_scale.py @@ -17,6 +17,7 @@ from backend.db_meta.enums.cluster_type import ClusterType from backend.flow.consts import MongoDBClusterRole from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs @@ -45,6 +46,9 @@ def replicaset_scale( # 获取主机信息 sub_get_kwargs.get_host_scale(mongodb_type=ClusterType.MongoReplicaSet.value, info=info) + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_set_increase_node.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_set_increase_node.py index 2f7fca4756..04e5b750fd 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_set_increase_node.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/replicaset_set_increase_node.py @@ -15,6 +15,7 @@ from django.utils.translation import ugettext as _ from backend.flow.engine.bamboo.scene.common.builder import SubBuilder +from backend.flow.engine.bamboo.scene.mongodb.mongodb_install import install_plugin from backend.flow.plugins.components.collections.mongodb.exec_actuator_job import ExecuteDBActuatorJobComponent from backend.flow.plugins.components.collections.mongodb.send_media import ExecSendMediaOperationComponent from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs @@ -46,6 +47,9 @@ def replicaset_set_increase_node( # 获取主机信息 sub_get_kwargs.get_host_increase_node(info=info) + # 安装蓝鲸插件 + install_plugin(pipeline=sub_pipeline, get_kwargs=sub_get_kwargs, new_cluster=False) + # 介质下发 kwargs = sub_get_kwargs.get_send_media_kwargs(media_type="all") sub_pipeline.add_act( diff --git a/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py b/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py index 0e25c87651..9dab9e8926 100644 --- a/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py +++ b/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py @@ -28,6 +28,7 @@ DEFAULT_DB_MODULE_ID, ConfigFileEnum, ConfigTypeEnum, + MediumEnum, MongoDBActuatorActionEnum, MongoDBDfaultAuthDB, MongoDBInstanceType, @@ -258,7 +259,7 @@ def get_backup_dir(self): def get_pkg(self): self.pkg = Package.get_latest_package( - version=self.payload["db_version"], pkg_type=self.db_release, db_type=DBType.MongoDB + version=self.db_release_version, pkg_type=MediumEnum.MongoDB, db_type=DBType.MongoDB ) @staticmethod @@ -293,9 +294,7 @@ def get_send_media_kwargs(self, media_type: str) -> dict: if media_type == "actuator": file_list = GetFileList(db_type=DBType.MongoDB).mongodb_actuator_pkg() elif media_type == "all": - file_list = GetFileList(db_type=DBType.MongoDB).mongodb_pkg( - db_version=self.payload["db_version"], release_info=self.db_release - ) + file_list = GetFileList(db_type=DBType.MongoDB).mongodb_pkg(db_version=self.db_release_version) ip_list = self.payload["hosts"] exec_ips = [host["ip"] for host in ip_list] return { @@ -352,6 +351,22 @@ def get_os_init_kwargs(self) -> dict: }, } + def get_install_plugin_kwargs(self, plugin_name: str, new_cluster: bool) -> dict: + """ + 安装蓝鲸插件的kwargs + new_cluster 是否新集群部署 + """ + + if new_cluster: + ips = [host["ip"] for host in self.payload["hosts"]] + else: + ips = [host["ip"] for host in self.payload["plugin_hosts"]] + return { + "plugin_name": plugin_name, + "ips": ips, + "bk_cloud_id": self.payload["hosts"][0]["bk_cloud_id"], + } + def get_install_mongod_kwargs(self, node: dict, cluster_role: str) -> dict: """复制集mongod安装的kwargs""" @@ -1147,11 +1162,13 @@ def get_host_replace(self, mongodb_type: str, info: dict): """替换获取host信息""" hosts = [] + plugin_hosts = [] if mongodb_type == ClusterType.MongoReplicaSet.value: # 源ip hosts.append({"ip": info["ip"], "bk_cloud_id": info["bk_cloud_id"]}) # 目标ip hosts.append({"ip": info["target"]["ip"], "bk_cloud_id": info["target"]["bk_cloud_id"]}) + plugin_hosts.append({"ip": info["target"]["ip"], "bk_cloud_id": info["target"]["bk_cloud_id"]}) # db版本 self.payload["db_version"] = info["instances"][0]["db_version"] @@ -1161,16 +1178,19 @@ def get_host_replace(self, mongodb_type: str, info: dict): hosts.append({"ip": mongos["ip"], "bk_cloud_id": mongos["bk_cloud_id"]}) # 目标ip hosts.append({"ip": mongos["target"]["ip"], "bk_cloud_id": mongos["target"]["bk_cloud_id"]}) + plugin_hosts.append({"ip": mongos["target"]["ip"], "bk_cloud_id": mongos["target"]["bk_cloud_id"]}) for config in info["mongo_config"]: # 源ip hosts.append({"ip": config["ip"], "bk_cloud_id": config["bk_cloud_id"]}) # 目标ip hosts.append({"ip": config["target"]["ip"], "bk_cloud_id": config["target"]["bk_cloud_id"]}) + plugin_hosts.append({"ip": config["target"]["ip"], "bk_cloud_id": config["target"]["bk_cloud_id"]}) for shard in info["mongodb"]: # 源ip hosts.append({"ip": shard["ip"], "bk_cloud_id": shard["bk_cloud_id"]}) # 目标ip hosts.append({"ip": shard["target"]["ip"], "bk_cloud_id": shard["target"]["bk_cloud_id"]}) + plugin_hosts.append({"ip": shard["target"]["ip"], "bk_cloud_id": shard["target"]["bk_cloud_id"]}) # 获取参数 if info["mongos"]: self.payload["db_version"] = info["mongos"][0]["instances"][0]["db_version"] @@ -1180,6 +1200,7 @@ def get_host_replace(self, mongodb_type: str, info: dict): self.payload["db_version"] = info["mongodb"][0]["instances"][0]["db_version"] self.payload["hosts"] = hosts + self.payload["plugin_hosts"] = plugin_hosts def get_mongos_host_replace(self): """替换configDB获取mongos主机""" @@ -1319,6 +1340,7 @@ def get_host_scale_mongos(self, info: dict, increase: bool): if increase: hosts = [{"ip": mongos["ip"], "bk_cloud_id": mongos["bk_cloud_id"]} for mongos in info["mongos"]] + self.payload["plugin_hosts"] = hosts else: hosts = [{"ip": mongos["ip"], "bk_cloud_id": mongos["bk_cloud_id"]} for mongos in info["reduce_nodes"]] self.payload["hosts"] = hosts @@ -1451,6 +1473,7 @@ def get_host_scale(self, mongodb_type: str, info: dict): """容量变更获取host信息""" hosts = [] + plugin_hosts = [] if mongodb_type == ClusterType.MongoReplicaSet.value: for instance_relationship in self.payload["instance_relationships"]: # 源ip @@ -1462,22 +1485,33 @@ def get_host_scale(self, mongodb_type: str, info: dict): "bk_cloud_id": instance_relationship["target"]["bk_cloud_id"], } ) + plugin_hosts.append( + { + "ip": instance_relationship["target"]["ip"], + "bk_cloud_id": instance_relationship["target"]["bk_cloud_id"], + } + ) # db版本 self.payload["db_version"] = self.payload["instance_relationships"][0]["instances"][0]["db_version"] self.db_main_version = self.payload["db_version"].split("-")[1].split(".")[0] elif mongodb_type == ClusterType.MongoShardedCluster.value: hosts_set = set() + plugin_hosts_set = set() bk_cloud_id = info["mongodb"][0][0]["bk_cloud_id"] for shards_instance_relationships in self.payload["shards_instance_relationships"]: for instance_relationship in shards_instance_relationships: hosts_set.add(instance_relationship["ip"]) hosts_set.add(instance_relationship["target"]["ip"]) + plugin_hosts_set.add(instance_relationship["target"]["ip"]) for host in hosts_set: hosts.append({"ip": host, "bk_cloud_id": bk_cloud_id}) + for host in plugin_hosts_set: + plugin_hosts.append({"ip": host, "bk_cloud_id": bk_cloud_id}) self.payload["db_version"] = info["db_version"] self.db_main_version = self.payload["db_version"].split("-")[1].split(".")[0] self.payload["hosts"] = hosts + self.payload["plugin_hosts"] = plugin_hosts def get_scale_change_meta(self, info: dict, instance: dict) -> dict: """容量变更修改meta""" @@ -1511,6 +1545,7 @@ def get_host_increase_node(self, info: dict): self.payload["db_version"] = info["db_version"] self.db_main_version = self.payload["db_version"].split("-")[1].split(".")[0] self.payload["hosts"] = hosts + self.payload["plugin_hosts"] = hosts def calc_increase_node(self, info: dict): """增加节点计算cluster对应关系"""