redis_enterprise/
services.rs1use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12use typed_builder::TypedBuilder;
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Service {
17 pub service_id: String,
19 pub name: String,
21 pub service_type: String,
23 pub enabled: bool,
25 #[serde(skip_serializing_if = "Option::is_none")]
27 pub config: Option<Value>,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub status: Option<String>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub node_uids: Option<Vec<u32>>,
34
35 #[serde(flatten)]
36 pub extra: Value,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
41pub struct ServiceConfigRequest {
42 pub enabled: bool,
44 #[serde(skip_serializing_if = "Option::is_none")]
46 #[builder(default, setter(strip_option))]
47 pub config: Option<Value>,
48 #[serde(skip_serializing_if = "Option::is_none")]
50 #[builder(default, setter(strip_option))]
51 pub node_uids: Option<Vec<u32>>,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
56pub struct ServiceStatus {
57 pub service_id: String,
59 pub status: String,
61 #[serde(skip_serializing_if = "Option::is_none")]
63 pub message: Option<String>,
64 #[serde(skip_serializing_if = "Option::is_none")]
66 pub node_statuses: Option<Vec<NodeServiceStatus>>,
67
68 #[serde(flatten)]
69 pub extra: Value,
70}
71
72#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct NodeServiceStatus {
75 pub node_uid: u32,
77 pub status: String,
79 #[serde(skip_serializing_if = "Option::is_none")]
81 pub message: Option<String>,
82}
83
84pub struct ServicesHandler {
86 client: RestClient,
87}
88
89impl ServicesHandler {
90 pub fn new(client: RestClient) -> Self {
91 ServicesHandler { client }
92 }
93
94 pub async fn list(&self) -> Result<Vec<Service>> {
96 self.client.get("/v1/services").await
97 }
98
99 pub async fn get(&self, service_id: &str) -> Result<Service> {
101 self.client
102 .get(&format!("/v1/services/{}", service_id))
103 .await
104 }
105
106 pub async fn update(&self, service_id: &str, request: ServiceConfigRequest) -> Result<Service> {
108 self.client
109 .put(&format!("/v1/services/{}", service_id), &request)
110 .await
111 }
112
113 pub async fn status(&self, service_id: &str) -> Result<ServiceStatus> {
115 self.client
116 .get(&format!("/v1/services/{}/status", service_id))
117 .await
118 }
119
120 pub async fn restart(&self, service_id: &str) -> Result<ServiceStatus> {
122 self.client
123 .post(
124 &format!("/v1/services/{}/restart", service_id),
125 &Value::Null,
126 )
127 .await
128 }
129
130 pub async fn stop(&self, service_id: &str) -> Result<ServiceStatus> {
132 self.client
133 .post(&format!("/v1/services/{}/stop", service_id), &Value::Null)
134 .await
135 }
136
137 pub async fn start(&self, service_id: &str) -> Result<ServiceStatus> {
139 self.client
140 .post(&format!("/v1/services/{}/start", service_id), &Value::Null)
141 .await
142 }
143
144 pub async fn create(&self, body: Value) -> Result<Service> {
146 self.client.post("/v1/services", &body).await
147 }
148}