From e8ae41b35b0c0858e9324161240a78a70e7129bd Mon Sep 17 00:00:00 2001 From: lvy010 <17338770572@163.com> Date: Sun, 1 Feb 2026 21:46:10 +0800 Subject: [PATCH] chore: move log models under buck2 types Signed-off-by: lvy010 <17338770572@163.com> --- api-model/src/buck2/types.rs | 72 +++++++++++++++++++++++++++++ api-model/src/lib.rs | 1 - api-model/src/orion/log.rs | 72 ----------------------------- api-model/src/orion/mod.rs | 1 - orion-server/src/api.rs | 16 +++---- orion-server/src/log/log_service.rs | 2 +- orion-server/src/server.rs | 13 +++--- 7 files changed, 87 insertions(+), 90 deletions(-) delete mode 100644 api-model/src/orion/log.rs delete mode 100644 api-model/src/orion/mod.rs diff --git a/api-model/src/buck2/types.rs b/api-model/src/buck2/types.rs index 4bd557d82..404b34044 100644 --- a/api-model/src/buck2/types.rs +++ b/api-model/src/buck2/types.rs @@ -39,3 +39,75 @@ impl ProjectRelativePath { opt.map(|s| Self(s.to_owned())) } } + +/// Supported read modes for log APIs. +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq, Default)] +#[serde(rename_all = "lowercase")] +pub enum LogReadMode { + #[default] + Full, + Segment, +} + +/// Log stream event emitted by Orion worker/build processing. +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct LogEvent { + pub task_id: String, + pub repo_name: String, + pub build_id: String, + pub line: String, + pub is_end: bool, +} + +/// Log segment read result. +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct LogSegment { + pub build_id: String, + pub offset: u64, + pub len: usize, + pub data: String, + pub next_offset: u64, + pub file_size: u64, + /// Whether we reached end of file + pub eof: bool, +} + +/// Query parameters for target log APIs. +#[derive(Debug, Clone, Deserialize, ToSchema)] +pub struct TargetLogQuery { + #[serde(default)] + pub r#type: LogReadMode, + pub offset: Option, + pub limit: Option, +} + +/// Query parameters for task history log APIs. +#[derive(Debug, Clone, Deserialize, ToSchema)] +pub struct TaskHistoryQuery { + pub task_id: String, + pub build_id: String, + pub repo: String, + pub start: Option, + pub end: Option, +} + +/// Log lines response for history reads. +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct LogLinesResponse { + pub data: Vec, + pub len: usize, +} + +/// Log lines response for target reads. +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct TargetLogLinesResponse { + pub data: Vec, + pub len: usize, + pub build_id: String, +} + +/// Error response for log-related APIs. +#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] +pub struct LogErrorResponse { + pub message: String, +} diff --git a/api-model/src/lib.rs b/api-model/src/lib.rs index bba18105e..14296a0e1 100644 --- a/api-model/src/lib.rs +++ b/api-model/src/lib.rs @@ -1,4 +1,3 @@ pub mod buck2; pub mod common; pub mod git; -pub mod orion; diff --git a/api-model/src/orion/log.rs b/api-model/src/orion/log.rs deleted file mode 100644 index 4f06ae050..000000000 --- a/api-model/src/orion/log.rs +++ /dev/null @@ -1,72 +0,0 @@ -use serde::{Deserialize, Serialize}; -use utoipa::ToSchema; - -/// Supported read modes for log APIs. -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, PartialEq, Eq, Default)] -#[serde(rename_all = "lowercase")] -pub enum LogReadMode { - #[default] - Full, - Segment, -} - -/// Log stream event emitted by Orion worker/build processing. -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -pub struct LogEvent { - pub task_id: String, - pub repo_name: String, - pub build_id: String, - pub line: String, - pub is_end: bool, -} - -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -pub struct LogSegment { - pub build_id: String, - pub offset: u64, - pub len: usize, - pub data: String, - pub next_offset: u64, - pub file_size: u64, - pub eof: bool, -} - -/// Query parameters for target log APIs. -#[derive(Debug, Clone, Deserialize, ToSchema)] -pub struct TargetLogQuery { - #[serde(default)] - pub r#type: LogReadMode, - pub offset: Option, - pub limit: Option, -} - -/// Query parameters for task history log APIs. -#[derive(Debug, Clone, Deserialize, ToSchema)] -pub struct TaskHistoryQuery { - pub task_id: String, - pub build_id: String, - pub repo: String, - pub start: Option, - pub end: Option, -} - -/// Log lines response for history reads. -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -pub struct LogLinesResponse { - pub data: Vec, - pub len: usize, -} - -/// Log lines response for target reads. -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -pub struct TargetLogLinesResponse { - pub data: Vec, - pub len: usize, - pub build_id: String, -} - -/// Error response for log-related APIs. -#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)] -pub struct LogErrorResponse { - pub message: String, -} diff --git a/api-model/src/orion/mod.rs b/api-model/src/orion/mod.rs deleted file mode 100644 index f4ee9bc8d..000000000 --- a/api-model/src/orion/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod log; diff --git a/orion-server/src/api.rs b/orion-server/src/api.rs index f9546cb47..5bdb61040 100644 --- a/orion-server/src/api.rs +++ b/orion-server/src/api.rs @@ -4,7 +4,7 @@ use std::{ }; use anyhow::Result; -use api_model::orion::log::{ +use api_model::buck2::types::{ LogErrorResponse, LogEvent, LogLinesResponse, LogReadMode, TargetLogLinesResponse, TargetLogQuery, TaskHistoryQuery, }; @@ -263,10 +263,10 @@ pub async fn task_output_handler( ("end" = Option, Query, description = "End line number"), ), responses( - (status = 200, description = "History Log", body = api_model::orion::log::LogLinesResponse), - (status = 400, description = "Invalid parameters", body = api_model::orion::log::LogErrorResponse), - (status = 404, description = "Log file not found", body = api_model::orion::log::LogErrorResponse), - (status = 500, description = "Failed to operate log file", body = api_model::orion::log::LogErrorResponse), + (status = 200, description = "History Log", body = api_model::buck2::types::LogLinesResponse), + (status = 400, description = "Invalid parameters", body = api_model::buck2::types::LogErrorResponse), + (status = 404, description = "Log file not found", body = api_model::buck2::types::LogErrorResponse), + (status = 500, description = "Failed to operate log file", body = api_model::buck2::types::LogErrorResponse), ) )] pub async fn task_history_output_handler( @@ -323,10 +323,10 @@ pub async fn task_history_output_handler( ( status = 200, description = "Target log content", - body = api_model::orion::log::TargetLogLinesResponse + body = api_model::buck2::types::TargetLogLinesResponse ), - (status = 404, description = "Target or log not found", body = api_model::orion::log::LogErrorResponse), - (status = 500, description = "Failed to read log", body = api_model::orion::log::LogErrorResponse) + (status = 404, description = "Target or log not found", body = api_model::buck2::types::LogErrorResponse), + (status = 500, description = "Failed to read log", body = api_model::buck2::types::LogErrorResponse) ) )] pub async fn target_logs_handler( diff --git a/orion-server/src/log/log_service.rs b/orion-server/src/log/log_service.rs index 04ef685fa..01e12e08a 100644 --- a/orion-server/src/log/log_service.rs +++ b/orion-server/src/log/log_service.rs @@ -1,6 +1,6 @@ use std::{path::Path, sync::Arc}; -use api_model::orion::log::LogEvent; +use api_model::buck2::types::LogEvent; use futures::{Stream, StreamExt}; use tokio_stream::wrappers::BroadcastStream; diff --git a/orion-server/src/server.rs b/orion-server/src/server.rs index eabd12f9a..7103efde5 100644 --- a/orion-server/src/server.rs +++ b/orion-server/src/server.rs @@ -44,16 +44,15 @@ use crate::{ components( schemas( crate::scheduler::BuildRequest, - api_model::orion::log::LogSegment, - api_model::orion::log::LogLinesResponse, - api_model::orion::log::TargetLogLinesResponse, - api_model::orion::log::LogErrorResponse, + api_model::buck2::types::LogLinesResponse, + api_model::buck2::types::TargetLogLinesResponse, + api_model::buck2::types::LogErrorResponse, api::TaskStatusEnum, api::BuildDTO, api::TargetDTO, - api_model::orion::log::TargetLogQuery, - api_model::orion::log::LogReadMode, - api_model::orion::log::TaskHistoryQuery, + api_model::buck2::types::TargetLogQuery, + api_model::buck2::types::LogReadMode, + api_model::buck2::types::TaskHistoryQuery, api::TaskInfoDTO, api::OrionClientInfo, api::OrionClientStatus,