Skip to content

Commit 68dd14c

Browse files
feat(backend): mysql和tendbcluster接入clb #10422
1 parent fd483dc commit 68dd14c

File tree

18 files changed

+492
-6
lines changed

18 files changed

+492
-6
lines changed

dbm-ui/backend/db_meta/api/cluster/tendbha/detail.py

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from django.utils.translation import gettext as _
1313

14-
from backend.db_meta.api.cluster.base.graph import ForeignRelationType, Graphic, Group, LineLabel
15-
from backend.db_meta.enums import InstanceInnerRole
14+
from backend.db_meta.api.cluster.base.graph import ForeignRelationType, Graphic, Group, GroupNameType, LineLabel
15+
from backend.db_meta.enums import ClusterEntryType, InstanceInnerRole
1616
from backend.db_meta.models import Cluster, StorageInstanceTuple
1717

1818

@@ -73,9 +73,36 @@ def scan_cluster(cluster: Cluster) -> Graphic:
7373
else:
7474
graph.add_foreign_cluster(ForeignRelationType.AccessTo, backend_instance_cluster)
7575

76-
master_be_group = Group(node_id="master_bind_entry_group", group_name=_("访问入口(主)"))
77-
for be in proxy_instance.bind_entry.all():
78-
dummy_be_node, master_be_group = graph.add_node(be, to_group=master_be_group)
79-
graph.add_line(source=master_be_group, target=proxy_instance_group, label=LineLabel.Bind)
76+
clb_entry_group = None
77+
master_entry_group = Group(node_id="master_bind_entry_group", group_name=_("访问入口(主)"))
78+
master_entry_names = []
79+
all_proxy_entrys = proxy_instance.bind_entry.all()
80+
if all_proxy_entrys.filter(cluster__clusterentry__cluster_entry_type=ClusterEntryType.CLB).exists():
81+
clb_entry_group = Group(node_id="clb_entry_group", group_name=_("访问入口(CLB IP)"))
82+
for entry in all_proxy_entrys:
83+
# clb肯定指向proxy
84+
if entry.cluster_entry_type == ClusterEntryType.CLB:
85+
dummy_be_node, clb_entry_group = graph.add_node(entry, to_group=clb_entry_group)
86+
graph.add_line(source=clb_entry_group, target=proxy_instance_group, label=LineLabel.Forward)
87+
88+
# clbDNS肯定指向clb
89+
elif entry.cluster_entry_type == ClusterEntryType.CLBDNS:
90+
clb_dns_entry_group = Group(node_id="clb_dns_entry_group", group_name=_("访问入口(CLB域名)"))
91+
dummy_be_node, clb_dns_entry_group = graph.add_node(entry, to_group=clb_dns_entry_group)
92+
graph.add_line(source=clb_dns_entry_group, target=clb_entry_group, label=LineLabel.Bind)
93+
94+
# dns默认指向proxy 指向clb之后不再指向proxy
95+
elif entry.cluster_entry_type == ClusterEntryType.DNS:
96+
if entry.forward_to:
97+
dns_entry_group = Group(node_id="dns_entry_group", group_name=_("访问入口(主)"))
98+
dummy_be_node, dns_entry_group = graph.add_node(entry, to_group=dns_entry_group)
99+
graph.add_line(source=dns_entry_group, target=clb_entry_group, label=LineLabel.Bind)
100+
101+
else:
102+
dummy_be_node, master_entry_group = graph.add_node(entry, to_group=master_entry_group)
103+
graph.add_line(source=master_entry_group, target=proxy_instance_group, label=LineLabel.Bind)
104+
master_entry_names.append(str(GroupNameType.get_choice_label(GroupNameType.DNS.value)))
105+
106+
master_entry_group.group_name = master_entry_group.group_name.format("、".join(master_entry_names))
80107

81108
return graph

dbm-ui/backend/db_services/bigdata/es/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from backend.db_services.bigdata.resources import yasg_slz
2222
from backend.db_services.bigdata.resources.views import BigdataResourceViewSet
2323
from backend.db_services.dbbase.resources import serializers
24+
from backend.iam_app.dataclass.actions import ActionEnum
2425

2526

2627
@method_decorator(
@@ -86,6 +87,12 @@ class EsClusterViewSetBigdata(BigdataResourceViewSet):
8687
query_serializer_class = serializers.ListResourceSLZ
8788
db_type = DBType.Es
8889

90+
list_perm_actions = [
91+
ActionEnum.ES_CREATE_CLB,
92+
ActionEnum.ES_DNS_BIND_CLB,
93+
ActionEnum.ES_CREATE_POLARIS,
94+
]
95+
8996
@action(methods=["GET"], detail=True, url_path="get_nodes", serializer_class=serializers.ListNodesSLZ)
9097
def get_nodes(self, request, bk_biz_id: int, cluster_id: int):
9198
"""获取特定角色的节点"""

dbm-ui/backend/db_services/mysql/resources/tendbcluster/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ class SpiderViewSet(viewsets.ResourceViewSet):
9797
ActionEnum.TENDBCLUSTER_EDIT,
9898
ActionEnum.TENDBCLUSTER_SPIDER_SLAVE_DESTROY,
9999
ActionEnum.TENDBCLUSTER_ENABLE_DISABLE,
100+
ActionEnum.TENDBCLUSTER_ADD_CLB,
101+
ActionEnum.TENDBCLUSTER_CLB_BIND_DOMAIN,
100102
ActionEnum.TENDBCLUSTER_WEBCONSOLE,
101103
ActionEnum.TENDBCLUSTER_DESTROY,
102104
ActionEnum.TENDBCLUSTER_SPIDER_ADD_NODES,

dbm-ui/backend/db_services/mysql/resources/tendbha/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ class DBHAViewSet(viewsets.ResourceViewSet):
9191

9292
list_perm_actions = [
9393
ActionEnum.MYSQL_ENABLE_DISABLE,
94+
ActionEnum.MYSQL_ADD_CLB,
95+
ActionEnum.MYSQL_CLB_BIND_DOMAIN,
9496
ActionEnum.MYSQL_DESTROY,
9597
ActionEnum.MYSQL_VIEW,
9698
ActionEnum.MYSQL_EDIT,

dbm-ui/backend/ticket/builders/common/bigdata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def validate_domain(cls, cluster_domain_prefix, cluster_name, db_app_abbr):
6969

7070
class BigDataSingleClusterOpsDetailsSerializer(BigDataDetailsSerializer):
7171
cluster_id = serializers.IntegerField(help_text=_("集群ID"))
72+
bk_cloud_id = serializers.IntegerField(help_text=_("云区域ID"), required=False)
7273
ext_info = serializers.DictField(help_text=_("操作额外信息(用于前端渲染)"), required=False)
7374

7475

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-Add commentMore actions
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
12+
from django.utils.translation import ugettext_lazy as _
13+
14+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
15+
from backend.ticket import builders
16+
from backend.ticket.builders.common.bigdata import BaseEsTicketFlowBuilder, BigDataSingleClusterOpsDetailsSerializer
17+
from backend.ticket.constants import TicketType
18+
19+
20+
class EsCreateCLBDetailSerializer(BigDataSingleClusterOpsDetailsSerializer):
21+
pass
22+
23+
24+
class EsCreateCLBFlowParamBuilder(builders.FlowParamBuilder):
25+
controller = MySQLClbController.clb_create
26+
27+
def format_ticket_data(self):
28+
super().format_ticket_data()
29+
30+
31+
@builders.BuilderFactory.register(TicketType.ES_CREATE_CLB)
32+
class EsCreateCLBFlowBuilder(BaseEsTicketFlowBuilder):
33+
serializer = EsCreateCLBDetailSerializer
34+
inner_flow_builder = EsCreateCLBFlowParamBuilder
35+
inner_flow_name = _("创建CLB")
36+
default_need_itsm = False
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-Add commentMore actions
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
12+
from django.utils.translation import ugettext_lazy as _
13+
14+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
15+
from backend.ticket import builders
16+
from backend.ticket.builders.common.bigdata import BaseEsTicketFlowBuilder, BigDataSingleClusterOpsDetailsSerializer
17+
from backend.ticket.constants import TicketType
18+
19+
20+
class EsCreatePolarisDetailSerializer(BigDataSingleClusterOpsDetailsSerializer):
21+
pass
22+
23+
24+
class EsCreatePolarisFlowParamBuilder(builders.FlowParamBuilder):
25+
controller = MySQLClbController.clb_create
26+
27+
def format_ticket_data(self):
28+
super().format_ticket_data()
29+
30+
31+
@builders.BuilderFactory.register(TicketType.ES_CREATE_CLB)
32+
class EsCreatePolarisFlowBuilder(BaseEsTicketFlowBuilder):
33+
serializer = EsCreatePolarisDetailSerializer
34+
inner_flow_builder = EsCreatePolarisFlowParamBuilder
35+
inner_flow_name = _("创建北极星")
36+
default_need_itsm = False
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-Add commentMore actions
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
12+
from django.utils.translation import ugettext_lazy as _
13+
14+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
15+
from backend.ticket import builders
16+
from backend.ticket.builders.common.bigdata import BaseEsTicketFlowBuilder, BigDataSingleClusterOpsDetailsSerializer
17+
from backend.ticket.constants import TicketType
18+
19+
20+
class EsDeletePolarisDetailSerializer(BigDataSingleClusterOpsDetailsSerializer):
21+
pass
22+
23+
24+
class EsDeletePolarisFlowParamBuilder(builders.FlowParamBuilder):
25+
controller = MySQLClbController.clb_create
26+
27+
def format_ticket_data(self):
28+
super().format_ticket_data()
29+
30+
31+
@builders.BuilderFactory.register(TicketType.ES_CREATE_CLB)
32+
class EsDeletePolarisFlowBuilder(BaseEsTicketFlowBuilder):
33+
serializer = EsDeletePolarisDetailSerializer
34+
inner_flow_builder = EsDeletePolarisFlowParamBuilder
35+
inner_flow_name = _("删除北极星")
36+
default_need_itsm = False
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
12+
from django.utils.translation import ugettext_lazy as _
13+
14+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
15+
from backend.ticket import builders
16+
from backend.ticket.builders.common.bigdata import BaseEsTicketFlowBuilder, BigDataSingleClusterOpsDetailsSerializer
17+
from backend.ticket.constants import TicketType
18+
19+
20+
class EsDnsBindCLBDetailSerializer(BigDataSingleClusterOpsDetailsSerializer):
21+
pass
22+
23+
24+
class EsDnsBindCLBFlowParamBuilder(builders.FlowParamBuilder):
25+
controller = MySQLClbController.clb_create
26+
27+
def format_ticket_data(self):
28+
super().format_ticket_data()
29+
30+
31+
@builders.BuilderFactory.register(TicketType.ES_CREATE_CLB)
32+
class EsDnsBindCLBFlowBuilder(BaseEsTicketFlowBuilder):
33+
serializer = EsDnsBindCLBDetailSerializer
34+
inner_flow_builder = EsDnsBindCLBFlowParamBuilder
35+
inner_flow_name = _("主域名绑定CLB")
36+
default_need_itsm = False
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
12+
from django.utils.translation import ugettext_lazy as _
13+
14+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
15+
from backend.ticket import builders
16+
from backend.ticket.builders.common.bigdata import BaseEsTicketFlowBuilder, BigDataSingleClusterOpsDetailsSerializer
17+
from backend.ticket.constants import TicketType
18+
19+
20+
class EsDnsUnBindCLBDetailSerializer(BigDataSingleClusterOpsDetailsSerializer):
21+
pass
22+
23+
24+
class EsDnsUnBindCLBFlowParamBuilder(builders.FlowParamBuilder):
25+
controller = MySQLClbController.clb_create
26+
27+
def format_ticket_data(self):
28+
super().format_ticket_data()
29+
30+
31+
@builders.BuilderFactory.register(TicketType.ES_CREATE_CLB)
32+
class EsDnsUnBindCLBFlowBuilder(BaseEsTicketFlowBuilder):
33+
serializer = EsDnsUnBindCLBDetailSerializer
34+
inner_flow_builder = EsDnsUnBindCLBFlowParamBuilder
35+
inner_flow_name = _("主域名解绑CLB")
36+
default_need_itsm = False

dbm-ui/backend/ticket/builders/mysql/base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ class MySQLBasePauseParamBuilder(builders.PauseParamBuilder):
5656
pass
5757

5858

59+
class MysqlSingleOpsBaseDetailSerializer(SkipToRepresentationMixin, serializers.Serializer):
60+
cluster_id = serializers.IntegerField(help_text=_("集群ID"))
61+
bk_cloud_id = serializers.IntegerField(help_text=_("云区域ID"))
62+
spider_role = serializers.CharField(help_text=_("接入层角色"), required=False)
63+
64+
def validate(self, attrs):
65+
"""
66+
公共校验:集群操作互斥校验
67+
"""
68+
super().validate(attrs)
69+
return attrs
70+
71+
5972
class MySQLBaseOperateDetailSerializer(
6073
SkipToRepresentationMixin, ParamValidateSerializerMixin, serializers.Serializer
6174
):
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-Add commentMore actions
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from django.utils.translation import ugettext_lazy as _
12+
13+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
14+
from backend.ticket import builders
15+
from backend.ticket.builders.mysql.base import BaseMySQLHATicketFlowBuilder, MysqlSingleOpsBaseDetailSerializer
16+
from backend.ticket.constants import TicketType
17+
18+
19+
class MysqlAddCLBDetailSerializer(MysqlSingleOpsBaseDetailSerializer):
20+
pass
21+
22+
23+
class MysqlAddCLBFlowParamBuilder(builders.FlowParamBuilder):
24+
controller = MySQLClbController.clb_create
25+
26+
def format_ticket_data(self):
27+
"""
28+
{
29+
"uid": "22346",
30+
"created_by": "makeyuan",
31+
"bk_biz_id": "20",
32+
"bk_cloud_id": 0,
33+
"ticket_type": "MYSQL_ADD_CLB",
34+
"cluster_id": 98
35+
}
36+
"""
37+
super().format_ticket_data()
38+
39+
40+
@builders.BuilderFactory.register(TicketType.MYSQL_ADD_CLB)
41+
class MysqlAddCLBFlowBuilder(BaseMySQLHATicketFlowBuilder):
42+
serializer = MysqlAddCLBDetailSerializer
43+
inner_flow_builder = MysqlAddCLBFlowParamBuilder
44+
inner_flow_name = _("创建CLB")
45+
default_need_itsm = False
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-Add commentMore actions
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from django.utils.translation import ugettext_lazy as _
12+
13+
from backend.flow.engine.controller.mysql_clb_operation import MySQLClbController
14+
from backend.ticket import builders
15+
from backend.ticket.builders.mysql.base import BaseMySQLHATicketFlowBuilder, MysqlSingleOpsBaseDetailSerializer
16+
from backend.ticket.constants import TicketType
17+
18+
19+
class MysqlCLBBindDomainDetailSerializer(MysqlSingleOpsBaseDetailSerializer):
20+
pass
21+
22+
23+
class MysqlCLBBindDomainFlowParamBuilder(builders.FlowParamBuilder):
24+
controller = MySQLClbController.clb_create
25+
26+
def format_ticket_data(self):
27+
"""
28+
{
29+
"uid": "22346",
30+
"created_by": "makeyuan",
31+
"bk_biz_id": "20",
32+
"bk_cloud_id": 0,
33+
"ticket_type": "MYSQL_CLB_BIND_DOMAIN",
34+
"cluster_id": 91
35+
}
36+
"""
37+
super().format_ticket_data()
38+
39+
40+
@builders.BuilderFactory.register(TicketType.MYSQL_CLB_BIND_DOMAIN)
41+
class MysqlCLBBindDomainFlowBuilder(BaseMySQLHATicketFlowBuilder):
42+
serializer = MysqlCLBBindDomainDetailSerializer
43+
inner_flow_builder = MysqlCLBBindDomainFlowParamBuilder
44+
inner_flow_name = _("主域名绑定CLB")
45+
default_need_itsm = False

0 commit comments

Comments
 (0)