Skip to content

Commit d9de575

Browse files
committed
add wrappers, simple test is working, but problem to got structure back
1 parent a4a292e commit d9de575

File tree

8 files changed

+310
-58
lines changed

8 files changed

+310
-58
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import ydb
2+
from ydb._grpc.v4.protos import ydb_coordination_pb2
3+
4+
5+
def test_coordination_nodes(driver_sync: ydb.Driver):
6+
client = driver_sync.coordination_client
7+
node_path = "/local/test_node"
8+
9+
try:
10+
drop_res = client.delete_node(node_path)
11+
print(f"Node deleted (pre-clean), operation id: {drop_res.operation.id}")
12+
except ydb.SchemeError:
13+
pass
14+
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}")
18+
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}")
22+
23+
describe_result_proto = ydb_coordination_pb2.DescribeNodeResult()
24+
describe_res.operation.result.Unpack(describe_result_proto)
25+
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}")
29+
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}")

ydb/_apis.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ydb_operation_v1_pb2_grpc,
1212
ydb_topic_v1_pb2_grpc,
1313
ydb_query_v1_pb2_grpc,
14+
ydb_coordination_v1_pb2_grpc,
1415
)
1516

1617
from ._grpc.v4.protos import (
@@ -22,6 +23,7 @@
2223
ydb_operation_pb2,
2324
ydb_common_pb2,
2425
ydb_query_pb2,
26+
ydb_coordination_pb2,
2527
)
2628

2729
else:
@@ -33,6 +35,7 @@
3335
ydb_operation_v1_pb2_grpc,
3436
ydb_topic_v1_pb2_grpc,
3537
ydb_query_v1_pb2_grpc,
38+
ydb_coordination_v1_pb2_grpc,
3639
)
3740

3841
from ._grpc.common.protos import (
@@ -44,6 +47,7 @@
4447
ydb_operation_pb2,
4548
ydb_common_pb2,
4649
ydb_query_pb2,
50+
ydb_coordination_pb2,
4751
)
4852

4953

@@ -56,6 +60,7 @@
5660
ydb_discovery = ydb_discovery_pb2
5761
ydb_operation = ydb_operation_pb2
5862
ydb_query = ydb_query_pb2
63+
ydb_coordination = ydb_coordination_pb2
5964

6065

6166
class CmsService(object):
@@ -134,3 +139,19 @@ class QueryService(object):
134139
ExecuteQuery = "ExecuteQuery"
135140
ExecuteScript = "ExecuteScript"
136141
FetchScriptResults = "FetchScriptResults"
142+
143+
class CoordinationService(object):
144+
Stub = ydb_coordination_v1_pb2_grpc.CoordinationServiceStub
145+
146+
Session = "Session"
147+
CreateNode = "CreateNode"
148+
AlterNode = "AlterNode"
149+
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
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import typing
2+
from dataclasses import dataclass
3+
4+
import ydb
5+
6+
if typing.TYPE_CHECKING:
7+
from ..v4.protos import ydb_coordination_pb2
8+
else:
9+
from ..common.protos import ydb_coordination_pb2
10+
11+
from .common_utils import IToProto, IFromProto, ServerStatus
12+
from . import ydb_coordination_public_types as public_types
13+
14+
15+
# -------------------- Requests --------------------
16+
17+
@dataclass
18+
class CreateNodeRequest(IToProto):
19+
path: str
20+
config: typing.Optional[public_types.NodeConfig] = None
21+
operation_params: typing.Any = None
22+
23+
def to_proto(self) -> ydb_coordination_pb2.CreateNodeRequest:
24+
cfg_proto = self.config.to_proto() if self.config else None
25+
return ydb_coordination_pb2.CreateNodeRequest(
26+
path=self.path,
27+
config=cfg_proto,
28+
operation_params=self.operation_params,
29+
)
30+
31+
32+
@dataclass
33+
class DescribeNodeRequest(IToProto):
34+
path: str
35+
operation_params: typing.Any = None
36+
37+
def to_proto(self) -> ydb_coordination_pb2.DescribeNodeRequest:
38+
return ydb_coordination_pb2.DescribeNodeRequest(
39+
path=self.path,
40+
operation_params=self.operation_params,
41+
)
42+
43+
44+
@dataclass
45+
class DropNodeRequest(IToProto):
46+
path: str
47+
operation_params: typing.Any = None
48+
49+
def to_proto(self) -> ydb_coordination_pb2.DropNodeRequest:
50+
return ydb_coordination_pb2.DropNodeRequest(
51+
path=self.path,
52+
operation_params=self.operation_params,
53+
)
54+
55+
56+
@dataclass
57+
class CreateNodeResponse(IFromProto):
58+
operation : ydb.Operation
59+
OPERATION_FIELD_NUMBER : int
60+
61+
@staticmethod
62+
def from_proto(msg: ydb_coordination_pb2.CreateNodeResponse) -> "CreateNodeResponse":
63+
return CreateNodeResponse(
64+
operation=msg.operation,
65+
OPERATION_FIELD_NUMBER=msg.OPERATION_FIELD_NUMBER
66+
)
67+
68+
69+
@dataclass
70+
class DescribeNodeResponse(IFromProto):
71+
operation : ydb.Operation
72+
OPERATION_FIELD_NUMBER : int
73+
74+
@staticmethod
75+
def from_proto(msg: "ydb_coordination_pb2.DescribeNodeResponse") -> "DescribeNodeResponse":
76+
return DescribeNodeResponse(
77+
operation=msg.operation,
78+
OPERATION_FIELD_NUMBER=msg.OPERATION_FIELD_NUMBER
79+
)
80+
81+
82+
@dataclass
83+
class DropNodeResponse(IFromProto):
84+
operation : ydb.Operation
85+
OPERATION_FIELD_NUMBER : int
86+
87+
@staticmethod
88+
def from_proto(msg: ydb_coordination_pb2.DropNodeResponse) -> "DropNodeResponse":
89+
return DropNodeResponse(
90+
operation=msg.operation,
91+
OPERATION_FIELD_NUMBER=msg.OPERATION_FIELD_NUMBER
92+
)
93+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from dataclasses import dataclass
2+
from enum import Enum
3+
import typing
4+
5+
if typing.TYPE_CHECKING:
6+
from ..v4.protos import ydb_coordination_pb2
7+
else:
8+
from ..common.protos import ydb_coordination_pb2
9+
10+
class ConsistencyMode(Enum):
11+
STRICT = 0
12+
RELAXED = 1
13+
14+
class RateLimiterCountersMode(Enum):
15+
NONE = 0
16+
BASIC = 1
17+
FULL = 2
18+
19+
@dataclass
20+
class NodeConfig:
21+
attach_consistency_mode: ConsistencyMode
22+
path: str
23+
rate_limiter_counters_mode: RateLimiterCountersMode
24+
read_consistency_mode: ConsistencyMode
25+
self_check_period_millis: int
26+
session_grace_period_millis: int
27+
28+
@staticmethod
29+
def from_proto(msg: ydb_coordination_pb2.Config) -> "NodeConfig":
30+
return NodeConfig(
31+
attach_consistency_mode=ConsistencyMode(msg.attach_consistency_mode),
32+
path=msg.path,
33+
rate_limiter_counters_mode=RateLimiterCountersMode(msg.rate_limiter_counters_mode),
34+
read_consistency_mode=ConsistencyMode(msg.read_consistency_mode),
35+
self_check_period_millis=msg.self_check_period_millis,
36+
session_grace_period_millis=msg.session_grace_period_millis,
37+
)
38+
39+
def to_proto(self) -> ydb_coordination_pb2.Config:
40+
return ydb_coordination_pb2.Config(
41+
attach_consistency_mode=self.attach_consistency_mode.value,
42+
path=self.path,
43+
rate_limiter_counters_mode=self.rate_limiter_counters_mode.value,
44+
read_consistency_mode=self.read_consistency_mode.value,
45+
self_check_period_millis=self.self_check_period_millis,
46+
session_grace_period_millis=self.session_grace_period_millis,
47+
)

ydb/coordination/client.py

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

0 commit comments

Comments
 (0)