Skip to content

Commit

Permalink
feat(es): 大数据清理机器的flow TencentBlueKing#8012
Browse files Browse the repository at this point in the history
  • Loading branch information
zvictorino authored and iSecloud committed Nov 27, 2024
1 parent ab5ea45 commit 4c14cd2
Show file tree
Hide file tree
Showing 38 changed files with 1,175 additions and 7 deletions.
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/api/cluster/doris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from .clear_machine import clear_machine
from .create import create
from .destroy import destroy
from .disable import disable
Expand Down
47 changes: 47 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/doris/clear_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- 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.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from backend.db_meta.models.instance import ProxyInstance, StorageInstance
from backend.db_meta.models.machine import Machine

logger = logging.getLogger("root")


@transaction.atomic
def clear_machine(machines: Optional[List]):
"""
根据machine信息回收机器相关信息for大数据
"""
for m in machines:
try:
machine = Machine.objects.get(ip=m["ip"], bk_cloud_id=m["bk_cloud_id"])
except ObjectDoesNotExist:
logger.warning(f"the machine [{m['bk_cloud_id']}:{m['ip']}] not exist ")
continue

proxys = ProxyInstance.objects.filter(machine=machine)
storages = StorageInstance.objects.filter(machine=machine)

# 清理proxy相关信息
for p in proxys:
p.delete(keep_parents=True)

# 清理storage相关信息
for s in storages:
s.delete(keep_parents=True)

machine.delete(keep_parents=True)
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/api/cluster/es/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from .clear_machine import clear_machine
from .create import create
from .destroy import destroy
from .disable import disable
Expand Down
47 changes: 47 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/es/clear_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- 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.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from backend.db_meta.models.instance import ProxyInstance, StorageInstance
from backend.db_meta.models.machine import Machine

logger = logging.getLogger("root")


@transaction.atomic
def clear_machine(machines: Optional[List]):
"""
根据machine信息回收机器相关信息for大数据
"""
for m in machines:
try:
machine = Machine.objects.get(ip=m["ip"], bk_cloud_id=m["bk_cloud_id"])
except ObjectDoesNotExist:
logger.warning(f"the machine [{m['bk_cloud_id']}:{m['ip']}] not exist ")
continue

proxys = ProxyInstance.objects.filter(machine=machine)
storages = StorageInstance.objects.filter(machine=machine)

# 清理proxy相关信息
for p in proxys:
p.delete(keep_parents=True)

# 清理storage相关信息
for s in storages:
s.delete(keep_parents=True)

machine.delete(keep_parents=True)
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/api/cluster/hdfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from .clear_machine import clear_machine
from .create import create
from .destroy import destroy
from .disable import disable
Expand Down
47 changes: 47 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/hdfs/clear_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- 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.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from backend.db_meta.models.instance import ProxyInstance, StorageInstance
from backend.db_meta.models.machine import Machine

logger = logging.getLogger("root")


@transaction.atomic
def clear_machine(machines: Optional[List]):
"""
根据machine信息回收机器相关信息for大数据
"""
for m in machines:
try:
machine = Machine.objects.get(ip=m["ip"], bk_cloud_id=m["bk_cloud_id"])
except ObjectDoesNotExist:
logger.warning(f"the machine [{m['bk_cloud_id']}:{m['ip']}] not exist ")
continue

proxys = ProxyInstance.objects.filter(machine=machine)
storages = StorageInstance.objects.filter(machine=machine)

# 清理proxy相关信息
for p in proxys:
p.delete(keep_parents=True)

# 清理storage相关信息
for s in storages:
s.delete(keep_parents=True)

machine.delete(keep_parents=True)
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/api/cluster/kafka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from .clear_machine import clear_machine
from .create import create
from .destroy import destroy
from .disable import disable
Expand Down
47 changes: 47 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/kafka/clear_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- 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.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from backend.db_meta.models.instance import ProxyInstance, StorageInstance
from backend.db_meta.models.machine import Machine

logger = logging.getLogger("root")


@transaction.atomic
def clear_machine(machines: Optional[List]):
"""
根据machine信息回收机器相关信息for大数据
"""
for m in machines:
try:
machine = Machine.objects.get(ip=m["ip"], bk_cloud_id=m["bk_cloud_id"])
except ObjectDoesNotExist:
logger.warning(f"the machine [{m['bk_cloud_id']}:{m['ip']}] not exist ")
continue

proxys = ProxyInstance.objects.filter(machine=machine)
storages = StorageInstance.objects.filter(machine=machine)

# 清理proxy相关信息
for p in proxys:
p.delete(keep_parents=True)

# 清理storage相关信息
for s in storages:
s.delete(keep_parents=True)

machine.delete(keep_parents=True)
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/api/cluster/pulsar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from .clear_machine import clear_machine
from .create import create
from .destroy import destroy
from .disable import disable
Expand Down
47 changes: 47 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/pulsar/clear_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- 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.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from backend.db_meta.models.instance import ProxyInstance, StorageInstance
from backend.db_meta.models.machine import Machine

logger = logging.getLogger("root")


@transaction.atomic
def clear_machine(machines: Optional[List]):
"""
根据machine信息回收机器相关信息for大数据
"""
for m in machines:
try:
machine = Machine.objects.get(ip=m["ip"], bk_cloud_id=m["bk_cloud_id"])
except ObjectDoesNotExist:
logger.warning(f"the machine [{m['bk_cloud_id']}:{m['ip']}] not exist ")
continue

proxys = ProxyInstance.objects.filter(machine=machine)
storages = StorageInstance.objects.filter(machine=machine)

# 清理proxy相关信息
for p in proxys:
p.delete(keep_parents=True)

# 清理storage相关信息
for s in storages:
s.delete(keep_parents=True)

machine.delete(keep_parents=True)
1 change: 1 addition & 0 deletions dbm-ui/backend/db_meta/api/cluster/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""
from .clear_machine import clear_machine
from .create import create
from .destroy import destroy
from .disable import disable
Expand Down
47 changes: 47 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/vm/clear_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- 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.core.exceptions import ObjectDoesNotExist
from django.db import transaction

from backend.db_meta.models.instance import ProxyInstance, StorageInstance
from backend.db_meta.models.machine import Machine

logger = logging.getLogger("root")


@transaction.atomic
def clear_machine(machines: Optional[List]):
"""
根据machine信息回收机器相关信息for大数据
"""
for m in machines:
try:
machine = Machine.objects.get(ip=m["ip"], bk_cloud_id=m["bk_cloud_id"])
except ObjectDoesNotExist:
logger.warning(f"the machine [{m['bk_cloud_id']}:{m['ip']}] not exist ")
continue

proxys = ProxyInstance.objects.filter(machine=machine)
storages = StorageInstance.objects.filter(machine=machine)

# 清理proxy相关信息
for p in proxys:
p.delete(keep_parents=True)

# 清理storage相关信息
for s in storages:
s.delete(keep_parents=True)

machine.delete(keep_parents=True)
Loading

0 comments on commit 4c14cd2

Please sign in to comment.