From 49426e380de9926a15eb46f99e80925cf3b0cbeb Mon Sep 17 00:00:00 2001 From: onewe Date: Thu, 14 Mar 2024 23:45:57 +0800 Subject: [PATCH] Fix: add some license for every files - extract UrlParam to single file - fix github ci error --- .github/workflows/github-actions.yml | 1 + common/base/src/extension_param.rs | 69 ++++ common/base/src/lib.rs | 4 + common/base/src/registry_param.rs | 339 +++++++++++++++++ common/base/src/url.rs | 2 +- config/src/router.rs | 17 + config/src/service.rs | 12 - dubbo/src/cluster/failover.rs | 20 +- .../router/condition/condition_router.rs | 17 + dubbo/src/cluster/router/condition/matcher.rs | 17 + dubbo/src/cluster/router/condition/mod.rs | 16 + .../cluster/router/condition/single_router.rs | 16 + .../router/manager/condition_manager.rs | 17 + dubbo/src/cluster/router/manager/mod.rs | 16 + .../cluster/router/manager/router_manager.rs | 17 + .../src/cluster/router/manager/tag_manager.rs | 17 + dubbo/src/cluster/router/mod.rs | 16 + .../cluster/router/nacos_config_center/mod.rs | 16 + .../nacos_config_center/nacos_client.rs | 17 + dubbo/src/cluster/router/router_chain.rs | 17 + dubbo/src/cluster/router/tag/mod.rs | 16 + dubbo/src/cluster/router/tag/tag_router.rs | 17 + dubbo/src/cluster/router/utils.rs | 17 + dubbo/src/codegen.rs | 3 +- dubbo/src/directory/mod.rs | 6 +- dubbo/src/extension/mod.rs | 99 ++--- dubbo/src/extension/registry_extension.rs | 355 ++---------------- dubbo/src/framework.rs | 8 +- dubbo/src/invoker/clone_body.rs | 19 +- dubbo/src/invoker/clone_invoker.rs | 19 +- dubbo/src/invoker/mod.rs | 17 +- dubbo/src/lib.rs | 1 - dubbo/src/loadbalancer/mod.rs | 18 +- dubbo/src/param.rs | 17 + dubbo/src/protocol/triple/triple_protocol.rs | 5 +- dubbo/src/registry/mod.rs | 7 +- dubbo/src/registry/protocol.rs | 4 +- .../registry/{n_registry.rs => registry.rs} | 97 ++--- dubbo/src/registry/types.rs | 54 --- dubbo/src/route/mod.rs | 21 +- dubbo/src/svc.rs | 47 +-- dubbo/src/triple/client/builder.rs | 5 +- dubbo/src/triple/server/builder.rs | 6 +- dubbo/src/triple/transport/connection.rs | 5 +- registry/nacos/src/lib.rs | 37 +- registry/nacos/src/utils/mod.rs | 102 ----- registry/zookeeper/src/lib.rs | 29 +- 47 files changed, 963 insertions(+), 731 deletions(-) create mode 100644 common/base/src/extension_param.rs create mode 100644 common/base/src/registry_param.rs rename dubbo/src/registry/{n_registry.rs => registry.rs} (74%) delete mode 100644 dubbo/src/registry/types.rs delete mode 100644 registry/nacos/src/utils/mod.rs diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index cae915ae..8f5e9aa2 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -64,6 +64,7 @@ jobs: image: nacos/nacos-server:v2.3.1 ports: - 8848:8848 + - 9848:9848 env: MODE: standalone steps: diff --git a/common/base/src/extension_param.rs b/common/base/src/extension_param.rs new file mode 100644 index 00000000..7d65bf06 --- /dev/null +++ b/common/base/src/extension_param.rs @@ -0,0 +1,69 @@ +use crate::{url::UrlParam, StdError}; +use std::{borrow::Cow, convert::Infallible, str::FromStr}; + +pub struct ExtensionName(String); + +impl ExtensionName { + pub fn new(name: String) -> Self { + ExtensionName(name) + } +} + +impl UrlParam for ExtensionName { + type TargetType = String; + + fn name() -> &'static str { + "extension-name" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for ExtensionName { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(ExtensionName::new(s.to_string())) + } +} + +pub enum ExtensionType { + Registry, +} + +impl UrlParam for ExtensionType { + type TargetType = String; + + fn name() -> &'static str { + "extension-type" + } + + fn value(&self) -> Self::TargetType { + match self { + ExtensionType::Registry => "registry".to_owned(), + } + } + + fn as_str(&self) -> Cow { + match self { + ExtensionType::Registry => Cow::Borrowed("registry"), + } + } +} + +impl FromStr for ExtensionType { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + match s { + "registry" => Ok(ExtensionType::Registry), + _ => panic!("the extension type enum is not in range"), + } + } +} diff --git a/common/base/src/lib.rs b/common/base/src/lib.rs index b97b342f..dcc92564 100644 --- a/common/base/src/lib.rs +++ b/common/base/src/lib.rs @@ -19,8 +19,12 @@ allow(dead_code, unused_imports, unused_variables, unused_mut) )] pub mod constants; +pub mod extension_param; pub mod node; +pub mod registry_param; pub mod url; pub use node::Node; pub use url::Url; + +pub type StdError = Box; diff --git a/common/base/src/registry_param.rs b/common/base/src/registry_param.rs new file mode 100644 index 00000000..a10b29bb --- /dev/null +++ b/common/base/src/registry_param.rs @@ -0,0 +1,339 @@ +use crate::{url::UrlParam, StdError, Url}; +use std::{borrow::Cow, convert::Infallible, str::FromStr}; + +pub struct RegistryUrl(Url); + +impl RegistryUrl { + pub fn new(url: Url) -> Self { + Self(url) + } +} + +impl UrlParam for RegistryUrl { + type TargetType = Url; + + fn name() -> &'static str { + "registry" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for RegistryUrl { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.parse()?)) + } +} + +pub struct ServiceNamespace(String); + +impl ServiceNamespace { + pub fn new(namespace: String) -> Self { + Self(namespace) + } +} + +impl UrlParam for ServiceNamespace { + type TargetType = String; + + fn name() -> &'static str { + "namespace" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for ServiceNamespace { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for ServiceNamespace { + fn default() -> Self { + Self("public".to_string()) + } +} + +pub struct AppName(String); + +impl AppName { + pub fn new(app_name: String) -> Self { + Self(app_name) + } +} + +impl UrlParam for AppName { + type TargetType = String; + + fn name() -> &'static str { + "app_name" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for AppName { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for AppName { + fn default() -> Self { + Self("UnknownApp".to_string()) + } +} + +pub struct InterfaceName(String); + +impl InterfaceName { + pub fn new(interface_name: String) -> Self { + Self(interface_name) + } +} + +impl UrlParam for InterfaceName { + type TargetType = String; + + fn name() -> &'static str { + "interface" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for InterfaceName { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for InterfaceName { + fn default() -> Self { + Self("".to_string()) + } +} + +pub struct Category(String); + +impl Category { + pub fn new(category: String) -> Self { + Self(category) + } +} + +impl UrlParam for Category { + type TargetType = String; + + fn name() -> &'static str { + "category" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for Category { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for Category { + fn default() -> Self { + Self("".to_string()) + } +} + +pub struct Version(String); + +impl Version { + pub fn new(version: String) -> Self { + Self(version) + } +} + +impl UrlParam for Version { + type TargetType = String; + + fn name() -> &'static str { + "version" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for Version { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for Version { + fn default() -> Self { + Self("".to_string()) + } +} + +pub struct Group(String); + +impl Group { + pub fn new(group: String) -> Self { + Self(group) + } +} + +impl UrlParam for Group { + type TargetType = String; + + fn name() -> &'static str { + "group" + } + + fn value(&self) -> Self::TargetType { + self.0.clone() + } + + fn as_str(&self) -> Cow { + self.0.as_str().into() + } +} + +impl FromStr for Group { + type Err = StdError; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for Group { + fn default() -> Self { + Self("".to_string()) + } +} + +pub enum Side { + Provider, + Consumer, +} + +impl UrlParam for Side { + type TargetType = String; + + fn name() -> &'static str { + "side" + } + + fn value(&self) -> Self::TargetType { + match self { + Side::Consumer => "consumer".to_owned(), + Side::Provider => "provider".to_owned(), + } + } + + fn as_str(&self) -> Cow { + match self { + Side::Consumer => Cow::Borrowed("consumer"), + Side::Provider => Cow::Borrowed("provider"), + } + } +} + +impl FromStr for Side { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + match s.to_lowercase().as_str() { + "consumer" => Ok(Side::Consumer), + "provider" => Ok(Side::Provider), + _ => Ok(Side::Consumer), + } + } +} + +impl Default for Side { + fn default() -> Self { + Side::Consumer + } +} + +pub struct StaticInvokerUrls(String); + +impl UrlParam for StaticInvokerUrls { + type TargetType = Vec; + + fn name() -> &'static str { + "static-invoker-urls" + } + + fn value(&self) -> Self::TargetType { + self.0.split(",").map(|url| url.parse().unwrap()).collect() + } + + fn as_str(&self) -> Cow { + Cow::Borrowed(&self.0) + } +} + +impl FromStr for StaticInvokerUrls { + type Err = Infallible; + + fn from_str(s: &str) -> Result { + Ok(Self(s.to_string())) + } +} + +impl Default for StaticInvokerUrls { + fn default() -> Self { + Self(String::default()) + } +} diff --git a/common/base/src/url.rs b/common/base/src/url.rs index 59f0e7ca..d0601ed2 100644 --- a/common/base/src/url.rs +++ b/common/base/src/url.rs @@ -173,5 +173,5 @@ pub trait UrlParam: FromStr { fn value(&self) -> Self::TargetType; - fn as_str<'a>(&'a self) -> Cow<'a, str>; + fn as_str(&self) -> Cow; } diff --git a/config/src/router.rs b/config/src/router.rs index b45bd478..7976f6ea 100644 --- a/config/src/router.rs +++ b/config/src/router.rs @@ -1,3 +1,20 @@ +/* + * 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 serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)] diff --git a/config/src/service.rs b/config/src/service.rs index 1f85a926..8a1f1910 100644 --- a/config/src/service.rs +++ b/config/src/service.rs @@ -41,16 +41,4 @@ impl ServiceConfig { pub fn protocol(self, protocol: String) -> Self { Self { protocol, ..self } } - - // pub fn get_url(&self) -> Vec { - // let mut urls = Vec::new(); - // for (_, conf) in self.protocol_configs.iter() { - // urls.push(Url { - // url: conf.to_owned().to_url(), - // service_key: "".to_string(), - // }); - // } - - // urls - // } } diff --git a/dubbo/src/cluster/failover.rs b/dubbo/src/cluster/failover.rs index 8a00c9fb..a223ddf6 100644 --- a/dubbo/src/cluster/failover.rs +++ b/dubbo/src/cluster/failover.rs @@ -1,12 +1,28 @@ +/* + * 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::task::Poll; +use dubbo_base::StdError; use futures_util::future; use http::Request; use tower::{retry::Retry, util::Oneshot, ServiceExt}; use tower_service::Service; -use crate::StdError; - pub struct Failover { inner: N, // loadbalancer service } diff --git a/dubbo/src/cluster/router/condition/condition_router.rs b/dubbo/src/cluster/router/condition/condition_router.rs index 73aca005..21b525ac 100644 --- a/dubbo/src/cluster/router/condition/condition_router.rs +++ b/dubbo/src/cluster/router/condition/condition_router.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::{ cluster::router::{condition::single_router::ConditionSingleRouter, Router}, codegen::RpcInvocation, diff --git a/dubbo/src/cluster/router/condition/matcher.rs b/dubbo/src/cluster/router/condition/matcher.rs index 92bbe2da..2ee33d6e 100644 --- a/dubbo/src/cluster/router/condition/matcher.rs +++ b/dubbo/src/cluster/router/condition/matcher.rs @@ -1,3 +1,20 @@ +/* + * 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 regex::Regex; use std::{collections::HashSet, error::Error, option::Option}; diff --git a/dubbo/src/cluster/router/condition/mod.rs b/dubbo/src/cluster/router/condition/mod.rs index 7285b88f..d4a83b90 100644 --- a/dubbo/src/cluster/router/condition/mod.rs +++ b/dubbo/src/cluster/router/condition/mod.rs @@ -1,3 +1,19 @@ +/* + * 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 condition_router; pub mod matcher; pub mod single_router; diff --git a/dubbo/src/cluster/router/condition/single_router.rs b/dubbo/src/cluster/router/condition/single_router.rs index 5f06aa8f..54c61cb1 100644 --- a/dubbo/src/cluster/router/condition/single_router.rs +++ b/dubbo/src/cluster/router/condition/single_router.rs @@ -1,3 +1,19 @@ +/* + * 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 dubbo_base::Url; use dubbo_logger::tracing::info; use regex::Regex; diff --git a/dubbo/src/cluster/router/manager/condition_manager.rs b/dubbo/src/cluster/router/manager/condition_manager.rs index 7ad5e1b6..77729503 100644 --- a/dubbo/src/cluster/router/manager/condition_manager.rs +++ b/dubbo/src/cluster/router/manager/condition_manager.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::cluster::router::condition::{ condition_router::{ConditionRouter, ConditionSingleRouters}, single_router::ConditionSingleRouter, diff --git a/dubbo/src/cluster/router/manager/mod.rs b/dubbo/src/cluster/router/manager/mod.rs index 025f6c16..593fa22d 100644 --- a/dubbo/src/cluster/router/manager/mod.rs +++ b/dubbo/src/cluster/router/manager/mod.rs @@ -1,3 +1,19 @@ +/* + * 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. + */ mod condition_manager; pub mod router_manager; mod tag_manager; diff --git a/dubbo/src/cluster/router/manager/router_manager.rs b/dubbo/src/cluster/router/manager/router_manager.rs index e963181e..e6c8b6c3 100644 --- a/dubbo/src/cluster/router/manager/router_manager.rs +++ b/dubbo/src/cluster/router/manager/router_manager.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::cluster::router::{ manager::{condition_manager::ConditionRouterManager, tag_manager::TagRouterManager}, nacos_config_center::nacos_client::NacosClient, diff --git a/dubbo/src/cluster/router/manager/tag_manager.rs b/dubbo/src/cluster/router/manager/tag_manager.rs index 8dc24999..f028af21 100644 --- a/dubbo/src/cluster/router/manager/tag_manager.rs +++ b/dubbo/src/cluster/router/manager/tag_manager.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::cluster::router::tag::tag_router::{TagRouter, TagRouterInner}; use dubbo_config::router::TagRouterConfig; use std::sync::{Arc, RwLock}; diff --git a/dubbo/src/cluster/router/mod.rs b/dubbo/src/cluster/router/mod.rs index 17c9aec2..edc081b8 100644 --- a/dubbo/src/cluster/router/mod.rs +++ b/dubbo/src/cluster/router/mod.rs @@ -1,3 +1,19 @@ +/* + * 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 condition; pub mod manager; pub mod nacos_config_center; diff --git a/dubbo/src/cluster/router/nacos_config_center/mod.rs b/dubbo/src/cluster/router/nacos_config_center/mod.rs index 7878fa9f..71722315 100644 --- a/dubbo/src/cluster/router/nacos_config_center/mod.rs +++ b/dubbo/src/cluster/router/nacos_config_center/mod.rs @@ -1 +1,17 @@ +/* + * 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 nacos_client; diff --git a/dubbo/src/cluster/router/nacos_config_center/nacos_client.rs b/dubbo/src/cluster/router/nacos_config_center/nacos_client.rs index ce72641a..68b5f096 100644 --- a/dubbo/src/cluster/router/nacos_config_center/nacos_client.rs +++ b/dubbo/src/cluster/router/nacos_config_center/nacos_client.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::cluster::router::manager::router_manager::{ get_global_router_manager, RouterConfigChangeEvent, }; diff --git a/dubbo/src/cluster/router/router_chain.rs b/dubbo/src/cluster/router/router_chain.rs index 42d5826f..601bc5e1 100644 --- a/dubbo/src/cluster/router/router_chain.rs +++ b/dubbo/src/cluster/router/router_chain.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::{cluster::router::BoxRouter, invocation::RpcInvocation}; use dubbo_base::Url; use std::{collections::HashMap, sync::Arc}; diff --git a/dubbo/src/cluster/router/tag/mod.rs b/dubbo/src/cluster/router/tag/mod.rs index 6ac5b218..673a7201 100644 --- a/dubbo/src/cluster/router/tag/mod.rs +++ b/dubbo/src/cluster/router/tag/mod.rs @@ -1 +1,17 @@ +/* + * 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 tag_router; diff --git a/dubbo/src/cluster/router/tag/tag_router.rs b/dubbo/src/cluster/router/tag/tag_router.rs index 7a83ea57..3d28f936 100644 --- a/dubbo/src/cluster/router/tag/tag_router.rs +++ b/dubbo/src/cluster/router/tag/tag_router.rs @@ -1,3 +1,20 @@ +/* + * 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 crate::{ cluster::router::{utils::to_original_map, Router}, codegen::RpcInvocation, diff --git a/dubbo/src/cluster/router/utils.rs b/dubbo/src/cluster/router/utils.rs index 2ca50fcc..eca98f6e 100644 --- a/dubbo/src/cluster/router/utils.rs +++ b/dubbo/src/cluster/router/utils.rs @@ -1,3 +1,20 @@ +/* + * 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 dubbo_base::Url; use std::{collections::HashMap, string::String}; diff --git a/dubbo/src/codegen.rs b/dubbo/src/codegen.rs index 452f560d..eb1d3850 100644 --- a/dubbo/src/codegen.rs +++ b/dubbo/src/codegen.rs @@ -22,6 +22,7 @@ pub use std::{ pub use async_trait::async_trait; pub use bytes::Bytes; +pub use dubbo_base::StdError; pub use http_body::Body; pub use hyper::Body as hyperBody; pub use tower_service::Service; @@ -39,7 +40,7 @@ pub use super::{ TripleServer, }, }, - BoxBody, BoxFuture, StdError, + BoxBody, BoxFuture, }; pub use crate::{ filter::{service::FilterService, Filter}, diff --git a/dubbo/src/directory/mod.rs b/dubbo/src/directory/mod.rs index a0d3c56c..ace67e68 100644 --- a/dubbo/src/directory/mod.rs +++ b/dubbo/src/directory/mod.rs @@ -28,9 +28,8 @@ use crate::{ invoker::{clone_invoker::CloneInvoker, NewInvoker}, param::Param, svc::NewService, - StdError, }; -use dubbo_base::Url; +use dubbo_base::{StdError, Url}; use dubbo_logger::tracing::{debug, error}; use futures_util::future; use tokio::sync::mpsc::channel; @@ -41,7 +40,8 @@ use tower::{ ServiceExt, }; -use crate::extension::registry_extension::{proxy::RegistryProxy, InterfaceName, Registry}; +use crate::extension::registry_extension::{proxy::RegistryProxy, Registry}; +use dubbo_base::registry_param::InterfaceName; use tower_service::Service; type BufferedDirectory = diff --git a/dubbo/src/extension/mod.rs b/dubbo/src/extension/mod.rs index df63b237..5641bea8 100644 --- a/dubbo/src/extension/mod.rs +++ b/dubbo/src/extension/mod.rs @@ -1,12 +1,27 @@ +/* + * 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 registry_extension; use crate::{ - extension::registry_extension::proxy::RegistryProxy, registry::n_registry::StaticRegistry, - StdError, + extension::registry_extension::proxy::RegistryProxy, registry::registry::StaticRegistry, }; -use dubbo_base::{url::UrlParam, Url}; +use dubbo_base::{extension_param::ExtensionType, url::UrlParam, StdError, Url}; use dubbo_logger::tracing::{error, info}; -use std::{borrow::Cow, convert::Infallible, str::FromStr}; use thiserror::Error; use tokio::sync::oneshot; @@ -120,6 +135,7 @@ pub struct ExtensionDirectoryCommander { } impl ExtensionDirectoryCommander { + #[allow(private_bounds)] pub async fn register(&self) -> Result<(), StdError> where T: Extension, @@ -164,6 +180,7 @@ impl ExtensionDirectoryCommander { } } + #[allow(private_bounds)] pub async fn remove(&self) -> Result<(), StdError> where T: Extension, @@ -235,10 +252,6 @@ impl ExtensionDirectoryCommander { match extensions { Extensions::Registry(proxy) => Ok(proxy), - _ => { - let err_msg = format!("load registry extension failed: {}", url_str); - Err(LoadExtensionError::new(err_msg).into()) - } } } } @@ -260,6 +273,7 @@ enum ExtensionOpt { pub(crate) trait Sealed {} +#[allow(private_bounds)] #[async_trait::async_trait] pub trait Extension: Sealed { type Target; @@ -269,6 +283,7 @@ pub trait Extension: Sealed { async fn create(url: &Url) -> Result; } +#[allow(private_bounds)] pub(crate) trait ExtensionMetaInfo { fn extension_type() -> ExtensionType; } @@ -281,6 +296,7 @@ pub(crate) enum ExtensionFactories { RegistryExtensionFactory(registry_extension::RegistryExtensionFactory), } +#[allow(private_bounds)] pub(crate) trait ConvertToExtensionFactories { fn convert_to_extension_factories() -> ExtensionFactories; } @@ -314,70 +330,3 @@ impl LoadExtensionError { LoadExtensionError(msg) } } - -pub struct ExtensionName(String); - -impl ExtensionName { - pub fn new(name: String) -> Self { - ExtensionName(name) - } -} - -impl UrlParam for ExtensionName { - type TargetType = String; - - fn name() -> &'static str { - "extension-name" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str(&self) -> Cow { - self.0.as_str().into() - } -} - -impl FromStr for ExtensionName { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(ExtensionName::new(s.to_string())) - } -} - -pub enum ExtensionType { - Registry, -} - -impl UrlParam for ExtensionType { - type TargetType = String; - - fn name() -> &'static str { - "extension-type" - } - - fn value(&self) -> Self::TargetType { - match self { - ExtensionType::Registry => "registry".to_owned(), - } - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - match self { - ExtensionType::Registry => Cow::Borrowed("registry"), - } - } -} - -impl FromStr for ExtensionType { - type Err = Infallible; - - fn from_str(s: &str) -> Result { - match s { - "registry" => Ok(ExtensionType::Registry), - _ => panic!("the extension type enum is not in range"), - } - } -} diff --git a/dubbo/src/extension/registry_extension.rs b/dubbo/src/extension/registry_extension.rs index e4b547f8..e27d6a58 100644 --- a/dubbo/src/extension/registry_extension.rs +++ b/dubbo/src/extension/registry_extension.rs @@ -1,21 +1,34 @@ -use std::{ - borrow::Cow, collections::HashMap, convert::Infallible, future::Future, pin::Pin, str::FromStr, -}; +/* + * 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, future::Future, pin::Pin}; use async_trait::async_trait; use thiserror::Error; use tokio::sync::mpsc::Receiver; use tower::discover::Change; -use dubbo_base::{url::UrlParam, Url}; +use dubbo_base::{ + extension_param::ExtensionName, registry_param::RegistryUrl, url::UrlParam, StdError, Url, +}; use proxy::RegistryProxy; -use crate::{ - extension::{ - ConvertToExtensionFactories, Extension, ExtensionFactories, ExtensionMetaInfo, - ExtensionName, ExtensionType, - }, - StdError, +use crate::extension::{ + ConvertToExtensionFactories, Extension, ExtensionFactories, ExtensionMetaInfo, ExtensionType, }; // extension://0.0.0.0/?extension-type=registry&extension-name=nacos®istry-url=nacos://127.0.0.1:8848 @@ -95,12 +108,6 @@ pub(super) struct RegistryExtensionLoader { } impl RegistryExtensionLoader { - pub(super) fn new() -> Self { - Self { - factories: HashMap::new(), - } - } - pub(crate) async fn register( &mut self, extension_name: String, @@ -131,7 +138,8 @@ type RegistryConstructor = for<'a> fn( ) -> Pin< Box, StdError>> + Send + 'a>, >; -pub(super) struct RegistryExtensionFactory { + +pub(crate) struct RegistryExtensionFactory { constructor: RegistryConstructor, instances: HashMap, } @@ -180,14 +188,10 @@ pub mod proxy { use thiserror::Error; use tokio::sync::oneshot; - - use dubbo_base::Url; + use dubbo_base::{StdError, Url}; use dubbo_logger::tracing::error; - use crate::{ - extension::registry_extension::{DiscoverStream, Registry}, - StdError, - }; + use crate::extension::registry_extension::{DiscoverStream, Registry}; pub(super) enum RegistryOpt { Register(Url, oneshot::Sender>), @@ -378,308 +382,3 @@ pub mod proxy { } } } - -pub struct RegistryUrl(Url); - -impl RegistryUrl { - pub fn new(url: Url) -> Self { - Self(url) - } -} - -impl UrlParam for RegistryUrl { - type TargetType = Url; - - fn name() -> &'static str { - "registry" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for RegistryUrl { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.parse()?)) - } -} - -pub struct ServiceNamespace(String); - -impl ServiceNamespace { - pub fn new(namespace: String) -> Self { - Self(namespace) - } -} - -impl UrlParam for ServiceNamespace { - type TargetType = String; - - fn name() -> &'static str { - "namespace" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for ServiceNamespace { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for ServiceNamespace { - fn default() -> Self { - Self("public".to_string()) - } -} - -pub struct AppName(String); - -impl AppName { - pub fn new(app_name: String) -> Self { - Self(app_name) - } -} - -impl UrlParam for AppName { - type TargetType = String; - - fn name() -> &'static str { - "app_name" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for AppName { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for AppName { - fn default() -> Self { - Self("UnknownApp".to_string()) - } -} - -pub struct InterfaceName(String); - -impl InterfaceName { - pub fn new(interface_name: String) -> Self { - Self(interface_name) - } -} - -impl UrlParam for InterfaceName { - type TargetType = String; - - fn name() -> &'static str { - "interface" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for InterfaceName { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for InterfaceName { - fn default() -> Self { - Self("".to_string()) - } -} - -pub struct Category(String); - -impl Category { - pub fn new(category: String) -> Self { - Self(category) - } -} - -impl UrlParam for Category { - type TargetType = String; - - fn name() -> &'static str { - "category" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for Category { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for Category { - fn default() -> Self { - Self("".to_string()) - } -} - -pub struct Version(String); - -impl Version { - pub fn new(version: String) -> Self { - Self(version) - } -} - -impl UrlParam for Version { - type TargetType = String; - - fn name() -> &'static str { - "version" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for Version { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for Version { - fn default() -> Self { - Self("".to_string()) - } -} - -pub struct Group(String); - -impl Group { - pub fn new(group: String) -> Self { - Self(group) - } -} - -impl UrlParam for Group { - type TargetType = String; - - fn name() -> &'static str { - "group" - } - - fn value(&self) -> Self::TargetType { - self.0.clone() - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - self.0.as_str().into() - } -} - -impl FromStr for Group { - type Err = StdError; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for Group { - fn default() -> Self { - Self("".to_string()) - } -} - -pub enum Side { - Provider, - Consumer, -} - -impl UrlParam for Side { - type TargetType = String; - - fn name() -> &'static str { - "side" - } - - fn value(&self) -> Self::TargetType { - match self { - Side::Consumer => "consumer".to_owned(), - Side::Provider => "provider".to_owned(), - } - } - - fn as_str<'a>(&'a self) -> Cow<'a, str> { - match self { - Side::Consumer => Cow::Borrowed("consumer"), - Side::Provider => Cow::Borrowed("provider"), - } - } -} - -impl FromStr for Side { - type Err = Infallible; - - fn from_str(s: &str) -> Result { - match s.to_lowercase().as_str() { - "consumer" => Ok(Side::Consumer), - "provider" => Ok(Side::Provider), - _ => Ok(Side::Consumer), - } - } -} - -impl Default for Side { - fn default() -> Self { - Side::Consumer - } -} diff --git a/dubbo/src/framework.rs b/dubbo/src/framework.rs index 7b0bd446..f3c6dc1a 100644 --- a/dubbo/src/framework.rs +++ b/dubbo/src/framework.rs @@ -15,15 +15,11 @@ * limitations under the License. */ -use std::{ - collections::HashMap, - error::Error, - pin::Pin, -}; +use std::{collections::HashMap, error::Error, pin::Pin}; use crate::{ extension, - extension::registry_extension::{Registry}, + extension::registry_extension::Registry, protocol::{BoxExporter, Protocol}, registry::protocol::RegistryProtocol, }; diff --git a/dubbo/src/invoker/clone_body.rs b/dubbo/src/invoker/clone_body.rs index 4de8f899..913910a5 100644 --- a/dubbo/src/invoker/clone_body.rs +++ b/dubbo/src/invoker/clone_body.rs @@ -1,3 +1,19 @@ +/* + * 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::VecDeque, pin::Pin, @@ -8,13 +24,12 @@ use std::{ use bytes::{Buf, BufMut, Bytes, BytesMut}; use futures_core::ready; +use dubbo_base::StdError; use http::HeaderMap; use http_body::Body; use pin_project::pin_project; use thiserror::Error; -use crate::StdError; - #[derive(Error, Debug)] #[error("buffered body reach max capacity.")] pub struct ReachMaxCapacityError; diff --git a/dubbo/src/invoker/clone_invoker.rs b/dubbo/src/invoker/clone_invoker.rs index c1fa00d8..557d76e0 100644 --- a/dubbo/src/invoker/clone_invoker.rs +++ b/dubbo/src/invoker/clone_invoker.rs @@ -1,5 +1,22 @@ +/* + * 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::{mem, pin::Pin, task::Poll}; +use dubbo_base::StdError; use dubbo_logger::tracing::debug; use futures_core::{future::BoxFuture, ready, Future, TryFuture}; use futures_util::FutureExt; @@ -16,8 +33,6 @@ use tokio_util::sync::ReusableBoxFuture; use tower::{buffer::Buffer, ServiceExt}; use tower_service::Service; -use crate::StdError; - use super::clone_body::CloneBody; enum Inner { diff --git a/dubbo/src/invoker/mod.rs b/dubbo/src/invoker/mod.rs index 512744e4..1c87c0ec 100644 --- a/dubbo/src/invoker/mod.rs +++ b/dubbo/src/invoker/mod.rs @@ -1,4 +1,19 @@ - +/* + * 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 crate::{codegen::TripleInvoker, invoker::clone_invoker::CloneInvoker, svc::NewService}; pub mod clone_body; diff --git a/dubbo/src/lib.rs b/dubbo/src/lib.rs index d0fc8070..1a521a2e 100644 --- a/dubbo/src/lib.rs +++ b/dubbo/src/lib.rs @@ -39,7 +39,6 @@ use std::{future::Future, pin::Pin}; pub use framework::Dubbo; -pub type StdError = Box; pub type BoxFuture = self::Pin> + Send + 'static>>; pub(crate) type Error = Box; pub type BoxBody = http_body::combinators::UnsyncBoxBody; diff --git a/dubbo/src/loadbalancer/mod.rs b/dubbo/src/loadbalancer/mod.rs index 4e26781d..74f22174 100644 --- a/dubbo/src/loadbalancer/mod.rs +++ b/dubbo/src/loadbalancer/mod.rs @@ -1,3 +1,20 @@ +/* + * 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 dubbo_base::StdError; use futures_core::future::BoxFuture; use tower::{discover::ServiceList, ServiceExt}; use tower_service::Service; @@ -7,7 +24,6 @@ use crate::{ invoker::{clone_body::CloneBody, clone_invoker::CloneInvoker}, param::Param, svc::NewService, - StdError, }; use crate::protocol::triple::triple_invoker::TripleInvoker; diff --git a/dubbo/src/param.rs b/dubbo/src/param.rs index bef50419..298c3b31 100644 --- a/dubbo/src/param.rs +++ b/dubbo/src/param.rs @@ -1,3 +1,20 @@ +/* + * 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 trait Param { fn param(&self) -> T; } diff --git a/dubbo/src/protocol/triple/triple_protocol.rs b/dubbo/src/protocol/triple/triple_protocol.rs index adbb9679..27174ba0 100644 --- a/dubbo/src/protocol/triple/triple_protocol.rs +++ b/dubbo/src/protocol/triple/triple_protocol.rs @@ -15,11 +15,10 @@ * limitations under the License. */ -use std::{boxed::Box, collections::HashMap}; +use std::collections::HashMap; -use crate::extension::registry_extension::InterfaceName; use async_trait::async_trait; -use dubbo_base::{url::UrlParam, Url}; +use dubbo_base::{registry_param::InterfaceName, url::UrlParam, Url}; use super::{ triple_exporter::TripleExporter, triple_invoker::TripleInvoker, triple_server::TripleServer, diff --git a/dubbo/src/registry/mod.rs b/dubbo/src/registry/mod.rs index f619d407..08ae175b 100644 --- a/dubbo/src/registry/mod.rs +++ b/dubbo/src/registry/mod.rs @@ -17,8 +17,8 @@ #![allow(unused_variables, dead_code, missing_docs)] -use crate::{extension, extension::registry_extension::proxy::RegistryProxy, StdError}; -use dubbo_base::Url; +use crate::{extension, extension::registry_extension::proxy::RegistryProxy}; +use dubbo_base::{StdError, Url}; use std::{ future::Future, pin::Pin, @@ -27,9 +27,8 @@ use std::{ use tower_service::Service; pub mod integration; -pub mod n_registry; pub mod protocol; -pub mod types; +pub mod registry; #[derive(Clone)] pub struct MkRegistryService { diff --git a/dubbo/src/registry/protocol.rs b/dubbo/src/registry/protocol.rs index 4d3e6df6..76350a42 100644 --- a/dubbo/src/registry/protocol.rs +++ b/dubbo/src/registry/protocol.rs @@ -15,7 +15,7 @@ * limitations under the License. */ -use dubbo_base::{url::UrlParam, Url}; +use dubbo_base::{registry_param::InterfaceName, url::UrlParam, Url}; use dubbo_logger::tracing; use std::{ collections::HashMap, @@ -23,7 +23,7 @@ use std::{ }; use crate::{ - extension::registry_extension::{proxy::RegistryProxy, InterfaceName, Registry}, + extension::registry_extension::{proxy::RegistryProxy, Registry}, protocol::{ triple::{triple_exporter::TripleExporter, triple_protocol::TripleProtocol}, BoxExporter, BoxInvoker, Protocol, diff --git a/dubbo/src/registry/n_registry.rs b/dubbo/src/registry/registry.rs similarity index 74% rename from dubbo/src/registry/n_registry.rs rename to dubbo/src/registry/registry.rs index 961ff0c6..85a81683 100644 --- a/dubbo/src/registry/n_registry.rs +++ b/dubbo/src/registry/registry.rs @@ -1,9 +1,20 @@ -use std::{ - borrow::Cow, - collections::{HashMap, HashSet}, - convert::Infallible, - str::FromStr, -}; +/* + * 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, HashSet}; use async_trait::async_trait; use itertools::Itertools; @@ -13,14 +24,16 @@ use tokio::sync::{ Mutex, }; -use dubbo_base::{url::UrlParam, Url}; +use dubbo_base::{ + extension_param::{ExtensionName, ExtensionType}, + registry_param::{InterfaceName, RegistryUrl, StaticInvokerUrls}, + url::UrlParam, + StdError, Url, +}; -use crate::{ - extension::{ - registry_extension::{DiscoverStream, InterfaceName, Registry, RegistryUrl, ServiceChange}, - Extension, ExtensionName, ExtensionType, - }, - StdError, +use crate::extension::{ + registry_extension::{DiscoverStream, Registry, ServiceChange}, + Extension, }; pub struct StaticServiceValues { @@ -60,11 +73,11 @@ impl StaticRegistry { let mut map = HashMap::with_capacity(static_urls.len()); for url in static_urls { - let service_name = url.query::().unwrap(); - let service_name = service_name.value(); + let interface_name = url.query::().unwrap(); + let interface_name = interface_name.value(); let static_values = map - .entry(service_name) + .entry(interface_name) .or_insert_with(|| StaticServiceValues { listeners: Vec::new(), urls: HashSet::new(), @@ -95,13 +108,13 @@ impl Default for StaticRegistry { #[async_trait] impl Registry for StaticRegistry { async fn register(&self, url: Url) -> Result<(), StdError> { - let service_name = url.query::().unwrap(); - let service_name = service_name.value(); + let interface_name = url.query::().unwrap(); + let interface_name = interface_name.value(); let mut lock = self.urls.lock().await; let static_values = lock - .entry(service_name) + .entry(interface_name) .or_insert_with(|| StaticServiceValues { listeners: Vec::new(), urls: HashSet::new(), @@ -118,12 +131,12 @@ impl Registry for StaticRegistry { } async fn unregister(&self, url: Url) -> Result<(), StdError> { - let service_name = url.query::().unwrap(); - let service_name = service_name.value(); + let interface_name = url.query::().unwrap(); + let interface_name = interface_name.value(); let mut lock = self.urls.lock().await; - match lock.get_mut(&service_name) { + match lock.get_mut(&interface_name) { None => Ok(()), Some(static_values) => { let url = url.to_string(); @@ -133,7 +146,7 @@ impl Registry for StaticRegistry { ret.is_ok() }); if static_values.urls.is_empty() { - lock.remove(&service_name); + lock.remove(&interface_name); } Ok(()) } @@ -141,13 +154,13 @@ impl Registry for StaticRegistry { } async fn subscribe(&self, url: Url) -> Result { - let service_name = url.query::().unwrap(); - let service_name = service_name.value(); + let interface_name = url.query::().unwrap(); + let interface_name = interface_name.value(); let change_rx = { let mut lock = self.urls.lock().await; let static_values = lock - .entry(service_name) + .entry(interface_name) .or_insert_with(|| StaticServiceValues { listeners: Vec::new(), urls: HashSet::new(), @@ -207,35 +220,3 @@ impl Extension for StaticRegistry { #[derive(Error, Debug)] #[error("static registry error: {0}")] struct StaticRegistryError(String); - -pub(crate) struct StaticInvokerUrls(String); - -impl UrlParam for StaticInvokerUrls { - type TargetType = Vec; - - fn name() -> &'static str { - "static-invoker-urls" - } - - fn value(&self) -> Self::TargetType { - self.0.split(",").map(|url| url.parse().unwrap()).collect() - } - - fn as_str(&self) -> Cow { - Cow::Borrowed(&self.0) - } -} - -impl FromStr for StaticInvokerUrls { - type Err = Infallible; - - fn from_str(s: &str) -> Result { - Ok(Self(s.to_string())) - } -} - -impl Default for StaticInvokerUrls { - fn default() -> Self { - Self(String::default()) - } -} diff --git a/dubbo/src/registry/types.rs b/dubbo/src/registry/types.rs deleted file mode 100644 index e39d8570..00000000 --- a/dubbo/src/registry/types.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 type Registries = Arc>>; -// -// pub const DEFAULT_REGISTRY_KEY: &str = "default"; -// -// pub trait RegistriesOperation { -// fn get(&self, registry_key: &str) -> ArcRegistry; -// fn insert(&self, registry_key: String, registry: ArcRegistry); -// fn default_registry(&self) -> ArcRegistry; -// } -// -// impl RegistriesOperation for Registries { -// fn get(&self, registry_key: &str) -> ArcRegistry { -// self.as_ref() -// .lock() -// .unwrap() -// .get(registry_key) -// .unwrap() -// .clone() -// } -// -// fn insert(&self, registry_key: String, registry: ArcRegistry) { -// self.as_ref().lock().unwrap().insert(registry_key, registry); -// } -// -// fn default_registry(&self) -> ArcRegistry { -// let guard = self.as_ref().lock().unwrap(); -// let (_, result) = guard -// .iter() -// .find_or_first(|e| e.0 == DEFAULT_REGISTRY_KEY) -// .unwrap() -// .to_owned(); -// result.clone() -// } -// } diff --git a/dubbo/src/route/mod.rs b/dubbo/src/route/mod.rs index c2448642..28dfda7c 100644 --- a/dubbo/src/route/mod.rs +++ b/dubbo/src/route/mod.rs @@ -1,5 +1,23 @@ +/* + * 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::pin::Pin; +use dubbo_base::StdError; use dubbo_logger::tracing::debug; use futures_core::{ready, Future}; use futures_util::{future::Ready, FutureExt, TryFutureExt}; @@ -11,7 +29,6 @@ use crate::{ invoker::clone_invoker::CloneInvoker, param::Param, svc::NewService, - StdError, }; pub struct NewRoutes { @@ -20,6 +37,7 @@ pub struct NewRoutes { pub struct NewRoutesFuture { inner: RoutesFutureInnerState, + #[allow(dead_code)] target: T, } @@ -39,6 +57,7 @@ pub enum RoutesFutureInnerState { #[derive(Clone)] pub struct Routes { + #[allow(dead_code)] target: T, invokers: Vec>, } diff --git a/dubbo/src/svc.rs b/dubbo/src/svc.rs index db59b92d..f8466636 100644 --- a/dubbo/src/svc.rs +++ b/dubbo/src/svc.rs @@ -1,4 +1,20 @@ -use std::{marker::PhantomData, sync::Arc}; +/* + * 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::sync::Arc; pub trait NewService { type Service; @@ -45,32 +61,3 @@ impl NewService for ArcNewService { self.inner.new_service(t) } } - -// inner: Box> + Send>>> + Send>, -pub struct BoxedService { - inner: N, - _mark: PhantomData, -} - -impl BoxedService { - pub fn layer() -> impl tower_layer::Layer { - tower_layer::layer_fn(|inner: N| Self { - inner, - _mark: PhantomData, - }) - } -} - -// impl NewService for BoxedService -// where -// N: NewService, -// N::Service: Service + Send, -// >::Future: Send + 'static, -// { -// type Service = Box>::Response, Error = >::Error, Future = Pin>::Response, >::Error>> + Send>>> + Send>; - -// fn new_service(&self, target: T) -> Self::Service { -// let service = self.inner.new_service(target); -// Box::new(service.map_future(|f|Box::pin(f) as _)) -// } -// } diff --git a/dubbo/src/triple/client/builder.rs b/dubbo/src/triple/client/builder.rs index 74d753ca..94c855b4 100644 --- a/dubbo/src/triple/client/builder.rs +++ b/dubbo/src/triple/client/builder.rs @@ -22,7 +22,7 @@ use crate::{ route::NewRoutes, utils::boxed_clone::BoxCloneService, }; -use crate::registry::{n_registry::StaticRegistry, MkRegistryService}; +use crate::registry::{registry::StaticRegistry, MkRegistryService}; use aws_smithy_http::body::SdkBody; use dubbo_base::Url; use tower::ServiceBuilder; @@ -39,7 +39,6 @@ pub struct ClientBuilder { pub connector: &'static str, registry_extension_url: Option, pub direct: bool, - host: String, } impl ClientBuilder { @@ -49,7 +48,6 @@ impl ClientBuilder { connector: "", registry_extension_url: None, direct: false, - host: "".to_string(), } } @@ -60,7 +58,6 @@ impl ClientBuilder { connector: "", registry_extension_url: Some(registry_extension_url), direct: true, - host: host.to_string(), } } diff --git a/dubbo/src/triple/server/builder.rs b/dubbo/src/triple/server/builder.rs index f846dda8..ab67982f 100644 --- a/dubbo/src/triple/server/builder.rs +++ b/dubbo/src/triple/server/builder.rs @@ -21,16 +21,14 @@ use std::{ str::FromStr, }; -use dubbo_base::{url::UrlParam, Url}; +use dubbo_base::{registry_param::InterfaceName, url::UrlParam, Url}; use dubbo_logger::tracing; use http::{Request, Response, Uri}; use hyper::body::Body; use tokio_rustls::rustls::{Certificate, PrivateKey}; use tower_service::Service; -use crate::{ - extension::registry_extension::InterfaceName, triple::transport::DubboServer, utils, BoxBody, -}; +use crate::{triple::transport::DubboServer, utils, BoxBody}; #[derive(Clone, Default, Debug)] pub struct ServerBuilder { diff --git a/dubbo/src/triple/transport/connection.rs b/dubbo/src/triple/transport/connection.rs index cb0b9d71..212c8807 100644 --- a/dubbo/src/triple/transport/connection.rs +++ b/dubbo/src/triple/transport/connection.rs @@ -15,12 +15,11 @@ * limitations under the License. */ +use dubbo_base::StdError; use hyper::client::{conn::Builder, service::Connect}; use tower_service::Service; -use crate::{ - boxed, invoker::clone_body::CloneBody, triple::transport::connector::get_connector, StdError, -}; +use crate::{boxed, invoker::clone_body::CloneBody, triple::transport::connector::get_connector}; type HyperConnect = Connect< crate::utils::boxed_clone::BoxCloneService, diff --git a/registry/nacos/src/lib.rs b/registry/nacos/src/lib.rs index c61f25b9..204846b2 100644 --- a/registry/nacos/src/lib.rs +++ b/registry/nacos/src/lib.rs @@ -14,24 +14,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -mod utils; use async_trait::async_trait; -use dubbo_base::Url; +use dubbo_base::{StdError, Url}; use std::{collections::HashMap, sync::Arc}; -use tokio::{sync::mpsc}; - -use dubbo::{ - extension::{ - registry_extension::{ - AppName, Category, DiscoverStream, Group, InterfaceName, - Registry, RegistryUrl, ServiceChange, ServiceNamespace, Version, - }, - Extension, +use tokio::sync::mpsc; + +use dubbo::extension::{ + registry_extension::{DiscoverStream, Registry, ServiceChange}, + Extension, +}; +use dubbo_base::{ + registry_param::{ + AppName, Category, Group, InterfaceName, RegistryUrl, ServiceNamespace, Version, }, - StdError, + url::UrlParam, }; -use dubbo_base::url::UrlParam; use dubbo_logger::tracing::info; use nacos_sdk::api::{ naming::{NamingEventListener, NamingService, NamingServiceBuilder, ServiceInstance}, @@ -39,7 +37,6 @@ use nacos_sdk::api::{ }; use tokio::sync::{watch, Notify}; - pub struct NacosRegistry { url: Url, nacos_service: Arc, @@ -352,14 +349,19 @@ impl NamingEventListener for NacosNamingEventListener { } struct NacosServiceName { + #[allow(dead_code)] category: String, + #[allow(dead_code)] interface: String, + #[allow(dead_code)] version: String, + #[allow(dead_code)] group: String, + #[allow(dead_code)] value: String, } @@ -388,22 +390,27 @@ impl NacosServiceName { } } + #[allow(dead_code)] fn category(&self) -> &str { &self.category } + #[allow(dead_code)] fn interface(&self) -> &str { &self.interface } + #[allow(dead_code)] fn version(&self) -> &str { &self.version } + #[allow(dead_code)] fn group(&self) -> &str { &self.group } + #[allow(dead_code)] fn value(&self) -> &str { &self.value } @@ -416,7 +423,7 @@ pub mod tests { use std::thread; use tracing::error; - use dubbo::extension::{registry_extension::Side, ExtensionName}; + use dubbo_base::{extension_param::ExtensionName, registry_param::Side}; use tracing::metadata::LevelFilter; use super::*; diff --git a/registry/nacos/src/utils/mod.rs b/registry/nacos/src/utils/mod.rs deleted file mode 100644 index df396294..00000000 --- a/registry/nacos/src/utils/mod.rs +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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 dubbo_base::Url; -use nacos_sdk::api::props::ClientProps; - -const APP_NAME_KEY: &str = "AppName"; - -const UNKNOWN_APP: &str = "UnknownApp"; - -const NAMESPACE_KEY: &str = "namespace"; - -const DEFAULT_NAMESPACE: &str = "public"; - -const USERNAME_KEY: &str = "username"; - -const PASSWORD_KEY: &str = "password"; - -const BACKUP_KEY: &str = "backup"; - -const WILDCARD: &str = "*"; - -const RANGE_STR_SEPARATOR: &str = ","; - -pub(crate) fn build_nacos_client_props(url: &Url) -> (nacos_sdk::api::props::ClientProps, bool) { - let host = url.host().unwrap(); - let port = url.port().unwrap(); - let backup = url - .query_param_by_kv(BACKUP_KEY) - .map(|mut data| { - data.insert(0, ','); - data - }) - .unwrap_or_default(); - let server_addr = format!("{}:{}{}", host, port, backup); - - let namespace = url - .query_param_by_kv(NAMESPACE_KEY) - .unwrap_or_else(|| DEFAULT_NAMESPACE.to_string()); - let app_name = url - .query_param_by_kv(APP_NAME_KEY) - .unwrap_or_else(|| UNKNOWN_APP.to_string()); - let username = url.query_param_by_kv(USERNAME_KEY).unwrap_or_default(); - let password = url.query_param_by_kv(PASSWORD_KEY).unwrap_or_default(); - - let enable_auth = !password.is_empty() && !username.is_empty(); - - // todo ext parameters - - let mut client_props = ClientProps::new(); - - client_props = client_props - .server_addr(server_addr) - .namespace(namespace) - .app_name(app_name) - .auth_username(username) - .auth_password(password); - - (client_props, enable_auth) -} - -pub(crate) fn is_wildcard_str(str: &str) -> bool { - str.eq(WILDCARD) -} - -pub(crate) fn is_range_str(str: &str) -> bool { - let ret = str.split(RANGE_STR_SEPARATOR); - let count = ret.count(); - count > 1 -} - -pub(crate) fn is_concrete_str(str: &str) -> bool { - !is_wildcard_str(str) && !is_range_str(str) -} - -pub(crate) fn match_range(range: &str, value: &str) -> bool { - if range.is_empty() { - return true; - } - - if !is_range_str(range) { - return false; - } - - range - .split(RANGE_STR_SEPARATOR) - .any(|data| (*data).eq(value)) -} diff --git a/registry/zookeeper/src/lib.rs b/registry/zookeeper/src/lib.rs index db9bb3de..dc44899d 100644 --- a/registry/zookeeper/src/lib.rs +++ b/registry/zookeeper/src/lib.rs @@ -22,18 +22,15 @@ use std::{collections::HashMap, env, sync::Arc, time::Duration}; use async_trait::async_trait; use dubbo_base::{ constants::{DUBBO_KEY, LOCALHOST_IP, PROVIDERS_KEY}, - Url, + StdError, Url, }; use dubbo_logger::tracing::{debug, error, info}; use serde::{Deserialize, Serialize}; use tokio::{select, sync::mpsc}; use zookeeper::{Acl, CreateMode, WatchedEvent, WatchedEventType, Watcher, ZooKeeper}; -use dubbo::{ - extension::registry_extension::{DiscoverStream, InterfaceName, Registry, ServiceChange}, - StdError, -}; -use dubbo_base::url::UrlParam; +use dubbo::extension::registry_extension::{DiscoverStream, Registry, ServiceChange}; +use dubbo_base::{registry_param::InterfaceName, url::UrlParam}; // 从url中获取服务注册的元数据 // rawURL = fmt.Sprintf("%s://%s%s?%s", c.Protocol, host, c.Path, s) @@ -264,23 +261,23 @@ impl Default for ZookeeperRegistry { impl Registry for ZookeeperRegistry { async fn register(&self, url: Url) -> Result<(), StdError> { debug!("register url: {}", url); - let service_name = url.query::().unwrap().value(); + let interface_name = url.query::().unwrap().value(); let url_str = url.as_str(); let zk_path = format!( "/{}/{}/{}/{}", - DUBBO_KEY, service_name, PROVIDERS_KEY, url_str + DUBBO_KEY, interface_name, PROVIDERS_KEY, url_str ); self.create_path_with_parent_check(zk_path.as_str(), LOCALHOST_IP, CreateMode::Ephemeral)?; Ok(()) } async fn unregister(&self, url: Url) -> Result<(), StdError> { - let service_name = url.query::().unwrap().value(); + let interface_name = url.query::().unwrap().value(); let url_str = url.as_str(); let zk_path = format!( "/{}/{}/{}/{}", - DUBBO_KEY, service_name, PROVIDERS_KEY, url_str + DUBBO_KEY, interface_name, PROVIDERS_KEY, url_str ); self.delete_path(zk_path.as_str()); Ok(()) @@ -288,9 +285,9 @@ impl Registry for ZookeeperRegistry { // for consumer to find the changes of providers async fn subscribe(&self, url: Url) -> Result { - let service_name = url.query::().unwrap().value(); + let interface_name = url.query::().unwrap().value(); - let zk_path = format!("/{}/{}/{}", DUBBO_KEY, service_name, PROVIDERS_KEY); + let zk_path = format!("/{}/{}/{}", DUBBO_KEY, interface_name, PROVIDERS_KEY); debug!("subscribe service: {}", zk_path); @@ -303,12 +300,12 @@ impl Registry for ZookeeperRegistry { let zk_client_in_task = self.zk_client.clone(); let zk_path_in_task = zk_path.clone(); - let service_name_in_task = service_name.clone(); + let interface_name_in_task = interface_name.clone(); let arc_listener_in_task = arc_listener.clone(); tokio::spawn(async move { let zk_client = zk_client_in_task; let zk_path = zk_path_in_task; - let service_name = service_name_in_task; + let interface_name = interface_name_in_task; let listener = arc_listener_in_task; let mut current_urls = Vec::new(); @@ -384,9 +381,9 @@ impl Registry for ZookeeperRegistry { } async fn unsubscribe(&self, url: Url) -> Result<(), StdError> { - let service_name = url.query::().unwrap().value(); + let interface_name = url.query::().unwrap().value(); - let zk_path = format!("/{}/{}/{}", DUBBO_KEY, &service_name, PROVIDERS_KEY); + let zk_path = format!("/{}/{}/{}", DUBBO_KEY, &interface_name, PROVIDERS_KEY); info!("unsubscribe service: {}", zk_path); Ok(())