1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
use crate::{client::Client, proto, Result};
use tracing::debug;
#[derive(Debug)]
pub struct TopologyBuilder(Client);
impl TopologyBuilder {
pub fn new(client: Client) -> Self {
TopologyBuilder(client)
}
#[tracing::instrument(skip(self), name = "topology")]
pub async fn send(mut self) -> Result<TopologyResponse> {
let req = proto::TopologyRequest {};
debug!(?req, "sending request");
let res = self
.0
.gateway_client
.topology(tonic::Request::new(req))
.await?;
Ok(TopologyResponse(res.into_inner()))
}
}
#[derive(Debug)]
pub struct TopologyResponse(proto::TopologyResponse);
impl TopologyResponse {
pub fn brokers(&self) -> Vec<BrokerInfo> {
self.0
.brokers
.iter()
.map(|proto| BrokerInfo(proto.clone()))
.collect()
}
pub fn cluster_size(&self) -> u32 {
self.0.cluster_size as u32
}
pub fn partitions_count(&self) -> u32 {
self.0.partitions_count as u32
}
pub fn replication_factor(&self) -> u32 {
self.0.replication_factor as u32
}
pub fn gateway_version(&self) -> &str {
&self.0.gateway_version
}
}
#[derive(Debug)]
pub struct BrokerInfo(proto::BrokerInfo);
impl BrokerInfo {
pub fn node_id(&self) -> i32 {
self.0.node_id
}
pub fn host(&self) -> &str {
&self.0.host
}
pub fn port(&self) -> u32 {
self.0.port as u32
}
pub fn partitions(&self) -> Vec<Partition> {
self.0
.partitions
.iter()
.map(|proto| Partition(proto.clone()))
.collect()
}
pub fn version(&self) -> &str {
&self.0.version
}
}
#[derive(Debug)]
pub struct Partition(proto::Partition);
impl Partition {
pub fn partition_id(&self) -> i32 {
self.0.partition_id
}
pub fn role(&self) -> i32 {
self.0.role
}
pub fn health(&self) -> i32 {
self.0.health
}
}