From 4c14cd24c46df47748a994186e4908a9bc2fad11 Mon Sep 17 00:00:00 2001 From: zvictorino Date: Fri, 22 Nov 2024 22:34:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(es):=20=E5=A4=A7=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B8=85=E7=90=86=E6=9C=BA=E5=99=A8=E7=9A=84flow=20#8012?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db_meta/api/cluster/doris/__init__.py | 1 + .../api/cluster/doris/clear_machine.py | 47 +++++ .../db_meta/api/cluster/es/__init__.py | 1 + .../db_meta/api/cluster/es/clear_machine.py | 47 +++++ .../db_meta/api/cluster/hdfs/__init__.py | 1 + .../db_meta/api/cluster/hdfs/clear_machine.py | 47 +++++ .../db_meta/api/cluster/kafka/__init__.py | 1 + .../api/cluster/kafka/clear_machine.py | 47 +++++ .../db_meta/api/cluster/pulsar/__init__.py | 1 + .../api/cluster/pulsar/clear_machine.py | 47 +++++ .../db_meta/api/cluster/vm/__init__.py | 1 + .../db_meta/api/cluster/vm/clear_machine.py | 47 +++++ .../scene/doris/doris_machine_clear_flow.py | 69 +++++++ .../bamboo/scene/es/es_machine_clear_flow.py | 69 +++++++ .../scene/hdfs/hdfs_machine_clear_flow.py | 69 +++++++ .../scene/kafka/kafka_machine_clear_flow.py | 69 +++++++ .../scene/pulsar/pulsar_machine_clear_flow.py | 69 +++++++ .../bamboo/scene/vm/vm_machine_clear_flow.py | 69 +++++++ .../backend/flow/engine/controller/doris.py | 8 + dbm-ui/backend/flow/engine/controller/es.py | 8 + dbm-ui/backend/flow/engine/controller/hdfs.py | 8 + .../backend/flow/engine/controller/kafka.py | 8 + .../backend/flow/engine/controller/pulsar.py | 8 + dbm-ui/backend/flow/engine/controller/vm.py | 8 + dbm-ui/backend/flow/urls.py | 12 ++ .../flow/utils/clear_machine_script.py | 184 ++++++++++++++++++ .../backend/flow/utils/doris/doris_db_meta.py | 10 +- dbm-ui/backend/flow/utils/es/es_db_meta.py | 6 + .../backend/flow/utils/hdfs/hdfs_db_meta.py | 6 + .../backend/flow/utils/kafka/kafka_db_meta.py | 8 +- .../flow/utils/pulsar/pulsar_db_meta.py | 8 +- dbm-ui/backend/flow/utils/vm/vm_db_meta.py | 12 +- .../backend/flow/views/doris_machine_clear.py | 31 +++ dbm-ui/backend/flow/views/es_machine_clear.py | 31 +++ .../backend/flow/views/hdfs_machine_clear.py | 31 +++ .../backend/flow/views/kafka_machine_clear.py | 31 +++ .../flow/views/pulsar_machine_clear.py | 31 +++ dbm-ui/backend/flow/views/vm_machine_clear.py | 31 +++ 38 files changed, 1175 insertions(+), 7 deletions(-) create mode 100644 dbm-ui/backend/db_meta/api/cluster/doris/clear_machine.py create mode 100644 dbm-ui/backend/db_meta/api/cluster/es/clear_machine.py create mode 100644 dbm-ui/backend/db_meta/api/cluster/hdfs/clear_machine.py create mode 100644 dbm-ui/backend/db_meta/api/cluster/kafka/clear_machine.py create mode 100644 dbm-ui/backend/db_meta/api/cluster/pulsar/clear_machine.py create mode 100644 dbm-ui/backend/db_meta/api/cluster/vm/clear_machine.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/doris/doris_machine_clear_flow.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/es/es_machine_clear_flow.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/hdfs/hdfs_machine_clear_flow.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/kafka/kafka_machine_clear_flow.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/pulsar/pulsar_machine_clear_flow.py create mode 100644 dbm-ui/backend/flow/engine/bamboo/scene/vm/vm_machine_clear_flow.py create mode 100644 dbm-ui/backend/flow/views/doris_machine_clear.py create mode 100644 dbm-ui/backend/flow/views/es_machine_clear.py create mode 100644 dbm-ui/backend/flow/views/hdfs_machine_clear.py create mode 100644 dbm-ui/backend/flow/views/kafka_machine_clear.py create mode 100644 dbm-ui/backend/flow/views/pulsar_machine_clear.py create mode 100644 dbm-ui/backend/flow/views/vm_machine_clear.py diff --git a/dbm-ui/backend/db_meta/api/cluster/doris/__init__.py b/dbm-ui/backend/db_meta/api/cluster/doris/__init__.py index 336548b2a3..f36b04f68c 100644 --- a/dbm-ui/backend/db_meta/api/cluster/doris/__init__.py +++ b/dbm-ui/backend/db_meta/api/cluster/doris/__init__.py @@ -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 diff --git a/dbm-ui/backend/db_meta/api/cluster/doris/clear_machine.py b/dbm-ui/backend/db_meta/api/cluster/doris/clear_machine.py new file mode 100644 index 0000000000..c650e22f1f --- /dev/null +++ b/dbm-ui/backend/db_meta/api/cluster/doris/clear_machine.py @@ -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) diff --git a/dbm-ui/backend/db_meta/api/cluster/es/__init__.py b/dbm-ui/backend/db_meta/api/cluster/es/__init__.py index 336548b2a3..f36b04f68c 100644 --- a/dbm-ui/backend/db_meta/api/cluster/es/__init__.py +++ b/dbm-ui/backend/db_meta/api/cluster/es/__init__.py @@ -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 diff --git a/dbm-ui/backend/db_meta/api/cluster/es/clear_machine.py b/dbm-ui/backend/db_meta/api/cluster/es/clear_machine.py new file mode 100644 index 0000000000..c650e22f1f --- /dev/null +++ b/dbm-ui/backend/db_meta/api/cluster/es/clear_machine.py @@ -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) diff --git a/dbm-ui/backend/db_meta/api/cluster/hdfs/__init__.py b/dbm-ui/backend/db_meta/api/cluster/hdfs/__init__.py index b5062e7577..0eba2ba31b 100644 --- a/dbm-ui/backend/db_meta/api/cluster/hdfs/__init__.py +++ b/dbm-ui/backend/db_meta/api/cluster/hdfs/__init__.py @@ -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 diff --git a/dbm-ui/backend/db_meta/api/cluster/hdfs/clear_machine.py b/dbm-ui/backend/db_meta/api/cluster/hdfs/clear_machine.py new file mode 100644 index 0000000000..c650e22f1f --- /dev/null +++ b/dbm-ui/backend/db_meta/api/cluster/hdfs/clear_machine.py @@ -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) diff --git a/dbm-ui/backend/db_meta/api/cluster/kafka/__init__.py b/dbm-ui/backend/db_meta/api/cluster/kafka/__init__.py index b5062e7577..0eba2ba31b 100644 --- a/dbm-ui/backend/db_meta/api/cluster/kafka/__init__.py +++ b/dbm-ui/backend/db_meta/api/cluster/kafka/__init__.py @@ -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 diff --git a/dbm-ui/backend/db_meta/api/cluster/kafka/clear_machine.py b/dbm-ui/backend/db_meta/api/cluster/kafka/clear_machine.py new file mode 100644 index 0000000000..c650e22f1f --- /dev/null +++ b/dbm-ui/backend/db_meta/api/cluster/kafka/clear_machine.py @@ -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) diff --git a/dbm-ui/backend/db_meta/api/cluster/pulsar/__init__.py b/dbm-ui/backend/db_meta/api/cluster/pulsar/__init__.py index b5062e7577..0eba2ba31b 100644 --- a/dbm-ui/backend/db_meta/api/cluster/pulsar/__init__.py +++ b/dbm-ui/backend/db_meta/api/cluster/pulsar/__init__.py @@ -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 diff --git a/dbm-ui/backend/db_meta/api/cluster/pulsar/clear_machine.py b/dbm-ui/backend/db_meta/api/cluster/pulsar/clear_machine.py new file mode 100644 index 0000000000..c650e22f1f --- /dev/null +++ b/dbm-ui/backend/db_meta/api/cluster/pulsar/clear_machine.py @@ -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) diff --git a/dbm-ui/backend/db_meta/api/cluster/vm/__init__.py b/dbm-ui/backend/db_meta/api/cluster/vm/__init__.py index b5062e7577..0eba2ba31b 100644 --- a/dbm-ui/backend/db_meta/api/cluster/vm/__init__.py +++ b/dbm-ui/backend/db_meta/api/cluster/vm/__init__.py @@ -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 diff --git a/dbm-ui/backend/db_meta/api/cluster/vm/clear_machine.py b/dbm-ui/backend/db_meta/api/cluster/vm/clear_machine.py new file mode 100644 index 0000000000..c650e22f1f --- /dev/null +++ b/dbm-ui/backend/db_meta/api/cluster/vm/clear_machine.py @@ -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) diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/doris/doris_machine_clear_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/doris/doris_machine_clear_flow.py new file mode 100644 index 0000000000..d3ab476a0e --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/doris/doris_machine_clear_flow.py @@ -0,0 +1,69 @@ +""" +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, Optional + +from django.utils.translation import ugettext as _ + +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.plugins.components.collections.common.exec_clear_machine import ClearMachineScriptComponent +from backend.flow.plugins.components.collections.doris.doris_db_meta import DorisMetaComponent +from backend.flow.utils.doris.doris_context_dataclass import DorisActKwargs + +logger = logging.getLogger("flow") + + +class ClearDorisMachineFlow(object): + """ + 构建清理doris机器的流程 + 兼容跨云区域的执行 + """ + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + @param root_id : 任务流程定义的root_id + @param data : 单据传递参数 + """ + self.root_id = root_id + self.data = data + self.data["ticket_type"] = "clear_machines" + + # 如果data里有bk_cloud_id这个字段,则bk_cloud_id=self.data["bk_cloud_id"] + # 否则,取clear_hosts里面的bk_cloud_id + if "bk_cloud_id" in self.data: + self.bk_cloud_id = self.data["bk_cloud_id"] + elif "clear_hosts" in self.data and len(self.data["clear_hosts"]) > 0: + self.bk_cloud_id = self.data["clear_hosts"][0].get("bk_cloud_id") + else: + self.bk_cloud_id = 0 + + def run_flow(self): + """ + 定义清理机器的执行流程 + 执行逻辑: + 1: 清理和机器相关的dbm元数据 + 2: 清理机器 + """ + # 定义主流程 + main_pipeline = Builder(root_id=self.root_id, data=self.data) + act_kwargs = DorisActKwargs(bk_cloud_id=self.bk_cloud_id) + main_pipeline.add_act( + act_name=_("清理机器cmdb元数据"), act_component_code=DorisMetaComponent.code, kwargs=asdict(act_kwargs) + ) + + main_pipeline.add_act( + act_name=_("清理机器"), + act_component_code=ClearMachineScriptComponent.code, + kwargs={"exec_ips": self.data["clear_hosts"]}, + ) + + main_pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/es/es_machine_clear_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/es/es_machine_clear_flow.py new file mode 100644 index 0000000000..bbeeca2c63 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/es/es_machine_clear_flow.py @@ -0,0 +1,69 @@ +""" +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, Optional + +from django.utils.translation import ugettext as _ + +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.plugins.components.collections.common.exec_clear_machine import ClearMachineScriptComponent +from backend.flow.plugins.components.collections.es.es_db_meta import EsMetaComponent +from backend.flow.utils.es.es_context_dataclass import EsActKwargs + +logger = logging.getLogger("flow") + + +class ClearEsMachineFlow(object): + """ + 构建清理es机器的流程 + 兼容跨云区域的执行 + """ + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + @param root_id : 任务流程定义的root_id + @param data : 单据传递参数 + """ + self.root_id = root_id + self.data = data + self.data["ticket_type"] = "clear_machines" + + # 如果data里有bk_cloud_id这个字段,则bk_cloud_id=self.data["bk_cloud_id"] + # 否则,取clear_hosts里面的bk_cloud_id + if "bk_cloud_id" in self.data: + self.bk_cloud_id = self.data["bk_cloud_id"] + elif "clear_hosts" in self.data and len(self.data["clear_hosts"]) > 0: + self.bk_cloud_id = self.data["clear_hosts"][0].get("bk_cloud_id") + else: + self.bk_cloud_id = 0 + + def run_flow(self): + """ + 定义清理机器的执行流程 + 执行逻辑: + 1: 清理和机器相关的dbm元数据 + 2: 清理机器 + """ + # 定义主流程 + main_pipeline = Builder(root_id=self.root_id, data=self.data) + act_kwargs = EsActKwargs(bk_cloud_id=self.bk_cloud_id) + main_pipeline.add_act( + act_name=_("清理机器cmdb元数据"), act_component_code=EsMetaComponent.code, kwargs=asdict(act_kwargs) + ) + + main_pipeline.add_act( + act_name=_("清理机器"), + act_component_code=ClearMachineScriptComponent.code, + kwargs={"exec_ips": self.data["clear_hosts"]}, + ) + + main_pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/hdfs/hdfs_machine_clear_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/hdfs/hdfs_machine_clear_flow.py new file mode 100644 index 0000000000..5ab1eca9a5 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/hdfs/hdfs_machine_clear_flow.py @@ -0,0 +1,69 @@ +""" +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, Optional + +from django.utils.translation import ugettext as _ + +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.plugins.components.collections.common.exec_clear_machine import ClearMachineScriptComponent +from backend.flow.plugins.components.collections.hdfs.hdfs_db_meta import HdfsDBMetaComponent +from backend.flow.utils.hdfs.hdfs_context_dataclass import ActKwargs + +logger = logging.getLogger("flow") + + +class ClearHdfsMachineFlow(object): + """ + 构建清理hdfs机器的流程 + 兼容跨云区域的执行 + """ + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + @param root_id : 任务流程定义的root_id + @param data : 单据传递参数 + """ + self.root_id = root_id + self.data = data + self.data["ticket_type"] = "clear_machines" + + # 如果data里有bk_cloud_id这个字段,则bk_cloud_id=self.data["bk_cloud_id"] + # 否则,取clear_hosts里面的bk_cloud_id + if "bk_cloud_id" in self.data: + self.bk_cloud_id = self.data["bk_cloud_id"] + elif "clear_hosts" in self.data and len(self.data["clear_hosts"]) > 0: + self.bk_cloud_id = self.data["clear_hosts"][0].get("bk_cloud_id") + else: + self.bk_cloud_id = 0 + + def run_flow(self): + """ + 定义清理机器的执行流程 + 执行逻辑: + 1: 清理和机器相关的dbm元数据 + 2: 清理机器 + """ + # 定义主流程 + main_pipeline = Builder(root_id=self.root_id, data=self.data) + act_kwargs = ActKwargs(bk_cloud_id=self.bk_cloud_id) + main_pipeline.add_act( + act_name=_("清理机器cmdb元数据"), act_component_code=HdfsDBMetaComponent.code, kwargs=asdict(act_kwargs) + ) + + main_pipeline.add_act( + act_name=_("清理机器"), + act_component_code=ClearMachineScriptComponent.code, + kwargs={"exec_ips": self.data["clear_hosts"]}, + ) + + main_pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/kafka/kafka_machine_clear_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/kafka/kafka_machine_clear_flow.py new file mode 100644 index 0000000000..6249bcb56b --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/kafka/kafka_machine_clear_flow.py @@ -0,0 +1,69 @@ +""" +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, Optional + +from django.utils.translation import ugettext as _ + +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.plugins.components.collections.common.exec_clear_machine import ClearMachineScriptComponent +from backend.flow.plugins.components.collections.kafka.kafka_db_meta import KafkaDBMetaComponent +from backend.flow.utils.kafka.kafka_context_dataclass import ActKwargs + +logger = logging.getLogger("flow") + + +class ClearKafkaMachineFlow(object): + """ + 构建清理kafka机器的流程 + 兼容跨云区域的执行 + """ + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + @param root_id : 任务流程定义的root_id + @param data : 单据传递参数 + """ + self.root_id = root_id + self.data = data + self.data["ticket_type"] = "clear_machines" + + # 如果data里有bk_cloud_id这个字段,则bk_cloud_id=self.data["bk_cloud_id"] + # 否则,取clear_hosts里面的bk_cloud_id + if "bk_cloud_id" in self.data: + self.bk_cloud_id = self.data["bk_cloud_id"] + elif "clear_hosts" in self.data and len(self.data["clear_hosts"]) > 0: + self.bk_cloud_id = self.data["clear_hosts"][0].get("bk_cloud_id") + else: + self.bk_cloud_id = 0 + + def run_flow(self): + """ + 定义清理机器的执行流程 + 执行逻辑: + 1: 清理和机器相关的dbm元数据 + 2: 清理机器 + """ + # 定义主流程 + main_pipeline = Builder(root_id=self.root_id, data=self.data) + act_kwargs = ActKwargs(bk_cloud_id=self.bk_cloud_id) + main_pipeline.add_act( + act_name=_("清理机器cmdb元数据"), act_component_code=KafkaDBMetaComponent.code, kwargs=asdict(act_kwargs) + ) + + main_pipeline.add_act( + act_name=_("清理机器"), + act_component_code=ClearMachineScriptComponent.code, + kwargs={"exec_ips": self.data["clear_hosts"]}, + ) + + main_pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/pulsar/pulsar_machine_clear_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/pulsar/pulsar_machine_clear_flow.py new file mode 100644 index 0000000000..c8e532b617 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/pulsar/pulsar_machine_clear_flow.py @@ -0,0 +1,69 @@ +""" +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, Optional + +from django.utils.translation import ugettext as _ + +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.plugins.components.collections.common.exec_clear_machine import ClearMachineScriptComponent +from backend.flow.plugins.components.collections.pulsar.pulsar_db_meta import PulsarDBMetaComponent +from backend.flow.utils.pulsar.pulsar_context_dataclass import PulsarActKwargs + +logger = logging.getLogger("flow") + + +class ClearPulsarMachineFlow(object): + """ + 构建清理pulsar机器的流程 + 兼容跨云区域的执行 + """ + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + @param root_id : 任务流程定义的root_id + @param data : 单据传递参数 + """ + self.root_id = root_id + self.data = data + self.data["ticket_type"] = "clear_machines" + + # 如果data里有bk_cloud_id这个字段,则bk_cloud_id=self.data["bk_cloud_id"] + # 否则,取clear_hosts里面的bk_cloud_id + if "bk_cloud_id" in self.data: + self.bk_cloud_id = self.data["bk_cloud_id"] + elif "clear_hosts" in self.data and len(self.data["clear_hosts"]) > 0: + self.bk_cloud_id = self.data["clear_hosts"][0].get("bk_cloud_id") + else: + self.bk_cloud_id = 0 + + def run_flow(self): + """ + 定义清理机器的执行流程 + 执行逻辑: + 1: 清理和机器相关的dbm元数据 + 2: 清理机器 + """ + # 定义主流程 + main_pipeline = Builder(root_id=self.root_id, data=self.data) + act_kwargs = PulsarActKwargs(bk_cloud_id=self.bk_cloud_id) + main_pipeline.add_act( + act_name=_("清理机器cmdb元数据"), act_component_code=PulsarDBMetaComponent.code, kwargs=asdict(act_kwargs) + ) + + main_pipeline.add_act( + act_name=_("清理机器"), + act_component_code=ClearMachineScriptComponent.code, + kwargs={"exec_ips": self.data["clear_hosts"]}, + ) + + main_pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/bamboo/scene/vm/vm_machine_clear_flow.py b/dbm-ui/backend/flow/engine/bamboo/scene/vm/vm_machine_clear_flow.py new file mode 100644 index 0000000000..c50f33a4d6 --- /dev/null +++ b/dbm-ui/backend/flow/engine/bamboo/scene/vm/vm_machine_clear_flow.py @@ -0,0 +1,69 @@ +""" +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, Optional + +from django.utils.translation import ugettext as _ + +from backend.flow.engine.bamboo.scene.common.builder import Builder +from backend.flow.plugins.components.collections.common.exec_clear_machine import ClearMachineScriptComponent +from backend.flow.plugins.components.collections.vm.vm_db_meta import VmMetaComponent +from backend.flow.utils.vm.vm_context_dataclass import VmActKwargs + +logger = logging.getLogger("flow") + + +class ClearVmMachineFlow(object): + """ + 构建清理vm机器的流程 + 兼容跨云区域的执行 + """ + + def __init__(self, root_id: str, data: Optional[Dict]): + """ + @param root_id : 任务流程定义的root_id + @param data : 单据传递参数 + """ + self.root_id = root_id + self.data = data + self.data["ticket_type"] = "clear_machines" + + # 如果data里有bk_cloud_id这个字段,则bk_cloud_id=self.data["bk_cloud_id"] + # 否则,取clear_hosts里面的bk_cloud_id + if "bk_cloud_id" in self.data: + self.bk_cloud_id = self.data["bk_cloud_id"] + elif "clear_hosts" in self.data and len(self.data["clear_hosts"]) > 0: + self.bk_cloud_id = self.data["clear_hosts"][0].get("bk_cloud_id") + else: + self.bk_cloud_id = 0 + + def run_flow(self): + """ + 定义清理机器的执行流程 + 执行逻辑: + 1: 清理和机器相关的dbm元数据 + 2: 清理机器 + """ + # 定义主流程 + main_pipeline = Builder(root_id=self.root_id, data=self.data) + act_kwargs = VmActKwargs(bk_cloud_id=self.bk_cloud_id) + main_pipeline.add_act( + act_name=_("清理机器cmdb元数据"), act_component_code=VmMetaComponent.code, kwargs=asdict(act_kwargs) + ) + + main_pipeline.add_act( + act_name=_("清理机器"), + act_component_code=ClearMachineScriptComponent.code, + kwargs={"exec_ips": self.data["clear_hosts"]}, + ) + + main_pipeline.run_pipeline() diff --git a/dbm-ui/backend/flow/engine/controller/doris.py b/dbm-ui/backend/flow/engine/controller/doris.py index 11199a34f6..4eef07f3b4 100644 --- a/dbm-ui/backend/flow/engine/controller/doris.py +++ b/dbm-ui/backend/flow/engine/controller/doris.py @@ -14,6 +14,7 @@ from backend.flow.engine.bamboo.scene.doris.doris_destroy_flow import DorisDestroyFlow from backend.flow.engine.bamboo.scene.doris.doris_disable_flow import DorisDisableFlow from backend.flow.engine.bamboo.scene.doris.doris_enable_flow import DorisEnableFlow +from backend.flow.engine.bamboo.scene.doris.doris_machine_clear_flow import ClearDorisMachineFlow from backend.flow.engine.bamboo.scene.doris.doris_reboot_flow import DorisRebootFlow from backend.flow.engine.bamboo.scene.doris.doris_replace_flow import DorisReplaceFlow from backend.flow.engine.bamboo.scene.doris.doris_scale_up_flow import DorisScaleUpFlow @@ -83,3 +84,10 @@ def doris_reboot_scene(self): """ flow = DorisRebootFlow(root_id=self.root_id, data=self.ticket_data) flow.reboot_doris_flow() + + def doris_machine_clear_scene(self): + """ + doris清理机器 + """ + flow = ClearDorisMachineFlow(root_id=self.root_id, data=self.ticket_data) + flow.run_flow() diff --git a/dbm-ui/backend/flow/engine/controller/es.py b/dbm-ui/backend/flow/engine/controller/es.py index b9818865ee..2236db5b4e 100644 --- a/dbm-ui/backend/flow/engine/controller/es.py +++ b/dbm-ui/backend/flow/engine/controller/es.py @@ -15,6 +15,7 @@ from backend.flow.engine.bamboo.scene.es.es_disable_flow import EsDisableFlow from backend.flow.engine.bamboo.scene.es.es_enable_flow import EsEnableFlow from backend.flow.engine.bamboo.scene.es.es_fake_apply_flow import EsFakeApplyFlow +from backend.flow.engine.bamboo.scene.es.es_machine_clear_flow import ClearEsMachineFlow from backend.flow.engine.bamboo.scene.es.es_reboot_flow import EsRebootFlow from backend.flow.engine.bamboo.scene.es.es_replace_flow import EsReplaceFlow from backend.flow.engine.bamboo.scene.es.es_scale_up_flow import EsScaleUpFlow @@ -91,3 +92,10 @@ def es_fake_apply_scene(self): """ flow = EsFakeApplyFlow(root_id=self.root_id, data=self.ticket_data) flow.fake_deploy_es_flow() + + def es_machine_clear_scene(self): + """ + es清理机器 + """ + flow = ClearEsMachineFlow(root_id=self.root_id, data=self.ticket_data) + flow.run_flow() diff --git a/dbm-ui/backend/flow/engine/controller/hdfs.py b/dbm-ui/backend/flow/engine/controller/hdfs.py index 3d08a99ab4..c5845106bf 100644 --- a/dbm-ui/backend/flow/engine/controller/hdfs.py +++ b/dbm-ui/backend/flow/engine/controller/hdfs.py @@ -13,6 +13,7 @@ from backend.flow.engine.bamboo.scene.hdfs.hdfs_disable_flow import HdfsDisableFlow from backend.flow.engine.bamboo.scene.hdfs.hdfs_enable_flow import HdfsEnableFlow from backend.flow.engine.bamboo.scene.hdfs.hdfs_fake_apply_flow import HdfsFakeApplyFlow +from backend.flow.engine.bamboo.scene.hdfs.hdfs_machine_clear_flow import ClearHdfsMachineFlow from backend.flow.engine.bamboo.scene.hdfs.hdfs_reboot_flow import HdfsRebootFlow from backend.flow.engine.bamboo.scene.hdfs.hdfs_replace_flow import HdfsReplaceFlow from backend.flow.engine.bamboo.scene.hdfs.hdfs_scale_up_flow import HdfsScaleUpFlow @@ -87,3 +88,10 @@ def hdfs_fake_apply_scene(self): """ flow = HdfsFakeApplyFlow(root_id=self.root_id, data=self.ticket_data) flow.fake_deploy_hdfs_flow() + + def hdfs_machine_clear_scene(self): + """ + hdfs清理机器 + """ + flow = ClearHdfsMachineFlow(root_id=self.root_id, data=self.ticket_data) + flow.run_flow() diff --git a/dbm-ui/backend/flow/engine/controller/kafka.py b/dbm-ui/backend/flow/engine/controller/kafka.py index 16252edc71..db85d5b0d6 100644 --- a/dbm-ui/backend/flow/engine/controller/kafka.py +++ b/dbm-ui/backend/flow/engine/controller/kafka.py @@ -14,6 +14,7 @@ from backend.flow.engine.bamboo.scene.kafka.kafka_disable_flow import KafkaDisableFlow from backend.flow.engine.bamboo.scene.kafka.kafka_enable_flow import KafkaEnableFlow from backend.flow.engine.bamboo.scene.kafka.kafka_fake_apply_flow import KafkaFakeApplyFlow +from backend.flow.engine.bamboo.scene.kafka.kafka_machine_clear_flow import ClearKafkaMachineFlow from backend.flow.engine.bamboo.scene.kafka.kafka_reboot_flow import KafkaRebootFlow from backend.flow.engine.bamboo.scene.kafka.kafka_replace_flow import KafkaReplaceFlow from backend.flow.engine.bamboo.scene.kafka.kafka_scale_up_flow import KafkaScaleUpFlow @@ -88,3 +89,10 @@ def kafka_fake_apply_scene(self): """ flow = KafkaFakeApplyFlow(root_id=self.root_id, data=self.ticket_data) flow.fake_deploy_kafka_flow() + + def kafka_machine_clear_scene(self): + """ + kafka清理机器 + """ + flow = ClearKafkaMachineFlow(root_id=self.root_id, data=self.ticket_data) + flow.run_flow() diff --git a/dbm-ui/backend/flow/engine/controller/pulsar.py b/dbm-ui/backend/flow/engine/controller/pulsar.py index aaf58540b2..fbc26def72 100644 --- a/dbm-ui/backend/flow/engine/controller/pulsar.py +++ b/dbm-ui/backend/flow/engine/controller/pulsar.py @@ -13,6 +13,7 @@ from backend.flow.engine.bamboo.scene.pulsar.pulsar_disable_flow import PulsarDisableFlow from backend.flow.engine.bamboo.scene.pulsar.pulsar_enable_flow import PulsarEnableFlow from backend.flow.engine.bamboo.scene.pulsar.pulsar_fake_apply_flow import PulsarFakeApplyFlow +from backend.flow.engine.bamboo.scene.pulsar.pulsar_machine_clear_flow import ClearPulsarMachineFlow from backend.flow.engine.bamboo.scene.pulsar.pulsar_reboot_flow import PulsarRebootFlow from backend.flow.engine.bamboo.scene.pulsar.pulsar_replace_flow import PulsarReplaceFlow from backend.flow.engine.bamboo.scene.pulsar.pulsar_scale_up_flow import PulsarScaleUpFlow @@ -87,3 +88,10 @@ def pulsar_fake_apply_scene(self): """ flow = PulsarFakeApplyFlow(root_id=self.root_id, data=self.ticket_data) flow.fake_deploy_pulsar_flow() + + def pulsar_machine_clear_scene(self): + """ + pulsar清理机器 + """ + flow = ClearPulsarMachineFlow(root_id=self.root_id, data=self.ticket_data) + flow.run_flow() diff --git a/dbm-ui/backend/flow/engine/controller/vm.py b/dbm-ui/backend/flow/engine/controller/vm.py index 72ff48207c..5da71a2593 100644 --- a/dbm-ui/backend/flow/engine/controller/vm.py +++ b/dbm-ui/backend/flow/engine/controller/vm.py @@ -14,6 +14,7 @@ from backend.flow.engine.bamboo.scene.vm.vm_destroy_flow import VmDestroyFlow from backend.flow.engine.bamboo.scene.vm.vm_disable_flow import VmDisableFlow from backend.flow.engine.bamboo.scene.vm.vm_enable_flow import VmEnableFlow +from backend.flow.engine.bamboo.scene.vm.vm_machine_clear_flow import ClearVmMachineFlow from backend.flow.engine.bamboo.scene.vm.vm_reboot_flow import VmRebootFlow from backend.flow.engine.bamboo.scene.vm.vm_replace_flow import VmReplaceFlow from backend.flow.engine.bamboo.scene.vm.vm_scale_up_flow import VmScaleUpFlow @@ -83,3 +84,10 @@ def vm_reboot_scene(self): """ flow = VmRebootFlow(root_id=self.root_id, data=self.ticket_data) flow.reboot_vm_flow() + + def vm_machine_clear_scene(self): + """ + vm清理机器 + """ + flow = ClearVmMachineFlow(root_id=self.root_id, data=self.ticket_data) + flow.run_flow() diff --git a/dbm-ui/backend/flow/urls.py b/dbm-ui/backend/flow/urls.py index 6fe9d156f4..c923d8e17b 100644 --- a/dbm-ui/backend/flow/urls.py +++ b/dbm-ui/backend/flow/urls.py @@ -25,6 +25,7 @@ from backend.flow.views.doris_destroy import DestroyDorisSceneApiView from backend.flow.views.doris_disable import DisableDorisSceneApiView from backend.flow.views.doris_enable import EnableDorisSceneApiView +from backend.flow.views.doris_machine_clear import DorisMachineClearApiView from backend.flow.views.doris_reboot import RebootDorisSceneApiView from backend.flow.views.doris_replace import ReplaceDorisSceneApiView from backend.flow.views.doris_scale_up import ScaleUpDorisSceneApiView @@ -35,6 +36,7 @@ from backend.flow.views.es_destroy import DestroyEsSceneApiView from backend.flow.views.es_disable import DisableEsSceneApiView from backend.flow.views.es_enable import EnableEsSceneApiView +from backend.flow.views.es_machine_clear import EsMachineClearApiView from backend.flow.views.es_reboot import RebootEsSceneApiView from backend.flow.views.es_replace import ReplaceEsSceneApiView from backend.flow.views.es_scale_up import ScaleUpEsSceneApiView @@ -43,6 +45,7 @@ from backend.flow.views.hdfs_destroy import DestroyHdfsSceneApiView from backend.flow.views.hdfs_disable import DisableHdfsSceneApiView from backend.flow.views.hdfs_enable import EnableHdfsSceneApiView +from backend.flow.views.hdfs_machine_clear import HdfsMachineClearApiView from backend.flow.views.hdfs_reboot import RebootHdfsSceneApiView from backend.flow.views.hdfs_replace import ReplaceHdfsSceneApiView from backend.flow.views.hdfs_scale_up import ScaleUpHdfsSceneApiView @@ -59,6 +62,7 @@ from backend.flow.views.kafka_destroy import DestroyKafkaSceneApiView from backend.flow.views.kafka_disable import DisableKafkaSceneApiView from backend.flow.views.kafka_enable import EnableKafkaSceneApiView +from backend.flow.views.kafka_machine_clear import KafkaMachineClearApiView from backend.flow.views.kafka_reboot import RebootKafkaSceneApiView from backend.flow.views.kafka_replace import ReplaceKafkaSceneApiView from backend.flow.views.kafka_scale_up import ScaleUpKafkaSceneApiView @@ -160,6 +164,7 @@ from backend.flow.views.pulsar_destroy import DestroyPulsarSceneApiView from backend.flow.views.pulsar_disable import DisablePulsarSceneApiView from backend.flow.views.pulsar_enable import EnablePulsarSceneApiView +from backend.flow.views.pulsar_machine_clear import PulsarMachineClearApiView from backend.flow.views.pulsar_reboot import RebootPulsarSceneApiView from backend.flow.views.pulsar_replace import ReplacePulsarSceneApiView from backend.flow.views.pulsar_scale_up import ScaleUpPulsarSceneApiView @@ -269,6 +274,7 @@ from backend.flow.views.vm_destroy import DestroyVmSceneApiView from backend.flow.views.vm_disable import DisableVmSceneApiView from backend.flow.views.vm_enable import EnableVmSceneApiView +from backend.flow.views.vm_machine_clear import VmMachineClearApiView from backend.flow.views.vm_reboot import RebootVmSceneApiView from backend.flow.views.vm_replace import ReplaceVmSceneApiView from backend.flow.views.vm_scale_up import ScaleUpVmSceneApiView @@ -390,6 +396,7 @@ url(r"^scene/shrink_kafka$", ShrinkKafkaSceneApiView.as_view()), url(r"^scene/replace_kafka$", ReplaceKafkaSceneApiView.as_view()), url(r"^scene/reboot_kafka$", RebootKafkaSceneApiView.as_view()), + url(r"^scene/kafka_machine_clear$", KafkaMachineClearApiView.as_view()), url(r"^scene/install_es$", InstallEsSceneApiView.as_view()), url(r"^scene/fake_install_es$", FakeInstallEsSceneApiView.as_view()), url(r"^scene/scale_up_es$", ScaleUpEsSceneApiView.as_view()), @@ -399,6 +406,7 @@ url(r"^scene/destroy_es$", DestroyEsSceneApiView.as_view()), url(r"^scene/reboot_es$", RebootEsSceneApiView.as_view()), url(r"^scene/replace_es$", ReplaceEsSceneApiView.as_view()), + url(r"^scene/es_machine_clear$", EsMachineClearApiView.as_view()), url(r"^scene/redis_keys_delete$", RedisKeysDeleteSceneApiView.as_view()), url(r"^scene/sql_semantic_check$", SqlSemanticCheckSceneApiView.as_view()), url(r"^scene/tendbha_rename_database", MySQLHARenameDatabaseView.as_view()), @@ -432,6 +440,7 @@ url(r"^scene/reboot_hdfs$", RebootHdfsSceneApiView.as_view()), url(r"^scene/replace_hdfs$", ReplaceHdfsSceneApiView.as_view()), url(r"^scene/fake_install_hdfs$", FakeInstallHdfsSceneApiView.as_view()), + url(r"^scene/hdfs_machine_clear$", HdfsMachineClearApiView.as_view()), url(r"^scene/switch_mysql_ha$", MySQLHASwitchSceneApiView.as_view()), url(r"^scene/master_ha_master_fail_over$", MySQLHAMasterFailOverApiView.as_view()), url(r"^scene/master_pt_table_sync$", MySQLPtTableSyncApiView.as_view()), @@ -454,6 +463,7 @@ url(r"^scene/replace_pulsar$", ReplacePulsarSceneApiView.as_view()), url(r"^scene/shrink_pulsar$", ShrinkPulsarSceneApiView.as_view()), url(r"^scene/fake_install_pulsar$", FakeInstallPulsarSceneApiView.as_view()), + url(r"^scene/pulsar_machine_clear$", PulsarMachineClearApiView.as_view()), url(r"^scene/import_resource_init$", ImportResourceInitStepApiView.as_view()), url("^scene/mysql_data_migrate$", MysqlDataMigrateSceneApiView.as_view()), url("^scene/mysql_machine_clear$", MysqlMachineClearApiView.as_view()), @@ -546,6 +556,7 @@ url("^scene/mysql_data_migrate$", MysqlDataMigrateSceneApiView.as_view()), url("^scene/download_dbactor$", DownloadDbactorApiView.as_view()), url("^scene/download_file$", DownloadFileApiView.as_view()), + url("^scene/doris_machine_clear$", DorisMachineClearApiView.as_view()), # vm url(r"^scene/install_vm$", InstallVmSceneApiView.as_view()), url(r"^scene/scale_up_vm$", ScaleUpVmSceneApiView.as_view()), @@ -555,4 +566,5 @@ url(r"^scene/reboot_vm$", RebootVmSceneApiView.as_view()), url(r"^scene/shrink_vm$", ShrinkVmSceneApiView.as_view()), url(r"^scene/replace_vm$", ReplaceVmSceneApiView.as_view()), + url("^scene/vm_machine_clear$", VmMachineClearApiView.as_view()), ] diff --git a/dbm-ui/backend/flow/utils/clear_machine_script.py b/dbm-ui/backend/flow/utils/clear_machine_script.py index 5ae8575750..95593685cd 100644 --- a/dbm-ui/backend/flow/utils/clear_machine_script.py +++ b/dbm-ui/backend/flow/utils/clear_machine_script.py @@ -58,13 +58,197 @@ echo 1 """ +es_clear_machine_script = """ +source /etc/profile +echo "Step 1: [crontab -u mysql -r]" +crontab -u mysql -r +echo "Step 1 completed" + +echo "Step 2: [supervisorctl stop all]" +supervisorctl stop all +echo "Step 2 completed" + +echo "Step 3: [ps -ef|egrep 'java|supervisord|exporter|telegraf|x-pack-ml|node'|grep -v grep |awk {'print "kill -9 " $2'}|sh]" +ps -ef | egrep 'java|supervisord|exporter|telegraf|x-pack-ml|node'|grep -v grep |awk {'print "kill -9 " $2'}|sh +echo "Step 3 completed" + +echo "Step 4: [rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java]" +rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java +echo "Step 4 completed" + +echo "Step 5: [sed -i '/esprofile/d' /etc/profile]" +sed -i '/esprofile/d' /etc/profile +echo "Step 5 completed" + +echo "Step 6: clear esenv/eslog/esdata" +rm -rf /data/esenv* +rm -rf /data*/esdata* +rm -rf /data*/eslog* +echo "Step 6 completed" +""" + +kafka_clear_machine_script = """ +source /etc/profile +echo "Step 1: [crontab -u mysql -r]" +crontab -u mysql -r +echo "Step 1 completed" + +echo "Step 2: [supervisorctl stop all]" +supervisorctl stop all +echo "Step 2 completed" + +echo "Step 3: [ps -ef|egrep 'supervisord|burrow|telegraf|java|exporter'|grep -v grep |awk {'print "kill -9 " $2'}|sh]" +ps -ef | egrep 'supervisord|burrow|telegraf|java|exporter'|grep -v grep |awk {'print "kill -9 " $2'}|sh +echo "Step 3 completed" + +echo "Step 4: [rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java]" +rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java +echo "Step 4 completed" + +echo "Step 5: [rm -f /etc/profile.d/kafka.sh]" +rm -f /etc/profile.d/kafka.sh +echo "Step 5 completed" + +echo "Step 6: clear kafkaenv/kafkalog/kafkadata/zk" +rm -rf /data/kafkaenv* +rm -rf /data*/kafkadata* +rm -rf /data*/kafkalog* +rm -rf /data*/zklog* +echo "Step 6 completed" +""" + +hdfs_clear_machine_script = """ +source /etc/profile +echo "Step 1: [crontab -u mysql -r]" +crontab -u mysql -r ; crontab -u hadoop -r +userdel hadoop +echo "Step 1 completed" + +echo "Step 2: [supervisorctl stop all]" +supervisorctl stop all +echo "Step 2 completed" + +echo "Step 3: [ps -ef|egrep 'supervisord|telegraf|consul'|grep -v grep |awk {'print "kill -9 " $2'}|sh]" +ps -ef | egrep 'supervisord|telegraf|consul'|grep -v grep |awk {'print "kill -9 " $2'}|sh +echo "Step 3 completed" + +echo "Step 4: [rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java]" +rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java +echo "Step 4 completed" + +echo "Step 5: [sed -i '/hdfsProfile/d' /etc/profile]" +sed -i '/hdfsProfile/d' /etc/profile +echo "Step 5 completed" + +echo "Step 6: clear hadoopenv/hadoopdata" +rm -rf /data/hadoopenv +df |grep data|grep -vw '/data'|awk '{print $NF}'|while read line;do mv $line/hadoopdata $line/bak_hadoopdata;done +echo "Step 6 completed" +""" + +pulsar_clear_machine_script = """ +source /etc/profile +echo "Step 1: [crontab -u mysql -r]" +crontab -u mysql -r +echo "Step 1 completed" + +echo "Step 2: [supervisorctl stop all]" +supervisorctl stop all +echo "Step 2 completed" + +echo "Step 3: [ps -ef|egrep 'java|supervisord|exporter'|grep -v grep |awk {'print "kill -9 " $2'}|sh]" +ps -ef | egrep 'java|supervisord|exporter'|grep -v grep |awk {'print "kill -9 " $2'}|sh +echo "Step 3 completed" + +echo "Step 4: [rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java]" +rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java +echo "Step 4 completed" + +echo "Step 5: [sed -i '/pulsarprofile/d' /etc/profile]" +sed -i '/pulsarprofile/d' /etc/profile +echo "Step 5 completed" + +echo "Step 6: clear pulsarenv/pulsarlog/pulsardata" +rm -rf /data/pulsarenv* +rm -rf /data*/pulsar* +echo "Step 6 completed" +""" + +doris_clear_machine_script = """ +source /etc/profile +echo "Step 1: [crontab -u mysql -r]" +crontab -u mysql -r +echo "Step 1 completed" + +echo "Step 2: [supervisorctl stop all]" +supervisorctl stop all +echo "Step 2 completed" + +echo "Step 3: [ps -ef|egrep 'supervisord|java|exporter'|grep -v grep |awk {'print "kill -9 " $2'}|sh]" +ps -ef | egrep 'supervisord|java|exporter'|grep -v grep |awk {'print "kill -9 " $2'}|sh +echo "Step 3 completed" + +echo "Step 4: [rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java]" +rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java +echo "Step 4 completed" + +echo "Step 5: [sed -i '/dorisprofile/d' /etc/profile]" +sed -i '/dorisprofile/d' /etc/profile +echo "Step 5 completed" + +echo "Step 6: clear doris dir" +rm -rf /data/doris* +df |grep data|grep -vw '/data'|awk '{print $NF}'|while read line;do rm -rf $line/dorisdata*;done +echo "Step 6 completed" +""" + +vm_clear_machine_script = """ +source /etc/profile +echo "Step 1: [crontab -u mysql -r]" +crontab -u mysql -r +echo "Step 1 completed" + +echo "Step 2: [supervisorctl stop all]" +supervisorctl stop all +echo "Step 2 completed" + +echo "Step 3: [ps -ef|egrep 'supervisord|exporter|vminsert|vmstorage|vmselect'|grep -v grep |awk {'print "kill -9 " $2'}|sh]" +ps -ef|egrep 'supervisord|node_exporter|telegraf|vminsert|vmstorage|vmselect'|grep -v grep|awk {'print "kill -9 " $2'}|sh +echo "Step 3 completed" + +echo "Step 4: [rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java]" +rm -f /etc/supervisord.conf /usr/local/bin/supervisorctl /usr/local/bin/supervisord /usr/bin/java +echo "Step 4 completed" + +echo "Step 5: [rm -f /etc/profile.d/vm.sh]" +rm -f /etc/profile.d/vm.sh +echo "Step 5 completed" + +echo "Step 6: clear vm dir" +rm -rf /data/vmenv* +rm -rf /data*/vmd* +rm -rf /data*/vm* +echo "Step 6 completed" +""" db_type_script_map = { DBType.MySQL.value: mysql_clear_machine_script, DBType.Sqlserver.value: sqlserver_clear_machine_script, + DBType.Es.value: es_clear_machine_script, + DBType.Kafka.value: kafka_clear_machine_script, + DBType.Hdfs.value: hdfs_clear_machine_script, + DBType.Pulsar.value: pulsar_clear_machine_script, + DBType.Doris.value: doris_clear_machine_script, + DBType.Vm.value: vm_clear_machine_script, } db_type_account_user_map = { DBType.MySQL.value: DBA_ROOT_USER, DBType.Sqlserver.value: WINDOW_SYSTEM_JOB_USER, + DBType.Es.value: DBA_ROOT_USER, + DBType.Kafka.value: DBA_ROOT_USER, + DBType.Hdfs.value: DBA_ROOT_USER, + DBType.Pulsar.value: DBA_ROOT_USER, + DBType.Doris.value: DBA_ROOT_USER, + DBType.Vm.value: DBA_ROOT_USER, } diff --git a/dbm-ui/backend/flow/utils/doris/doris_db_meta.py b/dbm-ui/backend/flow/utils/doris/doris_db_meta.py index d7e4b600fc..a98131c759 100644 --- a/dbm-ui/backend/flow/utils/doris/doris_db_meta.py +++ b/dbm-ui/backend/flow/utils/doris/doris_db_meta.py @@ -56,8 +56,8 @@ def __init__(self, ticket_data: dict): self.role_port_dict = { DorisRoleEnum.HOT.value: DEFAULT_BE_WEB_PORT, DorisRoleEnum.COLD.value: DEFAULT_BE_WEB_PORT, - DorisRoleEnum.FOLLOWER.value: ticket_data["query_port"], - DorisRoleEnum.OBSERVER.value: ticket_data["query_port"], + DorisRoleEnum.FOLLOWER.value: ticket_data.get("query_port", 0), + DorisRoleEnum.OBSERVER.value: ticket_data.get("query_port", 0), } def __get_node_ips_by_role(self, role: str) -> list: @@ -166,3 +166,9 @@ def doris_shrink(self) -> bool: storages=storage_instances, ) return True + + def clear_machines(self): + """ + 清理机器信息 + """ + api.cluster.doris.clear_machine(machines=self.ticket_data["clear_hosts"]) diff --git a/dbm-ui/backend/flow/utils/es/es_db_meta.py b/dbm-ui/backend/flow/utils/es/es_db_meta.py index 4e412dbf7f..f4aa48f69f 100644 --- a/dbm-ui/backend/flow/utils/es/es_db_meta.py +++ b/dbm-ui/backend/flow/utils/es/es_db_meta.py @@ -163,3 +163,9 @@ def es_shrink(self) -> bool: storages=storage_instances, ) return True + + def clear_machines(self): + """ + 清理机器信息 + """ + api.cluster.es.clear_machine(machines=self.ticket_data["clear_hosts"]) diff --git a/dbm-ui/backend/flow/utils/hdfs/hdfs_db_meta.py b/dbm-ui/backend/flow/utils/hdfs/hdfs_db_meta.py index 862530bf26..a7c1223c2d 100644 --- a/dbm-ui/backend/flow/utils/hdfs/hdfs_db_meta.py +++ b/dbm-ui/backend/flow/utils/hdfs/hdfs_db_meta.py @@ -366,3 +366,9 @@ def __generate_replace_machine(self, replace_role: str) -> list: {"ip": zk_ip, "bk_biz_id": bk_biz_id, "machine_type": MachineType.HDFS_MASTER.value} ) return machines + + def clear_machines(self): + """ + 清理机器信息 + """ + api.cluster.hdfs.clear_machine(machines=self.ticket_data["clear_hosts"]) diff --git a/dbm-ui/backend/flow/utils/kafka/kafka_db_meta.py b/dbm-ui/backend/flow/utils/kafka/kafka_db_meta.py index 0977b2442c..3e11d7faf0 100644 --- a/dbm-ui/backend/flow/utils/kafka/kafka_db_meta.py +++ b/dbm-ui/backend/flow/utils/kafka/kafka_db_meta.py @@ -44,7 +44,7 @@ def __init__(self, ticket_data: dict): } self.role_port_dict = { "zookeeper": 2181, - "broker": self.ticket_data["port"], + "broker": ticket_data.get("port", 0), } def __get_node_ips_by_role(self, role: str) -> list: @@ -299,6 +299,12 @@ def kafka_replace(self) -> bool: KafkaCCTopoOperator(cluster, self.ticket_data).transfer_instances_to_cluster_module(storage_objs) return True + def clear_machines(self): + """ + 清理机器信息 + """ + api.cluster.kafka.clear_machine(machines=self.ticket_data["clear_hosts"]) + def check_machines_duplicate(machines: list, ip: str) -> bool: """ diff --git a/dbm-ui/backend/flow/utils/pulsar/pulsar_db_meta.py b/dbm-ui/backend/flow/utils/pulsar/pulsar_db_meta.py index aa0c504378..b1d0104def 100644 --- a/dbm-ui/backend/flow/utils/pulsar/pulsar_db_meta.py +++ b/dbm-ui/backend/flow/utils/pulsar/pulsar_db_meta.py @@ -53,7 +53,7 @@ def __init__(self, ticket_data: dict): self.role_port_dict = { PulsarRoleEnum.ZooKeeper.value: PULSAR_ZOOKEEPER_SERVICE_PORT, PulsarRoleEnum.BookKeeper.value: PULSAR_BOOKKEEPER_SERVICE_PORT, - PulsarRoleEnum.Broker.value: self.ticket_data["port"], + PulsarRoleEnum.Broker.value: self.ticket_data.get("port", 0), } def __get_node_ips_by_role(self, role: str) -> list: @@ -211,3 +211,9 @@ def pulsar_replace(self) -> bool: ) return True + + def clear_machines(self): + """ + 清理机器信息 + """ + api.cluster.pulsar.clear_machine(machines=self.ticket_data["clear_hosts"]) diff --git a/dbm-ui/backend/flow/utils/vm/vm_db_meta.py b/dbm-ui/backend/flow/utils/vm/vm_db_meta.py index 8c49621b4b..b266e6391d 100644 --- a/dbm-ui/backend/flow/utils/vm/vm_db_meta.py +++ b/dbm-ui/backend/flow/utils/vm/vm_db_meta.py @@ -55,10 +55,10 @@ def __init__(self, ticket_data: dict): VmRoleEnum.VMSELECT.value: InstanceRole.VM_SELECT.value, } self.role_port_dict = { - VmRoleEnum.VMAUTH.value: ticket_data["vminsert_port"], + VmRoleEnum.VMAUTH.value: ticket_data.get("vminsert_port", 0), VmRoleEnum.VMSTORAGE.value: VMINSERT_STORAGE_PORT, - VmRoleEnum.VMINSERT.value: ticket_data["vminsert_port"], - VmRoleEnum.VMSELECT.value: ticket_data["vmselect_port"], + VmRoleEnum.VMINSERT.value: ticket_data.get("vminsert_port", 0), + VmRoleEnum.VMSELECT.value: ticket_data.get("vmselect_port", 0), } def __get_node_ips_by_role(self, role: str) -> list: @@ -168,3 +168,9 @@ def vm_shrink(self) -> bool: storages=storage_instances, ) return True + + def clear_machines(self): + """ + 清理机器信息 + """ + api.cluster.vm.clear_machine(machines=self.ticket_data["clear_hosts"]) diff --git a/dbm-ui/backend/flow/views/doris_machine_clear.py b/dbm-ui/backend/flow/views/doris_machine_clear.py new file mode 100644 index 0000000000..6b58016539 --- /dev/null +++ b/dbm-ui/backend/flow/views/doris_machine_clear.py @@ -0,0 +1,31 @@ +""" +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 rest_framework.response import Response + +from backend.flow.engine.controller.doris import DorisController +from backend.flow.views.base import FlowTestView +from backend.utils.basic import generate_root_id + +logger = logging.getLogger("root") + + +class DorisMachineClearApiView(FlowTestView): + """ + api: /apis/v1/flow/scene/doris_machine_clear + params: + """ + + def post(self, request): + root_id = generate_root_id() + flow = DorisController(root_id=root_id, ticket_data=request.data) + flow.doris_machine_clear_scene() + return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/es_machine_clear.py b/dbm-ui/backend/flow/views/es_machine_clear.py new file mode 100644 index 0000000000..6ccb28aba0 --- /dev/null +++ b/dbm-ui/backend/flow/views/es_machine_clear.py @@ -0,0 +1,31 @@ +""" +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 rest_framework.response import Response + +from backend.flow.engine.controller.es import EsController +from backend.flow.views.base import FlowTestView +from backend.utils.basic import generate_root_id + +logger = logging.getLogger("root") + + +class EsMachineClearApiView(FlowTestView): + """ + api: /apis/v1/flow/scene/es_machine_clear + params: + """ + + def post(self, request): + root_id = generate_root_id() + flow = EsController(root_id=root_id, ticket_data=request.data) + flow.es_machine_clear_scene() + return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/hdfs_machine_clear.py b/dbm-ui/backend/flow/views/hdfs_machine_clear.py new file mode 100644 index 0000000000..6a78616e38 --- /dev/null +++ b/dbm-ui/backend/flow/views/hdfs_machine_clear.py @@ -0,0 +1,31 @@ +""" +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 rest_framework.response import Response + +from backend.flow.engine.controller.hdfs import HdfsController +from backend.flow.views.base import FlowTestView +from backend.utils.basic import generate_root_id + +logger = logging.getLogger("root") + + +class HdfsMachineClearApiView(FlowTestView): + """ + api: /apis/v1/flow/scene/hdfs_machine_clear + params: + """ + + def post(self, request): + root_id = generate_root_id() + flow = HdfsController(root_id=root_id, ticket_data=request.data) + flow.hdfs_machine_clear_scene() + return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/kafka_machine_clear.py b/dbm-ui/backend/flow/views/kafka_machine_clear.py new file mode 100644 index 0000000000..61d4782fb4 --- /dev/null +++ b/dbm-ui/backend/flow/views/kafka_machine_clear.py @@ -0,0 +1,31 @@ +""" +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 rest_framework.response import Response + +from backend.flow.engine.controller.kafka import KafkaController +from backend.flow.views.base import FlowTestView +from backend.utils.basic import generate_root_id + +logger = logging.getLogger("root") + + +class KafkaMachineClearApiView(FlowTestView): + """ + api: /apis/v1/flow/scene/kafka_machine_clear + params: + """ + + def post(self, request): + root_id = generate_root_id() + flow = KafkaController(root_id=root_id, ticket_data=request.data) + flow.kafka_machine_clear_scene() + return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/pulsar_machine_clear.py b/dbm-ui/backend/flow/views/pulsar_machine_clear.py new file mode 100644 index 0000000000..c45cb5ce18 --- /dev/null +++ b/dbm-ui/backend/flow/views/pulsar_machine_clear.py @@ -0,0 +1,31 @@ +""" +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 rest_framework.response import Response + +from backend.flow.engine.controller.pulsar import PulsarController +from backend.flow.views.base import FlowTestView +from backend.utils.basic import generate_root_id + +logger = logging.getLogger("root") + + +class PulsarMachineClearApiView(FlowTestView): + """ + api: /apis/v1/flow/scene/pulsar_machine_clear + params: + """ + + def post(self, request): + root_id = generate_root_id() + flow = PulsarController(root_id=root_id, ticket_data=request.data) + flow.pulsar_machine_clear_scene() + return Response({"root_id": root_id}) diff --git a/dbm-ui/backend/flow/views/vm_machine_clear.py b/dbm-ui/backend/flow/views/vm_machine_clear.py new file mode 100644 index 0000000000..fed35063c3 --- /dev/null +++ b/dbm-ui/backend/flow/views/vm_machine_clear.py @@ -0,0 +1,31 @@ +""" +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 rest_framework.response import Response + +from backend.flow.engine.controller.vm import VmController +from backend.flow.views.base import FlowTestView +from backend.utils.basic import generate_root_id + +logger = logging.getLogger("root") + + +class VmMachineClearApiView(FlowTestView): + """ + api: /apis/v1/flow/scene/vm_machine_clear + params: + """ + + def post(self, request): + root_id = generate_root_id() + flow = VmController(root_id=root_id, ticket_data=request.data) + flow.vm_machine_clear_scene() + return Response({"root_id": root_id})