Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1237] feat(rust): support populating args by clap #1236

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/experimental/server/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/experimental/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ tokio-console = "0.1.8"
console-subscriber = "0.1.9"
pin-project-lite = "0.2.8"
signal-hook = "0.3.17"
clap = "3.0.14"

[dependencies.hdrs]
version = "0.3.0"
Expand Down
2 changes: 1 addition & 1 deletion rust/experimental/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ cargo build --features hdfs --release
```
2. worker run with tokio-console. the log level of `trace` must be enabled
```shell
WORKER_IP={ip} RUST_LOG=trace WORKER_CONFIG_PATH=./config.toml ./uniffle-worker
WORKER_IP={ip} RUST_LOG=trace ./uniffle-worker -c ./config.toml
```
3. tokio-console client side connect
```shell
Expand Down
16 changes: 10 additions & 6 deletions rust/experimental/server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ impl StorageType {
const CONFIG_FILE_PATH_KEY: &str = "WORKER_CONFIG_PATH";

impl Config {
pub fn from(cfg_path: &str) -> Self {
let path = Path::new(cfg_path);

// Read the file content as a string
let file_content = fs::read_to_string(path).expect("Failed to read file");

toml::from_str(&file_content).unwrap()
}

pub fn create_from_env() -> Config {
let path = match std::env::var(CONFIG_FILE_PATH_KEY) {
Ok(val) => val,
Expand All @@ -241,12 +250,7 @@ impl Config {
),
};

let path = Path::new(&path);

// Read the file content as a string
let file_content = fs::read_to_string(path).expect("Failed to read file");

toml::from_str(&file_content).unwrap()
Config::from(&path)
}
}

Expand Down
18 changes: 17 additions & 1 deletion rust/experimental/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use crate::signal::details::wait_for_signal;
use crate::util::{gen_worker_uid, get_local_ip};

use anyhow::Result;
use clap::{App, Arg};
use log::info;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::time::Duration;
Expand Down Expand Up @@ -166,7 +167,22 @@ fn init_log(log: &LogConfig) -> WorkerGuard {
}

fn main() -> Result<()> {
let config = Config::create_from_env();
let args_match = App::new("Uniffle Worker")
.version("0.9.0-SNAPSHOT")
.about("Rust based shuffle server for Apache Uniffle")
.arg(
Arg::with_name("config")
.short('c')
.long("config")
.value_name("FILE")
.default_value("./config.toml")
.help("Sets a custom config file")
.takes_value(true),
)
.get_matches();

let config_path = args_match.value_of("config").unwrap_or("./config.toml");
let config = Config::from(config_path);

let runtime_manager = RuntimeManager::from(config.runtime_config.clone());

Expand Down