This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-rust.git
The following commit(s) were added to refs/heads/main by this push:
new abfc747 Ftr: add common/utils subpackage (#123)
abfc747 is described below
commit abfc7474380174fb60e127b9cd5de5ad0333b0c2
Author: 墨舟 <[email protected]>
AuthorDate: Thu Mar 2 09:20:20 2023 +0800
Ftr: add common/utils subpackage (#123)
---
.github/workflows/github-actions.yml | 2 +-
Cargo.toml | 10 +-
examples/greeter/dubbo.yaml => application.yaml | 4 +-
common/logger/Cargo.toml | 4 +-
.../logger/src/{tracing_configurer.rs => level.rs} | 40 ++--
common/logger/src/lib.rs | 16 +-
common/logger/src/tracing_configurer.rs | 37 ++--
common/utils/Cargo.toml | 13 ++
common/utils/LICENSE | 202 +++++++++++++++++++++
{config => common/utils}/src/lib.rs | 19 +-
.../{logger/src/lib.rs => utils/src/path_util.rs} | 22 ++-
common/utils/src/yaml_util.rs | 96 ++++++++++
common/utils/tests/application.yaml | 4 +
config/Cargo.toml | 11 +-
config/src/config.rs | 43 ++---
config/src/lib.rs | 13 +-
dubbo.yaml | 26 ---
dubbo/Cargo.toml | 22 +--
dubbogo.yaml | 7 -
examples/greeter/{dubbo.yaml => application.yaml} | 2 +
remoting/net/Cargo.toml | 10 +-
.../net/benches/transport_benchmark/main.rs | 17 --
remoting/net/src/incoming.rs | 10 +-
scripts/ci-check.sh | 23 ---
24 files changed, 440 insertions(+), 213 deletions(-)
diff --git a/.github/workflows/github-actions.yml
b/.github/workflows/github-actions.yml
index e8881e0..b02b3bc 100644
--- a/.github/workflows/github-actions.yml
+++ b/.github/workflows/github-actions.yml
@@ -94,5 +94,5 @@ jobs:
../../target/debug/greeter-client
env:
ZOOKEEPER_SERVERS: 127.0.0.1:2181
- DUBBO_CONFIG_PATH: ./dubbo.yaml
+ DUBBO_CONFIG_PATH: ./application.yaml
working-directory: examples/greeter
diff --git a/Cargo.toml b/Cargo.toml
index ae339cd..c879e4d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,5 +1,7 @@
[workspace]
members = [
+ "common/logger",
+ "common/utils",
"xds",
"registry/zookeeper",
"registry/nacos",
@@ -24,12 +26,16 @@ async-trait = "0.1"
dashmap = "5"
lazy_static = "1"
futures = "0.3"
-tracing = "0.1"
-tracing-subscriber = "0.3.15"
serde = "1"
serde_json = "1"
urlencoding = "2.1.2"
logger = {path="./common/logger"}
+utils = {path="./common/utils"}
anyhow = "1.0.66"
dubbo = { path = "./dubbo/" }
+bb8 = "0.8.0" # A connecton pool based on tokio
+serde_yaml = "0.9.4" # yaml file parser
+once_cell = "1.16.0"
+itertools = "0.10.1"
+
diff --git a/examples/greeter/dubbo.yaml b/application.yaml
similarity index 70%
copy from examples/greeter/dubbo.yaml
copy to application.yaml
index 96daf95..0de344e 100644
--- a/examples/greeter/dubbo.yaml
+++ b/application.yaml
@@ -1,3 +1,5 @@
+logging:
+ level: debug
dubbo:
protocols:
triple:
@@ -7,7 +9,7 @@ dubbo:
registries:
demoZK:
protocol: zookeeper
- address: 10.0.6.6:2181
+ address: 0.0.0.0:2181
provider:
services:
GreeterProvider:
diff --git a/common/logger/Cargo.toml b/common/logger/Cargo.toml
index 14157bb..e965706 100644
--- a/common/logger/Cargo.toml
+++ b/common/logger/Cargo.toml
@@ -7,4 +7,6 @@ edition = "2021"
[dependencies]
tracing = "0.1"
-tracing-subscriber = "0.3"
\ No newline at end of file
+tracing-subscriber = "0.3"
+once_cell.workspace = true
+utils.workspace = true
\ No newline at end of file
diff --git a/common/logger/src/tracing_configurer.rs
b/common/logger/src/level.rs
similarity index 55%
copy from common/logger/src/tracing_configurer.rs
copy to common/logger/src/level.rs
index 40b1e84..097f105 100644
--- a/common/logger/src/tracing_configurer.rs
+++ b/common/logger/src/level.rs
@@ -14,30 +14,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+use crate::Level;
-// https://github.com/tokio-rs/tracing/issues/971
-
-use tracing::{debug, Level};
-
-pub(crate) fn default() {
- if let Some(true) = configured() {
- parse_from_config()
- } else {
- tracing_subscriber::fmt()
- .compact()
- .with_line_number(true)
- .with_max_level(Level::DEBUG)
- // sets this to be the default, global collector for this
application.
- .try_init()
- .expect("init err.");
- }
- debug!("Tracing configured.")
+pub(crate) struct LevelWrapper {
+ pub(crate) inner: Level,
}
-
-pub(crate) fn parse_from_config() {
- todo!()
+impl LevelWrapper {
+ pub fn new(level: Level) -> Self {
+ LevelWrapper { inner: level }
+ }
}
-pub(crate) fn configured() -> Option<bool> {
- None
+impl From<Option<String>> for LevelWrapper {
+ fn from(s: Option<String>) -> Self {
+ match s.unwrap().to_lowercase().as_str().trim() {
+ "error" => LevelWrapper::new(Level::ERROR),
+ "warn" => LevelWrapper::new(Level::WARN),
+ "info" => LevelWrapper::new(Level::INFO),
+ "debug" => LevelWrapper::new(Level::DEBUG),
+ "trace" => LevelWrapper::new(Level::TRACE),
+ _ => LevelWrapper::new(Level::INFO),
+ }
+ }
}
diff --git a/common/logger/src/lib.rs b/common/logger/src/lib.rs
index 2737274..6edce9f 100644
--- a/common/logger/src/lib.rs
+++ b/common/logger/src/lib.rs
@@ -15,22 +15,32 @@
* limitations under the License.
*/
+use std::sync::atomic::{AtomicBool, Ordering};
+
pub use tracing::{self, Level};
+// flag for the sake of avoiding multiple initialization
+static TRACING_CONFIGURED: AtomicBool = AtomicBool::new(false);
+
+mod level;
mod tracing_configurer;
// put on main method
pub fn init() {
- tracing_configurer::default()
+ if !TRACING_CONFIGURED.load(Ordering::SeqCst) {
+ tracing_configurer::default()
+ }
}
#[cfg(test)]
mod tests {
- use tracing::debug;
+ use tracing::{debug, info, trace};
#[test]
fn test_print_info_log() {
super::init();
- debug!("hello rust");
+ debug!("hello rust:debug");
+ trace!("hello rust:trace");
+ info!("hello rust:info");
}
}
diff --git a/common/logger/src/tracing_configurer.rs
b/common/logger/src/tracing_configurer.rs
index 40b1e84..1e2081f 100644
--- a/common/logger/src/tracing_configurer.rs
+++ b/common/logger/src/tracing_configurer.rs
@@ -17,27 +17,24 @@
// https://github.com/tokio-rs/tracing/issues/971
-use tracing::{debug, Level};
+use crate::level::LevelWrapper;
+use std::path::PathBuf;
+use tracing::debug;
+use utils::{path_util, yaml_util};
pub(crate) fn default() {
- if let Some(true) = configured() {
- parse_from_config()
- } else {
- tracing_subscriber::fmt()
- .compact()
- .with_line_number(true)
- .with_max_level(Level::DEBUG)
- // sets this to be the default, global collector for this
application.
- .try_init()
- .expect("init err.");
- }
+ let path_buf = PathBuf::new()
+ .join(path_util::app_root_dir())
+ .join("application.yaml");
+ let level: LevelWrapper = yaml_util::yaml_key_reader(path_buf,
"logging.level")
+ .unwrap()
+ .into();
+ tracing_subscriber::fmt()
+ .compact()
+ .with_line_number(true)
+ .with_max_level(level.inner)
+ // sets this to be the default, global collector for this application.
+ .try_init()
+ .expect("init err.");
debug!("Tracing configured.")
}
-
-pub(crate) fn parse_from_config() {
- todo!()
-}
-
-pub(crate) fn configured() -> Option<bool> {
- None
-}
diff --git a/common/utils/Cargo.toml b/common/utils/Cargo.toml
new file mode 100644
index 0000000..4665ab6
--- /dev/null
+++ b/common/utils/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "utils"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at
https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+serde_yaml.workspace = true
+serde = { workspace = true, features = ["derive"] }
+project-root = "0.2.2"
+anyhow.workspace=true
+once_cell.workspace = true
\ No newline at end of file
diff --git a/common/utils/LICENSE b/common/utils/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/common/utils/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/config/src/lib.rs b/common/utils/src/lib.rs
similarity index 77%
copy from config/src/lib.rs
copy to common/utils/src/lib.rs
index e56d933..47dbe62 100644
--- a/config/src/lib.rs
+++ b/common/utils/src/lib.rs
@@ -14,20 +14,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-pub mod config;
-pub mod protocol;
-pub mod provider;
-pub mod registry;
-pub mod service;
-
-pub use config::*;
-
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- let result = 2 + 2;
- assert_eq!(result, 4);
- }
-}
+pub mod path_util;
+pub mod yaml_util;
diff --git a/common/logger/src/lib.rs b/common/utils/src/path_util.rs
similarity index 69%
copy from common/logger/src/lib.rs
copy to common/utils/src/path_util.rs
index 2737274..347f108 100644
--- a/common/logger/src/lib.rs
+++ b/common/utils/src/path_util.rs
@@ -15,22 +15,24 @@
* limitations under the License.
*/
-pub use tracing::{self, Level};
+use std::{env, path::PathBuf};
-mod tracing_configurer;
-
-// put on main method
-pub fn init() {
- tracing_configurer::default()
+pub fn app_root_dir() -> PathBuf {
+ match project_root::get_project_root() {
+ // Cargo.lock file as app root dir
+ Ok(p) => p,
+ Err(_) => env::current_dir().unwrap(),
+ }
}
#[cfg(test)]
mod tests {
- use tracing::debug;
+
+ use super::*;
#[test]
- fn test_print_info_log() {
- super::init();
- debug!("hello rust");
+ fn test_app_root_dir() {
+ let dir = app_root_dir().join("application.yaml");
+ println!("dir: {}", dir.display());
}
}
diff --git a/common/utils/src/yaml_util.rs b/common/utils/src/yaml_util.rs
new file mode 100644
index 0000000..f8e0adf
--- /dev/null
+++ b/common/utils/src/yaml_util.rs
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+use std::{collections::HashMap, fs, path::PathBuf, sync::Mutex};
+
+use anyhow::Error;
+use once_cell::sync::Lazy;
+use serde_yaml::{from_slice, Value};
+
+static YAML_VALUE_CACHE_MAP: Lazy<Mutex<HashMap<PathBuf, Value>>> =
+ Lazy::new(|| Mutex::new(HashMap::new()));
+
+// parse yaml file to structs
+pub fn yaml_file_parser<T>(path: PathBuf) -> Result<T, Error>
+where
+ T: serde::de::DeserializeOwned + std::fmt::Debug,
+{
+ if !path.is_file() {
+ return Err(anyhow::anyhow!("path is not a file: {:?}", path));
+ }
+ let data = fs::read(path.as_path())?;
+ Ok(from_slice(&data).unwrap())
+}
+
+// read value by a key like: logging.level
+pub fn yaml_key_reader(path: PathBuf, key: &str) -> Result<Option<String>,
Error> {
+ if !path.is_file() {
+ return Err(anyhow::anyhow!("path is not a file: {:?}", path));
+ }
+ let cache_map = YAML_VALUE_CACHE_MAP.lock().unwrap();
+ let split_keys = key.split('.');
+ let data = fs::read(path.as_path())?;
+ let mut value: Value;
+ match cache_map.contains_key(path.as_path()) {
+ true => {
+ value = cache_map.get(path.as_path()).unwrap().clone();
+ }
+ false => {
+ value = from_slice(&data).unwrap();
+ }
+ }
+ for key in split_keys {
+ value = value[key].clone();
+ }
+ if value.is_null() {
+ return Ok(None);
+ }
+ Ok(Some(value.as_str().unwrap().to_string()))
+}
+
+#[cfg(test)]
+mod tests {
+ use std::collections::HashMap;
+
+ use crate::{
+ path_util::app_root_dir,
+ yaml_util::{yaml_file_parser, yaml_key_reader},
+ };
+
+ #[test]
+ fn test_yaml_file_parser() {
+ let path = app_root_dir()
+ .join("common")
+ .join("utils")
+ .join("tests")
+ .join("application.yaml");
+ let config = yaml_file_parser::<HashMap<String, HashMap<String,
String>>>(path).unwrap();
+ println!("{:?}", config);
+ }
+
+ #[test]
+ fn test_yaml_key_reader() {
+ let path = app_root_dir()
+ .join("common")
+ .join("utils")
+ .join("tests")
+ .join("application.yaml");
+ let config = yaml_key_reader(path.clone(), "logging.level").unwrap();
+ println!("{:?}", config);
+ let config = yaml_key_reader(path, "logging.file.path").unwrap();
+ println!("{:?}", config);
+ }
+}
diff --git a/common/utils/tests/application.yaml
b/common/utils/tests/application.yaml
new file mode 100644
index 0000000..a40e4fe
--- /dev/null
+++ b/common/utils/tests/application.yaml
@@ -0,0 +1,4 @@
+logging:
+ level: INFO
+ file:
+ path: /tmp/test.log
diff --git a/config/Cargo.toml b/config/Cargo.toml
index 1eaa89c..b4e19d4 100644
--- a/config/Cargo.toml
+++ b/config/Cargo.toml
@@ -10,8 +10,9 @@ repository = "https://github.com/apache/dubbo-rust.git"
# See more keys and their definitions at
https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-serde = {version="1.0.138", features = ["derive"]}
-serde_yaml = "0.9.4"
-tracing = "0.1"
-lazy_static = "1.3.0"
-once_cell = "1.16.0"
+serde = { workspace = true, features = ["derive"] }
+serde_yaml.workspace = true
+lazy_static.workspace = true
+once_cell.workspace = true
+utils.workspace = true
+logger.workspace=true
\ No newline at end of file
diff --git a/config/src/config.rs b/config/src/config.rs
index ed3a714..f63b490 100644
--- a/config/src/config.rs
+++ b/config/src/config.rs
@@ -15,16 +15,17 @@
* limitations under the License.
*/
-use std::{collections::HashMap, env, fs};
+use std::{collections::HashMap, env, path::PathBuf};
use crate::{protocol::Protocol, registry::RegistryConfig};
+use logger::tracing;
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
-use tracing::trace;
+use utils::yaml_util::yaml_file_parser;
use super::{protocol::ProtocolConfig, provider::ProviderConfig,
service::ServiceConfig};
-pub const DUBBO_CONFIG_PATH: &str = "./dubbo.yaml";
+pub const DUBBO_CONFIG_PATH: &str = "application.yaml";
pub static GLOBAL_ROOT_CONFIG: OnceCell<RootConfig> = OnceCell::new();
pub const DUBBO_CONFIG_PREFIX: &str = "dubbo";
@@ -78,14 +79,16 @@ impl RootConfig {
err,
DUBBO_CONFIG_PATH
);
- DUBBO_CONFIG_PATH.to_string()
+ utils::path_util::app_root_dir()
+ .join(DUBBO_CONFIG_PATH)
+ .to_str()
+ .unwrap()
+ .to_string()
}
};
- tracing::info!("current path: {:?}", env::current_dir());
- let data = fs::read(config_path)?;
- trace!("config data: {:?}", String::from_utf8(data.clone()));
- let conf: HashMap<String, RootConfig> =
serde_yaml::from_slice(&data).unwrap();
+ let conf: HashMap<String, RootConfig> =
+ yaml_file_parser(PathBuf::new().join(config_path)).unwrap();
let root_config: RootConfig =
conf.get(DUBBO_CONFIG_PREFIX).unwrap().clone();
tracing::debug!("origin config: {:?}", conf);
Ok(root_config)
@@ -181,27 +184,9 @@ mod tests {
#[test]
fn test_load() {
- // case 1: read config yaml from default path
- println!("current path: {:?}", env::current_dir());
+ logger::init();
let r = RootConfig::new();
- r.load();
- }
-
- #[test]
- fn test_load1() {
- // case 2: read config yaml from path in env
- println!("current path: {:?}", env::current_dir());
- let r = RootConfig::new();
- r.load();
- }
-
- #[test]
- fn test_write_yaml() {
- let mut r = RootConfig::new();
- r.test_config();
- let yaml = serde_yaml::to_string(&r).unwrap();
- println!("config data: {:?}", yaml);
-
- fs::write("./test_dubbo.yaml", yaml);
+ let r = r.load().unwrap();
+ println!("{:#?}", r);
}
}
diff --git a/config/src/lib.rs b/config/src/lib.rs
index e56d933..0748c66 100644
--- a/config/src/lib.rs
+++ b/config/src/lib.rs
@@ -15,19 +15,10 @@
* limitations under the License.
*/
+pub use config::*;
+
pub mod config;
pub mod protocol;
pub mod provider;
pub mod registry;
pub mod service;
-
-pub use config::*;
-
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- let result = 2 + 2;
- assert_eq!(result, 4);
- }
-}
diff --git a/dubbo.yaml b/dubbo.yaml
deleted file mode 100644
index e14b530..0000000
--- a/dubbo.yaml
+++ /dev/null
@@ -1,26 +0,0 @@
-name: dubbo
-service:
- echo:
- version: 1.0.0
- group: test
- protocol: triple
- registry: ''
- serializer: json
- protocol_configs:
- triple:
- ip: 0.0.0.0
- port: '8888'
- name: triple
- listener: tcp
- # helloworld.Greeter:
- # version: 1.0.0
- # group: test
- # protocol: triple
- # registry: ''
- # serializer: json
-protocols:
- triple:
- ip: 0.0.0.0
- port: '8888'
- name: triple
- listener: tcp
diff --git a/dubbo/Cargo.toml b/dubbo/Cargo.toml
index b552b25..5700e81 100644
--- a/dubbo/Cargo.toml
+++ b/dubbo/Cargo.toml
@@ -10,23 +10,22 @@ repository = "https://github.com/apache/dubbo-rust.git"
# See more keys and their definitions at
https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-hyper = { version = "0.14.19", features = ["full"]}
+hyper = { version = "0.14.19", features = ["full"] }
http = "0.2"
tower-service = "0.3.1"
http-body = "0.4.4"
-tower = { version = "0.4.12", features = ["timeout"]}
+tower = { version = "0.4.12", features = ["timeout"] }
futures-util = "0.3.23"
-futures-core ="0.3.23"
-tokio = { version = "1.0", features = [ "rt-multi-thread", "time", "fs",
"macros", "net", "signal"] }
+futures-core = "0.3.23"
+tokio = { version = "1.0", features = ["rt-multi-thread", "time", "fs",
"macros", "net", "signal"] }
prost = "0.10.4"
-lazy_static = "1.3.0"
async-trait = "0.1.56"
tower-layer = "0.3"
bytes = "1.0"
-pin-project = "1.0"
+pin-project.workspace = true
rand = "0.8.5"
-serde_json = "1.0.82"
-serde = {version="1.0.138", features = ["derive"]}
+serde_json.workspace = true
+serde = { workspace = true, features = ["derive"] }
futures = "0.3"
tracing = "0.1"
tracing-subscriber = "0.3.15"
@@ -34,10 +33,11 @@ axum = "0.5.9"
async-stream = "0.3"
flate2 = "1.0"
aws-smithy-http = "0.54.1"
-itertools = "0.10.1"
-urlencoding = "2.1.2"
+itertools.workspace = true
+urlencoding.workspace = true
+lazy_static.workspace = true
-dubbo-config = {path = "../config", version = "0.3.0" }
+dubbo-config = { path = "../config", version = "0.3.0" }
#对象存储
state = { version = "0.5", features = ["tls"] }
diff --git a/dubbogo.yaml b/dubbogo.yaml
deleted file mode 100644
index 2e6fe5b..0000000
--- a/dubbogo.yaml
+++ /dev/null
@@ -1,7 +0,0 @@
-dubbo:
- consumer:
- references:
- GreeterClientImpl:
- protocol: tri
- url: "tri://localhost:8889"
- interface: helloworld.Greeter
\ No newline at end of file
diff --git a/examples/greeter/dubbo.yaml b/examples/greeter/application.yaml
similarity index 78%
rename from examples/greeter/dubbo.yaml
rename to examples/greeter/application.yaml
index 96daf95..6683c6d 100644
--- a/examples/greeter/dubbo.yaml
+++ b/examples/greeter/application.yaml
@@ -1,3 +1,5 @@
+logging:
+ level: INFO
dubbo:
protocols:
triple:
diff --git a/remoting/net/Cargo.toml b/remoting/net/Cargo.toml
index c39a362..c62082e 100644
--- a/remoting/net/Cargo.toml
+++ b/remoting/net/Cargo.toml
@@ -1,12 +1,15 @@
[package]
-name = "remoting"
+name = "net"
version = "0.1.0"
edition = "2021"
+[[bench]]
+name = "transport_benchmark"
+harness=false
[dependencies]
pin-project.workspace = true
-tokio = { workspace = true, features = ["net", "time", "sync",
"io-util","test-util","macros"] }
+tokio = { workspace = true, features = ["net", "time", "sync", "io-util",
"test-util", "macros"] }
tokio-stream = { workspace = true, features = ["net"] }
tower.workspace = true
socket2.workspace = true
@@ -14,4 +17,5 @@ async-trait.workspace = true
dashmap.workspace = true
lazy_static.workspace = true
futures.workspace = true
-tracing.workspace = true
+logger.workspace = true
+bb8.workspace = true
diff --git a/config/src/lib.rs
b/remoting/net/benches/transport_benchmark/main.rs
similarity index 77%
copy from config/src/lib.rs
copy to remoting/net/benches/transport_benchmark/main.rs
index e56d933..2944f98 100644
--- a/config/src/lib.rs
+++ b/remoting/net/benches/transport_benchmark/main.rs
@@ -14,20 +14,3 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-pub mod config;
-pub mod protocol;
-pub mod provider;
-pub mod registry;
-pub mod service;
-
-pub use config::*;
-
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- let result = 2 + 2;
- assert_eq!(result, 4);
- }
-}
diff --git a/remoting/net/src/incoming.rs b/remoting/net/src/incoming.rs
index 8267260..bca797e 100644
--- a/remoting/net/src/incoming.rs
+++ b/remoting/net/src/incoming.rs
@@ -20,6 +20,7 @@ use std::{
};
use futures::Stream;
+use logger::tracing;
use pin_project::pin_project;
use tokio::net::TcpListener;
#[cfg(target_family = "unix")]
@@ -111,6 +112,7 @@ impl Stream for DefaultIncoming {
#[cfg(test)]
mod tests {
+ use logger::tracing::debug;
use tokio::{io::AsyncReadExt, net::TcpListener};
use tokio_stream::wrappers::TcpListenerStream;
@@ -123,24 +125,24 @@ mod tests {
.make_incoming()
.await
.unwrap();
- println!("[Dubbo-Rust] server start at: {:?}", incoming);
+ debug!("[Dubbo-Rust] server start at: {:?}", incoming);
let join_handle = tokio::spawn(async move {
let mut incoming = incoming;
match incoming.accept().await.unwrap() {
Some(mut conn) => {
- println!(
+ debug!(
"[Dubbo-Rust] recv a connection from: {:?}",
conn.info.peer_addr
);
let mut buf = vec![0; 1024];
let n = conn.read(&mut buf).await.unwrap();
- println!(
+ debug!(
"[Dubbo-Rust] recv a connection from: {:?}",
String::from_utf8(buf[..n].to_vec()).unwrap()
);
}
None => {
- println!("[Dubbo-Rust] recv a connection from: None");
+ debug!("[Dubbo-Rust] recv a connection from: None");
}
}
});
diff --git a/scripts/ci-check.sh b/scripts/ci-check.sh
deleted file mode 100755
index 5ffd46d..0000000
--- a/scripts/ci-check.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/bash
-
-#/*
-# * Licensed to the Apache Software Foundation (ASF) under one or more
-# * contributor license agreements. See the NOTICE file distributed with
-# * this work for additional information regarding copyright ownership.
-# * The ASF licenses this file to You under the Apache License, Version 2.0
-# * (the "License"); you may not use this file except in compliance with
-# * the License. You may obtain a copy of the License at
-# *
-# * http://www.apache.org/licenses/LICENSE-2.0
-# *
-# * Unless required by applicable law or agreed to in writing, software
-# * distributed under the License is distributed on an "AS IS" BASIS,
-# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# * See the License for the specific language governing permissions and
-# * limitations under the License.
-# */
-
-cargo fmt --all -- --check
-# use stable channel
-cargo check
-target/debug/greeter-server && target/debug/greeter-client && sleep 3s ;