Skip to main content

kafka_client_engine/admin/list_partition_reassignments/
model.rs

1//! Engine-owned scalar intent for partition-reassignment listing.
2
3use kafka_client_core::{
4    ListPartitionReassignmentTarget as CoreTarget, ListPartitionReassignmentsPlan,
5    ListPartitionReassignmentsPlanError,
6};
7
8/// One inert caller-ordered topic-partition selection.
9#[derive(Clone, Debug, Eq, PartialEq)]
10pub struct ListPartitionReassignmentTarget {
11    topic: String,
12    partition: i32,
13}
14
15impl ListPartitionReassignmentTarget {
16    /// Creates one target for validation at the admission boundary.
17    pub const fn new(topic: String, partition: i32) -> Self {
18        Self { topic, partition }
19    }
20}
21
22/// Explicit inert request mode; selected and all-active cannot be confused.
23#[derive(Clone, Debug, Eq, PartialEq)]
24pub enum ListPartitionReassignmentsRequestSelection {
25    /// One caller-ordered batch validated during submission.
26    Selected(Vec<ListPartitionReassignmentTarget>),
27    /// Every active reassignment visible through the controller.
28    AllActive,
29}
30
31/// One inert controller reassignment query.
32#[derive(Clone, Debug, Eq, PartialEq)]
33pub struct ListPartitionReassignmentsRequest {
34    selection: ListPartitionReassignmentsRequestSelection,
35}
36
37impl ListPartitionReassignmentsRequest {
38    /// Creates one inert explicit topic-partition selection.
39    pub const fn selected(targets: Vec<ListPartitionReassignmentTarget>) -> Self {
40        Self {
41            selection: ListPartitionReassignmentsRequestSelection::Selected(targets),
42        }
43    }
44
45    /// Creates one explicit all-active query.
46    pub const fn all_active() -> Self {
47        Self {
48            selection: ListPartitionReassignmentsRequestSelection::AllActive,
49        }
50    }
51
52    pub(crate) fn canonicalize(mut self) -> Self {
53        if let ListPartitionReassignmentsRequestSelection::Selected(targets) = &mut self.selection {
54            for target in targets {
55                target.topic = target.topic.clone().into_boxed_str().into_string();
56            }
57        }
58        self
59    }
60
61    pub(crate) fn into_plan(
62        self,
63    ) -> Result<ListPartitionReassignmentsPlan, ListPartitionReassignmentsPlanError> {
64        match self.selection {
65            ListPartitionReassignmentsRequestSelection::Selected(targets) => {
66                ListPartitionReassignmentsPlan::selected(
67                    targets
68                        .into_iter()
69                        .map(|target| CoreTarget::new(target.topic, target.partition))
70                        .collect(),
71                )
72            }
73            ListPartitionReassignmentsRequestSelection::AllActive => {
74                Ok(ListPartitionReassignmentsPlan::all_active())
75            }
76        }
77    }
78}