Skip to main content

reduct_base/msg/
replication_api.rs

1// Copyright 2024 ReductSoftware UG
2// This Source Code Form is subject to the terms of the Mozilla Public
3//    License, v. 2.0. If a copy of the MPL was not distributed with this
4//    file, You can obtain one at https://mozilla.org/MPL/2.0/.
5use crate::msg::diagnostics::Diagnostics;
6use crate::Labels;
7use serde::{Deserialize, Serialize};
8use serde_json::Value;
9
10/// Replication mode
11#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
12#[serde(rename_all = "lowercase")]
13pub enum ReplicationMode {
14    /// Replication is active and sends records
15    Enabled,
16    /// Replication stores transactions but doesn't send them
17    Paused,
18    /// Replication ignores new transactions
19    Disabled,
20}
21
22impl Default for ReplicationMode {
23    fn default() -> Self {
24        Self::Enabled
25    }
26}
27
28/// Replication settings
29#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
30pub struct ReplicationSettings {
31    /// Source bucket
32    pub src_bucket: String,
33    /// Destination bucket
34    pub dst_bucket: String,
35    /// Destination host URL (e.g. https://reductstore.com)
36    pub dst_host: String,
37    /// Destination access token
38    pub dst_token: Option<String>,
39    /// Entries to replicate. If empty, all entries are replicated. Wildcards are supported.
40    #[serde(default)]
41    pub entries: Vec<String>,
42    /// Labels to include
43    #[serde(default)]
44    pub include: Labels,
45    /// Labels to exclude
46    #[serde(default)]
47    pub exclude: Labels,
48    /// Replication each N-th record
49    #[serde(default)]
50    pub each_n: Option<u64>,
51    /// Replication a record every S seconds
52    #[serde(default)]
53    pub each_s: Option<f64>,
54    /// When condition
55    #[serde(default)]
56    pub when: Option<Value>,
57    /// Mode
58    #[serde(default)]
59    pub mode: ReplicationMode,
60}
61
62/// Replication info
63#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
64pub struct ReplicationInfo {
65    /// Replication name
66    pub name: String,
67    /// Replication mode
68    #[serde(default)] // for backward compatibility with older versions of reduct-rs
69    pub mode: ReplicationMode,
70    /// Remote instance is available and replication is active
71    pub is_active: bool,
72    /// Replication is provisioned
73    pub is_provisioned: bool,
74    /// Number of records pending replication
75    pub pending_records: u64,
76}
77
78/// Payload for updating replication mode
79#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq)]
80pub struct ReplicationModePayload {
81    pub mode: ReplicationMode,
82}
83
84/// Replication list
85#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default)]
86pub struct ReplicationList {
87    /// Replication list
88    pub replications: Vec<ReplicationInfo>,
89}
90
91/// Replication settings
92#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
93pub struct FullReplicationInfo {
94    /// Info
95    pub info: ReplicationInfo,
96    /// Settings
97    pub settings: ReplicationSettings,
98    /// Diagnostics
99    pub diagnostics: Diagnostics,
100}