Skip to content

Commit 7701a05

Browse files
committed
several fixes plus wrappers
1 parent d9de575 commit 7701a05

File tree

11 files changed

+1023
-250
lines changed

11 files changed

+1023
-250
lines changed

First_look_on_api_and_examples_from_zookeeper.patch

Lines changed: 942 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.
Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
11
import ydb
2-
from ydb._grpc.v4.protos import ydb_coordination_pb2
32

43

54
def test_coordination_nodes(driver_sync: ydb.Driver):
65
client = driver_sync.coordination_client
76
node_path = "/local/test_node"
87

98
try:
10-
drop_res = client.delete_node(node_path)
11-
print(f"Node deleted (pre-clean), operation id: {drop_res.operation.id}")
9+
client.delete_node(node_path)
1210
except ydb.SchemeError:
1311
pass
1412

15-
create_res = client.create_node(node_path)
16-
assert create_res.operation.id is not None
17-
print(f"Node created, operation id: {create_res.operation.id}")
13+
client.create_node(node_path)
1814

19-
describe_res = client.describe_node(node_path)
20-
assert describe_res.operation.id is not None
21-
print(f"Node described, operation id: {describe_res.operation.id}")
15+
node = client.describe_node(node_path)
2216

23-
describe_result_proto = ydb_coordination_pb2.DescribeNodeResult()
24-
describe_res.operation.result.Unpack(describe_result_proto)
17+
assert node.status == ydb.StatusCode.SUCCESS, f"Unexpected operation status: {node.status}"
2518

26-
print(f"Node path: {describe_result_proto.path}")
27-
if describe_result_proto.HasField("config"):
28-
print(f"Node config: {describe_result_proto.config}")
19+
assert node.path.split("/")[-1] == "test_node", "Node name mismatch"
2920

30-
# --- Удаляем узел ---
31-
drop_res = client.delete_node(node_path)
32-
assert drop_res.operation.id is not None
33-
print(f"Node deleted, operation id: {drop_res.operation.id}")
21+
22+
assert node.config is not None, "Node config is missing"
23+
24+
client.delete_node(node_path)

ydb/_apis.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,4 @@ class CoordinationService(object):
147147
CreateNode = "CreateNode"
148148
AlterNode = "AlterNode"
149149
DropNode = "DropNode"
150-
DescribeNode = "DescribeNode"
151-
152-
Request = ydb_coordination.CreateNodeRequest
153-
Response = ydb_coordination.CreateNodeResponse
154-
DescribeRequest = ydb_coordination.DescribeNodeRequest
155-
DescribeResponse = ydb_coordination.DescribeNodeResponse
156-
DropRequest = ydb_coordination.DropNodeRequest
157-
DropResponse = ydb_coordination.DropNodeResponse
150+
DescribeNode = "DescribeNode"
Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
11
import typing
22
from typing import Optional
33

4-
import ydb
54
from ydb import _apis, issues
65

7-
from .coordination_lock import CoordinationLock
8-
from .сoordination_session import CoordinationSession
96

7+
from .operations import DescribeNodeOperation, CreateNodeOperation, DropNodeOperation
108

11-
def wrapper_create_node(rpc_state, response_pb, *_args, **_kwargs):
12-
from .._grpc.grpcwrapper.ydb_coordination import CreateNodeResponse
139

10+
if typing.TYPE_CHECKING:
11+
import ydb
12+
13+
14+
def wrapper_create_node(rpc_state, response_pb, path, *_args, **_kwargs):
1415
issues._process_response(response_pb.operation)
15-
return CreateNodeResponse.from_proto(response_pb)
16+
return CreateNodeOperation(rpc_state, response_pb, path)
1617

1718

1819
def wrapper_describe_node(rpc_state, response_pb, *_args, **_kwargs):
19-
from .._grpc.grpcwrapper.ydb_coordination import DescribeNodeResponse
20-
2120
issues._process_response(response_pb.operation)
22-
return DescribeNodeResponse.from_proto(response_pb)
23-
21+
return DescribeNodeOperation(rpc_state, response_pb)
2422

25-
def wrapper_delete_node(rpc_state, response_pb, *_args, **_kwargs):
26-
from .._grpc.grpcwrapper.ydb_coordination import DropNodeResponse
2723

24+
def wrapper_delete_node(rpc_state, response_pb, path, *_args, **_kwargs):
2825
issues._process_response(response_pb.operation)
29-
return DropNodeResponse.from_proto(response_pb)
26+
return DropNodeOperation(rpc_state, response_pb, path)
3027

3128

3229
class CoordinationClient:
3330
def __init__(self, driver: "ydb.Driver"):
3431
self._driver = driver
3532

36-
def session(self) -> "CoordinationSession":
37-
return CoordinationSession(self._driver)
38-
3933
def _call_node(
4034
self,
4135
request,
4236
rpc_method,
4337
wrapper_fn,
38+
wrap_args=(),
4439
settings: Optional["ydb.BaseRequestSettings"] = None,
4540
):
4641
return self._driver(
4742
request,
4843
_apis.CoordinationService.Stub,
4944
rpc_method,
5045
wrap_result=wrapper_fn,
51-
wrap_args=(),
46+
wrap_args=wrap_args,
5247
settings=settings,
5348
)
5449

@@ -58,7 +53,7 @@ def create_node(
5853
config: typing.Optional[typing.Any] = None,
5954
operation_params: typing.Optional[typing.Any] = None,
6055
settings: Optional["ydb.BaseRequestSettings"] = None,
61-
) -> _apis.ydb_coordination.CreateNodeResponse:
56+
) -> CreateNodeOperation:
6257
request = _apis.ydb_coordination.CreateNodeRequest(
6358
path=path,
6459
config=config,
@@ -68,15 +63,16 @@ def create_node(
6863
request,
6964
_apis.CoordinationService.CreateNode,
7065
wrapper_create_node,
71-
settings,
66+
wrap_args=(path,),
67+
settings=settings,
7268
)
7369

7470
def describe_node(
7571
self,
7672
path: str,
7773
operation_params: typing.Optional[typing.Any] = None,
7874
settings: Optional["ydb.BaseRequestSettings"] = None,
79-
) -> _apis.ydb_coordination.DescribeNodeResponse:
75+
) -> DescribeNodeOperation:
8076
request = _apis.ydb_coordination.DescribeNodeRequest(
8177
path=path,
8278
operation_params=operation_params,
@@ -85,15 +81,16 @@ def describe_node(
8581
request,
8682
_apis.CoordinationService.DescribeNode,
8783
wrapper_describe_node,
88-
settings,
84+
wrap_args=(path,),
85+
settings=settings,
8986
)
9087

9188
def delete_node(
9289
self,
9390
path: str,
9491
operation_params: typing.Optional[typing.Any] = None,
9592
settings: Optional["ydb.BaseRequestSettings"] = None,
96-
) -> _apis.ydb_coordination.DropNodeResponse:
93+
):
9794
request = _apis.ydb_coordination.DropNodeRequest(
9895
path=path,
9996
operation_params=operation_params,
@@ -102,13 +99,7 @@ def delete_node(
10299
request,
103100
_apis.CoordinationService.DropNode,
104101
wrapper_delete_node,
105-
settings,
102+
wrap_args=(path,),
103+
settings=settings,
106104
)
107105

108-
def lock(
109-
self,
110-
path: str,
111-
timeout: int = 5000,
112-
count: int = 1,
113-
) -> "CoordinationLock":
114-
return CoordinationLock(self.session(), path, timeout, count)

ydb/coordination/coordination_lock.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

ydb/coordination/exceptions.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

ydb/coordination/operations.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from ydb import operation as ydb_op
2+
from ydb import _apis
3+
4+
class DescribeNodeOperation(ydb_op.Operation):
5+
def __init__(self, rpc_state, response, driver=None):
6+
super().__init__(rpc_state, response, driver)
7+
8+
self.status = response.operation.status
9+
10+
result = _apis.ydb_coordination.DescribeNodeResult()
11+
response.operation.result.Unpack(result)
12+
13+
node_info = result.self
14+
self.path = node_info.name
15+
self.node_owner = node_info.owner
16+
self.effective_permissions = node_info.effective_permissions
17+
self.config = result.config
18+
19+
if self.config:
20+
self.session_grace_period_millis = self.config.session_grace_period_millis
21+
self.attach_consistency_mode = self.config.attach_consistency_mode
22+
self.read_consistency_mode = self.config.read_consistency_mode
23+
else:
24+
self.session_grace_period_millis = None
25+
self.attach_consistency_mode = None
26+
self.read_consistency_mode = None
27+
28+
def __repr__(self):
29+
return f"DescribeNodeOperation<id={self.id}, path={self.path}, status={self.status}>"
30+
31+
__str__ = __repr__
32+
33+
34+
class CreateNodeOperation(ydb_op.Operation):
35+
def __init__(self, rpc_state, response, path, driver=None):
36+
super().__init__(rpc_state, response, driver)
37+
self.path = path
38+
self.status = response.operation.status
39+
40+
def __repr__(self):
41+
return f"CreateNodeOperation<id={self.id}, path={self.path}, status={self.status}>"
42+
43+
class DropNodeOperation(ydb_op.Operation):
44+
def __init__(self, rpc_state, response, path, driver=None):
45+
super().__init__(rpc_state, response, driver)
46+
self.path = path
47+
self.status = response.operation.status
48+
49+
def __repr__(self):
50+
return f"DropNodeOperation<id={self.id}, path={self.path}, status={self.status}>"

ydb/coordination/tests/test_coordination_minimal.py

Lines changed: 0 additions & 93 deletions
This file was deleted.

ydb/coordination/ydb-protos

Submodule ydb-protos deleted from a0c108c

0 commit comments

Comments
 (0)