Skip to content

Commit

Permalink
Intermediate state
Browse files Browse the repository at this point in the history
Issue-Id: #1
  • Loading branch information
christoph-hamm committed Sep 22, 2023
1 parent cb5896b commit 9d2e945
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 43 deletions.
8 changes: 1 addition & 7 deletions agent/src/podman/podman_kube_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@ pub struct PlayKubeError {}
#[async_trait]
impl Runtime for PodmanKubeRuntime {
type Id = PodmanKubeWorkloadId;
type Rc = PodmanKubeConfig;
type StateChecker = GenericPollingStateChecker;

async fn create_workload(
&self,
workload_spec: &WorkloadSpec,
runtime_cfg: &Self::Rc,
) -> Result<(Self::Id, Self::StateChecker), RuntimeError> {
todo!()
}

async fn delete_workload(
&self,
workload_id: Self::Id,
runtime_cfg: &Self::Rc,
) -> Result<(Self::Id, Self::StateChecker), RuntimeError> {
async fn delete_workload(&self, workload_id: Self::Id) -> Result<(), RuntimeError> {
todo!()
}
}
12 changes: 3 additions & 9 deletions agent/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,14 @@ pub trait RuntimeConfig {}

#[async_trait]
// #[cfg_attr(test, automock(type State=String; type Id=String;))]
pub trait Runtime{
type Id: WorkloadId;
type Rc: RuntimeConfig;
pub trait Runtime: Sync + Send {
type Id;
type StateChecker: Send + StoppableStateChecker; // This is definitely not Clone

async fn create_workload(
&self,
workload_spec: &WorkloadSpec,
runtime_cfg: &Self::Rc,
) -> Result<(Self::Id, Self::StateChecker), RuntimeError>;

async fn delete_workload(
&self,
workload_id: Self::Id,
runtime_cfg: &Self::Rc,
) -> Result<(Self::Id, Self::StateChecker), RuntimeError>;
async fn delete_workload(&self, workload_id: Self::Id) -> Result<(), RuntimeError>;
}
4 changes: 2 additions & 2 deletions agent/src/runtime_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use common::objects::{DeletedWorkload, WorkloadSpec};
use crate::{workload::NewWorkload, workload_factory::WorkloadFactory};

struct RuntimeManager {
workloads: HashMap<String, NewWorkload>,
workloads: HashMap<String, Box<dyn NewWorkload>>,
wl_factory: WorkloadFactory,
}

Expand All @@ -17,7 +17,7 @@ impl RuntimeManager {
) {
for workload in deleted_workloads {
if let Some(x) = self.workloads.remove(&workload.name) {
x.delete()
x.delete().await
}
}

Expand Down
35 changes: 22 additions & 13 deletions agent/src/workload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ use crate::{
stoppable_state_checker::StoppableStateChecker,
workload_id::WorkloadId,
};
use common::objects::WorkloadSpec;
use async_trait::async_trait;
use common::objects::RuntimeWorkload;

// #[derive(Debug)]
pub struct NewWorkload {
#[async_trait]
pub trait NewWorkload {
fn update(&self, spec: RuntimeWorkload);
async fn delete(self: Box<Self>);
}

// #[derive(Debug)]
pub struct GenericWorkload<Id, StateChecker: StoppableStateChecker> {
// channel: CommandChannel,
// workload_spec: WorkloadSpec,
pub workload_id: Box<dyn WorkloadId>,
pub runtime: Arc<
dyn Runtime<
Id = dyn WorkloadId,
Rc = dyn RuntimeConfig,
StateChecker = dyn StoppableStateChecker,
>,
>,
pub workload_id: Id,
pub runtime: Arc<dyn Runtime<Id = Id, StateChecker = StateChecker>>,
}

impl NewWorkload {
pub fn delete(self) {
// TODO delete workload
#[async_trait]
impl<Id: Send, StateChecker: StoppableStateChecker + Send> NewWorkload
for GenericWorkload<Id, StateChecker>
{
fn update(&self, spec: RuntimeWorkload) {
todo!()
}

async fn delete(self: Box<Self>) {
self.runtime.delete_workload(self.workload_id).await;
}
}
19 changes: 7 additions & 12 deletions agent/src/workload_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,24 @@ use crate::{
workload_id::WorkloadId,
};

type BoxedRuntime = Arc<
dyn Runtime<
Id = dyn WorkloadId,
Rc = dyn RuntimeConfig,
StateChecker = dyn StoppableStateChecker,
>,
>;
type BoxedRuntime = Arc<dyn Runtime<Id = dyn WorkloadId, StateChecker = dyn StoppableStateChecker>>;

pub struct WorkloadFactory {
runtime_map: HashMap<String, BoxedRuntime>,
}

impl WorkloadFactory {
pub fn create_workload(&self, runtime_id: String) -> NewWorkload {
pub fn create_workload(&self, runtime_id: String) -> Box<dyn NewWorkload> {
let runtime = self.runtime_map.get(&runtime_id).unwrap().clone();

let wl_id = PodmanKubeWorkloadId {
manifest: "bla bla".to_string(),
};

NewWorkload {
workload_id: Box::new(wl_id),
runtime,
}
// NewWorkload {
// workload_id: Box::new(wl_id),
// runtime,
// }
todo!()
}
}

0 comments on commit 9d2e945

Please sign in to comment.