Skip to content

Commit

Permalink
feat(backend): mangos 扩缩容接入层联调 #3557
Browse files Browse the repository at this point in the history
  • Loading branch information
ygcyao authored and zhangzhw8 committed Mar 19, 2024
1 parent e1007c2 commit 6649c1a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
11 changes: 11 additions & 0 deletions dbm-ui/backend/ticket/builders/mongodb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,17 @@ def add_cluster_type_info(cls, infos):
info["cluster_type"] = id__cluster[info["cluster_id"]].cluster_type
return infos

@classmethod
def add_cluster_info(cls, infos):
"""给每个info加上集群类型、版本信息、名称"""
cluster_ids = [info["cluster_id"] for info in infos]
id__cluster = {cluster.id: cluster for cluster in Cluster.objects.filter(id__in=cluster_ids)}
for info in infos:
info["cluster_type"] = id__cluster[info["cluster_id"]].cluster_type
info["db_version"] = id__cluster[info["cluster_id"]].major_version
info["cluster_name"] = id__cluster[info["cluster_id"]].name
return infos


class BaseMongoDBOperateResourceParamBuilder(BaseOperateResourceParamBuilder):
@classmethod
Expand Down
17 changes: 11 additions & 6 deletions dbm-ui/backend/ticket/builders/mongodb/mongo_add_mongos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rest_framework import serializers

from backend.db_meta.enums import ClusterType, MachineType
from backend.db_meta.models import AppCache
from backend.db_services.dbbase.constants import IpSource
from backend.flow.engine.controller.mongodb import MongoDBController
from backend.ticket import builders
Expand All @@ -20,8 +21,8 @@
BaseMongoDBOperateDetailSerializer,
BaseMongoDBOperateResourceParamBuilder,
BaseMongoDBTicketFlowBuilder,
BaseMongoOperateFlowParamBuilder,
)
from backend.ticket.builders.mongodb.mongo_backup import MongoDBBackupFlowParamBuilder
from backend.ticket.constants import TicketType


Expand All @@ -43,11 +44,13 @@ def validate(self, attrs):
return attrs


class MongoDBAddMongosFlowParamBuilder(builders.FlowParamBuilder):
controller = MongoDBController.fake_scene
class MongoDBAddMongosFlowParamBuilder(BaseMongoOperateFlowParamBuilder):
controller = MongoDBController.increase_mongos

def format_ticket_data(self):
MongoDBBackupFlowParamBuilder.add_cluster_type_info(self.ticket_data["infos"])
bk_biz_id = self.ticket_data["bk_biz_id"]
self.ticket_data["db_app_abbr"] = AppCache.objects.get(bk_biz_id=bk_biz_id).db_app_abbr
self.ticket_data["infos"] = self.add_cluster_info(self.ticket_data["infos"])


class MongoDBAddMongosResourceParamBuilder(BaseMongoDBOperateResourceParamBuilder):
Expand All @@ -58,8 +61,10 @@ def format(self):

def post_callback(self):
with self.next_flow_manager() as next_flow:
machine_specs = self.format_machine_specs(next_flow.details["ticket_data"]["resource_spec"])
next_flow.details["ticket_data"].update(machine_specs=machine_specs)
for info in next_flow.details["ticket_data"]["infos"]:
# 格式化mongodb节点信息和machine_specs规格信息
self.format_mongo_node_infos(info)
info["machine_specs"] = self.format_machine_specs(info["resource_spec"])


@builders.BuilderFactory.register(TicketType.MONGODB_ADD_MONGOS, is_apply=True)
Expand Down
16 changes: 11 additions & 5 deletions dbm-ui/backend/ticket/builders/mongodb/mongo_reduce_mongos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
from rest_framework import serializers

from backend.db_meta.enums import ClusterType, MachineType
from backend.db_meta.models import Cluster
from backend.db_meta.models import AppCache, Cluster
from backend.flow.engine.controller.mongodb import MongoDBController
from backend.ticket import builders
from backend.ticket.builders.common.base import CommonValidate, HostInfoSerializer
from backend.ticket.builders.mongodb.base import BaseMongoDBOperateDetailSerializer, BaseMongoDBTicketFlowBuilder
from backend.ticket.builders.mongodb.base import (
BaseMongoDBOperateDetailSerializer,
BaseMongoDBTicketFlowBuilder,
BaseMongoOperateFlowParamBuilder,
)
from backend.ticket.constants import TicketType


Expand Down Expand Up @@ -60,11 +64,13 @@ def validate(self, attrs):
return attrs


class MongoDBReduceMongosFlowParamBuilder(builders.FlowParamBuilder):
controller = MongoDBController.fake_scene
class MongoDBReduceMongosFlowParamBuilder(BaseMongoOperateFlowParamBuilder):
controller = MongoDBController.reduce_mongos

def format_ticket_data(self):
pass
bk_biz_id = self.ticket_data["bk_biz_id"]
self.ticket_data["db_app_abbr"] = AppCache.objects.get(bk_biz_id=bk_biz_id).db_app_abbr
self.ticket_data["infos"] = self.add_cluster_info(self.ticket_data["infos"])


@builders.BuilderFactory.register(TicketType.MONGODB_REDUCE_MONGOS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MongoShardedClusterApplyFlowParamBuilder(builders.FlowParamBuilder):

def format_ticket_data(self):
self.ticket_data["bk_app_abbr"] = self.ticket_data["db_app_abbr"]
self.ticket_data["proxy_port"] = self.ticket_data["start_port"]


class MongoShardedClusterResourceParamBuilder(BaseMongoDBOperateResourceParamBuilder):
Expand Down

0 comments on commit 6649c1a

Please sign in to comment.