Skip to content

Commit 2fa4651

Browse files
committed
Rename ClientRouteEntry to ClientRoutesContactPoint
Rename class and all related fields: deployments -> contact_points, endpoints -> contact_points, _initial_endpoints -> _initial_contact_points, _connection_ids -> _initial_contact_points. Update logs, error messages, docstrings, and tests to match.
1 parent 64a717d commit 2fa4651

4 files changed

Lines changed: 63 additions & 57 deletions

File tree

cassandra/client_routes.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ClientRoutesChangeType(enum.Enum):
5050
UPDATE_NODES = "UPDATE_NODES"
5151

5252

53-
class PrivateLinkDeployment:
53+
class ClientRoutesContactPoint:
5454

5555
connection_id: str
5656
connection_addr: Optional[str]
@@ -67,37 +67,37 @@ def __init__(self, connection_id: str, connection_addr: Optional[str] = None):
6767
self.connection_addr = connection_addr
6868

6969
def __repr__(self) -> str:
70-
return f"PrivateLinkDeployment(connection_id={self.connection_id}, connection_addr={self.connection_addr})"
70+
return f"ClientRoutesContactPoint(connection_id={self.connection_id}, connection_addr={self.connection_addr})"
7171

7272

7373
class ClientRoutesConfig:
7474
"""
7575
Configuration for client routes (Private Link support).
7676
77-
:param deployments: List of :class:`PrivateLinkDeployment` objects
78-
(REQUIRED, at least one)
77+
:param contact_points: List of ClientRoutesContactPoint objects (REQUIRED, at least one)
78+
:param cache_ttl_seconds: How long DNS resolution results are cached (default: 300 seconds = 5 minutes)
7979
"""
8080

81-
deployments: List[PrivateLinkDeployment]
82-
83-
def __init__(self, deployments: List[PrivateLinkDeployment]):
81+
def __init__(self, contact_points: List[ClientRoutesContactPoint],
82+
cache_ttl_seconds: int = 300):
8483
"""
85-
:param deployments: List of PrivateLinkDeployment objects
84+
:param contact_points: List of ClientRoutesContactPoint objects
85+
:param cache_ttl_seconds: DNS cache TTL in seconds (must be >= 0, default: 300 = 5 minutes)
8686
"""
87-
if not deployments:
88-
raise ValueError("At least one deployment must be specified")
87+
if not contact_points:
88+
raise ValueError("At least one contact point must be specified")
8989

90-
if not isinstance(deployments, (list, tuple)):
91-
raise TypeError("deployments must be a list or tuple")
90+
if not isinstance(contact_points, (list, tuple)):
91+
raise TypeError("contact_points must be a list or tuple")
9292

93-
for dep in deployments:
94-
if not isinstance(dep, PrivateLinkDeployment):
95-
raise TypeError("All deployments must be PrivateLinkDeployment instances")
93+
for cp in contact_points:
94+
if not isinstance(cp, ClientRoutesContactPoint):
95+
raise TypeError("All contact_points must be ClientRoutesContactPoint instances")
9696

97-
self.deployments = list(deployments)
97+
self.contact_points = list(contact_points)
9898

9999
def __repr__(self) -> str:
100-
return f"ClientRoutesConfig(deployments={self.deployments})"
100+
return f"ClientRoutesConfig(contact_points={self.contact_points})"
101101

102102

103103
@dataclass
@@ -214,7 +214,7 @@ class _ClientRoutesHandler:
214214
config: 'ClientRoutesConfig'
215215
ssl_enabled: bool
216216
_routes: _RouteStore
217-
_initial_endpoints: Set[str]
217+
_initial_contact_points: Set[str]
218218
_dns_cache: Dict[str, Tuple[str, float]]
219219
_dns_cache_lock: threading.Lock
220220

@@ -229,7 +229,7 @@ def __init__(self, config: 'ClientRoutesConfig', ssl_enabled: bool = False):
229229
self.config = config
230230
self.ssl_enabled = ssl_enabled
231231
self._routes = _RouteStore()
232-
self._connection_ids = {dep.connection_id for dep in config.deployments}
232+
self._initial_contact_points = {dep.connection_id for dep in config.contact_points}
233233

234234
def initialize(self, control_connection: 'ControlConnection') -> None:
235235
"""
@@ -240,10 +240,10 @@ def initialize(self, control_connection: 'ControlConnection') -> None:
240240
241241
:param control_connection: The ControlConnection instance
242242
"""
243-
log.info("[client routes] Initializing with %d deployments", len(self.config.deployments))
243+
log.info("[client routes] Initializing with %d contact points", len(self.config.contact_points))
244244

245245
try:
246-
connection_ids = self._connection_ids
246+
connection_ids = self._initial_contact_points
247247
routes = self._query_routes(control_connection, connection_ids=connection_ids)
248248

249249
self._routes.update(routes)
@@ -267,7 +267,7 @@ def handle_client_routes_change(self, control_connection: 'ControlConnection',
267267
"""
268268
filtered_conn_ids = None
269269
if connection_ids:
270-
configured_ids = self._connection_ids
270+
configured_ids = self._initial_contact_points
271271
filtered = [cid for cid in connection_ids if cid in configured_ids]
272272
if not filtered:
273273
return
@@ -301,7 +301,7 @@ def handle_control_connection_reconnect(self, control_connection: 'ControlConnec
301301
"""
302302
log.info("[client routes] Control connection reconnected, reloading all routes")
303303

304-
connection_ids = self._connection_ids
304+
connection_ids = self._initial_contact_points
305305
max_attempts = 3
306306
for attempt in range(1, max_attempts + 1):
307307
try:

cassandra/cluster.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,12 +1311,12 @@ def __init__(self,
13111311
self._client_routes_handler = _ClientRoutesHandler(client_routes_config, ssl_enabled=ssl_enabled)
13121312

13131313
if contact_points is _NOT_SET or not self._contact_points_explicit:
1314-
seed_addrs = [dep.connection_addr for dep in client_routes_config.deployments
1315-
if dep.connection_addr]
1314+
seed_addrs = [cp.connection_addr for cp in client_routes_config.contact_points
1315+
if cp.connection_addr]
13161316
if seed_addrs:
13171317
self.contact_points = seed_addrs
13181318
self._contact_points_explicit = True
1319-
log.info("[client routes] Using %d deployment connection addresses as contact points",
1319+
log.info("[client routes] Using %d contact point connection addresses as seed contact points",
13201320
len(seed_addrs))
13211321

13221322
if self._client_routes_handler is not None:

tests/integration/standard/test_client_routes.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import urllib.request
4040

4141
from cassandra.cluster import Cluster
42-
from cassandra.client_routes import ClientRoutesConfig, PrivateLinkDeployment
42+
from cassandra.client_routes import ClientRoutesConfig, ClientRoutesContactPoint
4343
from cassandra.connection import ClientRoutesEndPoint
4444
from cassandra.policies import RoundRobinPolicy
4545
from tests.integration import (
@@ -573,7 +573,7 @@ class TestGetHostPortMapping(unittest.TestCase):
573573
@classmethod
574574
def setUpClass(cls):
575575
cls.cluster = TestCluster(client_routes_config=ClientRoutesConfig(
576-
deployments=[PrivateLinkDeployment("conn_id", "127.0.0.1")]))
576+
contact_points=[ClientRoutesContactPoint("conn_id", "127.0.0.1")]))
577577
cls.session = cls.cluster.connect()
578578

579579
cls.host_ids = [uuid.uuid4() for _ in range(3)]
@@ -701,8 +701,8 @@ def _make_client_routes_cluster(self, **extra_kwargs):
701701
contact_points=[NLBEmulator.LISTEN_HOST],
702702
port=self.nlb.discovery_port,
703703
client_routes_config=ClientRoutesConfig(
704-
deployments=[PrivateLinkDeployment(self.connection_id, NLBEmulator.LISTEN_HOST)],
705-
704+
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
705+
cache_ttl_seconds=0,
706706
),
707707
load_balancing_policy=RoundRobinPolicy(),
708708
**extra_kwargs,
@@ -823,8 +823,8 @@ def test_route_update_causes_reconnect_to_new_port(self):
823823
contact_points=[NLBEmulator.LISTEN_HOST],
824824
port=nlb_v1.discovery_port,
825825
client_routes_config=ClientRoutesConfig(
826-
deployments=[PrivateLinkDeployment(self.connection_id, NLBEmulator.LISTEN_HOST)],
827-
826+
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
827+
cache_ttl_seconds=0,
828828
),
829829
load_balancing_policy=RoundRobinPolicy(),
830830
) as cluster:
@@ -956,8 +956,8 @@ def test_mixed_direct_and_nlb_connections(self):
956956
with Cluster(
957957
contact_points=["127.0.0.1"],
958958
client_routes_config=ClientRoutesConfig(
959-
deployments=[PrivateLinkDeployment(self.connection_id, NLBEmulator.LISTEN_HOST)],
960-
959+
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
960+
cache_ttl_seconds=0,
961961
),
962962
load_balancing_policy=RoundRobinPolicy(),
963963
) as cluster:
@@ -1087,8 +1087,8 @@ def routes_visible():
10871087
port=nlb.discovery_port,
10881088
ssl_context=ssl_ctx,
10891089
client_routes_config=ClientRoutesConfig(
1090-
deployments=[PrivateLinkDeployment(self.connection_id, NLBEmulator.LISTEN_HOST)],
1091-
1090+
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
1091+
cache_ttl_seconds=0,
10921092
),
10931093
load_balancing_policy=RoundRobinPolicy(),
10941094
) as cluster:
@@ -1119,7 +1119,7 @@ def test_ssl_with_hostname_verification_raises_error(self):
11191119
contact_points=[NLBEmulator.LISTEN_HOST],
11201120
ssl_context=ssl_ctx,
11211121
client_routes_config=ClientRoutesConfig(
1122-
deployments=[PrivateLinkDeployment("test-id", NLBEmulator.LISTEN_HOST)],
1122+
contact_points=[ClientRoutesContactPoint("test-id", NLBEmulator.LISTEN_HOST)],
11231123
),
11241124
)
11251125
self.assertIn("check_hostname", str(cm.exception))
@@ -1177,8 +1177,8 @@ def test_should_survive_full_node_replacement_through_nlb(self):
11771177
contact_points=[NLBEmulator.LISTEN_HOST],
11781178
port=nlb.discovery_port,
11791179
client_routes_config=ClientRoutesConfig(
1180-
deployments=[PrivateLinkDeployment(self.connection_id, NLBEmulator.LISTEN_HOST)],
1181-
1180+
contact_points=[ClientRoutesContactPoint(self.connection_id, NLBEmulator.LISTEN_HOST)],
1181+
cache_ttl_seconds=0,
11821182
),
11831183
load_balancing_policy=RoundRobinPolicy(),
11841184
) as cluster:

tests/unit/test_client_routes.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from unittest.mock import Mock, patch
1919

2020
from cassandra.client_routes import (
21-
PrivateLinkDeployment,
21+
ClientRoutesContactPoint,
2222
ClientRoutesConfig,
2323
_RouteStore,
2424
_Route,
@@ -29,29 +29,35 @@
2929
from cassandra import DriverException
3030

3131

32-
class TestPrivateLinkDeployment(unittest.TestCase):
32+
class TestClientRoutesContactPoint(unittest.TestCase):
3333

3434
def test_endpoint_none_connection_id(self):
3535
with self.assertRaises(ValueError):
36-
PrivateLinkDeployment(None)
36+
ClientRoutesContactPoint(None)
3737

3838

3939
class TestClientRoutesConfig(unittest.TestCase):
4040

41-
def test_config_with_deployments(self):
42-
ep1 = PrivateLinkDeployment(str(uuid.uuid4()), "10.0.0.1")
43-
ep2 = PrivateLinkDeployment(str(uuid.uuid4()), "10.0.0.2")
41+
def test_config_with_endpoints(self):
42+
ep1 = ClientRoutesContactPoint(str(uuid.uuid4()), "10.0.0.1")
43+
ep2 = ClientRoutesContactPoint(str(uuid.uuid4()), "10.0.0.2")
4444
config = ClientRoutesConfig([ep1, ep2])
45-
self.assertEqual(len(config.deployments), 2)
45+
self.assertEqual(len(config.contact_points), 2)
4646

47-
def test_config_empty_deployments(self):
47+
def test_config_empty_contact_points(self):
4848
with self.assertRaises(ValueError):
4949
ClientRoutesConfig([])
5050

51-
def test_config_invalid_deployment_type(self):
51+
def test_config_invalid_contact_point_type(self):
5252
with self.assertRaises(TypeError):
53-
ClientRoutesConfig(["not-a-deployment"])
53+
ClientRoutesConfig(["not-a-contact-point"])
5454

55+
def test_config_cache_ttl_validation(self):
56+
ep = ClientRoutesContactPoint(str(uuid.uuid4()))
57+
with self.assertRaises(ValueError):
58+
ClientRoutesConfig([ep], cache_ttl_seconds=-1)
59+
config = ClientRoutesConfig([ep], cache_ttl_seconds=0)
60+
self.assertEqual(config.cache_ttl_seconds, 0)
5561

5662

5763
class TestRouteStore(unittest.TestCase):
@@ -98,8 +104,8 @@ class TestClientRoutesHandler(unittest.TestCase):
98104

99105
def setUp(self):
100106
self.conn_id = uuid.uuid4()
101-
self.deployment = PrivateLinkDeployment(str(self.conn_id), "10.0.0.1")
102-
self.config = ClientRoutesConfig([self.deployment])
107+
self.endpoint = ClientRoutesContactPoint(str(self.conn_id), "10.0.0.1")
108+
self.config = ClientRoutesConfig([self.endpoint])
103109

104110
def test_handler_initialization(self):
105111
handler = _ClientRoutesHandler(self.config, ssl_enabled=False)
@@ -132,8 +138,8 @@ class TestClientRoutesEndPoint(unittest.TestCase):
132138

133139
def setUp(self):
134140
self.conn_id = uuid.uuid4()
135-
self.deployment = PrivateLinkDeployment(str(self.conn_id), "10.0.0.1")
136-
self.config = ClientRoutesConfig([self.deployment])
141+
self.endpoint_entry = ClientRoutesContactPoint(str(self.conn_id), "10.0.0.1")
142+
self.config = ClientRoutesConfig([self.endpoint_entry])
137143
self.handler = _ClientRoutesHandler(self.config, ssl_enabled=False)
138144

139145
def test_resolve_falls_back_when_no_mapping(self):
@@ -155,7 +161,7 @@ def test_check_hostname_with_ssl_context_raises(self):
155161
self.assertTrue(ssl_ctx.check_hostname)
156162

157163
config = ClientRoutesConfig(
158-
deployments=[PrivateLinkDeployment(str(uuid.uuid4()), "10.0.0.1")]
164+
contact_points=[ClientRoutesContactPoint(str(uuid.uuid4()), "10.0.0.1")]
159165
)
160166
with self.assertRaises(ValueError) as cm:
161167
Cluster(
@@ -168,7 +174,7 @@ def test_check_hostname_with_ssl_context_raises(self):
168174
def test_check_hostname_with_ssl_options_raises(self):
169175
"""Cluster should reject check_hostname=True in ssl_options with client_routes_config."""
170176
config = ClientRoutesConfig(
171-
deployments=[PrivateLinkDeployment(str(uuid.uuid4()), "10.0.0.1")]
177+
contact_points=[ClientRoutesContactPoint(str(uuid.uuid4()), "10.0.0.1")]
172178
)
173179
with self.assertRaises(ValueError) as cm:
174180
Cluster(
@@ -184,7 +190,7 @@ def test_disabled_check_hostname_with_client_routes_ok(self):
184190
ssl_ctx.check_hostname = False
185191

186192
config = ClientRoutesConfig(
187-
deployments=[PrivateLinkDeployment(str(uuid.uuid4()), "10.0.0.1")]
193+
contact_points=[ClientRoutesContactPoint(str(uuid.uuid4()), "10.0.0.1")]
188194
)
189195
# Should not raise
190196
cluster = Cluster(
@@ -197,7 +203,7 @@ def test_disabled_check_hostname_with_client_routes_ok(self):
197203
def test_no_ssl_with_client_routes_ok(self):
198204
"""Cluster should allow client_routes_config without SSL."""
199205
config = ClientRoutesConfig(
200-
deployments=[PrivateLinkDeployment(str(uuid.uuid4()), "10.0.0.1")]
206+
contact_points=[ClientRoutesContactPoint(str(uuid.uuid4()), "10.0.0.1")]
201207
)
202208
# Should not raise
203209
cluster = Cluster(

0 commit comments

Comments
 (0)