opendal/services/alluxio/
config.rs1use std::fmt::Debug;
19
20use serde::Deserialize;
21use serde::Serialize;
22
23use super::ALLUXIO_SCHEME;
24use super::backend::AlluxioBuilder;
25
26#[derive(Default, Serialize, Deserialize, Clone, PartialEq, Eq)]
28#[serde(default)]
29#[non_exhaustive]
30pub struct AlluxioConfig {
31 pub root: Option<String>,
37 pub endpoint: Option<String>,
41}
42
43impl Debug for AlluxioConfig {
44 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
45 f.debug_struct("AlluxioConfig")
46 .field("root", &self.root)
47 .field("endpoint", &self.endpoint)
48 .finish_non_exhaustive()
49 }
50}
51
52impl crate::Configurator for AlluxioConfig {
53 type Builder = AlluxioBuilder;
54
55 fn from_uri(uri: &crate::types::OperatorUri) -> crate::Result<Self> {
56 let authority = uri.authority().ok_or_else(|| {
57 crate::Error::new(crate::ErrorKind::ConfigInvalid, "uri authority is required")
58 .with_context("service", ALLUXIO_SCHEME)
59 })?;
60
61 let mut map = uri.options().clone();
62 map.insert("endpoint".to_string(), format!("http://{authority}"));
63
64 if let Some(root) = uri.root() {
65 if !root.is_empty() {
66 map.insert("root".to_string(), root.to_string());
67 }
68 }
69
70 Self::from_iter(map)
71 }
72
73 #[allow(deprecated)]
74 fn into_builder(self) -> Self::Builder {
75 AlluxioBuilder {
76 config: self,
77 http_client: None,
78 }
79 }
80}
81
82#[cfg(test)]
83mod tests {
84 use super::*;
85 use crate::Configurator;
86 use crate::types::OperatorUri;
87
88 #[test]
89 fn from_uri_sets_endpoint_and_root() {
90 let uri = OperatorUri::new(
91 "alluxio://127.0.0.1:39999/data/raw",
92 Vec::<(String, String)>::new(),
93 )
94 .unwrap();
95
96 let cfg = AlluxioConfig::from_uri(&uri).unwrap();
97 assert_eq!(cfg.endpoint.as_deref(), Some("http://127.0.0.1:39999"));
98 assert_eq!(cfg.root.as_deref(), Some("data/raw"));
99 }
100}