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

config file location & config api #127

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
02ad8af
Add: add remoting/net member
mozhou-tech Feb 26, 2023
b3cb54a
Add: add remoting/net member
mozhou-tech Feb 26, 2023
b49eb41
Add: remoting/net/incoming
mozhou-tech Feb 26, 2023
fbe02d6
Add: remoting/net/incoming
mozhou-tech Feb 27, 2023
d48ae45
Add: License
mozhou-tech Feb 27, 2023
8c4cbb4
Add: License
mozhou-tech Feb 27, 2023
27925ea
Merge branch 'main' into main
mozhou-tech Feb 28, 2023
76c2001
Merge branch 'apache:main' into main
mozhou-tech Feb 28, 2023
8bd727d
Merge remote-tracking branch 'origin/main' into main
mozhou-tech Mar 1, 2023
9ddb8d9
Rft: using subpackage to manage registry implementations for avoiding…
mozhou-tech Mar 1, 2023
3e594fa
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
b45d1ba
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
05095fa
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
11139c6
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
d3a048a
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
e777e6b
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
319868c
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
e696071
Ftr: add common/utils subpackage
mozhou-tech Mar 1, 2023
8040708
Merge branch 'apache:main' into main
mozhou-tech Mar 2, 2023
5edc821
Merge remote-tracking branch 'origin/main' into main
mozhou-tech Mar 3, 2023
07ed112
Merge remote-tracking branch 'origin/main' into main
mozhou-tech Mar 4, 2023
b229836
Ftr: config api
mozhou-tech Mar 6, 2023
71fe285
Ftr: config api
mozhou-tech Mar 6, 2023
de8c016
Ftr: config api
mozhou-tech Mar 6, 2023
ab95b3b
Ftr: config api
mozhou-tech Mar 6, 2023
01ce2dd
Ftr: config api
mozhou-tech Mar 6, 2023
46e01fe
Ftr: config api
mozhou-tech Mar 6, 2023
a81f098
Ftr: config api
mozhou-tech Mar 6, 2023
fd3b053
Ftr: config api
mozhou-tech Mar 6, 2023
72926e7
Ftr: config api
mozhou-tech Mar 6, 2023
de3746c
Ftr: config api
mozhou-tech Mar 6, 2023
143920d
Ftr: config api
mozhou-tech Mar 6, 2023
1c7c55d
Ftr: config api
mozhou-tech Mar 6, 2023
e2128d7
Ftr: config api
mozhou-tech Mar 6, 2023
a3844dd
Ftr: config api
mozhou-tech Mar 6, 2023
4d36be1
Ftr: config api
mozhou-tech Mar 6, 2023
cec0ce7
Ftr: config api
mozhou-tech Mar 6, 2023
03f8ab9
Ftr: config api
mozhou-tech Mar 7, 2023
3f7c874
Ftr: config api
mozhou-tech Mar 7, 2023
7f0c7f0
Ftr: config api
mozhou-tech Mar 7, 2023
4599463
Ftr: config api
mozhou-tech Mar 7, 2023
51d1b44
Ftr: config api
mozhou-tech Mar 7, 2023
b17e2b3
Ftr: config api
mozhou-tech Mar 7, 2023
15cdb66
Ftr: config api
mozhou-tech Mar 7, 2023
623dee5
Ftr: config api
mozhou-tech Mar 7, 2023
152fb63
Ftr: config api
mozhou-tech Mar 7, 2023
57277a4
Ftr: config api
mozhou-tech Mar 7, 2023
c41788a
Ftr: config api
mozhou-tech Mar 7, 2023
a00c9a5
Ftr: config api
mozhou-tech Mar 7, 2023
80d06a4
Ftr: config api
mozhou-tech Mar 7, 2023
5350505
Ftr: config api
mozhou-tech Mar 7, 2023
b75cd70
Ftr: config api
mozhou-tech Mar 7, 2023
29c7993
Ftr: config api
mozhou-tech Mar 7, 2023
012b0ed
Merge remote-tracking branch 'origin/main' into main
mozhou-tech Mar 7, 2023
895d366
Merge branch 'main' into config_api
mozhou-tech Mar 7, 2023
59ec9e8
Ftr: config api
mozhou-tech Mar 7, 2023
f01336a
Ftr: config api
mozhou-tech Mar 7, 2023
fb96b3f
Ftr: config api
mozhou-tech Mar 7, 2023
52f9fde
Ftr: config api
mozhou-tech Mar 7, 2023
9af298b
Ftr: config api
mozhou-tech Mar 7, 2023
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: 0 additions & 1 deletion .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,4 @@ jobs:
../../target/debug/greeter-client
env:
ZOOKEEPER_SERVERS: 127.0.0.1:2181
DUBBO_CONFIG_PATH: ./application.yaml
working-directory: examples/greeter
9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protocol-dubbo2 = {path="./protocol/dubbo2"}
protocol-triple = {path="./protocol/triple"}
registry-zookeeper = {path="./registry/zookeeper"}
registry-nacos = {path="./registry/nacos"}
config = {path="./config"}
anyhow = "1.0.66"
thiserror = "1.0.30"
dubbo = { path = "./dubbo/" }
Expand All @@ -57,6 +58,8 @@ serde_yaml = "0.9.4" # yaml file parser
once_cell = "1.16.0"
itertools = "0.10.1"
bytes = "1.0"



ctor = "0.1.23"
getset = "0.1.2"
validator = "0.15"
tracing = "0.1.29"
tracing-subscriber = "0.3.1"
3 changes: 2 additions & 1 deletion common/base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ edition = "2021"
[dependencies]
urlencoding.workspace = true
http = "0.2"
logger.workspace = true
tracing.workspace=true
anyhow.workspace = true
12 changes: 12 additions & 0 deletions common/base/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub const REGISTRY_PROTOCOL: &str = "registry_protocol";
pub const PROTOCOL: &str = "protocol";
pub const REGISTRY: &str = "registry";

pub const REGISTRY_TYPE_SERVICE: &str = "service";
pub const REGISTRY_TYPE_APPLICATION: &str = "application";

// URL key
pub const DUBBO_KEY: &str = "dubbo";
pub const PROVIDERS_KEY: &str = "providers";
Expand All @@ -29,3 +32,12 @@ pub const INTERFACE_KEY: &str = "interface";
pub const ANYHOST_KEY: &str = "anyhost";
pub const SIDE_KEY: &str = "side";
pub const TIMESTAMP_KEY: &str = "timestamp";

// file name
pub const DEFAULT_CONFIG_FILE: &str = "dubbo.yaml";

// env keys
pub const ENV_DUBBO_CONFIG_PATH: &str = "DUBBO_CONFIG_PATH";
pub const ENV_DUBBO_CONFIG_FILE: &str = "DUBBO_CONFIG_FILE";

// config keys
1 change: 1 addition & 0 deletions common/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)]
pub mod constants;
pub mod node;
pub mod types;
pub mod url;

pub use node::Node;
Expand Down
38 changes: 38 additions & 0 deletions common/base/src/types/alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/
// type for registryName;can be customized;RegistryKey eg. zookeeper/nacos/consul
pub type RegistryId = String;
pub type RegistryKey = String;
// service/application
pub type RegistryType = String;
// protocolKey defined in protocol layer, mean specified protocol
pub type ServiceName = String;
pub type ServiceKey = String;
pub type SerializationKey = String;
//
pub type ProtocolId = String;
pub type ProtocolKey = String;
pub type GroupId = String;
pub type VersionNumber = String;

pub type InterfaceName = String;

pub type ClusterStrategy = String;
pub type FilterKey = String;
pub type ParamKey = String;

pub type Port = String;
16 changes: 16 additions & 0 deletions common/base/src/types/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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.
*/
18 changes: 18 additions & 0 deletions common/base/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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.
*/
pub mod alias;
pub mod error;
11 changes: 7 additions & 4 deletions common/base/src/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ use std::{
fmt::{Display, Formatter},
};

use crate::constants::{GROUP_KEY, INTERFACE_KEY, VERSION_KEY};
use crate::{
constants::{GROUP_KEY, INTERFACE_KEY, VERSION_KEY},
types::alias::{ProtocolKey, ServiceKey, ServiceName},
};
use http::Uri;

#[derive(Debug, Clone, Default, PartialEq)]
Expand Down Expand Up @@ -48,7 +51,7 @@ impl Url {
let uri = url
.parse::<http::Uri>()
.map_err(|err| {
logger::tracing::error!("fail to parse url({}), err: {:?}", url, err);
tracing::error!("fail to parse url({}), err: {:?}", url, err);
})
.unwrap();
let query = uri.path_and_query().unwrap().query();
Expand All @@ -70,11 +73,11 @@ impl Url {
Some(url_inst)
}

pub fn get_service_key(&self) -> String {
pub fn get_service_key(&self) -> ServiceKey {
self.service_key.clone()
}

pub fn get_service_name(&self) -> String {
pub fn get_service_name(&self) -> ServiceName {
self.service_name.clone()
}

Expand Down
7 changes: 4 additions & 3 deletions common/logger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tracing = "0.1"
tracing-subscriber = "0.3"
tracing.workspace=true
tracing-subscriber.workspace=true
once_cell.workspace = true
utils.workspace = true
utils.workspace = true
config.workspace = true
11 changes: 3 additions & 8 deletions common/logger/src/tracing_configurer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@
// https://github.com/tokio-rs/tracing/issues/971

use crate::level::LevelWrapper;
use std::path::PathBuf;
use config::{resolve_config_location, util::yaml_key_reader};
use tracing::debug;
use utils::{path_util, yaml_util};

pub(crate) fn default() {
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();
let path_buf = resolve_config_location();
let level: LevelWrapper = yaml_key_reader(path_buf, "logging.level").unwrap().into();
tracing_subscriber::fmt()
.compact()
.with_line_number(true)
Expand Down
2 changes: 1 addition & 1 deletion common/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ project-root = "0.2.2"
anyhow.workspace=true
once_cell.workspace = true
local-ip-address = "0.5.1"
port-selector = "0.1.6"
port-selector = "0.1.6"
40 changes: 40 additions & 0 deletions common/utils/src/env_util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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::env;

pub fn get_env_value(env_key: &str) -> Option<String> {
env::var(env_key).ok()
}

pub fn get_env_value_for_i32(env_key: &str) -> Option<i32> {
get_env_value(env_key).map(|v| v.parse::<i32>().unwrap())
}

#[cfg(test)]
mod tests {
use crate::env_util::{get_env_value, get_env_value_for_i32};
use std::env;

#[test]
fn test_get_env_value() {
env::set_var("TEST_ENV", "testxxx1");
env::set_var("TEST_ENV3", "999");
assert!(get_env_value("TEST_ENV").is_some());
assert!(get_env_value("TEST_ENV2").is_none());
assert_eq!(get_env_value_for_i32("TEST_ENV3"), Some(999_i32))
}
}
6 changes: 3 additions & 3 deletions common/utils/src/host_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ pub use port_selector::Port;

// get local ip for linux/macos/windows
#[allow(dead_code)]
pub(crate) fn local_ip() -> IpAddr {
pub fn local_ip() -> IpAddr {
local_ip_address::local_ip().unwrap()
}

#[allow(dead_code)]
pub(crate) fn is_free_port(port: Port) -> bool {
pub fn is_free_port(port: Port) -> bool {
is_free(port)
}

// scan from the give port
#[allow(dead_code)]
pub(crate) fn scan_free_port(port: Port) -> Port {
pub fn scan_free_port(port: Port) -> Port {
for selected_port in port..65535 {
if is_free_port(selected_port) {
return selected_port;
Expand Down
2 changes: 1 addition & 1 deletion common/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
pub mod env_util;
pub mod host_util;
pub mod path_util;
pub mod yaml_util;
2 changes: 1 addition & 1 deletion common/utils/src/path_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod tests {

#[test]
fn test_app_root_dir() {
let dir = app_root_dir().join("application.yaml");
let dir = app_root_dir().join("../../../dubbo.yaml");
println!("dir: {}", dir.display());
}
}
4 changes: 0 additions & 4 deletions common/utils/tests/application.yaml

This file was deleted.

11 changes: 9 additions & 2 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "dubbo-config"
name = "config"
version = "0.3.0"
edition = "2021"
license = "Apache-2.0"
Expand All @@ -15,4 +15,11 @@ serde_yaml.workspace = true
lazy_static.workspace = true
once_cell.workspace = true
utils.workspace = true
logger.workspace=true
base.workspace = true
tracing.workspace = true
tokio.workspace = true
getset.workspace = true
thiserror.workspace = true
anyhow.workspace = true
[dev-dependencies]
ctor.workspace = true
Loading