refactor(tvix): move service addrs into shared clap struct
Change-Id: I7cab29ecfa1823c2103b4c47b7d784bc31459d55 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12008 Tested-by: BuildkiteCI Reviewed-by: flokli <flokli@flokli.de> Autosubmit: yuka <yuka@yuka.dev>
This commit is contained in:
parent
6774d9c59c
commit
67335c41b7
12 changed files with 132 additions and 149 deletions
|
|
@ -29,16 +29,81 @@ pub struct CompositionConfigs {
|
|||
>,
|
||||
}
|
||||
|
||||
#[derive(clap::Parser, Clone)]
|
||||
pub struct ServiceUrls {
|
||||
#[arg(
|
||||
long,
|
||||
env,
|
||||
default_value = "objectstore+file:///var/lib/tvix-store/blobs.object_store"
|
||||
)]
|
||||
blob_service_addr: String,
|
||||
|
||||
#[arg(
|
||||
long,
|
||||
env,
|
||||
default_value = "sled:///var/lib/tvix-store/directories.sled"
|
||||
)]
|
||||
directory_service_addr: String,
|
||||
|
||||
#[arg(long, env, default_value = "sled:///var/lib/tvix-store/pathinfo.sled")]
|
||||
path_info_service_addr: String,
|
||||
}
|
||||
|
||||
/// like ServiceUrls, but with different clap defaults
|
||||
#[derive(clap::Parser, Clone)]
|
||||
pub struct ServiceUrlsGrpc {
|
||||
#[arg(long, env, default_value = "grpc+http://[::1]:8000")]
|
||||
blob_service_addr: String,
|
||||
|
||||
#[arg(long, env, default_value = "grpc+http://[::1]:8000")]
|
||||
directory_service_addr: String,
|
||||
|
||||
#[arg(long, env, default_value = "grpc+http://[::1]:8000")]
|
||||
path_info_service_addr: String,
|
||||
}
|
||||
|
||||
/// like ServiceUrls, but with different clap defaults
|
||||
#[derive(clap::Parser, Clone)]
|
||||
pub struct ServiceUrlsMemory {
|
||||
#[arg(long, env, default_value = "memory://")]
|
||||
blob_service_addr: String,
|
||||
|
||||
#[arg(long, env, default_value = "memory://")]
|
||||
directory_service_addr: String,
|
||||
|
||||
#[arg(long, env, default_value = "memory://")]
|
||||
path_info_service_addr: String,
|
||||
}
|
||||
|
||||
impl From<ServiceUrlsGrpc> for ServiceUrls {
|
||||
fn from(urls: ServiceUrlsGrpc) -> ServiceUrls {
|
||||
ServiceUrls {
|
||||
blob_service_addr: urls.blob_service_addr,
|
||||
directory_service_addr: urls.directory_service_addr,
|
||||
path_info_service_addr: urls.path_info_service_addr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ServiceUrlsMemory> for ServiceUrls {
|
||||
fn from(urls: ServiceUrlsMemory) -> ServiceUrls {
|
||||
ServiceUrls {
|
||||
blob_service_addr: urls.blob_service_addr,
|
||||
directory_service_addr: urls.directory_service_addr,
|
||||
path_info_service_addr: urls.path_info_service_addr,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn addrs_to_configs(
|
||||
blob_service_addr: impl AsRef<str>,
|
||||
directory_service_addr: impl AsRef<str>,
|
||||
path_info_service_addr: impl AsRef<str>,
|
||||
urls: impl Into<ServiceUrls>,
|
||||
) -> Result<CompositionConfigs, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let urls: ServiceUrls = urls.into();
|
||||
let mut configs: CompositionConfigs = Default::default();
|
||||
|
||||
let blob_service_url = Url::parse(blob_service_addr.as_ref())?;
|
||||
let directory_service_url = Url::parse(directory_service_addr.as_ref())?;
|
||||
let path_info_service_url = Url::parse(path_info_service_addr.as_ref())?;
|
||||
let blob_service_url = Url::parse(&urls.blob_service_addr)?;
|
||||
let directory_service_url = Url::parse(&urls.directory_service_addr)?;
|
||||
let path_info_service_url = Url::parse(&urls.path_info_service_addr)?;
|
||||
|
||||
configs.blobservices.insert(
|
||||
"default".into(),
|
||||
|
|
@ -58,9 +123,7 @@ pub fn addrs_to_configs(
|
|||
|
||||
/// Construct the store handles from their addrs.
|
||||
pub async fn construct_services(
|
||||
blob_service_addr: impl AsRef<str>,
|
||||
directory_service_addr: impl AsRef<str>,
|
||||
path_info_service_addr: impl AsRef<str>,
|
||||
urls: impl Into<ServiceUrls>,
|
||||
) -> Result<
|
||||
(
|
||||
Arc<dyn BlobService>,
|
||||
|
|
@ -70,11 +133,7 @@ pub async fn construct_services(
|
|||
),
|
||||
Box<dyn std::error::Error + Send + Sync>,
|
||||
> {
|
||||
let configs = addrs_to_configs(
|
||||
blob_service_addr,
|
||||
directory_service_addr,
|
||||
path_info_service_addr,
|
||||
)?;
|
||||
let configs = addrs_to_configs(urls)?;
|
||||
construct_services_from_configs(configs).await
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue