Skip to content

Commit 3f9bbfb

Browse files
committed
feat:support polaris-rust sdk client
1 parent f4b6311 commit 3f9bbfb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+5781
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
Cargo.lock

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/polarismesh.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/polaris-rust.iml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "polaris-rust"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[dependencies]
8+
serde = { version = "1.0.198", features = ["derive"] }
9+
serde_json = "1.0.116"
10+
serde-duration-ext = "0.1.0"
11+
schemars = "0.8.16"
12+
serde_yaml = "0.9.34"
13+
bytes = {version = "1.4.0"}
14+
prost = {version = "0.12.4" }
15+
prost-types = {version = "0.12.4" }
16+
prost-build = {version = "0.12.4" }

src/circuitbreaker/api.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
pub trait CircuitBreakerAPI {
17+
18+
}

src/circuitbreaker/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
mod api;
17+
mod req;

src/circuitbreaker/req.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+

src/config/api.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
pub trait ConfigFileAPI {
17+
18+
}
19+
20+
pub trait ConfigGroupAPI {
21+
22+
}

src/config/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
pub mod api;
17+
pub mod req;

src/config/req.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+

src/core/config/config.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
use std::{fs, io};
17+
use serde::Deserialize;
18+
use crate::core::config::config_file::ConfigFileConfig;
19+
use crate::core::config::consumer::ConsumerConfig;
20+
use crate::core::config::global::GlobalConfig;
21+
use crate::core::config::provider::ProviderConfig;
22+
23+
#[derive(Deserialize)]
24+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
25+
pub struct Configuration {
26+
pub global: GlobalConfig,
27+
pub consumer: ConsumerConfig,
28+
pub provider: ProviderConfig,
29+
pub config: ConfigFileConfig,
30+
}
31+
32+
pub fn load(path: String) -> Result<*const Configuration, io::Error> {
33+
let val = fs::read_to_string(path);
34+
if val.is_ok() {
35+
let data = val.ok().unwrap();
36+
let config: Configuration = serde_yaml::from_str(&*data).expect(&format!("failure to format yaml str {}", &data));
37+
return Ok(&config)
38+
}
39+
return Err(val.err().unwrap())
40+
}
41+
42+
#[cfg(test)]
43+
mod tests {
44+
use std::env;
45+
use crate::core::config::config::load;
46+
47+
#[test]
48+
fn test_load() {
49+
let ret = load(env::var("TEST_LOAD_FILE").unwrap());
50+
if ret.is_ok() {
51+
let conf = ret.ok().unwrap();
52+
println!("{:?}", conf)
53+
} else {
54+
println!("{:?}", ret.err().unwrap())
55+
}
56+
}
57+
}

src/core/config/config_file.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
use serde::Deserialize;
17+
18+
#[derive(Deserialize)]
19+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
20+
pub struct ConfigFileConfig {
21+
pub properties_value_cache_size: u32,
22+
pub properties_value_expire_time: u32,
23+
}

src/core/config/consumer.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Tencent is pleased to support the open source community by making Polaris available.
2+
//
3+
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
4+
//
5+
// Licensed under the BSD 3-Clause License (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// https://opensource.org/licenses/BSD-3-Clause
10+
//
11+
// Unless required by applicable law or agreed to in writing, software distributed
12+
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13+
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
14+
// specific language governing permissions and limitations under the License.
15+
16+
use std::time::Duration;
17+
use schemars::Map;
18+
use serde::Deserialize;
19+
20+
#[derive(Deserialize)]
21+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
22+
pub struct ConsumerConfig {
23+
pub service_router: ServiceRouterConfig,
24+
pub circuit_breaker: CircuitBreakerConfig,
25+
pub load_balancer: LoadBalancerConfig,
26+
}
27+
28+
#[derive(Deserialize)]
29+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
30+
pub struct ServiceRouterConfig {
31+
pub before_chain: Vec<ServiceRouterPluginConfig>,
32+
pub core_chain: Vec<ServiceRouterPluginConfig>,
33+
pub after_chain: Vec<ServiceRouterPluginConfig>,
34+
}
35+
36+
#[derive(Deserialize)]
37+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
38+
pub struct ServiceRouterPluginConfig {
39+
pub name: String,
40+
pub options: Option<Map<String, String>>
41+
}
42+
43+
#[derive(Deserialize)]
44+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
45+
pub struct LoadBalancerConfig {
46+
pub plugins: Option<Vec<String>>
47+
}
48+
49+
#[derive(Deserialize)]
50+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
51+
pub struct CircuitBreakerConfig {
52+
pub enable: bool,
53+
pub enable_remote_pull: bool,
54+
}

0 commit comments

Comments
 (0)