kafka_client_engine/admin/list_partition_reassignments/
outcome.rs1use core::fmt;
4
5use kafka_client_core::{
6 DeliveryStatus as CoreDeliveryStatus, ListPartitionReassignmentsFailureKind as CoreFailureKind,
7 ListPartitionReassignmentsTerminal as CoreTerminal,
8};
9
10#[derive(Clone, Copy, Debug, Eq, PartialEq)]
12pub enum ListPartitionReassignmentsDeliveryStatus {
13 NotSent,
15 PossiblySent,
17}
18
19#[derive(Clone, Debug, Eq, PartialEq)]
21pub struct PartitionReassignment {
22 replicas: Vec<i32>,
23 adding_replicas: Vec<i32>,
24 removing_replicas: Vec<i32>,
25}
26
27impl PartitionReassignment {
28 pub fn into_parts(self) -> (Vec<i32>, Vec<i32>, Vec<i32>) {
30 (self.replicas, self.adding_replicas, self.removing_replicas)
31 }
32}
33
34#[derive(Clone, Debug, Eq, PartialEq)]
36pub struct PartitionReassignmentResult {
37 topic: String,
38 partition: i32,
39 reassignment: PartitionReassignment,
40}
41
42impl PartitionReassignmentResult {
43 pub fn into_parts(self) -> (String, i32, PartitionReassignment) {
45 (self.topic, self.partition, self.reassignment)
46 }
47}
48
49#[derive(Clone, Debug, Eq, PartialEq)]
51pub struct ListPartitionReassignmentsBatch {
52 throttle_time_ms: u32,
53 reassignments: Vec<PartitionReassignmentResult>,
54}
55
56impl ListPartitionReassignmentsBatch {
57 pub fn into_parts(self) -> (u32, Vec<PartitionReassignmentResult>) {
59 (self.throttle_time_ms, self.reassignments)
60 }
61}
62
63#[derive(Clone, Debug, Eq, PartialEq)]
65pub struct ListPartitionReassignmentsBrokerError {
66 code: i16,
67 message: Option<String>,
68 message_truncated: bool,
69}
70
71impl ListPartitionReassignmentsBrokerError {
72 pub fn into_parts(self) -> (i16, Option<String>, bool) {
74 (self.code, self.message, self.message_truncated)
75 }
76}
77
78#[derive(Clone, Debug, Eq, PartialEq)]
80pub enum ListPartitionReassignmentsFailureKind {
81 DeadlineElapsed,
83 DriverRejected,
85 Transport,
87 Broker(ListPartitionReassignmentsBrokerError),
89 ResponseTooLarge,
91 Compatibility,
93 InvalidResponse,
95}
96
97#[derive(Clone, Debug, Eq, PartialEq)]
99pub struct ListPartitionReassignmentsFailure {
100 kind: ListPartitionReassignmentsFailureKind,
101 delivery: ListPartitionReassignmentsDeliveryStatus,
102}
103
104impl ListPartitionReassignmentsFailure {
105 pub fn into_parts(
107 self,
108 ) -> (
109 ListPartitionReassignmentsFailureKind,
110 ListPartitionReassignmentsDeliveryStatus,
111 ) {
112 (self.kind, self.delivery)
113 }
114}
115
116#[derive(Clone, Debug, Eq, PartialEq)]
118pub enum ListPartitionReassignmentsOutcome {
119 Reassignments(ListPartitionReassignmentsBatch),
121 Failed(ListPartitionReassignmentsFailure),
123}
124
125#[derive(Clone, Copy, Debug, Eq, PartialEq)]
127pub enum ListPartitionReassignmentsObserverError {
128 AlreadyObserved,
130 Stale,
132}
133
134impl fmt::Display for ListPartitionReassignmentsObserverError {
135 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
136 formatter.write_str(match self {
137 Self::AlreadyObserved => "ListPartitionReassignments result was already observed",
138 Self::Stale => "ListPartitionReassignments observer is stale",
139 })
140 }
141}
142
143impl std::error::Error for ListPartitionReassignmentsObserverError {}
144
145pub(crate) fn translate_terminal(terminal: CoreTerminal) -> ListPartitionReassignmentsOutcome {
146 match terminal {
147 CoreTerminal::Reassignments(batch) => {
148 let (throttle_time_ms, reassignments) = batch.into_parts();
149 ListPartitionReassignmentsOutcome::Reassignments(ListPartitionReassignmentsBatch {
150 throttle_time_ms,
151 reassignments: reassignments
152 .into_iter()
153 .map(|outcome| {
154 let (topic, partition, reassignment) = outcome.into_parts();
155 let (replicas, adding_replicas, removing_replicas) =
156 reassignment.into_parts();
157 PartitionReassignmentResult {
158 topic,
159 partition,
160 reassignment: PartitionReassignment {
161 replicas,
162 adding_replicas,
163 removing_replicas,
164 },
165 }
166 })
167 .collect(),
168 })
169 }
170 CoreTerminal::Failed(failure) => {
171 ListPartitionReassignmentsOutcome::Failed(ListPartitionReassignmentsFailure {
172 kind: failure_kind(failure.kind().clone()),
173 delivery: delivery(failure.delivery()),
174 })
175 }
176 }
177}
178
179fn failure_kind(kind: CoreFailureKind) -> ListPartitionReassignmentsFailureKind {
180 match kind {
181 CoreFailureKind::DeadlineElapsed => ListPartitionReassignmentsFailureKind::DeadlineElapsed,
182 CoreFailureKind::DriverRejected => ListPartitionReassignmentsFailureKind::DriverRejected,
183 CoreFailureKind::Transport => ListPartitionReassignmentsFailureKind::Transport,
184 CoreFailureKind::Broker(error) => {
185 ListPartitionReassignmentsFailureKind::Broker(ListPartitionReassignmentsBrokerError {
186 code: error.code(),
187 message: error.message().map(str::to_owned),
188 message_truncated: error.message_truncated(),
189 })
190 }
191 CoreFailureKind::ResponseTooLarge => {
192 ListPartitionReassignmentsFailureKind::ResponseTooLarge
193 }
194 CoreFailureKind::Compatibility => ListPartitionReassignmentsFailureKind::Compatibility,
195 CoreFailureKind::InvalidResponse => ListPartitionReassignmentsFailureKind::InvalidResponse,
196 }
197}
198
199const fn delivery(status: CoreDeliveryStatus) -> ListPartitionReassignmentsDeliveryStatus {
200 match status {
201 CoreDeliveryStatus::NotSent => ListPartitionReassignmentsDeliveryStatus::NotSent,
202 CoreDeliveryStatus::PossiblySent => ListPartitionReassignmentsDeliveryStatus::PossiblySent,
203 }
204}