Skip to content

Commit 08d218b

Browse files
authored
[DPE-7640] Migrate from Management API to nodetool (#6)
* Get rid of Management API. * Get rid of read_file & write_file functions from Workload.
1 parent c460398 commit 08d218b

File tree

6 files changed

+17
-93
lines changed

6 files changed

+17
-93
lines changed

src/charm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, *args):
3030

3131
state = ApplicationState(self)
3232
workload = CassandraWorkload()
33-
cluster_manager = ClusterManager()
33+
cluster_manager = ClusterManager(workload=workload)
3434
config_manager = ConfigManager(workload=workload)
3535

3636
self.framework.observe(self.on.collect_unit_status, self._on_collect_unit_status)

src/common/management_client.py

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

src/core/workload.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ def alive(self) -> bool:
7070
"""
7171
pass
7272

73-
@abstractmethod
74-
def write_file(self, content: str, file: str) -> None:
75-
"""Write content to a file.
76-
77-
Args:
78-
content (str): Content to write to the file.
79-
file (str): Path to the file.
80-
"""
81-
pass
82-
83-
@abstractmethod
84-
def read_file(self, file: str) -> str:
85-
"""Read content from file.
86-
87-
Args:
88-
file (str): Path to the file.
89-
"""
90-
pass
91-
9273
@abstractmethod
9374
def stop(self) -> None:
9475
"""Stop the workload service."""

src/events/cassandra.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ def _on_collect_unit_status(self, event: CollectStatusEvent) -> None:
106106
if self.state.unit.workload_state == UnitWorkloadState.STARTING.value:
107107
event.add_status(Status.STARTING.value)
108108

109-
if (
110-
self.state.unit.workload_state == UnitWorkloadState.ACTIVE.value
111-
and not self.cluster_manager.is_healthy
109+
if self.state.unit.workload_state == UnitWorkloadState.ACTIVE.value and (
110+
not self.workload.alive() or not self.cluster_manager.is_healthy
112111
):
113112
event.add_status(Status.STARTING.value)
114113

src/managers/cluster.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,29 @@
77
import logging
88
import socket
99

10-
from common.management_client import ManagementClient
10+
from common.exceptions import ExecError
11+
from core.workload import WorkloadBase
1112

1213
logger = logging.getLogger(__name__)
1314

15+
_NODETOOL = "charmed-cassandra.nodetool"
16+
1417

1518
class ClusterManager:
1619
"""Manage cluster members, quorum and authorization."""
1720

18-
def __init__(self):
19-
self.management_client = ManagementClient()
21+
def __init__(self, workload: WorkloadBase):
22+
self._workload = workload
23+
pass
2024

2125
@property
2226
def is_healthy(self) -> bool:
23-
"""Perform cassandra helth and readiness checks and return True if healthy.
24-
25-
Returns:
26-
bool: True if the cluster or node is healthy.
27-
"""
28-
return self.management_client.is_healthy()
27+
"""TODO."""
28+
try:
29+
stdout, _ = self._workload.exec([_NODETOOL, "info"])
30+
return "Native Transport active: true" in stdout
31+
except ExecError:
32+
return False
2933

3034
def network_address(self) -> tuple[str, str]:
3135
"""TODO."""

src/workload.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
SNAP_NAME = "charmed-cassandra"
2323
SNAP_REVISION = "8"
24-
SNAP_SERVICE = "mgmt-server"
24+
SNAP_SERVICE = "daemon"
2525

2626
logger = logging.getLogger(__name__)
2727

@@ -66,19 +66,6 @@ def alive(self) -> bool:
6666
except KeyError:
6767
return False
6868

69-
@override
70-
def write_file(self, content: str, file: str) -> None:
71-
path = self.root / file
72-
path.parent.mkdir(exist_ok=True, parents=True)
73-
path.write_text(content)
74-
75-
@override
76-
def read_file(self, file: str) -> str:
77-
path = self.root / file
78-
if not path.exists():
79-
raise FileNotFoundError(f"File '{file}' does not exist.")
80-
return path.read_text()
81-
8269
@override
8370
def stop(self) -> None:
8471
self._cassandra_snap.stop(services=[SNAP_SERVICE])

0 commit comments

Comments
 (0)