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
//! Database group configuration
//!
//! ## Overview
//! - Manage database groups
//! - Configure group settings
//! - Query group membership
use crate::client::RestClient;
use crate::error::Result;
use serde::{Deserialize, Serialize};
/// Database group information
/// Represents a group of databases that share a memory pool
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BdbGroup {
/// Cluster unique ID of the database group
pub uid: u32,
/// Group name (may be auto-generated if not specified)
pub name: String,
/// The common memory pool size limit for all databases in the group, expressed in bytes
#[serde(skip_serializing_if = "Option::is_none")]
pub memory_size: Option<u64>,
/// A list of UIDs of member databases (read-only)
#[serde(skip_serializing_if = "Option::is_none")]
pub members: Option<Vec<String>>,
}
/// Response wrapper for `GET /v1/bdb_groups`.
///
/// The API returns `{"bdb_groups": [...]}`. Kept private; consumers go
/// through [`BdbGroupsHandler::list`] which unwraps to a flat
/// `Vec<BdbGroup>`.
#[derive(Debug, Clone, Deserialize)]
struct BdbGroupsListResponse {
#[serde(default)]
bdb_groups: Vec<BdbGroup>,
}
/// Handler for database group operations
pub struct BdbGroupsHandler {
client: RestClient,
}
impl BdbGroupsHandler {
/// Create a new handler bound to the given REST client.
pub fn new(client: RestClient) -> Self {
BdbGroupsHandler { client }
}
/// List all database groups.
///
/// `GET /v1/bdb_groups`. The API wraps the array under a
/// `bdb_groups` key; this method unwraps the wrapper so callers
/// get a flat `Vec<BdbGroup>`.
pub async fn list(&self) -> Result<Vec<BdbGroup>> {
let resp: BdbGroupsListResponse = self.client.get("/v1/bdb_groups").await?;
Ok(resp.bdb_groups)
}
/// Get a single database group by UID.
pub async fn get(&self, uid: u32) -> Result<BdbGroup> {
self.client.get(&format!("/v1/bdb_groups/{}", uid)).await
}
/// Create a new database group.
pub async fn create(&self, body: CreateBdbGroupRequest) -> Result<BdbGroup> {
self.client.post("/v1/bdb_groups", &body).await
}
/// Update an existing database group.
pub async fn update(&self, uid: u32, body: UpdateBdbGroupRequest) -> Result<BdbGroup> {
self.client
.put(&format!("/v1/bdb_groups/{}", uid), &body)
.await
}
/// Delete a database group.
pub async fn delete(&self, uid: u32) -> Result<()> {
self.client.delete(&format!("/v1/bdb_groups/{}", uid)).await
}
}
/// Request to create a new database group
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateBdbGroupRequest {
/// Name.
pub name: String,
}
/// Request to update an existing database group
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateBdbGroupRequest {
/// Name.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
}