use crate::client::RestClient;
use crate::error::{RestError, Result};
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Endpoint {
pub uid: String,
pub bdb_uid: u32,
pub node_uid: u32,
pub addr: String,
pub port: u16,
#[serde(skip_serializing_if = "Option::is_none")]
pub dns_name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub role: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ssl: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub error_code: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndpointStats {
pub uid: String,
pub intervals: Vec<StatsInterval>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StatsInterval {
pub interval: String,
pub timestamps: Vec<i64>,
pub values: Vec<Value>,
}
pub struct EndpointsHandler {
client: RestClient,
}
impl EndpointsHandler {
pub fn new(client: RestClient) -> Self {
EndpointsHandler { client }
}
#[deprecated(note = "Redis Software only exposes the endpoint statistics collection")]
pub async fn list(&self) -> Result<Vec<Endpoint>> {
crate::error::unsupported_operation("list endpoints")
}
#[deprecated(note = "Redis Software only exposes the endpoint statistics collection")]
pub async fn get(&self, _uid: &str) -> Result<Endpoint> {
crate::error::unsupported_operation("get endpoint")
}
pub async fn stats(&self, uid: &str) -> Result<EndpointStats> {
self.all_stats()
.await?
.into_iter()
.find(|stats| stats.uid == uid)
.ok_or(RestError::NotFound)
}
pub async fn all_stats(&self) -> Result<Vec<EndpointStats>> {
self.client.get("/v1/endpoints/stats").await
}
#[deprecated(note = "Redis Software does not register database-scoped endpoint routes")]
pub async fn list_by_database(&self, _bdb_uid: u32) -> Result<Vec<Endpoint>> {
crate::error::unsupported_operation("list database endpoints")
}
#[deprecated(note = "Redis Software does not register node-scoped endpoint routes")]
pub async fn list_by_node(&self, _node_uid: u32) -> Result<Vec<Endpoint>> {
crate::error::unsupported_operation("list node endpoints")
}
}