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