Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redis): redis 主从启停和下架 #4223 #4702

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions dbm-ui/backend/db_meta/api/cluster/nosqlcomm/decommission.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ def decommission_cluster(cluster: Cluster):
logger.info("user request decmmission cluster {}".format(cluster.immute_domain))

try:
if cluster.cluster_type not in (ClusterType.MongoReplicaSet.value):
if cluster.cluster_type not in (ClusterType.TendisRedisInstance.value):
proxies = [
{"ip": proxy_obj.machine.ip, "port": proxy_obj.port} for proxy_obj in cluster.proxyinstance_set.all()
]
decommission_proxies(cluster, proxies, True)

machines = set([storage_obj.machine.ip for storage_obj in cluster.storageinstance_set.all()])
storages = [
{"ip": storage_obj.machine.ip, "port": storage_obj.port}
for storage_obj in cluster.storageinstance_set.all()
Expand All @@ -162,7 +163,15 @@ def decommission_cluster(cluster: Cluster):

logger.info("cluster {}".format(cluster.__dict__))
db_type = ClusterType.cluster_type_to_db_type(cluster.cluster_type)
CcManage(cluster.bk_biz_id, cluster.cluster_type).delete_cluster_modules(db_type=db_type, cluster=cluster)
# 主从实例下架,需要检查机器上是否还有其他实例,如果有,则不允许挪模块
move_cc_flag = True
for machine_ip in machines:
if StorageInstance.objects.filter(machine__ip=machine_ip).exists():
logger.info("ignore move cc. {} have other ins".format(machine_ip))
move_cc_flag = False
break
if move_cc_flag:
CcManage(cluster.bk_biz_id, cluster.cluster_type).delete_cluster_modules(db_type=db_type, cluster=cluster)
cluster.delete()

except Exception as e:
Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"info",
"PSYNC",
"twemproxy_mon",
"readonly",
]

# twemproxy seg总数
Expand Down Expand Up @@ -414,6 +415,7 @@ class RedisActuatorActionEnum(str, StructuredEnum):
Close = EnumField("close", _("close"))
Operate = EnumField("operate", _("operate"))
Capturer = EnumField("capturer", _("capturer"))
ChangePwd = EnumField("change_password", _("change_password"))
KillConn = EnumField("kill_conn", _("kill_conn"))
SyncParam = EnumField("param_sync", _("param_sync"))
CheckSync = EnumField("sync_check", _("sync_check"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,4 @@ def AccessManagerAtomJob(root_id, ticket_data, act_kwargs: ActKwargs, param: Dic

sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data)
sub_pipeline.add_parallel_sub_pipeline(sub_flow_list=sub_builder_list)
return sub_pipeline.build_sub_process(sub_name=_("dns/clb 接入层子任务"))
return sub_pipeline.build_sub_process(sub_name=_("{}-{}-dns/clb 接入层子任务".format(cluster_id, param["op_type"])))
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- 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 dataclasses import asdict
from typing import Dict

from django.utils.translation import ugettext as _

from backend.flow.engine.bamboo.scene.common.builder import SubBuilder
from backend.flow.plugins.components.collections.redis.exec_actuator_script import ExecuteDBActuatorScriptComponent
from backend.flow.plugins.components.collections.redis.redis_config import RedisConfigComponent
from backend.flow.utils.redis.redis_act_playload import RedisActPayload
from backend.flow.utils.redis.redis_context_dataclass import ActKwargs

logger = logging.getLogger("flow")


def RedisChangePwdAtomJob(root_id, ticket_data, act_kwargs: ActKwargs, param: Dict) -> SubBuilder:
"""
修改redis密码原子任务
Args:
param (Dict): {
"change_ins":[{"ip":xx,"role":"xx"}]
"port": 30000,
"old_pwd": "",
"new_pwd": "",

"domain_name": "",
}
"""
domain_name = param["domain_name"]
change_ins = param["change_ins"]
port = param["port"]
old_pwd = param["old_pwd"]
new_pwd = param["new_pwd"]
change_sub_pipeline = SubBuilder(root_id=root_id, data=ticket_data)

# 修改配置中心密码
# 只有master的时候,才去修改配置中心密码
act_kwargs.cluster = {
"pwd_conf": {
"proxy_pwd": new_pwd,
"proxy_admin_pwd": new_pwd,
"redis_pwd": new_pwd,
},
"domain_name": domain_name,
}
act_kwargs.get_redis_payload_func = RedisActPayload.update_cluster_password.__name__
change_sub_pipeline.add_act(
act_name=_("修改{}配置中心密码").format(domain_name),
act_component_code=RedisConfigComponent.code,
kwargs=asdict(act_kwargs),
)

# 如果是主从,修改的是master和slave的密码
# 如果是集群,修改的是proxy的密码
change_ins_param = [{"port": port, "old_password": old_pwd, "new_password": new_pwd}]
acts_list = []
for change_ins in change_ins:
act_kwargs.exec_ip = change_ins["ip"]
act_kwargs.cluster["role"] = change_ins["role"]
act_kwargs.cluster["ins_param"] = change_ins_param
act_kwargs.get_redis_payload_func = RedisActPayload.change_pwd.__name__
acts_list.append(
{
"act_name": _("修改实例密码: {}:{}").format(change_ins["ip"], port),
"act_component_code": ExecuteDBActuatorScriptComponent.code,
"kwargs": asdict(act_kwargs),
}
)
change_sub_pipeline.add_parallel_acts(acts_list)
return change_sub_pipeline.build_sub_process(sub_name=_("redis集群修改密码子任务"))

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def redis_cluster_shutdown_flow(self):
# 卸载dbmon前置
acts_list = []
for ip in proxy_ips + redis_ips:
act_kwargs.exec_ip = ip
act_kwargs.cluster = {
"servers": [
{
Expand Down
Loading
Loading