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

843 fix testmode #844

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Bob versions changelog


#### Fixed
- Fix testmode launch prerequisites (#843)


#### Updated
Expand Down
31 changes: 20 additions & 11 deletions bob-apps/bin/bobd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,9 @@ async fn main() {
}).expect("Node config parsing error");

check_folders(&node, matches.is_present("init_folders"));
initialize_logger(&node, &cluster);
}

let mut extra_logstash_fields = HashMap::new();
extra_logstash_fields.insert("node_name".to_string(), serde_json::Value::String(node.name().to_string()));
if let Some(cluster_node_info) = cluster.nodes().iter().find(|item| item.name() == node.name()) {
extra_logstash_fields.insert("node_address".to_string(), serde_json::Value::String(cluster_node_info.address().to_string()));
}
log4rs::init_file(node.log_config(), log4rs::config::Deserializers::default().with_logstash_extra(extra_logstash_fields))
.expect("can't find log config");

let mut mapper = VirtualMapper::new(&node, &cluster);

let bind = node.bind();
Expand Down Expand Up @@ -198,9 +191,15 @@ fn configure_testmode(sub_matches: &ArgMatches) -> AnyResult<(ClusterConfig, Nod
addresses.push(format!("127.0.0.1:{port}"))
}
let this_node_index = this_node.ok_or(anyhow!("current node address not found"))?;
let cluster = ClusterConfig::get_testmode(
sub_matches.value_of("data").unwrap_or(format!("data_{this_node_index}").as_str()).to_string(),
addresses)?;
let dir = match sub_matches.value_of("data") {
Some(d) => d.to_string(),
None => {
let dir = format!("data_{this_node_index}");
create_dir(&dir)?;
dir
},
};
let cluster = ClusterConfig::get_testmode(dir, addresses)?;
let http_api_port = match sub_matches.value_of("restapi-port") {
Some(v) => Some(v.parse().context("could not parse --restapi-port")?),
None => None
Expand Down Expand Up @@ -344,6 +343,16 @@ fn spawn_signal_handler<A: Authenticator, TFut: futures::Future<Output = &'stati
});
}

fn initialize_logger(node: &NodeConfig, cluster: &ClusterConfig) {
let mut extra_logstash_fields = HashMap::new();
extra_logstash_fields.insert("node_name".to_string(), serde_json::Value::String(node.name().to_string()));
if let Some(cluster_node_info) = cluster.nodes().iter().find(|item| item.name() == node.name()) {
extra_logstash_fields.insert("node_address".to_string(), serde_json::Value::String(cluster_node_info.address().to_string()));
}
log4rs::init_file(node.log_config(), log4rs::config::Deserializers::default().with_logstash_extra(extra_logstash_fields))
.expect("can't find log config");
}

fn check_folders(node: &NodeConfig, init_flag: bool) {
if let BackendType::Pearl = node.backend_type() {
let root_dir = node.pearl().settings().root_dir_name();
Expand Down
Loading