Browse Source

Convert to lib+bin crate and fix axum route parameter syntax for 0.7

Adds lib.rs re-exporting all public modules for integration test access.
Refactors main.rs to import from seaweed_volume:: lib crate. Fixes route
parameter syntax from {path} (axum 0.8) to :path (axum 0.7) — the old
brace syntax silently failed to match requests.
rust-volume-server
Chris Lu 6 days ago
parent
commit
d081198a0e
  1. 18
      seaweed-volume/src/lib.rs
  2. 40
      seaweed-volume/src/main.rs
  3. 13
      seaweed-volume/src/server/volume_server.rs

18
seaweed-volume/src/lib.rs

@ -0,0 +1,18 @@
pub mod config;
pub mod storage;
pub mod security;
pub mod server;
pub mod metrics;
/// Generated protobuf modules.
pub mod pb {
pub mod remote_pb {
tonic::include_proto!("remote_pb");
}
pub mod volume_server_pb {
tonic::include_proto!("volume_server_pb");
}
pub mod master_pb {
tonic::include_proto!("master_pb");
}
}

40
seaweed-volume/src/main.rs

@ -1,32 +1,15 @@
mod config;
mod storage;
mod security;
mod server;
/// Generated protobuf modules.
pub mod pb {
pub mod remote_pb {
tonic::include_proto!("remote_pb");
}
pub mod volume_server_pb {
tonic::include_proto!("volume_server_pb");
}
pub mod master_pb {
tonic::include_proto!("master_pb");
}
}
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use tracing::{info, error}; use tracing::{info, error};
use crate::config::VolumeServerConfig;
use crate::security::{Guard, SigningKey};
use crate::server::grpc_server::VolumeGrpcService;
use crate::server::volume_server::VolumeServerState;
use crate::storage::store::Store;
use crate::storage::types::DiskType;
use crate::pb::volume_server_pb::volume_server_server::VolumeServerServer;
use seaweed_volume::config::{self, VolumeServerConfig};
use seaweed_volume::metrics;
use seaweed_volume::security::{Guard, SigningKey};
use seaweed_volume::server::grpc_server::VolumeGrpcService;
use seaweed_volume::server::volume_server::VolumeServerState;
use seaweed_volume::storage::store::Store;
use seaweed_volume::storage::types::DiskType;
use seaweed_volume::pb::volume_server_pb::volume_server_server::VolumeServerServer;
fn main() { fn main() {
// Initialize tracing // Initialize tracing
@ -40,6 +23,9 @@ fn main() {
let config = config::parse_cli(); let config = config::parse_cli();
info!("SeaweedFS Volume Server (Rust) v{}", env!("CARGO_PKG_VERSION")); info!("SeaweedFS Volume Server (Rust) v{}", env!("CARGO_PKG_VERSION"));
// Register Prometheus metrics
metrics::register_metrics();
// Build the tokio runtime and run the async entry point // Build the tokio runtime and run the async entry point
let rt = tokio::runtime::Builder::new_multi_thread() let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
@ -94,7 +80,7 @@ async fn run(config: VolumeServerConfig) {
}); });
// Build HTTP routers // Build HTTP routers
let admin_router = server::volume_server::build_admin_router(state.clone());
let admin_router = seaweed_volume::server::volume_server::build_admin_router(state.clone());
let admin_addr = format!("{}:{}", config.bind_ip, config.port); let admin_addr = format!("{}:{}", config.bind_ip, config.port);
let public_port = config.public_port; let public_port = config.public_port;
@ -160,7 +146,7 @@ async fn run(config: VolumeServerConfig) {
}); });
let public_handle = if needs_public { let public_handle = if needs_public {
let public_router = server::volume_server::build_public_router(state.clone());
let public_router = seaweed_volume::server::volume_server::build_public_router(state.clone());
let public_addr = format!("{}:{}", config.bind_ip, public_port); let public_addr = format!("{}:{}", config.bind_ip, public_port);
let listener = tokio::net::TcpListener::bind(&public_addr) let listener = tokio::net::TcpListener::bind(&public_addr)
.await .await

13
seaweed-volume/src/server/volume_server.rs

@ -30,9 +30,10 @@ pub fn build_admin_router(state: Arc<VolumeServerState>) -> Router {
Router::new() Router::new()
.route("/status", get(handlers::status_handler)) .route("/status", get(handlers::status_handler))
.route("/healthz", get(handlers::healthz_handler)) .route("/healthz", get(handlers::healthz_handler))
.route("/metrics", get(handlers::metrics_handler))
// Volume operations: GET/HEAD/POST/PUT/DELETE on /{vid},{fid} // Volume operations: GET/HEAD/POST/PUT/DELETE on /{vid},{fid}
.route( .route(
"/{path}",
"/:path",
get(handlers::get_or_head_handler) get(handlers::get_or_head_handler)
.head(handlers::get_or_head_handler) .head(handlers::get_or_head_handler)
.post(handlers::post_handler) .post(handlers::post_handler)
@ -41,7 +42,7 @@ pub fn build_admin_router(state: Arc<VolumeServerState>) -> Router {
) )
// Also support /{vid}/{fid} and /{vid}/{fid}/{filename} paths // Also support /{vid}/{fid} and /{vid}/{fid}/{filename} paths
.route( .route(
"/{vid}/{fid}",
"/:vid/:fid",
get(handlers::get_or_head_handler) get(handlers::get_or_head_handler)
.head(handlers::get_or_head_handler) .head(handlers::get_or_head_handler)
.post(handlers::post_handler) .post(handlers::post_handler)
@ -49,7 +50,7 @@ pub fn build_admin_router(state: Arc<VolumeServerState>) -> Router {
.delete(handlers::delete_handler), .delete(handlers::delete_handler),
) )
.route( .route(
"/{vid}/{fid}/{filename}",
"/:vid/:fid/:filename",
get(handlers::get_or_head_handler) get(handlers::get_or_head_handler)
.head(handlers::get_or_head_handler), .head(handlers::get_or_head_handler),
) )
@ -61,17 +62,17 @@ pub fn build_public_router(state: Arc<VolumeServerState>) -> Router {
Router::new() Router::new()
.route("/healthz", get(handlers::healthz_handler)) .route("/healthz", get(handlers::healthz_handler))
.route( .route(
"/{path}",
"/:path",
get(handlers::get_or_head_handler) get(handlers::get_or_head_handler)
.head(handlers::get_or_head_handler), .head(handlers::get_or_head_handler),
) )
.route( .route(
"/{vid}/{fid}",
"/:vid/:fid",
get(handlers::get_or_head_handler) get(handlers::get_or_head_handler)
.head(handlers::get_or_head_handler), .head(handlers::get_or_head_handler),
) )
.route( .route(
"/{vid}/{fid}/{filename}",
"/:vid/:fid/:filename",
get(handlers::get_or_head_handler) get(handlers::get_or_head_handler)
.head(handlers::get_or_head_handler), .head(handlers::get_or_head_handler),
) )

Loading…
Cancel
Save