use crate::conversation::Conversation;
use crate::reconcile::Error;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActorState {
Resuming,
Running,
Suspending,
Suspended,
Pausing,
Paused,
Crashed,
Deleting,
Reverting,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActorSnapshot {
pub uid: String,
pub state: ActorState,
pub template: String,
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("substrate control API: {0}")]
pub struct ActorControlError(pub String);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ResumeOutcome {
Running,
NoCapacity,
}
#[async_trait::async_trait]
pub trait ActorControl: Send + Sync {
async fn ensure_atespace(&self, atespace: &str) -> Result<(), ActorControlError>;
async fn get(
&self,
atespace: &str,
name: &str,
) -> Result<Option<ActorSnapshot>, ActorControlError>;
async fn create(
&self,
atespace: &str,
name: &str,
template: &str,
) -> Result<ActorSnapshot, ActorControlError>;
async fn suspend(&self, atespace: &str, name: &str) -> Result<(), ActorControlError>;
async fn resume(&self, atespace: &str, name: &str) -> Result<ResumeOutcome, ActorControlError>;
async fn set_template(
&self,
atespace: &str,
name: &str,
template: &str,
) -> Result<(), ActorControlError>;
async fn delete(&self, atespace: &str, name: &str, uid: &str) -> Result<(), ActorControlError>;
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct UnitReadiness {
pub unit_present: bool,
pub address: Option<DialAddress>,
pub harness_ready: bool,
pub crashed: bool,
pub uid: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum DialAddress {
Actor {
atespace: String,
name: String,
},
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EnsuredUnit {
pub uid: String,
}
#[async_trait::async_trait]
pub trait ExecutionBackend: Send + Sync {
async fn ensure(
&self,
conv: &Conversation,
name: &str,
template: &str,
ns: &str,
) -> Result<EnsuredUnit, Error>;
async fn readiness(&self, name: &str, ns: &str) -> Result<UnitReadiness, Error>;
async fn suspend(&self, name: &str, ns: &str) -> Result<(), Error>;
async fn retemplate(&self, name: &str, template: &str, ns: &str) -> Result<(), Error>;
async fn teardown(&self, owner: &Conversation, name: &str, ns: &str) -> Result<(), Error>;
fn kind(&self) -> &'static str;
}