|
1 | 1 | #![allow(unused_imports, unused_assignments, unused_variables)] |
2 | 2 | use crate::common::option_utils::OptionUtils; |
3 | 3 | use crate::naming::model::{Instance, ServiceKey}; |
4 | | -use crate::naming::service::SubscriberInfoDto; |
| 4 | +use crate::naming::service::{ServiceInfoDto, SubscriberInfoDto}; |
5 | 5 | use crate::naming::NamingUtils; |
6 | 6 | use crate::utils::get_bool_from_string; |
7 | 7 | use serde::{Deserialize, Serialize}; |
@@ -358,3 +358,48 @@ pub struct ServiceQuerySubscribersListResponce { |
358 | 358 | pub count: usize, |
359 | 359 | pub subscribers: Vec<SubscriberInfoDto>, |
360 | 360 | } |
| 361 | + |
| 362 | +#[derive(Debug, Serialize, Deserialize, Default)] |
| 363 | +#[serde(rename_all = "camelCase")] |
| 364 | +pub struct ServiceInfoVo { |
| 365 | + pub namespace_id: Arc<String>, |
| 366 | + pub group_name: Arc<String>, |
| 367 | + pub name: Arc<String>, |
| 368 | + pub protect_threshold: f32, |
| 369 | + pub metadata: Option<Arc<HashMap<String, String>>>, |
| 370 | + pub selector: HashMap<String, String>, |
| 371 | + pub clusters: Vec<ClusterVo>, |
| 372 | +} |
| 373 | + |
| 374 | +#[derive(Debug, Serialize, Deserialize, Default)] |
| 375 | +#[serde(rename_all = "camelCase")] |
| 376 | +pub struct ClusterVo { |
| 377 | + pub name: String, |
| 378 | + pub health_checker: HashMap<String, String>, |
| 379 | + pub metadata: HashMap<String, String>, |
| 380 | +} |
| 381 | + |
| 382 | +impl ServiceInfoVo { |
| 383 | + /// 从 ServiceInfoDto 创建 ServiceInfoVo,使用默认的命名空间和集群信息 |
| 384 | + pub fn from_dto(dto: ServiceInfoDto, namespace_id: Arc<String>) -> Self { |
| 385 | + let mut selector = HashMap::new(); |
| 386 | + selector.insert("type".to_owned(), "none".to_string()); |
| 387 | + selector.insert("contextType".to_owned(), "NONE".to_string()); |
| 388 | + let mut health_checker = HashMap::new(); |
| 389 | + health_checker.insert("type".to_owned(), "TCP".to_string()); |
| 390 | + |
| 391 | + Self { |
| 392 | + namespace_id, |
| 393 | + group_name: dto.group_name, |
| 394 | + name: dto.service_name, |
| 395 | + protect_threshold: dto.protect_threshold.unwrap_or(0.0), |
| 396 | + metadata: dto.metadata, |
| 397 | + selector, |
| 398 | + clusters: vec![ClusterVo { |
| 399 | + name: "DEFAULT".to_string(), |
| 400 | + health_checker, |
| 401 | + metadata: HashMap::new(), |
| 402 | + }], |
| 403 | + } |
| 404 | + } |
| 405 | +} |
0 commit comments