Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ops/storages/neo4j.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ impl components::SetupOperator for SetupComponentOperator {
type Key = ComponentKey;
type State = ComponentState;
type SetupState = SetupState;
type Context = ();

fn describe_key(&self, key: &Self::Key) -> String {
format!("{} {}", key.kind.describe(), key.name)
Expand Down Expand Up @@ -724,7 +725,7 @@ impl components::SetupOperator for SetupComponentOperator {
current == desired
}

async fn create(&self, state: &ComponentState) -> Result<()> {
async fn create(&self, state: &ComponentState, _context: &Self::Context) -> Result<()> {
let graph = self.graph_pool.get_graph(&self.conn_spec).await?;
let key = state.key();
let qualifier = CORE_ELEMENT_MATCHER_VAR;
Expand Down Expand Up @@ -762,7 +763,7 @@ impl components::SetupOperator for SetupComponentOperator {
Ok(graph.run(query).await?)
}

async fn delete(&self, key: &ComponentKey) -> Result<()> {
async fn delete(&self, key: &ComponentKey, _context: &Self::Context) -> Result<()> {
let graph = self.graph_pool.get_graph(&self.conn_spec).await?;
let query = neo4rs::query(&format!(
"DROP {kind} {name} IF EXISTS",
Expand Down Expand Up @@ -1131,7 +1132,7 @@ impl StorageFactoryBase for Factory {
}
}

apply_component_changes(components).await?;
apply_component_changes(components, &()).await?;
Ok(())
}
}
18 changes: 10 additions & 8 deletions src/setup/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ pub trait SetupOperator: 'static + Send + Sync {
type Key: Debug + Hash + Eq + Clone + Send + Sync;
type State: State<Self::Key>;
type SetupState: Send + Sync + IntoIterator<Item = Self::State>;
type Context: Sync;

fn describe_key(&self, key: &Self::Key) -> String;

fn describe_state(&self, state: &Self::State) -> String;

fn is_up_to_date(&self, current: &Self::State, desired: &Self::State) -> bool;

async fn create(&self, state: &Self::State) -> Result<()>;
async fn create(&self, state: &Self::State, context: &Self::Context) -> Result<()>;

async fn delete(&self, key: &Self::Key) -> Result<()>;
async fn delete(&self, key: &Self::Key, context: &Self::Context) -> Result<()>;

async fn update(&self, state: &Self::State) -> Result<()> {
self.delete(&state.key()).await?;
self.create(state).await
async fn update(&self, state: &Self::State, context: &Self::Context) -> Result<()> {
self.delete(&state.key(), context).await?;
self.create(state, context).await
}
}

Expand Down Expand Up @@ -150,21 +151,22 @@ impl<D: SetupOperator + Send + Sync> ResourceSetupStatus for SetupStatus<D> {

pub async fn apply_component_changes<D: SetupOperator>(
changes: Vec<&SetupStatus<D>>,
context: &D::Context,
) -> Result<()> {
// First delete components that need to be removed
for change in changes.iter() {
for key in &change.keys_to_delete {
change.desc.delete(key).await?;
change.desc.delete(key, context).await?;
}
}

// Then upsert components that need to be updated
for change in changes.iter() {
for state in &change.states_to_upsert {
if state.already_exists {
change.desc.update(&state.state).await?;
change.desc.update(&state.state, context).await?;
} else {
change.desc.create(&state.state).await?;
change.desc.create(&state.state, context).await?;
}
}
}
Expand Down
Loading