Skip to content

Commit 23deb22

Browse files
committed
Documentation.
1 parent a36ff07 commit 23deb22

File tree

6 files changed

+34
-50
lines changed

6 files changed

+34
-50
lines changed

src/core/state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def state(self, value: ClusterState) -> None:
173173

174174
@property
175175
def is_active(self) -> bool:
176-
"""Is Cassandra cluster state `ACTIVE`."""
176+
"""Whether Cassandra cluster state is `ACTIVE`."""
177177
return self.state == ClusterState.ACTIVE
178178

179179

src/core/workload.py

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,104 +13,85 @@
1313

1414

1515
class CassandraPaths:
16-
"""TODO."""
16+
"""Filesystem paths of the Cassandra workload."""
1717

1818
env: pathops.PathProtocol
1919
config_dir: pathops.PathProtocol
2020
data_dir: pathops.PathProtocol
2121

2222
@property
2323
def config(self) -> pathops.PathProtocol:
24-
"""TODO."""
24+
"""Main config file."""
2525
return self.config_dir / "cassandra.yaml"
2626

2727
@property
2828
def commitlog_directory(self) -> pathops.PathProtocol:
29-
"""TODO."""
29+
"""Commitlog data directory."""
3030
return self.data_dir / "commitlog"
3131

3232
@property
3333
def data_file_directory(self) -> pathops.PathProtocol:
34-
"""TODO."""
34+
"""Main data directory."""
3535
return self.data_dir / "data"
3636

3737
@property
3838
def hints_directory(self) -> pathops.PathProtocol:
39-
"""TODO."""
39+
"""Hints data directory."""
4040
return self.data_dir / "hints"
4141

4242
@property
4343
def saved_caches_directory(self) -> pathops.PathProtocol:
44-
"""TODO."""
44+
"""Saved caches data directory."""
4545
return self.data_dir / "saved_caches"
4646

4747

4848
class WorkloadBase(ABC):
49-
"""Base interface for common workload operations."""
49+
"""Base interface for workload operations."""
5050

5151
substrate: Substrate
5252
cassandra_paths: CassandraPaths
5353

5454
@abstractmethod
5555
def start(self) -> None:
56-
"""Start the workload service."""
56+
"""Start Cassandra service."""
5757
pass
5858

5959
@abstractmethod
6060
def install(self) -> None:
61-
"""Install the cassandra snap."""
61+
"""Install Cassandra."""
6262
pass
6363

6464
@abstractmethod
65-
def alive(self) -> bool:
66-
"""Check if the workload is running.
67-
68-
Returns:
69-
bool: True if the workload is running, False otherwise.
70-
"""
65+
def is_alive(self) -> bool:
66+
"""Whether Cassandra service running."""
7167
pass
7268

7369
@abstractmethod
7470
def stop(self) -> None:
75-
"""Stop the workload service."""
71+
"""Stop Cassandra service."""
7672
pass
7773

7874
@abstractmethod
7975
def restart(self) -> None:
80-
"""Restart the workload service."""
76+
"""Restart Cassandra service."""
8177
pass
8278

8379
@abstractmethod
8480
def remove_file(self, file: str) -> None:
85-
"""Remove a file.
86-
87-
Args:
88-
file (str): Path to the file.
89-
"""
81+
"""Remove file."""
9082
pass
9183

9284
@abstractmethod
9385
def remove_directory(self, directory: str) -> None:
94-
"""Remove a directory.
95-
96-
Args:
97-
directory (str): Path to the directory.
98-
"""
86+
"""Remove directory recursively."""
9987
pass
10088

10189
@abstractmethod
10290
def path_exists(self, path: str) -> bool:
103-
"""Check if a file or directory exists.
104-
105-
Args:
106-
path (str): Path to the file or directory.
107-
108-
Returns:
109-
bool: True if the file or directory exists, False otherwise.
110-
"""
91+
"""Check if file or directory exists."""
11192
pass
11293

11394
@abstractmethod
11495
def exec(self, command: list[str], suppress_error_log: bool = False) -> tuple[str, str]:
115-
"""Run a command on the workload substrate."""
96+
"""Execute command."""
11697
pass

src/events/cassandra.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2025 Canonical Ltd.
33
# See LICENSE file for licensing details.
44

5-
"""TODO."""
5+
"""Handler for main Cassandra charm events."""
66

77
import logging
88

@@ -28,7 +28,7 @@
2828

2929

3030
class CassandraEvents(Object):
31-
"""Handle all base and cassandra related events."""
31+
"""Handler for main Cassandra charm events."""
3232

3333
def __init__(
3434
self,
@@ -152,7 +152,11 @@ def _on_collect_app_status(self, event: CollectStatusEvent) -> None:
152152
event.add_status(Status.ACTIVE.value)
153153

154154
def _update_network_address(self) -> bool:
155-
"""TODO."""
155+
"""Update hostname & ip in this unit context.
156+
157+
Returns:
158+
whether the hostname or ip changed.
159+
"""
156160
old_ip = self.state.unit.ip
157161
old_hostname = self.state.unit.hostname
158162
self.state.unit.ip, self.state.unit.hostname = self.cluster_manager.network_address()

src/managers/cluster.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2025 Canonical Ltd.
33
# See LICENSE file for licensing details.
44

5-
"""TODO."""
5+
"""Cluster manager."""
66

77
import logging
88
import socket
@@ -16,22 +16,22 @@
1616

1717

1818
class ClusterManager:
19-
"""Manage cluster members, quorum and authorization."""
19+
"""Manager of Cassandra cluster, including this unit."""
2020

2121
def __init__(self, workload: WorkloadBase):
2222
self._workload = workload
2323
pass
2424

2525
@property
2626
def is_healthy(self) -> bool:
27-
"""TODO."""
27+
"""Whether Cassandra healthy and ready in this unit."""
2828
try:
2929
stdout, _ = self._workload.exec([_NODETOOL, "info"], suppress_error_log=True)
3030
return "Native Transport active: true" in stdout
3131
except ExecError:
3232
return False
3333

3434
def network_address(self) -> tuple[str, str]:
35-
"""TODO."""
35+
"""Get hostname and IP of this unit."""
3636
hostname = socket.gethostname()
3737
return socket.gethostbyname(hostname), hostname

src/managers/config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2025 Canonical Ltd.
33
# See LICENSE file for licensing details.
44

5-
"""Manager for handling configuration building + writing."""
5+
"""Config manager."""
66

77
import logging
88
from typing import Iterable
@@ -15,7 +15,7 @@
1515

1616

1717
class ConfigManager:
18-
"""Handle the configuration of Cassandra."""
18+
"""Manager of config files."""
1919

2020
def __init__(
2121
self,
@@ -26,7 +26,7 @@ def __init__(
2626
def render_cassandra_config(
2727
self, cluster_name: str, listen_address: str, seeds: list[str]
2828
) -> None:
29-
"""TODO."""
29+
"""Generate and write cassandra config."""
3030
config = {
3131
"allocate_tokens_for_local_replication_factor": 3,
3232
"authenticator": "AllowAllAuthenticator",
@@ -87,7 +87,7 @@ def render_cassandra_config(
8787
)
8888

8989
def render_env(self, cassandra_limit_memory_mb: int | None) -> None:
90-
"""TODO."""
90+
"""Update environment config."""
9191
self.workload.cassandra_paths.env.write_text(
9292
self._render_env(
9393
[

src/workload.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def start(self) -> None:
5151

5252
@override
5353
def install(self) -> None:
54-
"""Install the cassandra snap."""
5554
logger.debug("Installing & configuring Cassandra snap")
5655
self._cassandra_snap.ensure(snap.SnapState.Present, revision=SNAP_REVISION)
5756
self._cassandra_snap.connect("process-control")
@@ -60,7 +59,7 @@ def install(self) -> None:
6059
self._cassandra_snap.hold()
6160

6261
@override
63-
def alive(self) -> bool:
62+
def is_alive(self) -> bool:
6463
try:
6564
return bool(self._cassandra_snap.services[SNAP_SERVICE]["active"])
6665
except KeyError:

0 commit comments

Comments
 (0)