Skip to content

Commit

Permalink
fix(mongodb): mongodb安装时修复db版本名称bug,增加蓝鲸插件安装节点 TencentBlueKing#5075
Browse files Browse the repository at this point in the history
  • Loading branch information
yyhenryyy committed Jun 21, 2024
1 parent 903bb5c commit b779965
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

// 执行脚本
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
# )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 24 additions & 2 deletions dbm-ui/backend/flow/engine/bamboo/scene/mongodb/mongodb_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"""

Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading

0 comments on commit b779965

Please sign in to comment.