|
5 | 5 | from . import aio, Credentials, _apis |
6 | 6 |
|
7 | 7 | from . import scheme |
| 8 | +from . import driver |
8 | 9 |
|
9 | 10 | from ._grpc.grpcwrapper.ydb_topic_public_types import ( |
10 | 11 | DropTopicRequestParams as _DropTopicRequestParams, |
|
43 | 44 |
|
44 | 45 | from ._grpc.grpcwrapper import ydb_topic as _ydb_topic |
45 | 46 | from ._grpc.grpcwrapper import ydb_topic_public_types as _ydb_topic_public_types |
| 47 | +from ._grpc.grpcwrapper.ydb_topic_public_types import ( |
| 48 | + PublicDescribeTopicResult as TopicDescription, |
| 49 | + PublicMultipleWindowsStat as TopicStatWindow, |
| 50 | + PublicPartitionStats as TopicPartitionStats, |
| 51 | + PublicCodec as TopicCodec, |
| 52 | + PublicConsumer as TopicConsumer, |
| 53 | + PublicMeteringMode as TopicMeteringMode, |
| 54 | +) |
46 | 55 |
|
47 | 56 |
|
48 | 57 | class TopicClientAsyncIO: |
@@ -94,7 +103,7 @@ async def create_topic( |
94 | 103 | _wrap_operation, |
95 | 104 | ) |
96 | 105 |
|
97 | | - async def describe(self, path: str, include_stats: bool = False): |
| 106 | + async def describe(self, path: str, include_stats: bool = False) -> TopicDescription: |
98 | 107 | args = locals().copy() |
99 | 108 | del args["self"] |
100 | 109 | req = _DescribeTopicRequestParams(**args) |
@@ -164,8 +173,74 @@ def topic_writer( |
164 | 173 |
|
165 | 174 |
|
166 | 175 | class TopicClient: |
167 | | - def __init__(self, driver, topic_client_settings: "TopicClientSettings" = None): |
168 | | - pass |
| 176 | + _driver: driver.Driver |
| 177 | + _credentials: Union[Credentials, None] |
| 178 | + |
| 179 | + def __init__(self, driver: driver.Driver, topic_client_settings: "TopicClientSettings" = None): |
| 180 | + self._driver = driver |
| 181 | + |
| 182 | + def create_topic( |
| 183 | + self, |
| 184 | + path: str, |
| 185 | + min_active_partitions: Optional[ |
| 186 | + int |
| 187 | + ] = None, # Minimum partition count auto merge would stop working at. |
| 188 | + partition_count_limit: Optional[ |
| 189 | + int |
| 190 | + ] = None, # Limit for total partition count, including active (open for write) and read-only partitions. |
| 191 | + retention_period: Optional[ |
| 192 | + datetime.timedelta |
| 193 | + ] = None, # How long data in partition should be stored |
| 194 | + retention_storage_mb: Optional[ |
| 195 | + int |
| 196 | + ] = None, # How much data in partition should be stored |
| 197 | + # List of allowed codecs for writers. |
| 198 | + # Writes with codec not from this list are forbidden. |
| 199 | + supported_codecs: Optional[List[Union[TopicCodec, int]]] = None, |
| 200 | + partition_write_speed_bytes_per_second: Optional[ |
| 201 | + int |
| 202 | + ] = None, # Partition write speed in bytes per second |
| 203 | + partition_write_burst_bytes: Optional[ |
| 204 | + int |
| 205 | + ] = None, # Burst size for write in partition, in bytes |
| 206 | + # User and server attributes of topic. Server attributes starts from "_" and will be validated by server. |
| 207 | + attributes: Optional[Dict[str, str]] = None, |
| 208 | + # List of consumers for this topic |
| 209 | + consumers: Optional[List[Union[TopicConsumer, str]]] = None, |
| 210 | + # Metering mode for the topic in a serverless database |
| 211 | + metering_mode: Optional[TopicMeteringMode] = None, |
| 212 | + ): |
| 213 | + args = locals().copy() |
| 214 | + del args["self"] |
| 215 | + req = _ydb_topic_public_types.CreateTopicRequestParams(**args) |
| 216 | + req = _ydb_topic.CreateTopicRequest.from_public(req) |
| 217 | + self._driver( |
| 218 | + req.to_proto(), |
| 219 | + _apis.TopicService.Stub, |
| 220 | + _apis.TopicService.CreateTopic, |
| 221 | + _wrap_operation, |
| 222 | + ) |
| 223 | + |
| 224 | + def describe(self, path: str, include_stats: bool = False) -> TopicDescription: |
| 225 | + args = locals().copy() |
| 226 | + del args["self"] |
| 227 | + req = _DescribeTopicRequestParams(**args) |
| 228 | + res = self._driver( |
| 229 | + req.to_proto(), |
| 230 | + _apis.TopicService.Stub, |
| 231 | + _apis.TopicService.DescribeTopic, |
| 232 | + _create_result_wrapper(_ydb_topic.DescribeTopicResult), |
| 233 | + ) # type: _ydb_topic.DescribeTopicResult |
| 234 | + return res.to_public() |
| 235 | + |
| 236 | + def drop_topic(self, path: str): |
| 237 | + req = _DropTopicRequestParams(path=path) |
| 238 | + self._driver( |
| 239 | + req.to_proto(), |
| 240 | + _apis.TopicService.Stub, |
| 241 | + _apis.TopicService.DropTopic, |
| 242 | + _wrap_operation, |
| 243 | + ) |
169 | 244 |
|
170 | 245 | def topic_reader( |
171 | 246 | self, |
|
0 commit comments