Skip to content

Commit

Permalink
feat(backend): 镜像文件编译参数改造 & riak开发 #1688
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Nov 7, 2023
1 parent 4d2e0b7 commit 8d9c539
Show file tree
Hide file tree
Showing 25 changed files with 317 additions and 94 deletions.
3 changes: 2 additions & 1 deletion dbm-services/bigdata/db-tools/dbactuator/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
SHELL := /bin/bash
BASE_DIR = $(shell pwd)
VERSION = 0.0.1
GITHASH = ""
APPNAME = dbactuator
GOOS ?= linux
BUILD_FLAG = "-X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=`git rev-parse HEAD` "
BUILD_FLAG = "-X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=${GITHASH} "

.PHONY: all build clean

Expand Down
7 changes: 4 additions & 3 deletions dbm-services/mysql/db-tools/dbactuator/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
SHELL := /bin/bash
BASE_DIR = $(shell pwd)
VERSION = 0.0.1
GITHASH = ""
APPNAME = dbactuator
GOOS ?= linux
BUILD_FLAG = " -X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=`git rev-parse HEAD` "
BUILD_EXTERNAL_FLAG = " -X main.external=ON -X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=`git rev-parse HEAD` "
BUILD_MINI_FLAG = " -s -w -X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=`git rev-parse HEAD` "
BUILD_FLAG = " -X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=${GITHASH} "
BUILD_EXTERNAL_FLAG = " -X main.external=ON -X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=${GITHASH} "
BUILD_MINI_FLAG = " -s -w -X main.version=${VERSION} -X main.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.githash=${GITHASH} "

.PHONY: all build clean

Expand Down
3 changes: 2 additions & 1 deletion dbm-services/mysql/db-tools/mysql-crond/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
PROJ="mysql-crond"
MODULE="dbm-services/mysql/db-tools/mysql-crond"
VERSION = $(error please set VERSION flag)
GITHASH = ""
#VERSION=$(shell date +'%y%m%d.%H.%M')
PKG=${PROJ}.tar.gz
OUTPUT_DIR=build
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=`git rev-parse HEAD` "
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=${GITHASH} "
DEV_BUILD_FLAG = "-X ${MODULE}/cmd.version="develop" -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash="" "

.PHONY: release-bin
Expand Down
3 changes: 2 additions & 1 deletion dbm-services/mysql/db-tools/mysql-monitor/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
PROJ="mysql-monitor"
MODULE="dbm-services/mysql/db-tools/mysql-monitor"
VERSION = $(error please set VERSION flag)
GITHASH = ""
PKG = ${PROJ}.tar.gz
OUTPUT_DIR = build
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=`git rev-parse HEAD` "
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=${GITHASH} "
DEV_BUILD_FLAG = "-X ${MODULE}/cmd.version="develop" -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash="" "


Expand Down
3 changes: 2 additions & 1 deletion dbm-services/mysql/db-tools/mysql-rotatebinlog/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ PROJ="mysql-rotatebinlog"
PROJ_BIN="rotatebinlog"
MODULE="dbm-services/mysql/db-tools/mysql-rotatebinlog"
VERSION = $(error please set VERSION flag)
GITHASH = ""
PROJ_PKG = ${PROJ}.tar.gz
OUTPUT_DIR = build
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=`git rev-parse HEAD` "
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=${GITHASH} "
BETA_BUILD_FLAG = "-X ${MODULE}/cmd.version="develop" -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash="" "
BASE_DIR = $(shell pwd)

Expand Down
3 changes: 2 additions & 1 deletion dbm-services/mysql/db-tools/mysql-table-checksum/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
PROJ="mysql-table-checksum"
MODULE="dbm-services/mysql/db-tools/mysql-table-checksum"
VERSION = $(error please set VERSION flag)
GITHASH = ""
PKG="mysql-checksum.tar.gz" # 这是个不太好改的错误了
OUTPUT_DIR=build
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=`git rev-parse HEAD` "
RELEASE_BUILD_FLAG = "-X ${MODULE}/cmd.version=${VERSION} -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash=${GITHASH} "
DEV_BUILD_FLAG = "-X ${MODULE}/cmd.version="develop" -X ${MODULE}/cmd.buildStamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X ${MODULE}/cmd.gitHash="" "

.PHONY: release-bin
Expand Down
3 changes: 2 additions & 1 deletion dbm-services/redis/db-tools/dbactuator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ SHELL := /bin/bash
BASE_DIR = $(shell pwd)
SRV_NAME=dbactuator_redis
VERSION = 0.0.1
GITHASH = ""

PACKAGE_PATH="dbm-services/redis/db-tools/dbactuator/cmd"

BUILD_FLAG = " -X ${PACKAGE_PATH}.version=${VERSION} -X ${PACKAGE_PATH}.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%z'` -X ${PACKAGE_PATH}.githash=`git rev-parse HEAD` "
BUILD_FLAG = " -X ${PACKAGE_PATH}.version=${VERSION} -X ${PACKAGE_PATH}.buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%z'` -X ${PACKAGE_PATH}.githash=${GITHASH} "

build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags="all=-trimpath=${PWD}" -asmflags="all=-trimpath=${PWD}" -ldflags ${BUILD_FLAG} -o ${BASE_DIR}/build/$(SRV_NAME) -v main.go
Expand Down
25 changes: 25 additions & 0 deletions dbm-ui/backend/db_meta/api/cluster/riak/detail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- 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.
"""

from django.utils.translation import gettext as _

from backend.db_meta.api.cluster.base.graph import Graphic, LineLabel
from backend.db_meta.enums import InstanceRole
from backend.db_meta.models import Cluster


def scan_cluster(cluster: Cluster) -> Graphic:
"""
绘制kafka的拓扑结构图
"""
graph = Graphic(node_id=Graphic.generate_graphic_id(cluster))
graph.add_instance_nodes(cluster=cluster, roles=InstanceRole.RIAK_NODE, group_name=_("Riak 节点"))
return graph
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_package/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create(self, request, *args, **kwargs):
@action(methods=["POST"], detail=False, serializer_class=UpdateOrCreateSerializer)
def update_or_create(self, request, *args, **kwargs):
data = self.params_validate(self.get_serializer_class())
Package.objects.update_or_create(md5=data["md5"], defaults=data)
Package.objects.update_or_create(md5=data["md5"], db_type=data["db_type"], defaults=data)
return Response()

@common_swagger_auto_schema(
Expand Down
10 changes: 10 additions & 0 deletions dbm-ui/backend/db_services/bigdata/riak/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- 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.
"""
12 changes: 12 additions & 0 deletions dbm-ui/backend/db_services/bigdata/riak/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- 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.
"""

RESOURCE_TAG = "db_services/resources/riak"
34 changes: 34 additions & 0 deletions dbm-ui/backend/db_services/bigdata/riak/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- 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.
"""

from django.utils.translation import ugettext_lazy as _

from backend.db_meta.api.cluster.riak.detail import scan_cluster
from backend.db_meta.enums import InstanceRole
from backend.db_meta.enums.cluster_type import ClusterType
from backend.db_meta.models import Cluster
from backend.db_services.bigdata.resources.query import BigDataBaseListRetrieveResource


class RiakListRetrieveResource(BigDataBaseListRetrieveResource):

cluster_types = [ClusterType.Riak]
instance_roles = [InstanceRole.RIAK_NODE]
fields = [
*BigDataBaseListRetrieveResource.fields,
{"name": _("riak节点"), "key": "riak_node"},
]

@classmethod
def get_topo_graph(cls, bk_biz_id: int, cluster_id: int) -> dict:
cluster = Cluster.objects.get(bk_biz_id=bk_biz_id, id=cluster_id)
graph = scan_cluster(cluster).to_dict()
return graph
19 changes: 19 additions & 0 deletions dbm-ui/backend/db_services/bigdata/riak/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- 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.
"""

from rest_framework.routers import DefaultRouter

from backend.db_services.bigdata.riak.views import RiakClusterViewSet

router = DefaultRouter(trailing_slash=True)
router.register(r"riak_resources", RiakClusterViewSet, basename="riak_resources")

urlpatterns = router.urls
75 changes: 75 additions & 0 deletions dbm-ui/backend/db_services/bigdata/riak/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- 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.
"""
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from rest_framework import status

from backend.bk_web.swagger import common_swagger_auto_schema
from backend.db_services.bigdata.kafka import constants
from backend.db_services.bigdata.resources import yasg_slz
from backend.db_services.bigdata.resources.views import ResourceViewSet
from backend.db_services.bigdata.riak.query import RiakListRetrieveResource
from backend.db_services.dbbase.resources import serializers


@method_decorator(
name="list",
decorator=common_swagger_auto_schema(
operation_summary=_("获取集群列表"),
query_serializer=serializers.ListResourceSLZ(),
responses={status.HTTP_200_OK: yasg_slz.PaginatedResourceSLZ()},
tags=[constants.RESOURCE_TAG],
),
)
@method_decorator(
name="retrieve",
decorator=common_swagger_auto_schema(
operation_summary=_("获取集群详情"),
responses={status.HTTP_200_OK: yasg_slz.ResourceSLZ()},
tags=[constants.RESOURCE_TAG],
),
)
@method_decorator(
name="list_instances",
decorator=common_swagger_auto_schema(
operation_summary=_("获取实例列表"),
query_serializer=serializers.ListInstancesSerializer(),
responses={status.HTTP_200_OK: yasg_slz.PaginatedResourceSLZ()},
tags=[constants.RESOURCE_TAG],
),
)
@method_decorator(
name="retrieve_instance",
decorator=common_swagger_auto_schema(
operation_summary=_("获取实例详情"),
query_serializer=serializers.RetrieveInstancesSerializer(),
tags=[constants.RESOURCE_TAG],
),
)
@method_decorator(
name="get_table_fields",
decorator=common_swagger_auto_schema(
operation_summary=_("获取查询返回字段"),
responses={status.HTTP_200_OK: yasg_slz.ResourceFieldSLZ()},
tags=[constants.RESOURCE_TAG],
),
)
@method_decorator(
name="get_topo_graph",
decorator=common_swagger_auto_schema(
operation_summary=_("获取集群拓扑"),
responses={status.HTTP_200_OK: yasg_slz.ResourceTopoGraphSLZ()},
tags=[constants.RESOURCE_TAG],
),
)
class RiakClusterViewSet(ResourceViewSet):
query_class = RiakListRetrieveResource
query_serializer_class = serializers.ListResourceSLZ
1 change: 1 addition & 0 deletions dbm-ui/backend/db_services/bigdata/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
path("bizs/<int:bk_biz_id>/kafka/", include("backend.db_services.bigdata.kafka.urls")),
path("bizs/<int:bk_biz_id>/pulsar/", include("backend.db_services.bigdata.pulsar.urls")),
path("bizs/<int:bk_biz_id>/influxdb/", include("backend.db_services.bigdata.influxdb.urls")),
path("bizs/<int:bk_biz_id>/riak/", include("backend.db_services.bigdata.riak.urls")),
]
Loading

0 comments on commit 8d9c539

Please sign in to comment.