Skip to main content

soma_fleet/
ports.rs

1use async_trait::async_trait;
2use soma_ops::Timestamp;
3use tokio_util::sync::CancellationToken;
4
5use crate::{
6    CommandOutput, CommandRequest, FleetResult, HostRecord, TopologySnapshot, TransferReceipt,
7    TransferRequest,
8};
9
10/// Source of immutable fleet topology snapshots.
11#[async_trait]
12pub trait HostRepository: Send + Sync {
13    /// Loads one internally consistent topology snapshot.
14    async fn snapshot(&self) -> FleetResult<TopologySnapshot>;
15}
16
17/// Driver that opens and closes revision-bound host connections.
18#[async_trait]
19pub trait ConnectionFactory: Send + Sync {
20    /// Concrete connection handle cached by consumers.
21    type Connection: Send + Sync + 'static;
22
23    /// Opens a connection for the exact host revision.
24    async fn connect(
25        &self,
26        host: &HostRecord,
27        cancellation: &CancellationToken,
28    ) -> FleetResult<Self::Connection>;
29
30    /// Closes a connection explicitly when invalidated or evicted.
31    async fn close(&self, connection: &Self::Connection) -> FleetResult<()>;
32}
33
34/// Exec-style command driver for local, SSH, or other host transports.
35#[async_trait]
36pub trait CommandExecutor: Send + Sync {
37    /// Executes a validated command request on one exact host revision.
38    async fn execute(
39        &self,
40        host: &HostRecord,
41        request: &CommandRequest,
42        cancellation: &CancellationToken,
43    ) -> FleetResult<CommandOutput>;
44}
45
46/// Descriptor-confined file transfer driver.
47#[async_trait]
48pub trait FileTransfer: Send + Sync {
49    /// Transfers one validated path pair between exact host revisions.
50    async fn transfer(
51        &self,
52        source: &HostRecord,
53        destination: &HostRecord,
54        request: &TransferRequest,
55        cancellation: &CancellationToken,
56    ) -> FleetResult<TransferReceipt>;
57}
58
59/// Clock used for request deadline admission and deterministic tests.
60pub trait FleetClock: Send + Sync {
61    /// Returns current Unix-millisecond time.
62    fn now(&self) -> Timestamp;
63}
64
65/// System-wall-clock implementation.
66#[derive(Debug, Clone, Copy, Default)]
67pub struct SystemFleetClock;
68
69impl FleetClock for SystemFleetClock {
70    fn now(&self) -> Timestamp {
71        Timestamp::now()
72    }
73}
74
75#[cfg(test)]
76#[path = "ports_tests.rs"]
77mod tests;