redis_enterprise/
endpoints.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Endpoint {
16 pub uid: String,
17 pub bdb_uid: u32,
18 pub node_uid: u32,
19 pub addr: String,
20 pub port: u16,
21 #[serde(skip_serializing_if = "Option::is_none")]
22 pub dns_name: Option<String>,
23 #[serde(skip_serializing_if = "Option::is_none")]
24 pub role: Option<String>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub ssl: Option<bool>,
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub status: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
31 pub description: Option<String>,
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub error_code: Option<String>,
35
36 #[serde(flatten)]
37 pub extra: Value,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct EndpointStats {
43 pub uid: String,
44 pub intervals: Vec<StatsInterval>,
45
46 #[serde(flatten)]
47 pub extra: Value,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct StatsInterval {
52 pub interval: String,
53 pub timestamps: Vec<i64>,
54 pub values: Vec<Value>,
55}
56
57pub struct EndpointsHandler {
59 client: RestClient,
60}
61
62impl EndpointsHandler {
63 pub fn new(client: RestClient) -> Self {
64 EndpointsHandler { client }
65 }
66
67 pub async fn list(&self) -> Result<Vec<Endpoint>> {
69 self.client.get("/v1/endpoints").await
70 }
71
72 pub async fn get(&self, uid: &str) -> Result<Endpoint> {
74 self.client.get(&format!("/v1/endpoints/{}", uid)).await
75 }
76
77 pub async fn stats(&self, uid: &str) -> Result<EndpointStats> {
79 self.client
80 .get(&format!("/v1/endpoints/{}/stats", uid))
81 .await
82 }
83
84 pub async fn all_stats(&self) -> Result<Vec<EndpointStats>> {
86 self.client.get("/v1/endpoints/stats").await
87 }
88
89 pub async fn list_by_database(&self, bdb_uid: u32) -> Result<Vec<Endpoint>> {
91 self.client
92 .get(&format!("/v1/bdbs/{}/endpoints", bdb_uid))
93 .await
94 }
95
96 pub async fn list_by_node(&self, node_uid: u32) -> Result<Vec<Endpoint>> {
98 self.client
99 .get(&format!("/v1/nodes/{}/endpoints", node_uid))
100 .await
101 }
102}