Skip to content

Commit 5f1e6ca

Browse files
committed
Documentation
1 parent 4d7d899 commit 5f1e6ca

File tree

7 files changed

+57
-59
lines changed

7 files changed

+57
-59
lines changed

src/charm.py

Lines changed: 2 additions & 2 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-
"""Charm the application."""
5+
"""Charm definiton."""
66

77
import logging
88

@@ -20,7 +20,7 @@
2020

2121

2222
class CassandraCharm(TypedCharmBase[CharmConfig]):
23-
"""Charm the application."""
23+
"""Application charm."""
2424

2525
config_type = CharmConfig
2626

src/common/cassandra_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class CassandraClient:
19-
"""TODO."""
19+
"""Cassandra CQL client."""
2020

2121
def __init__(self, hosts: list[str], user: str | None = None, password: str | None = None):
2222
self.execution_profile = ExecutionProfile(

src/core/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-
"""Charm config definition."""
5+
"""Charm config."""
66

77
from typing import Literal
88

@@ -13,15 +13,15 @@
1313

1414

1515
class CharmConfig(BaseConfigModel):
16-
"""Manager for the structured configuration."""
16+
"""Structured charm config."""
1717

18-
profile: ConfigProfile
1918
cluster_name: str
19+
profile: ConfigProfile
2020

2121
@field_validator("cluster_name")
2222
@classmethod
2323
def cluster_name_values(cls, value: str) -> str:
24-
"""TODO."""
24+
"""Validate cluster_name."""
2525
if len(value) == 0:
2626
raise ValueError("cluster_name cannot be empty")
2727

src/core/state.py

Lines changed: 47 additions & 49 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+
"""Application state definition."""
66

77
import logging
88
from enum import StrEnum
@@ -16,30 +16,36 @@
1616
from ops import Application, CharmBase, Object, Relation, Unit
1717

1818
PEER_RELATION = "cassandra-peers"
19-
PEER_PORT = 7000
20-
CLIENT_PORT = 9042
19+
CASSANDRA_PEER_PORT = 7000
20+
CASSANDRA_CLIENT_PORT = 9042
2121

2222
logger = logging.getLogger(__name__)
2323

2424

2525
class ClusterState(StrEnum):
26-
"""TODO."""
26+
"""Current state of the Cassandra cluster."""
2727

2828
UNKNOWN = ""
29+
"""Cassandra cluster isn't yet initialized by the leader unit."""
2930
ACTIVE = "active"
31+
"""Cassandra cluster is initialized by the leader unit and active."""
3032

3133

3234
class UnitWorkloadState(StrEnum):
33-
"""TODO."""
35+
"""Current state of the Cassandra workload."""
3436

3537
INSTALLING = ""
38+
"""Cassandra is installing."""
3639
WAITING_FOR_START = "waiting_for_start"
40+
"""Subordinate unit is waiting for leader to initialize cluster before it starts workload."""
3741
STARTING = "starting"
42+
"""Cassandra is starting."""
3843
ACTIVE = "active"
44+
"""Cassandra is active and ready."""
3945

4046

4147
class RelationState:
42-
"""Relation state object."""
48+
"""Basic class for relation bag mapping classes."""
4349

4450
def __init__(
4551
self,
@@ -54,9 +60,8 @@ def __init__(
5460

5561
def _field_setter_wrapper(self, field: str, value: str) -> None:
5662
if not self.relation:
57-
logger.warning(
58-
f"Field `{field}` were attempted to\
59-
be written on the relation before it exists."
63+
logger.error(
64+
f"Field `{field}` were attempted to be written on the relation before it exists."
6065
)
6166
return
6267

@@ -70,7 +75,10 @@ def _field_setter_wrapper(self, field: str, value: str) -> None:
7075

7176

7277
class UnitContext(RelationState):
73-
"""State/Relation data collection for a unit."""
78+
"""Unit context of the application state.
79+
80+
Provides mappings for the unit data bag of peer relation.
81+
"""
7482

7583
def __init__(
7684
self,
@@ -88,14 +96,9 @@ def unit_id(self) -> int:
8896

8997
@property
9098
def unit_name(self) -> str:
91-
"""The id of the unit from the unit name."""
99+
"""Unit name."""
92100
return self.unit.name
93101

94-
@property
95-
def node_name(self) -> str:
96-
"""The Human-readable name for this cassandra cluster node."""
97-
return f"{self.unit.app.name}{self.unit_id}"
98-
99102
@property
100103
def hostname(self) -> str:
101104
"""The hostname for the unit."""
@@ -116,17 +119,17 @@ def ip(self, value: str) -> None:
116119

117120
@property
118121
def peer_url(self) -> str:
119-
"""The peer connection endpoint for the cassandra server."""
120-
return f"{self.ip}:{PEER_PORT}"
122+
"""The internode connection endpoint for the cassandra server from unit IP."""
123+
return f"{self.ip}:{CASSANDRA_PEER_PORT}"
121124

122125
@property
123126
def client_url(self) -> str:
124-
"""The client connection endpoint for the cassandra server."""
125-
return f"{self.ip}:{CLIENT_PORT}"
127+
"""The client connection endpoint for the cassandra server from unit IP."""
128+
return f"{self.ip}:{CASSANDRA_CLIENT_PORT}"
126129

127130
@property
128131
def workload_state(self) -> UnitWorkloadState:
129-
"""TODO."""
132+
"""Current state of the Cassandra workload."""
130133
return self.relation_data.get("workload_state", UnitWorkloadState.INSTALLING)
131134

132135
@workload_state.setter
@@ -135,7 +138,10 @@ def workload_state(self, value: UnitWorkloadState) -> None:
135138

136139

137140
class ClusterContext(RelationState):
138-
"""State/Relation data collection for the cassandra application."""
141+
"""Cluster context of the application state.
142+
143+
Provides mappings for the application data bag of peer relation.
144+
"""
139145

140146
def __init__(
141147
self,
@@ -148,7 +154,7 @@ def __init__(
148154

149155
@property
150156
def seeds(self) -> list[str]:
151-
"""TODO."""
157+
"""List of peer urls of Cassandra seed nodes."""
152158
seeds = self.relation_data.get("seeds", "")
153159
return seeds.split(",") if seeds else []
154160

@@ -158,22 +164,21 @@ def seeds(self, value: list[str]) -> None:
158164

159165
@property
160166
def state(self) -> ClusterState:
161-
"""The cluster state ('new' or 'existing') of the cassandra cluster."""
167+
"""Current state of the Cassandra cluster."""
162168
return self.relation_data.get("cluster_state", ClusterState.UNKNOWN)
163169

164170
@state.setter
165171
def state(self, value: ClusterState) -> None:
166-
"""TODO."""
167172
self._field_setter_wrapper("cluster_state", value.value)
168173

169174
@property
170175
def is_active(self) -> bool:
171-
"""TODO."""
176+
"""Is Cassandra cluster state `ACTIVE`."""
172177
return self.state == ClusterState.ACTIVE
173178

174179

175180
class ApplicationState(Object):
176-
"""Global state object for the cassandra cluster."""
181+
"""Mappings for the charm relations that forms global application state."""
177182

178183
def __init__(self, charm: CharmBase):
179184
super().__init__(parent=charm, key="charm_state")
@@ -185,12 +190,12 @@ def __init__(self, charm: CharmBase):
185190

186191
@property
187192
def peer_relation(self) -> Relation | None:
188-
"""Get the cluster peer relation."""
193+
"""Cluster peer relation."""
189194
return self.model.get_relation(PEER_RELATION)
190195

191196
@property
192197
def peer_relation_units(self) -> dict[Unit, DataPeerOtherUnitData]:
193-
"""Get unit data interface of all peer units from the cluster peer relation."""
198+
"""Unit data interface of all units in the cluster peer relation."""
194199
if not self.peer_relation or not self.peer_relation.units:
195200
return {}
196201

@@ -201,7 +206,7 @@ def peer_relation_units(self) -> dict[Unit, DataPeerOtherUnitData]:
201206

202207
@property
203208
def cluster(self) -> ClusterContext:
204-
"""Get the cluster context of the entire cassandra application."""
209+
"""Cluster context."""
205210
return ClusterContext(
206211
relation=self.peer_relation,
207212
data_interface=self.peer_app_interface,
@@ -210,7 +215,7 @@ def cluster(self) -> ClusterContext:
210215

211216
@property
212217
def unit(self) -> UnitContext:
213-
"""Get the server state of this unit."""
218+
"""This unit context."""
214219
return UnitContext(
215220
relation=self.peer_relation,
216221
data_interface=self.peer_unit_interface,
@@ -219,24 +224,17 @@ def unit(self) -> UnitContext:
219224

220225
@property
221226
def units(self) -> set[UnitContext]:
222-
"""Get all nodes/units in the current peer relation, including this unit itself.
223-
224-
Note: This is not to be confused with the list of cluster members.
225-
226-
Returns:
227-
Set of CassandraUnitContexts with their unit data.
228-
"""
229-
if not self.peer_relation:
230-
return set()
227+
"""Contexts of all the units in the cluster peer relation, including this unit itself."""
228+
return {self.unit, *self.other_units}
231229

230+
@property
231+
def other_units(self) -> set[UnitContext]:
232+
"""Contexts of other units in the cluster peer relation."""
232233
return {
233-
self.unit,
234-
*(
235-
UnitContext(
236-
relation=self.peer_relation,
237-
data_interface=data_interface,
238-
component=unit,
239-
)
240-
for unit, data_interface in self.peer_relation_units.items()
241-
),
234+
UnitContext(
235+
relation=self.peer_relation,
236+
data_interface=data_interface,
237+
component=unit,
238+
)
239+
for unit, data_interface in self.peer_relation_units.items()
242240
}

src/core/statuses.py

Lines changed: 1 addition & 1 deletion
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+
"""Charm statuses."""
66

77
from enum import Enum
88

src/core/workload.py

Lines changed: 1 addition & 1 deletion
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+
"""Workload definition."""
66

77
from abc import ABC, abstractmethod
88
from typing import Literal

src/workload.py

Lines changed: 1 addition & 1 deletion
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+
"""Workload VM Implementation."""
66

77
import logging
88
import subprocess

0 commit comments

Comments
 (0)