From f982c915f5be852255081c7a05bd4191ad80c09f Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Mon, 11 Nov 2024 16:43:34 +0100 Subject: [PATCH] api types: implement api type for `BackupGroupDeleteStats` Make the `BackupGroupDeleteStats` exposable via the API by implementing the ApiTypes trait via the api macro invocation and add an additional field to account for the number of deleted groups. Further, add a method to add up the statistics. Signed-off-by: Christian Ebner --- pbs-api-types/src/datastore.rs | 36 +++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/pbs-api-types/src/datastore.rs b/pbs-api-types/src/datastore.rs index a4a48d2c..3d2b0eab 100644 --- a/pbs-api-types/src/datastore.rs +++ b/pbs-api-types/src/datastore.rs @@ -1581,8 +1581,28 @@ pub fn print_store_and_ns(store: &str, ns: &BackupNamespace) -> String { } } -#[derive(Default)] +pub const DELETE_STATS_COUNT_SCHEMA: Schema = + IntegerSchema::new("Number of entities").minimum(0).schema(); + +#[api( + properties: { + "removed-groups": { + schema: DELETE_STATS_COUNT_SCHEMA, + }, + "protected-snapshots": { + schema: DELETE_STATS_COUNT_SCHEMA, + }, + "removed-snapshots": { + schema: DELETE_STATS_COUNT_SCHEMA, + }, + }, +)] +#[derive(Default, Deserialize, Serialize)] +#[serde(rename_all = "kebab-case")] +/// Statistics for removed backup groups pub struct BackupGroupDeleteStats { + // Count of removed groups + removed_groups: usize, // Count of protected snapshots, therefore not removed protected_snapshots: usize, // Count of deleted snapshots @@ -1594,6 +1614,10 @@ impl BackupGroupDeleteStats { self.protected_snapshots == 0 } + pub fn removed_groups(&self) -> usize { + self.removed_groups + } + pub fn removed_snapshots(&self) -> usize { self.removed_snapshots } @@ -1602,6 +1626,16 @@ impl BackupGroupDeleteStats { self.protected_snapshots } + pub fn add(&mut self, rhs: &Self) { + self.removed_groups += rhs.removed_groups; + self.protected_snapshots += rhs.protected_snapshots; + self.removed_snapshots += rhs.removed_snapshots; + } + + pub fn increment_removed_groups(&mut self) { + self.removed_groups += 1; + } + pub fn increment_removed_snapshots(&mut self) { self.removed_snapshots += 1; }