Skip to content

Commit

Permalink
fix(backend): mongodb 集群容量变更协议调整 #3602
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Mar 21, 2024
1 parent 4d02a52 commit ca10db6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions dbm-ui/backend/db_services/dbresource/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ class ResourceHandler(object):
@classmethod
def spec_resource_count(cls, bk_biz_id: int, bk_cloud_id: int, spec_ids: List[int]):
specs = Spec.objects.filter(spec_id__in=spec_ids)
if not specs.exists():
return {}
# 获取resource_type
spec_cluster_type = list(set(specs.values_list("spec_cluster_type", flat=True)))
if len(spec_cluster_type) > 1:
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/db_services/mongodb/resources/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _to_cluster_representation(
).count()
shard_node_count = len(mongodb) / shard_num

# 获取mongodb总机器数量、机器组数、单机部署实例数
# 获取单机部署实例数、mongodb总机器数量、机器组数
machine_instance_num = mongodb_insts[0].machine.storageinstance_set.count()
mongodb_machine_num = len(set([m.machine.bk_host_id for m in mongodb_insts]))
mongodb_machine_pair = mongodb_machine_num // shard_node_count
Expand Down
18 changes: 17 additions & 1 deletion dbm-ui/backend/ticket/builders/mongodb/mongo_scale_updown.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
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 collections import defaultdict
from typing import Dict, List

from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers

from backend.db_meta.models import Cluster
from backend.db_services.dbbase.constants import IpSource
from backend.flow.engine.controller.mongodb import MongoDBController
from backend.ticket import builders
Expand Down Expand Up @@ -71,14 +75,26 @@ def format(self):

def post_callback(self):
with self.next_flow_manager() as next_flow:
cluster_ids = [info["cluster_id"] for info in next_flow.details["ticket_data"]["infos"]]
id__cluster = Cluster.objects.filter(id__in=cluster_ids)

mongo_type__apply_infos: Dict[str, List] = defaultdict(list)
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"])
# 补充集群信息
cluster = id__cluster[info["cluster_id"]]
info["db_version"] = cluster.major_version
info["disaster_tolerance_level"] = cluster.disaster_tolerance_level
# 根据mongo集群类型归类
mongo_type__apply_infos[cluster.cluster_type].append(info)

next_flow.details["ticket_data"]["infos"] = mongo_type__apply_infos


@builders.BuilderFactory.register(TicketType.MONGODB_SCALE_UPDOWN, is_apply=True)
class MongoDBAddMongosApplyFlowBuilder(BaseMongoDBTicketFlowBuilder):
class MongoDBScaleUpDownFlowBuilder(BaseMongoDBTicketFlowBuilder):
serializer = MongoDBScaleUpDownDetailSerializer
inner_flow_builder = MongoDBScaleUpDownFlowParamBuilder
inner_flow_name = _("MongoDB 集群容量变更执行")
Expand Down

0 comments on commit ca10db6

Please sign in to comment.