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

fix(backend): 调整es缩容校验逻辑 #3674 #3676

Merged
merged 1 commit into from
Mar 25, 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
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def add_account_rule(self, account_rule: AccountRuleMeta) -> Optional[Any]:
resp = MySQLPrivManagerApi.add_account_rule(
{
"bk_biz_id": self.bk_biz_id,
"creator": self.operator,
"operator": self.operator,
"cluster_type": self.account_type,
"account_id": account_rule.account_id,
"priv": account_rule.privilege,
Expand Down
27 changes: 13 additions & 14 deletions dbm-ui/backend/ticket/builders/es/es_shrink.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@ def validate(self, attrs):

cluster = Cluster.objects.get(id=attrs["cluster_id"])

all_shrink_hosts = []
all_exist_hosts = []
# 暂时只需要校验hot节点至少保留一台,cold和client不校验
for role in [InstanceRole.ES_DATANODE_HOT]:
shrink_hosts = {host["bk_host_id"] for host in role_hash[role]}
exist_hosts = set(
cluster.storageinstance_set.filter(instance_role=role).values_list("machine__bk_host_id", flat=True)
)

all_shrink_hosts.extend(shrink_hosts)
all_exist_hosts.extend(exist_hosts)

if not (exist_hosts - shrink_hosts):
raise serializers.ValidationError(_("{}: 至少保留1台!").format(role.name))
# 暂时只需要校验hot+cold节点至少保留一台,client不校验
backend_es_role = [InstanceRole.ES_DATANODE_HOT, InstanceRole.ES_DATANODE_COLD]
shrink_backend_hosts = {host["bk_host_id"] for role in backend_es_role for host in role_hash[role]}
exist_storages = cluster.storageinstance_set.filter(instance_role__in=backend_es_role)
exist_backend_hosts = set(exist_storages.values_list("machine__bk_host_id", flat=True))

if not (exist_backend_hosts - shrink_backend_hosts):
raise serializers.ValidationError(_("热节点和冷节点至少保留1台!"))

# 不允许缩容master节点
all_shrink_hosts = {host["bk_host_id"] for role in role_hash for host in role_hash[role]}
all_exist_storages = cluster.storageinstance_set.exclude(instance_role=InstanceRole.ES_MASTER)
all_exist_hosts = all_exist_storages.values_list("machine__bk_host_id", flat=True)

if not set(all_exist_hosts).issuperset(set(all_shrink_hosts)):
raise serializers.ValidationError(_("缩容仅支持hot、cold和client"))
Expand Down
Loading