forked from TencentBlueKing/blueking-dbm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: doris缩容替换flow TencentBlueKing#3991
- Loading branch information
Showing
19 changed files
with
1,038 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- 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 | ||
from typing import List, Optional | ||
|
||
from django.db import transaction | ||
|
||
from backend.db_meta import request_validator | ||
from backend.db_meta.api import common | ||
from backend.db_meta.enums import InstanceRole | ||
from backend.db_meta.models import Cluster, ClusterEntry, StorageInstance | ||
from backend.flow.utils.cc_manage import CcManage | ||
|
||
logger = logging.getLogger("root") | ||
|
||
|
||
@transaction.atomic | ||
def shrink( | ||
cluster_id: int, | ||
storages: Optional[List] = None, | ||
): | ||
""" | ||
缩容清理DBMeta | ||
""" | ||
|
||
cluster = Cluster.objects.get(id=cluster_id) | ||
cluster_entry = ClusterEntry.objects.get(cluster=cluster) | ||
|
||
storages = request_validator.validated_storage_list(storages, allow_empty=False, allow_null=False) | ||
storage_objs = common.filter_out_instance_obj(storages, StorageInstance.objects.all()) | ||
for storage in storage_objs: | ||
storage.delete(keep_parents=True) | ||
if not storage.machine.storageinstance_set.exists(): | ||
# 将机器挪到 待回收 模块 | ||
CcManage(storage.bk_biz_id, cluster.cluster_type).recycle_host([storage.machine.bk_host_id]) | ||
storage.machine.delete(keep_parents=True) | ||
|
||
cluster.storageinstance_set.remove(*storage_objs) | ||
cluster.save() | ||
cluster_entry.storageinstance_set.remove(*storage_objs) | ||
cluster_entry.save() | ||
|
||
# 当集群入口(域名)找不到实例,需要更新 | ||
if not cluster_entry.storageinstance_set.exists(): | ||
observers = cluster.storageinstance_set.filter(instance_role=InstanceRole.DORIS_OBSERVER) | ||
followers = cluster.storageinstance_set.filter(instance_role=InstanceRole.DORIS_FOLLOWER) | ||
|
||
if observers.exists(): | ||
for observer in observers: | ||
cluster_entry.storageinstance_set.add(observer) | ||
elif followers.exists(): | ||
for follower in followers: | ||
cluster_entry.storageinstance_set.add(follower) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.