33
33
)
34
34
35
35
36
- class Codec (int , IToPublic ):
36
+ class Codec (int , IToPublic , IFromPublic ):
37
37
CODEC_UNSPECIFIED = 0
38
38
CODEC_RAW = 1
39
39
CODEC_GZIP = 2
@@ -47,9 +47,13 @@ def from_proto_iterable(codecs: typing.Iterable[int]) -> List["Codec"]:
47
47
def to_public (self ) -> ydb_topic_public_types .PublicCodec :
48
48
return ydb_topic_public_types .PublicCodec (int (self ))
49
49
50
+ @staticmethod
51
+ def from_public (codec : Union [ydb_topic_public_types .PublicCodec , int ]) -> "Codec" :
52
+ return Codec (int (codec ))
53
+
50
54
51
55
@dataclass
52
- class SupportedCodecs (IToProto , IFromProto , IToPublic ):
56
+ class SupportedCodecs (IToProto , IFromProto , IToPublic , IFromPublic ):
53
57
codecs : List [Codec ]
54
58
55
59
def to_proto (self ) -> ydb_topic_pb2 .SupportedCodecs :
@@ -69,6 +73,15 @@ def from_proto(msg: Optional[ydb_topic_pb2.SupportedCodecs]) -> "SupportedCodecs
69
73
def to_public (self ) -> List [ydb_topic_public_types .PublicCodec ]:
70
74
return list (map (Codec .to_public , self .codecs ))
71
75
76
+ @staticmethod
77
+ def from_public (
78
+ codecs : Optional [List [Union [ydb_topic_public_types .PublicCodec , int ]]]
79
+ ) -> Optional ["SupportedCodecs" ]:
80
+ if codecs is None :
81
+ return None
82
+
83
+ return SupportedCodecs (codecs = [Codec .from_public (codec ) for codec in codecs ])
84
+
72
85
73
86
@dataclass (order = True )
74
87
class OffsetsRange (IFromProto , IToProto ):
@@ -883,6 +896,41 @@ def from_proto(
883
896
)
884
897
885
898
899
+ @dataclass
900
+ class AlterConsumer (IToProto , IFromPublic ):
901
+ name : str
902
+ set_important : Optional [bool ]
903
+ set_read_from : Optional [datetime .datetime ]
904
+ set_supported_codecs : Optional [SupportedCodecs ]
905
+ alter_attributes : Optional [Dict [str , str ]]
906
+
907
+ def to_proto (self ) -> ydb_topic_pb2 .AlterConsumer :
908
+ supported_codecs = None
909
+ if self .set_supported_codecs is not None :
910
+ supported_codecs = self .set_supported_codecs .to_proto ()
911
+
912
+ return ydb_topic_pb2 .AlterConsumer (
913
+ name = self .name ,
914
+ set_important = self .set_important ,
915
+ set_read_from = proto_timestamp_from_datetime (self .set_read_from ),
916
+ set_supported_codecs = supported_codecs ,
917
+ alter_attributes = self .alter_attributes ,
918
+ )
919
+
920
+ @staticmethod
921
+ def from_public (alter_consumer : ydb_topic_public_types .PublicAlterConsumer ) -> AlterConsumer :
922
+ if not alter_consumer :
923
+ return None
924
+
925
+ return AlterConsumer (
926
+ name = alter_consumer .name ,
927
+ set_important = alter_consumer .set_important ,
928
+ set_read_from = alter_consumer .set_read_from ,
929
+ set_supported_codecs = SupportedCodecs .from_public (alter_consumer .set_supported_codecs ),
930
+ alter_attributes = alter_consumer .alter_attributes ,
931
+ )
932
+
933
+
886
934
@dataclass
887
935
class PartitioningSettings (IToProto , IFromProto ):
888
936
min_active_partitions : int
@@ -902,6 +950,18 @@ def to_proto(self) -> ydb_topic_pb2.PartitioningSettings:
902
950
)
903
951
904
952
953
+ @dataclass
954
+ class AlterPartitioningSettings (IToProto ):
955
+ set_min_active_partitions : Optional [int ]
956
+ set_partition_count_limit : Optional [int ]
957
+
958
+ def to_proto (self ) -> ydb_topic_pb2 .AlterPartitioningSettings :
959
+ return ydb_topic_pb2 .AlterPartitioningSettings (
960
+ set_min_active_partitions = self .set_min_active_partitions ,
961
+ set_partition_count_limit = self .set_partition_count_limit ,
962
+ )
963
+
964
+
905
965
class MeteringMode (int , IFromProto , IFromPublic , IToPublic ):
906
966
UNSPECIFIED = 0
907
967
RESERVED_CAPACITY = 1
@@ -995,6 +1055,78 @@ class CreateTopicResult:
995
1055
pass
996
1056
997
1057
1058
+ @dataclass
1059
+ class AlterTopicRequest (IToProto , IFromPublic ):
1060
+ path : str
1061
+ add_consumers : Optional [List ["Consumer" ]]
1062
+ alter_partitioning_settings : Optional [AlterPartitioningSettings ]
1063
+ set_retention_period : Optional [datetime .timedelta ]
1064
+ set_retention_storage_mb : Optional [int ]
1065
+ set_supported_codecs : Optional [SupportedCodecs ]
1066
+ set_partition_write_burst_bytes : Optional [int ]
1067
+ set_partition_write_speed_bytes_per_second : Optional [int ]
1068
+ alter_attributes : Optional [Dict [str , str ]]
1069
+ alter_consumers : Optional [List [AlterConsumer ]]
1070
+ drop_consumers : Optional [List [str ]]
1071
+ set_metering_mode : Optional ["MeteringMode" ]
1072
+
1073
+ def to_proto (self ) -> ydb_topic_pb2 .AlterTopicRequest :
1074
+ supported_codecs = None
1075
+ if self .set_supported_codecs is not None :
1076
+ supported_codecs = self .set_supported_codecs .to_proto ()
1077
+
1078
+ return ydb_topic_pb2 .AlterTopicRequest (
1079
+ path = self .path ,
1080
+ add_consumers = [consumer .to_proto () for consumer in self .add_consumers ],
1081
+ alter_partitioning_settings = self .alter_partitioning_settings .to_proto (),
1082
+ set_retention_period = proto_duration_from_timedelta (self .set_retention_period ),
1083
+ set_retention_storage_mb = self .set_retention_storage_mb ,
1084
+ set_supported_codecs = supported_codecs ,
1085
+ set_partition_write_burst_bytes = self .set_partition_write_burst_bytes ,
1086
+ set_partition_write_speed_bytes_per_second = self .set_partition_write_speed_bytes_per_second ,
1087
+ alter_attributes = self .alter_attributes ,
1088
+ alter_consumers = [consumer .to_proto () for consumer in self .alter_consumers ],
1089
+ drop_consumers = list (self .drop_consumers ),
1090
+ set_metering_mode = self .set_metering_mode ,
1091
+ )
1092
+
1093
+ @staticmethod
1094
+ def from_public (req : ydb_topic_public_types .AlterTopicRequestParams ) -> AlterTopicRequest :
1095
+ add_consumers = []
1096
+ if req .add_consumers :
1097
+ for consumer in req .add_consumers :
1098
+ if isinstance (consumer , str ):
1099
+ consumer = ydb_topic_public_types .PublicConsumer (name = consumer )
1100
+ add_consumers .append (Consumer .from_public (consumer ))
1101
+
1102
+ alter_consumers = []
1103
+ if req .alter_consumers :
1104
+ for consumer in req .alter_consumers :
1105
+ if isinstance (consumer , str ):
1106
+ consumer = ydb_topic_public_types .PublicAlterConsumer (name = consumer )
1107
+ alter_consumers .append (AlterConsumer .from_public (consumer ))
1108
+
1109
+ drop_consumers = req .drop_consumers if req .drop_consumers else []
1110
+
1111
+ return AlterTopicRequest (
1112
+ path = req .path ,
1113
+ alter_partitioning_settings = AlterPartitioningSettings (
1114
+ set_min_active_partitions = req .set_min_active_partitions ,
1115
+ set_partition_count_limit = req .set_partition_count_limit ,
1116
+ ),
1117
+ add_consumers = add_consumers ,
1118
+ set_retention_period = req .set_retention_period ,
1119
+ set_retention_storage_mb = req .set_retention_storage_mb ,
1120
+ set_supported_codecs = SupportedCodecs .from_public (req .set_supported_codecs ),
1121
+ set_partition_write_burst_bytes = req .set_partition_write_burst_bytes ,
1122
+ set_partition_write_speed_bytes_per_second = req .set_partition_write_speed_bytes_per_second ,
1123
+ alter_attributes = req .alter_attributes ,
1124
+ alter_consumers = alter_consumers ,
1125
+ drop_consumers = drop_consumers ,
1126
+ set_metering_mode = MeteringMode .from_public (req .set_metering_mode ),
1127
+ )
1128
+
1129
+
998
1130
@dataclass
999
1131
class DescribeTopicRequest :
1000
1132
path : str
0 commit comments