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#[async_trait]
12pub trait HostRepository: Send + Sync {
13 async fn snapshot(&self) -> FleetResult<TopologySnapshot>;
15}
16
17#[async_trait]
19pub trait ConnectionFactory: Send + Sync {
20 type Connection: Send + Sync + 'static;
22
23 async fn connect(
25 &self,
26 host: &HostRecord,
27 cancellation: &CancellationToken,
28 ) -> FleetResult<Self::Connection>;
29
30 async fn close(&self, connection: &Self::Connection) -> FleetResult<()>;
32}
33
34#[async_trait]
36pub trait CommandExecutor: Send + Sync {
37 async fn execute(
39 &self,
40 host: &HostRecord,
41 request: &CommandRequest,
42 cancellation: &CancellationToken,
43 ) -> FleetResult<CommandOutput>;
44}
45
46#[async_trait]
48pub trait FileTransfer: Send + Sync {
49 async fn transfer(
51 &self,
52 source: &HostRecord,
53 destination: &HostRecord,
54 request: &TransferRequest,
55 cancellation: &CancellationToken,
56 ) -> FleetResult<TransferReceipt>;
57}
58
59pub trait FleetClock: Send + Sync {
61 fn now(&self) -> Timestamp;
63}
64
65#[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;