|
| 1 | +use super::list_types::{Codec, TopicDescription}; |
1 | 2 | use crate::client::TimeoutSettings;
|
2 |
| -use crate::client_topic::list_types::{Consumer, MeteringMode, SupportedCodecs}; |
| 3 | +use crate::client_topic::list_types::{AlterConsumer, Consumer, MeteringMode}; |
3 | 4 | use crate::client_topic::topicwriter::writer::TopicWriter;
|
4 | 5 | use crate::client_topic::topicwriter::writer_options::{
|
5 | 6 | TopicWriterOptions, TopicWriterOptionsBuilder,
|
6 | 7 | };
|
7 | 8 | use crate::errors;
|
8 | 9 | use crate::grpc_connection_manager::GrpcConnectionManager;
|
| 10 | +use crate::grpc_wrapper::raw_topic_service::alter_topic::RawAlterTopicRequest; |
9 | 11 | use crate::grpc_wrapper::raw_topic_service::create_topic::RawCreateTopicRequest;
|
10 |
| -use crate::grpc_wrapper::raw_topic_service::delete_topic::RawDropTopicRequest; |
| 12 | +use crate::grpc_wrapper::raw_topic_service::describe_topic::RawDescribeTopicRequest; |
| 13 | +use crate::grpc_wrapper::raw_topic_service::drop_topic::RawDropTopicRequest; |
11 | 14 | use crate::YdbError::InternalError;
|
12 | 15 | use crate::{grpc_wrapper, YdbResult};
|
13 | 16 | use derive_builder::{Builder, UninitializedFieldError};
|
14 | 17 | use std::collections::HashMap;
|
| 18 | +use std::time::Duration; |
15 | 19 |
|
16 | 20 | #[derive(Builder)]
|
17 | 21 | #[builder(build_fn(error = "errors::YdbError"))]
|
18 |
| -pub struct TopicOptions { |
19 |
| - // Use TopicOptionsBuilder |
20 |
| - #[builder(setter(strip_option), default)] |
21 |
| - pub metering_mode: Option<MeteringMode>, |
| 22 | +pub struct CreateTopicOptions { |
| 23 | + // Use CreateTopicOptionsBuilder |
22 | 24 | #[builder(default)]
|
23 | 25 | pub min_active_partitions: i64,
|
24 | 26 | #[builder(default)]
|
25 | 27 | pub partition_count_limit: i64,
|
26 | 28 | #[builder(setter(strip_option), default)]
|
27 |
| - pub retention_period: Option<core::time::Duration>, |
| 29 | + pub retention_period: Option<Duration>, |
28 | 30 | #[builder(default)]
|
29 | 31 | pub retention_storage_mb: i64,
|
30 | 32 | #[builder(default)]
|
31 |
| - pub supported_codecs: SupportedCodecs, |
| 33 | + pub supported_codecs: Vec<Codec>, |
32 | 34 | #[builder(default)]
|
33 | 35 | pub partition_write_speed_bytes_per_second: i64,
|
34 | 36 | #[builder(default)]
|
35 | 37 | pub partition_write_burst_bytes: i64,
|
36 | 38 | #[builder(default)]
|
| 39 | + pub consumers: Vec<Consumer>, |
| 40 | + #[builder(default)] |
37 | 41 | pub attributes: HashMap<String, String>,
|
| 42 | + #[builder(setter(strip_option), default)] |
| 43 | + pub metering_mode: Option<MeteringMode>, |
| 44 | +} |
| 45 | + |
| 46 | +#[derive(Builder)] |
| 47 | +#[builder(build_fn(error = "errors::YdbError"))] |
| 48 | +pub struct AlterTopicOptions { |
| 49 | + // Use AlterTopicOptionsBuilder |
| 50 | + #[builder(setter(strip_option), default)] |
| 51 | + pub set_min_active_partitions: Option<i64>, |
| 52 | + |
| 53 | + #[builder(setter(strip_option), default)] |
| 54 | + pub set_partition_count_limit: Option<i64>, |
| 55 | + |
| 56 | + #[builder(setter(strip_option), default)] |
| 57 | + pub set_retention_period: Option<Duration>, |
| 58 | + |
| 59 | + #[builder(setter(strip_option), default)] |
| 60 | + pub set_retention_storage_mb: Option<i64>, |
| 61 | + |
| 62 | + #[builder(setter(strip_option), default)] |
| 63 | + pub set_supported_codecs: Option<Vec<Codec>>, |
| 64 | + |
| 65 | + #[builder(setter(strip_option), default)] |
| 66 | + pub set_partition_write_speed_bytes_per_second: Option<i64>, |
| 67 | + |
| 68 | + #[builder(setter(strip_option), default)] |
| 69 | + pub set_partition_write_burst_bytes: Option<i64>, |
| 70 | + |
38 | 71 | #[builder(default)]
|
39 |
| - pub consumers: Vec<Consumer>, |
| 72 | + pub alter_attributes: HashMap<String, String>, |
| 73 | + |
| 74 | + #[builder(default)] |
| 75 | + pub add_consumers: Vec<Consumer>, |
| 76 | + |
| 77 | + #[builder(default)] |
| 78 | + pub drop_consumers: Vec<String>, |
| 79 | + |
| 80 | + #[builder(default)] |
| 81 | + pub alter_consumers: Vec<AlterConsumer>, |
| 82 | + |
| 83 | + #[builder(setter(strip_option), default)] |
| 84 | + pub set_metering_mode: Option<MeteringMode>, |
| 85 | +} |
| 86 | + |
| 87 | +#[derive(Builder)] |
| 88 | +#[builder(build_fn(error = "errors::YdbError"))] |
| 89 | +pub struct DescribeTopicOptions { |
| 90 | + // Use DescribeTopicOptionsBuilder |
| 91 | + #[builder(default)] |
| 92 | + pub include_stats: bool, |
| 93 | + #[builder(default)] |
| 94 | + pub include_location: bool, |
40 | 95 | }
|
41 | 96 |
|
42 | 97 | impl From<UninitializedFieldError> for errors::YdbError {
|
@@ -64,16 +119,39 @@ impl TopicClient {
|
64 | 119 | pub async fn create_topic(
|
65 | 120 | &mut self,
|
66 | 121 | path: String,
|
67 |
| - topic_options: TopicOptions, |
| 122 | + options: CreateTopicOptions, |
68 | 123 | ) -> YdbResult<()> {
|
69 |
| - let req = RawCreateTopicRequest::new(path, self.timeouts.operation_params(), topic_options); |
| 124 | + let req = RawCreateTopicRequest::new(path, self.timeouts.operation_params(), options); |
70 | 125 |
|
71 | 126 | let mut service = self.raw_client_connection().await?;
|
72 | 127 | service.create_topic(req).await?;
|
73 | 128 |
|
74 | 129 | Ok(())
|
75 | 130 | }
|
76 | 131 |
|
| 132 | + pub async fn alter_topic(&mut self, path: String, options: AlterTopicOptions) -> YdbResult<()> { |
| 133 | + let req = RawAlterTopicRequest::new(path, self.timeouts.operation_params(), options); |
| 134 | + |
| 135 | + let mut service = self.raw_client_connection().await?; |
| 136 | + service.alter_topic(req).await?; |
| 137 | + |
| 138 | + Ok(()) |
| 139 | + } |
| 140 | + |
| 141 | + pub async fn describe_topic( |
| 142 | + &mut self, |
| 143 | + path: String, |
| 144 | + options: DescribeTopicOptions, |
| 145 | + ) -> YdbResult<TopicDescription> { |
| 146 | + let req = RawDescribeTopicRequest::new(path, self.timeouts.operation_params(), options); |
| 147 | + |
| 148 | + let mut service = self.raw_client_connection().await?; |
| 149 | + let result = service.describe_topic(req).await?; |
| 150 | + let description = TopicDescription::from(result); |
| 151 | + |
| 152 | + Ok(description) |
| 153 | + } |
| 154 | + |
77 | 155 | pub async fn drop_topic(&mut self, path: String) -> YdbResult<()> {
|
78 | 156 | let req = RawDropTopicRequest {
|
79 | 157 | operation_params: self.timeouts.operation_params(),
|
|
0 commit comments