Skip to content

Commit

Permalink
fix(mongodb): 拷贝dbactuator二进制文件修复 TencentBlueKing#3395
Browse files Browse the repository at this point in the history
  • Loading branch information
yyhenryyy committed Feb 28, 2024
1 parent ac3e0e2 commit ed3902a
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion dbm-ui/backend/db_monitor/views/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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流程
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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为维度
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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.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
Expand Down Expand Up @@ -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为维度
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/flow/engine/controller/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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}",
Expand Down
15 changes: 15 additions & 0 deletions dbm-ui/backend/flow/utils/mongodb/mongodb_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""

Expand Down
8 changes: 5 additions & 3 deletions dbm-ui/backend/flow/utils/mongodb/mongodb_script_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}} \
Expand All @@ -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}} \
Expand Down
3 changes: 1 addition & 2 deletions dbm-ui/backend/flow/utils/sqlserver/payload_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/iam_app/dataclass/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion dbm-ui/backend/iam_app/handlers/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit ed3902a

Please sign in to comment.