Skip to content

Commit

Permalink
fix(backend): 增加聚合启用规格过滤参数 #8348
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud committed Dec 3, 2024
1 parent 02a0589 commit 5b8263b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions dbm-ui/backend/db_services/dbresource/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class ResourceSummarySerializer(serializers.Serializer):
help_text=_("集群类型"), choices=SpecClusterType.get_choices(), required=False, default=""
)
spec_id_list = serializers.CharField(help_text=_("规格ID"), required=False, default="")
enable_spec = serializers.BooleanField(help_text=_("仅聚合启用规格"), required=False, default=False)

for_biz = serializers.IntegerField(help_text=_("专用业务ID"), required=False, default=0)
city = serializers.CharField(help_text=_("城市名"), required=False, allow_blank=True)
Expand Down
21 changes: 13 additions & 8 deletions dbm-ui/backend/db_services/taskflow/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
RevokePipelineException,
SkipNodeException,
)
from backend.flow.consts import StateType
from backend.flow.consts import PENDING_STATES, StateType
from backend.flow.engine.bamboo.engine import BambooEngine
from backend.flow.models import FlowNode, FlowTree
from backend.utils.string import format_json_string
Expand All @@ -52,7 +52,7 @@ def revoke_pipeline(self):

# 如果当前的pipeline未被创建,则直接更新FlowTree的状态为撤销态
tree = FlowTree.objects.get(root_id=self.root_id)
if tree.status in [StateType.CREATED, StateType.READY]:
if tree.status in PENDING_STATES:
tree.status = StateType.REVOKED
tree.save()
return EngineAPIResult(result=True, message=_("pipeline未创建,仅更新FlowTree"))
Expand Down Expand Up @@ -209,15 +209,20 @@ def bklog_esquery_search(indices, query_string, start_time, end_time):

def get_version_logs(self, node_id: str, version_id: str) -> List[Dict[str, Dict[str, str]]]:
"""获取节点的日志信息"""
try:
flow_node = FlowNode.objects.get(root_id=self.root_id, node_id=node_id)
except FlowNode.DoesNotExist:
if not FlowNode.objects.filter(root_id=self.root_id, node_id=node_id).count():
return [self.generate_log_record(message=_("节点尚未运行,请稍后查看"))]
if flow_node.updated_at < timezone.now() - timedelta(days=env.BKLOG_DEFAULT_RETENTION):

try:
node_histories_map = {h["version"]: h for h in self.get_node_histories(node_id)}
history = node_histories_map[version_id]
except KeyError:
return [self.generate_log_record(message=_("无法找到当前版本{}的节点日志").format(version_id))]

if history["finished_time"] < timezone.now() - timedelta(days=env.BKLOG_DEFAULT_RETENTION):
return [self.generate_log_record(message=_("节点日志仅保留{}天").format(env.BKLOG_DEFAULT_RETENTION))]

start_time = datetime2str(flow_node.started_at)
end_time = datetime2str(flow_node.updated_at + timedelta(days=7))
start_time = datetime2str(history["started_time"])
end_time = datetime2str(history["finished_time"] + timedelta(days=1))
dbm_logs = self.bklog_esquery_search(
indices=f"{env.DBA_APP_BK_BIZ_ID}_bklog.dbm_log",
query_string=f"({self.root_id} AND {node_id} AND {version_id})"
Expand Down
4 changes: 2 additions & 2 deletions dbm-ui/backend/flow/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
DEPENDENCIES_PLUGINS = ["bkmonitorbeat", "bkunifylogbeat"]
BIGDATA_DEPEND_PLUGINS = ["bkmonitorbeat"]


# 默认flow缓存数据过期时间:7天
DEFAULT_FLOW_CACHE_EXPIRE_TIME = 7 * 24 * 60 * 60

Expand Down Expand Up @@ -175,8 +174,9 @@ class StateType(str, StructuredEnum):
EXPIRED = EnumField("EXPIRED", _("已过期"))


PENDING_STATES = [StateType.CREATED.value, StateType.READY.value]
FAILED_STATES = [StateType.FAILED.value, StateType.REVOKED.value]
SUCCEED_STATES = [StateType.FINISHED]
SUCCEED_STATES = [StateType.FINISHED.value]

# 备份系统文件TAG
BACKUP_TAG = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def get_replicaset_resource_spec(cls, ticket_data):
"resource_spec": {
"mongo_machine_set": {
**spec.get_spec_info(),
"spec_name": spec.spec_name,
"affinity": ticket_data["disaster_tolerance_level"],
"location_spec": {"city": ticket_data["city_code"], "sub_zone_ids": []},
# 副本集的亲和性要求至少跨两个机房
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/backend/ticket/builders/redis/redis_destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class RedisInstanceDestroyDetailSerializer(SkipToRepresentationMixin, serializer


class RedisInstanceDestroyFlowParamBuilder(builders.FlowParamBuilder):
controller = RedisController.fake_scene
controller = RedisController.redis_ins_shutdown


@builders.BuilderFactory.register(TicketType.REDIS_INSTANCE_DESTROY, phase=ClusterPhase.DESTROY)
Expand Down

0 comments on commit 5b8263b

Please sign in to comment.