pub struct ClientBuilder { /* private fields */ }Expand description
Builds a new Client instance. Configs will be loaded with the following precedence:
- If method
ClientBuilder::with_config_diris invoked, configs will be loaded from${config_dir}/{core,hdfs}-site.xml - If the
HADOOP_CONF_DIRenvironment variable is defined, configs will be loaded from${HADOOP_CONF_DIR}/{core,hdfs}-site.xml - If the
HADOOP_HOMEenvironment variable is defined, configs will be loaded from${HADOOP_HOME}/etc/hadoop/{core,hdfs}-site.xml - Otherwise no configs are defined
Finally, configs set by with_config will override the configs loaded above.
If no URL is defined, the fs.defaultFS config must be defined and is used as the URL.
§Examples
Create a new client with given config directory
let client = ClientBuilder::new()
.with_config_dir("/opt/hadoop/etc/hadoop")
.build()
.unwrap();Create a new client with the environment variable
unsafe { std::env::set_var("HADOOP_CONF_DIR", "/opt/hadoop/etc/hadoop") };
let client = ClientBuilder::new()
.build()
.unwrap();Create a new client using the fs.defaultFS config
let client = ClientBuilder::new()
.with_config(vec![("fs.defaultFS", "hdfs://127.0.0.1:9000")])
.build()
.unwrap();Create a new client connecting to a specific URL:
let client = ClientBuilder::new()
.with_url("hdfs://127.0.0.1:9000")
.build()
.unwrap();Create a new client using a dedicated tokio runtime for spawned tasks and IO operations
let client = ClientBuilder::new()
.with_url("hdfs://127.0.0.1:9000")
.with_io_runtime(tokio::runtime::Runtime::new().unwrap())
.build()
.unwrap();Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new ClientBuilder
Sourcepub fn with_url(self, url: impl Into<String>) -> Self
pub fn with_url(self, url: impl Into<String>) -> Self
Set the URL to connect to. Can be the address of a single NameNode, or a logical NameService
Sourcepub fn with_config(
self,
config: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
) -> Self
pub fn with_config( self, config: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>, ) -> Self
Set configs to use for the client. The provided configs will override any found in the config files loaded
Sourcepub fn with_config_dir(self, config_dir: impl Into<String>) -> Self
pub fn with_config_dir(self, config_dir: impl Into<String>) -> Self
Set the configration directory path to read from. The provided path will override the one provided by environment variable.