11import typing
22from dataclasses import dataclass
33
4-
54if typing .TYPE_CHECKING :
65 from ..v4 .protos import ydb_coordination_pb2
76else :
87 from ..common .protos import ydb_coordination_pb2
98
109from .common_utils import IToProto
1110
11+ # ---------- CRUD для узлов ----------
1212
1313@dataclass
1414class CreateNodeRequest (IToProto ):
1515 path : str
1616 config : typing .Any
1717
18- def to_proto (self ) -> ydb_coordination_pb2 .CreateNodeRequest :
18+ def to_proto (self ) -> " ydb_coordination_pb2.CreateNodeRequest" :
1919 cfg_proto = self .config .to_proto () if self .config else None
2020 return ydb_coordination_pb2 .CreateNodeRequest (
2121 path = self .path ,
@@ -28,7 +28,7 @@ class AlterNodeRequest(IToProto):
2828 path : str
2929 config : typing .Any
3030
31- def to_proto (self ) -> ydb_coordination_pb2 .AlterNodeRequest :
31+ def to_proto (self ) -> " ydb_coordination_pb2.AlterNodeRequest" :
3232 cfg_proto = self .config .to_proto () if self .config else None
3333 return ydb_coordination_pb2 .AlterNodeRequest (
3434 path = self .path ,
@@ -40,7 +40,7 @@ def to_proto(self) -> ydb_coordination_pb2.AlterNodeRequest:
4040class DescribeNodeRequest (IToProto ):
4141 path : str
4242
43- def to_proto (self ) -> ydb_coordination_pb2 .DescribeNodeRequest :
43+ def to_proto (self ) -> " ydb_coordination_pb2.DescribeNodeRequest" :
4444 return ydb_coordination_pb2 .DescribeNodeRequest (
4545 path = self .path ,
4646 )
@@ -50,11 +50,12 @@ def to_proto(self) -> ydb_coordination_pb2.DescribeNodeRequest:
5050class DropNodeRequest (IToProto ):
5151 path : str
5252
53- def to_proto (self ) -> ydb_coordination_pb2 .DropNodeRequest :
53+ def to_proto (self ) -> " ydb_coordination_pb2.DropNodeRequest" :
5454 return ydb_coordination_pb2 .DropNodeRequest (
5555 path = self .path ,
5656 )
5757
58+ # ---------- Сессии и семафоры ----------
5859
5960@dataclass
6061class SessionStart (IToProto ):
@@ -65,7 +66,7 @@ class SessionStart(IToProto):
6566 seq_no : int = 0
6667 protection_key : bytes = b""
6768
68- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
69+ def to_proto (self ) -> " ydb_coordination_pb2.SessionRequest" :
6970 return ydb_coordination_pb2 .SessionRequest (
7071 session_start = ydb_coordination_pb2 .SessionRequest .SessionStart (
7172 path = self .path ,
@@ -80,15 +81,17 @@ def to_proto(self) -> ydb_coordination_pb2.SessionRequest:
8081
8182@dataclass
8283class SessionStop (IToProto ):
83- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
84- return ydb_coordination_pb2 .SessionRequest (session_stop = ydb_coordination_pb2 .SessionRequest .SessionStop ())
84+ def to_proto (self ) -> "ydb_coordination_pb2.SessionRequest" :
85+ return ydb_coordination_pb2 .SessionRequest (
86+ session_stop = ydb_coordination_pb2 .SessionRequest .SessionStop ()
87+ )
8588
8689
8790@dataclass
8891class Ping (IToProto ):
8992 opaque : int = 0
9093
91- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
94+ def to_proto (self ) -> " ydb_coordination_pb2.SessionRequest" :
9295 return ydb_coordination_pb2 .SessionRequest (
9396 ping = ydb_coordination_pb2 .SessionRequest .PingPong (opaque = self .opaque )
9497 )
@@ -101,42 +104,14 @@ class CreateSemaphore(IToProto):
101104 limit : int
102105 data : bytes = b""
103106
104- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
107+ def to_proto (self ) -> " ydb_coordination_pb2.SessionRequest" :
105108 return ydb_coordination_pb2 .SessionRequest (
106109 create_semaphore = ydb_coordination_pb2 .SessionRequest .CreateSemaphore (
107110 req_id = self .req_id , name = self .name , limit = self .limit , data = self .data
108111 )
109112 )
110113
111114
112- @dataclass
113- class UpdateSemaphore (IToProto ):
114- name : str
115- req_id : int
116- data : bytes
117-
118- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
119- return ydb_coordination_pb2 .SessionRequest (
120- update_semaphore = ydb_coordination_pb2 .SessionRequest .UpdateSemaphore (
121- req_id = self .req_id , name = self .name , data = self .data
122- )
123- )
124-
125-
126- @dataclass
127- class DeleteSemaphore (IToProto ):
128- name : str
129- req_id : int
130- force : bool = False
131-
132- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
133- return ydb_coordination_pb2 .SessionRequest (
134- delete_semaphore = ydb_coordination_pb2 .SessionRequest .DeleteSemaphore (
135- req_id = self .req_id , name = self .name , force = self .force
136- )
137- )
138-
139-
140115@dataclass
141116class AcquireSemaphore (IToProto ):
142117 name : str
@@ -146,7 +121,7 @@ class AcquireSemaphore(IToProto):
146121 data : bytes = b""
147122 ephemeral : bool = False
148123
149- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
124+ def to_proto (self ) -> " ydb_coordination_pb2.SessionRequest" :
150125 return ydb_coordination_pb2 .SessionRequest (
151126 acquire_semaphore = ydb_coordination_pb2 .SessionRequest .AcquireSemaphore (
152127 req_id = self .req_id ,
@@ -164,9 +139,11 @@ class ReleaseSemaphore(IToProto):
164139 name : str
165140 req_id : int
166141
167- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
142+ def to_proto (self ) -> " ydb_coordination_pb2.SessionRequest" :
168143 return ydb_coordination_pb2 .SessionRequest (
169- release_semaphore = ydb_coordination_pb2 .SessionRequest .ReleaseSemaphore (req_id = self .req_id , name = self .name )
144+ release_semaphore = ydb_coordination_pb2 .SessionRequest .ReleaseSemaphore (
145+ req_id = self .req_id , name = self .name
146+ )
170147 )
171148
172149
@@ -179,7 +156,7 @@ class DescribeSemaphore(IToProto):
179156 watch_data : bool
180157 watch_owners : bool
181158
182- def to_proto (self ) -> ydb_coordination_pb2 .SessionRequest :
159+ def to_proto (self ) -> " ydb_coordination_pb2.SessionRequest" :
183160 return ydb_coordination_pb2 .SessionRequest (
184161 describe_semaphore = ydb_coordination_pb2 .SessionRequest .DescribeSemaphore (
185162 include_owners = self .include_owners ,
@@ -191,20 +168,47 @@ def to_proto(self) -> ydb_coordination_pb2.SessionRequest:
191168 )
192169 )
193170
171+ @dataclass
172+ class UpdateSemaphore (IToProto ):
173+ name : str
174+ req_id : int
175+ data : bytes
176+
177+ def to_proto (self ) -> "ydb_coordination_pb2.SessionRequest" :
178+ return ydb_coordination_pb2 .SessionRequest (
179+ update_semaphore = ydb_coordination_pb2 .SessionRequest .UpdateSemaphore (
180+ req_id = self .req_id , name = self .name , data = self .data
181+ )
182+ )
183+
184+
185+ @dataclass
186+ class DeleteSemaphore (IToProto ):
187+ name : str
188+ req_id : int
189+ force : bool = False
190+
191+ def to_proto (self ) -> "ydb_coordination_pb2.SessionRequest" :
192+ return ydb_coordination_pb2 .SessionRequest (
193+ delete_semaphore = ydb_coordination_pb2 .SessionRequest .DeleteSemaphore (
194+ req_id = self .req_id , name = self .name , force = self .force
195+ )
196+ )
197+
194198
195199@dataclass
196200class FromServer :
197- raw : ydb_coordination_pb2 .SessionResponse
201+ raw : " ydb_coordination_pb2.SessionResponse"
198202
199203 @staticmethod
200- def from_proto (resp : ydb_coordination_pb2 .SessionResponse ) -> "FromServer" :
204+ def from_proto (resp : " ydb_coordination_pb2.SessionResponse" ) -> "FromServer" :
201205 return FromServer (raw = resp )
202206
203207 def __getattr__ (self , name : str ):
204208 return getattr (self .raw , name )
205209
206210 @property
207- def session_started (self ) -> typing .Optional [ydb_coordination_pb2 .SessionResponse .SessionStarted ]:
211+ def session_started (self ) -> typing .Optional [" ydb_coordination_pb2.SessionResponse.SessionStarted" ]:
208212 s = self .raw .session_started
209213 return s if s .session_id else None
210214
@@ -215,23 +219,9 @@ def opaque(self) -> typing.Optional[int]:
215219 return None
216220
217221 @property
218- def acquire_semaphore_result (self ) -> typing . Optional [ ydb_coordination_pb2 . SessionResponse . AcquireSemaphoreResult ] :
222+ def acquire_semaphore_result (self ):
219223 return self .raw .acquire_semaphore_result if self .raw .HasField ("acquire_semaphore_result" ) else None
220224
221225 @property
222- def create_semaphore_result (self ) -> typing . Optional [ ydb_coordination_pb2 . SessionResponse . CreateSemaphoreResult ] :
226+ def create_semaphore_result (self ):
223227 return self .raw .create_semaphore_result if self .raw .HasField ("create_semaphore_result" ) else None
224-
225- @property
226- def delete_semaphore_result (self ) -> typing .Optional [ydb_coordination_pb2 .SessionResponse .DeleteSemaphoreResult ]:
227- return self .raw .delete_semaphore_result if self .raw .HasField ("delete_semaphore_result" ) else None
228-
229- @property
230- def update_semaphore_result (self ) -> typing .Optional [ydb_coordination_pb2 .SessionResponse .UpdateSemaphoreResult ]:
231- return self .raw .update_semaphore_result if self .raw .HasField ("update_semaphore_result" ) else None
232-
233- @property
234- def describe_semaphore_result (
235- self ,
236- ) -> typing .Optional [ydb_coordination_pb2 .SessionResponse .DescribeSemaphoreResult ]:
237- return self .raw .describe_semaphore_result if self .raw .HasField ("describe_semaphore_result" ) else None
0 commit comments