confluent_kafka/admin/options/alter_partition_reassignments_options.rs
1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Options for `Admin::alter_partition_reassignments`.
16
17/// Options for `Admin::alter_partition_reassignments`.
18#[derive(Clone, Debug)]
19#[doc(alias = "org.apache.kafka.clients.admin.AlterPartitionReassignmentsOptions")]
20pub struct AlterPartitionReassignmentsOptions {
21 timeout_ms: Option<i32>,
22 allow_replication_factor_change: bool,
23}
24
25impl Default for AlterPartitionReassignmentsOptions {
26 fn default() -> Self {
27 // Mirrors Java's field initializer `allowReplicationFactorChange = true`.
28 Self { timeout_ms: None, allow_replication_factor_change: true }
29 }
30}
31
32impl AlterPartitionReassignmentsOptions {
33 /// Creates default options (default API timeout, replication-factor change
34 /// allowed).
35 #[doc(
36 alias = "org.apache.kafka.clients.admin.AlterPartitionReassignmentsOptions#AlterPartitionReassignmentsOptions"
37 )]
38 pub fn new() -> Self {
39 Self::default()
40 }
41
42 /// Set the timeout in milliseconds for this operation, or `None` if the default
43 /// API timeout for the `AdminClient` should be used.
44 ///
45 /// # Arguments
46 ///
47 /// - `timeout_ms` - the timeout in milliseconds, or `None` for the default API timeout.
48 ///
49 /// # Returns
50 ///
51 /// This `AlterPartitionReassignmentsOptions` instance.
52 #[must_use]
53 #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
54 pub fn set_timeout_ms(mut self, timeout_ms: Option<i32>) -> Self {
55 self.timeout_ms = timeout_ms;
56 self
57 }
58
59 /// Returns the timeout in milliseconds for this operation, or `None` if the
60 /// default API timeout for the `AdminClient` should be used.
61 #[doc(alias = "org.apache.kafka.clients.admin.AbstractOptions#timeoutMs")]
62 pub fn timeout_ms(&self) -> Option<i32> {
63 self.timeout_ms
64 }
65
66 /// Set the option indicating if the alter partition reassignments call should be
67 /// allowed to alter the replication factor of a partition.
68 /// In cases where it is not allowed, any replication factor change will result in an error
69 /// returned by the API.
70 ///
71 /// # Arguments
72 ///
73 /// - `allow` - whether the replication factor of a partition may change.
74 ///
75 /// # Returns
76 ///
77 /// This `AlterPartitionReassignmentsOptions` instance.
78 #[must_use]
79 #[doc(alias = "org.apache.kafka.clients.admin.AlterPartitionReassignmentsOptions#allowReplicationFactorChange")]
80 pub fn set_allow_replication_factor_change(mut self, allow: bool) -> Self {
81 self.allow_replication_factor_change = allow;
82 self
83 }
84
85 /// Returns a boolean indicating if the alter partition reassignments should be
86 /// allowed to alter the replication factor of a partition.
87 /// In cases where it is not allowed, any replication factor change will result in an error
88 /// returned by the API.
89 #[doc(alias = "org.apache.kafka.clients.admin.AlterPartitionReassignmentsOptions#allowReplicationFactorChange")]
90 pub fn allow_replication_factor_change(&self) -> bool {
91 self.allow_replication_factor_change
92 }
93}
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98
99 #[test]
100 fn defaults_match_java() {
101 let options = AlterPartitionReassignmentsOptions::new();
102 assert_eq!(options.timeout_ms(), None);
103 assert!(options.allow_replication_factor_change());
104 }
105
106 #[test]
107 fn fluent_setters() {
108 let options = AlterPartitionReassignmentsOptions::new()
109 .set_timeout_ms(Some(5000))
110 .set_allow_replication_factor_change(false);
111 assert_eq!(options.timeout_ms(), Some(5000));
112 assert!(!options.allow_replication_factor_change());
113 }
114}