From ed3902a4a4512854004f27e166f0c68954691781 Mon Sep 17 00:00:00 2001 From: yyhenryyy Date: Wed, 28 Feb 2024 16:30:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(mongodb):=20=E6=8B=B7=E8=B4=9Ddbactuator?= =?UTF-8?q?=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20#3395?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/cluster/tendbsingle/decommission.py | 2 +- dbm-ui/backend/db_monitor/views/policy.py | 1 - .../mysql/permission/authorize/views.py | 2 +- .../mysql/permission/db_account/views.py | 2 +- .../bamboo/scene/mongodb/mongodb_deinstall.py | 7 +++++++ .../bamboo/scene/mongodb/mongodb_install.py | 6 ++++++ .../scene/mongodb/sub_task/cluster_replace.py | 6 ++++++ .../bamboo/scene/mongodb/sub_task/exec_script.py | 6 ++++++ .../scene/mongodb/sub_task/instance_restart.py | 6 ++++++ .../scene/mongodb/sub_task/replicaset_replace.py | 7 +++++++ .../engine/bamboo/scene/mongodb/sub_task/user.py | 6 ++++++ dbm-ui/backend/flow/engine/controller/redis.py | 2 +- .../collections/mongodb/exec_actuator_job.py | 3 +++ .../flow/utils/mongodb/mongodb_dataclass.py | 15 +++++++++++++++ .../flow/utils/mongodb/mongodb_script_template.py | 8 +++++--- .../flow/utils/sqlserver/payload_handler.py | 3 +-- dbm-ui/backend/iam_app/dataclass/resources.py | 2 +- dbm-ui/backend/iam_app/handlers/signal.py | 3 ++- 18 files changed, 75 insertions(+), 12 deletions(-) diff --git a/dbm-ui/backend/db_meta/api/cluster/tendbsingle/decommission.py b/dbm-ui/backend/db_meta/api/cluster/tendbsingle/decommission.py index e5cdb1d617..39d964b997 100644 --- a/dbm-ui/backend/db_meta/api/cluster/tendbsingle/decommission.py +++ b/dbm-ui/backend/db_meta/api/cluster/tendbsingle/decommission.py @@ -12,8 +12,8 @@ from django.db import transaction -from backend.configuration.constants import DBType from backend.components import DBPrivManagerApi +from backend.configuration.constants import DBType from backend.db_meta.models import Cluster, ClusterEntry from backend.flow.consts import MySQLPrivComponent, UserName from backend.flow.utils.cc_manage import CcManage diff --git a/dbm-ui/backend/db_monitor/views/policy.py b/dbm-ui/backend/db_monitor/views/policy.py index 53180cbe93..b3af590cd7 100644 --- a/dbm-ui/backend/db_monitor/views/policy.py +++ b/dbm-ui/backend/db_monitor/views/policy.py @@ -21,7 +21,6 @@ from backend.bk_web.swagger import common_swagger_auto_schema from backend.bk_web.viewsets import AuditedModelViewSet - from backend.db_monitor import serializers from ...configuration.constants import PLAT_BIZ_ID, DBType diff --git a/dbm-ui/backend/db_services/mysql/permission/authorize/views.py b/dbm-ui/backend/db_services/mysql/permission/authorize/views.py index 1d40724b89..1df6b9b576 100644 --- a/dbm-ui/backend/db_services/mysql/permission/authorize/views.py +++ b/dbm-ui/backend/db_services/mysql/permission/authorize/views.py @@ -18,9 +18,9 @@ MySQLAuthorizeMeta, MySQLExcelAuthorizeMeta, ) -from backend.iam_app.handlers.drf_perm.base import DBManagePermission from backend.db_services.mysql.permission.authorize.handlers import MySQLAuthorizeHandler from backend.db_services.mysql.permission.authorize.serializers import GetHostInAuthorizeSerializer +from backend.iam_app.handlers.drf_perm.base import DBManagePermission SWAGGER_TAG = "db_services/permission/authorize" diff --git a/dbm-ui/backend/db_services/mysql/permission/db_account/views.py b/dbm-ui/backend/db_services/mysql/permission/db_account/views.py index 7e5680c2fa..fec7a8f936 100644 --- a/dbm-ui/backend/db_services/mysql/permission/db_account/views.py +++ b/dbm-ui/backend/db_services/mysql/permission/db_account/views.py @@ -9,10 +9,10 @@ specific language governing permissions and limitations under the License. """ from backend.db_services.dbpermission.constants import AccountType +from backend.db_services.dbpermission.db_account.views import BaseDBAccountViewSet from backend.iam_app.dataclass.actions import ActionEnum from backend.iam_app.dataclass.resources import ResourceEnum from backend.iam_app.handlers.drf_perm.base import DBManagePermission, ResourceActionPermission -from backend.db_services.dbpermission.db_account.views import BaseDBAccountViewSet class DBAccountViewSet(BaseDBAccountViewSet): 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 87f3960c83..5775c001ba 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 @@ -15,6 +15,7 @@ from backend.flow.engine.bamboo.scene.common.builder import Builder from backend.flow.engine.bamboo.scene.mongodb.sub_task 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 @@ -48,6 +49,12 @@ def prepare_job(self, pipeline: Builder): act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs ) + # 创建原子任务执行目录 + kwargs = self.get_kwargs.get_create_dir_kwargs() + pipeline.add_act( + act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + def multi_cluster_deinstall_flow(self): """ multi cluster deinstall流程 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 76bca5a388..e72de146c6 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 @@ -61,6 +61,12 @@ def prepare_job(self, pipeline: Builder): act_name=_("MongoDB-介质下发"), act_component_code=ExecSendMediaOperationComponent.code, kwargs=kwargs ) + # 创建原子任务执行目录 + kwargs = self.get_kwargs.get_create_dir_kwargs() + pipeline.add_act( + act_name=_("MongoDB-创建原子任务执行目录"), act_component_code=ExecuteDBActuatorJobComponent.code, kwargs=kwargs + ) + # 机器初始化——job的api可以多个IP并行执行 kwargs = self.get_kwargs.get_os_init_kwargs() 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 f8d104badb..201b8d2961 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 @@ -60,6 +60,12 @@ def cluster_replace(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKw 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 + ) + # 进行shard和config替换——并行 sub_sub_pipelines = [] # 替换config 以ip为维度 diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/exec_script.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/exec_script.py index 0cfe04d2a9..c64d0b0a24 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/exec_script.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/exec_script.py @@ -42,6 +42,12 @@ def exec_script(root_id: str, ticket_data: Optional[Dict], sub_kwargs: ActKwargs 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 + ) + # 执行脚本 for script in sub_get_kwargs.payload["script_contents"]: kwargs = sub_get_kwargs.get_exec_script_kwargs(cluster_id=cluster_id, admin_user=admin_user, script=script) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/instance_restart.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/instance_restart.py index 6ebcb630e5..67bd93e6ce 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/instance_restart.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/instance_restart.py @@ -42,6 +42,12 @@ def instance_restart( 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 + ) + # 重启实例 for instance in instances_info["instances"]: kwargs = sub_get_kwargs.get_instance_restart_kwargs( 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 a69e631ad0..60379df9ed 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.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 from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs @@ -48,6 +49,12 @@ def replicaset_replace( 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.calc_param_replace(info=info) # 进行替换——并行 以ip为维度 diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/user.py b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/user.py index 47d91f910c..3f1e7561fd 100644 --- a/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/user.py +++ b/dbm-ui/backend/flow/engine/bamboo/scene/mongodb/sub_task/user.py @@ -43,6 +43,12 @@ def user( 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 + ) + # 创建或删除用户 kwargs = sub_get_kwargs.get_user_kwargs(create=create, admin_user=MongoDBManagerUser.DbaUser.value, info=info) if create: diff --git a/dbm-ui/backend/flow/engine/controller/redis.py b/dbm-ui/backend/flow/engine/controller/redis.py index 5bf5b2ac95..507e34155d 100644 --- a/dbm-ui/backend/flow/engine/controller/redis.py +++ b/dbm-ui/backend/flow/engine/controller/redis.py @@ -33,10 +33,10 @@ from backend.flow.engine.bamboo.scene.redis.redis_instance_apply_flow import RedisInstanceApplyFlow from backend.flow.engine.bamboo.scene.redis.redis_keys_delete import RedisKeysDeleteFlow from backend.flow.engine.bamboo.scene.redis.redis_keys_extract import RedisKeysExtractFlow +from backend.flow.engine.bamboo.scene.redis.redis_predixy_cluster_apply_flow import TendisPlusApplyFlow from backend.flow.engine.bamboo.scene.redis.redis_predixy_config_servers_rewrite import ( RedisPredixyConfigServersRewriteFlow, ) -from backend.flow.engine.bamboo.scene.redis.redis_predixy_cluster_apply_flow import TendisPlusApplyFlow from backend.flow.engine.bamboo.scene.redis.redis_proxy_scale import RedisProxyScaleFlow from backend.flow.engine.bamboo.scene.redis.redis_remove_dts_server import RedisRemoveDtsServerFlow from backend.flow.engine.bamboo.scene.redis.redis_reupload_old_backup_records import RedisReuploadOldBackupRecordsFlow diff --git a/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py b/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py index 86f90fa500..72ea04e8ae 100644 --- a/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py +++ b/dbm-ui/backend/flow/plugins/components/collections/mongodb/exec_actuator_job.py @@ -28,6 +28,7 @@ from backend.flow.utils.mongodb.mongodb_dataclass import ActKwargs from backend.flow.utils.mongodb.mongodb_script_template import ( mongodb_actuator_template, + mongodb_create_actuator_dir_template, mongodb_fast_execute_script_common_kwargs, mongodb_os_init_actuator_template, ) @@ -170,6 +171,8 @@ def _execute(self, data, parent_data) -> bool: template = jinja_env.from_string(mongodb_actuator_template) if kwargs.get("init_flag", False): template = jinja_env.from_string(mongodb_os_init_actuator_template) + elif kwargs.get("create_dir", False): + template = jinja_env.from_string(mongodb_create_actuator_dir_template) body = { "bk_biz_id": env.JOB_BLUEKING_BIZ_ID, "task_name": f"DBM_{node_name}_{node_id}", diff --git a/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py b/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py index f920fadf50..729e1b2bf7 100644 --- a/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py +++ b/dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py @@ -226,6 +226,21 @@ def get_send_media_kwargs(self) -> dict: "file_target_path": self.file_path + "/install", } + def get_create_dir_kwargs(self) -> dict: + """创建dbactuator执行目录的kwargs""" + + return { + "create_dir": True, + "set_trans_data_dataclass": CommonContext.__name__, + "get_trans_data_ip_var": None, + "bk_cloud_id": self.payload["hosts"][0]["bk_cloud_id"], + "exec_ip": self.payload["hosts"], + "db_act_template": { + "file_path": self.file_path, + "payload": {}, + }, + } + def get_os_init_kwargs(self) -> dict: """os初始化的kwargs""" diff --git a/dbm-ui/backend/flow/utils/mongodb/mongodb_script_template.py b/dbm-ui/backend/flow/utils/mongodb/mongodb_script_template.py index 73d97c9e5b..ce8e539c1d 100644 --- a/dbm-ui/backend/flow/utils/mongodb/mongodb_script_template.py +++ b/dbm-ui/backend/flow/utils/mongodb/mongodb_script_template.py @@ -17,9 +17,13 @@ } -mongodb_actuator_template = """ +mongodb_create_actuator_dir_template = """ mkdir -p {{file_path}}/install/dbactuator-{{uid}}/logs cp {{file_path}}/install/mongo-dbactuator {{file_path}}/install/dbactuator-{{uid}} +""" + + +mongodb_actuator_template = """ cd {{file_path}}/install/dbactuator-{{uid}} chmod +x mongo-dbactuator ./mongo-dbactuator --uid {{uid}} --root_id {{root_id}} --node_id {{node_id}} \ @@ -29,8 +33,6 @@ mongodb_script_template = {"mongodb_actuator_template": mongodb_actuator_template} mongodb_os_init_actuator_template = """ -mkdir -p {{file_path}}/install/dbactuator-{{uid}}/logs -cp {{file_path}}/install/mongo-dbactuator {{file_path}}/install/dbactuator-{{uid}} cd {{file_path}}/install/dbactuator-{{uid}} chmod +x mongo-dbactuator ./mongo-dbactuator --uid {{uid}} --root_id {{root_id}} --node_id {{node_id}} \ diff --git a/dbm-ui/backend/flow/utils/sqlserver/payload_handler.py b/dbm-ui/backend/flow/utils/sqlserver/payload_handler.py index 8edebda848..1a01ea6ac1 100644 --- a/dbm-ui/backend/flow/utils/sqlserver/payload_handler.py +++ b/dbm-ui/backend/flow/utils/sqlserver/payload_handler.py @@ -12,9 +12,8 @@ from django.utils.crypto import get_random_string -from backend.flow.consts import MSSQL_ADMIN, MSSQL_EXPORTER from backend.components import DBPrivManagerApi -from backend.flow.consts import DEFAULT_INSTANCE, SqlserverComponent, SqlserverUserName +from backend.flow.consts import DEFAULT_INSTANCE, MSSQL_ADMIN, MSSQL_EXPORTER, SqlserverComponent, SqlserverUserName logger = logging.getLogger("flow") diff --git a/dbm-ui/backend/iam_app/dataclass/resources.py b/dbm-ui/backend/iam_app/dataclass/resources.py index 75afef6534..172451311f 100644 --- a/dbm-ui/backend/iam_app/dataclass/resources.py +++ b/dbm-ui/backend/iam_app/dataclass/resources.py @@ -455,7 +455,7 @@ def cluster_type_to_resource_meta(cls, cluster_type): return cls.MYSQL if cluster_type in ClusterType.redis_cluster_types(): return cls.REDIS - return getattr(cls, cluster_type.upper()) + return getattr(cls, cluster_type.upper(), None) @classmethod def instance_type_to_resource_meta(cls, instance_role): diff --git a/dbm-ui/backend/iam_app/handlers/signal.py b/dbm-ui/backend/iam_app/handlers/signal.py index f6e4c4e5e8..411dc4a17d 100644 --- a/dbm-ui/backend/iam_app/handlers/signal.py +++ b/dbm-ui/backend/iam_app/handlers/signal.py @@ -14,6 +14,7 @@ from django.db.models.signals import post_save from django.dispatch import receiver +from backend import env from backend.db_meta.enums import MachineType from backend.db_meta.models import Cluster, StorageInstance from backend.db_monitor.models import DutyRule, MonitorPolicy @@ -28,7 +29,7 @@ def post_save_grant_iam(resource_meta, model, instance, creator, created): - if not created or not creator: + if not created or not creator or env.BK_IAM_SKIP: return resource = resource_meta.create_instance(getattr(instance, resource_meta.lookup_field))