use std::collections::HashSet;
use crate::orchestration::state::OrchestratorState;
#[derive(Debug, Clone)]
pub(super) struct ReducerWorkSnapshot {
reducer_present: bool,
acquisition_complete: bool,
queued_intent_ids: Vec<String>,
ordinary_eligible_ids: HashSet<String>,
final_terminal_stop_ids: HashSet<String>,
active_ids: HashSet<String>,
resolving_ids: HashSet<String>,
merge_wait_ids: HashSet<String>,
resolve_wait_ids: HashSet<String>,
reject_wait_ids: HashSet<String>,
acceptance_stalled_ids: HashSet<String>,
externally_blocked_ids: HashSet<String>,
settled_ids: HashSet<String>,
terminal_error_ids: HashSet<String>,
}
impl ReducerWorkSnapshot {
pub(super) fn from_state(state: &OrchestratorState) -> Self {
let terminal_error_ids = state
.initial_change_ids()
.iter()
.filter(|id| state.is_terminal_error_change(id))
.cloned()
.collect();
Self {
reducer_present: true,
acquisition_complete: true,
queued_intent_ids: state.queued_change_ids(),
ordinary_eligible_ids: state.ordinary_queue_eligible_change_ids(),
final_terminal_stop_ids: state.final_terminal_dispatch_stop_change_ids(),
active_ids: state.active_change_ids().into_iter().collect(),
resolving_ids: state.resolving_change_ids(),
merge_wait_ids: state.merge_wait_change_ids().into_iter().collect(),
resolve_wait_ids: state.resolve_wait_change_ids().into_iter().collect(),
reject_wait_ids: state.reject_wait_change_ids().into_iter().collect(),
acceptance_stalled_ids: state.acceptance_stalled_change_ids(),
externally_blocked_ids: state.externally_blocked_change_ids(),
settled_ids: state.settled_lifecycle_change_ids(),
terminal_error_ids,
}
}
pub(super) fn absent() -> Self {
Self::empty(false, true)
}
pub(super) fn incomplete() -> Self {
Self::empty(true, false)
}
fn empty(reducer_present: bool, acquisition_complete: bool) -> Self {
Self {
reducer_present,
acquisition_complete,
queued_intent_ids: Vec::new(),
ordinary_eligible_ids: HashSet::new(),
final_terminal_stop_ids: HashSet::new(),
active_ids: HashSet::new(),
resolving_ids: HashSet::new(),
merge_wait_ids: HashSet::new(),
resolve_wait_ids: HashSet::new(),
reject_wait_ids: HashSet::new(),
acceptance_stalled_ids: HashSet::new(),
externally_blocked_ids: HashSet::new(),
settled_ids: HashSet::new(),
terminal_error_ids: HashSet::new(),
}
}
pub(super) fn is_complete(&self) -> bool {
self.acquisition_complete
}
pub(super) fn reducer_present(&self) -> bool {
self.reducer_present
}
pub(super) fn queued_intent_ids(&self) -> &[String] {
&self.queued_intent_ids
}
pub(super) fn active_ids(&self) -> &HashSet<String> {
&self.active_ids
}
pub(super) fn resolving_ids(&self) -> &HashSet<String> {
&self.resolving_ids
}
pub(super) fn merge_wait_ids(&self) -> &HashSet<String> {
&self.merge_wait_ids
}
pub(super) fn resolve_wait_ids(&self) -> &HashSet<String> {
&self.resolve_wait_ids
}
pub(super) fn reject_wait_ids(&self) -> &HashSet<String> {
&self.reject_wait_ids
}
pub(super) fn settled_ids(&self) -> &HashSet<String> {
&self.settled_ids
}
pub(super) fn terminal_error_ids(&self) -> &HashSet<String> {
&self.terminal_error_ids
}
pub(super) fn held_ids(&self) -> HashSet<String> {
self.acceptance_stalled_ids
.iter()
.chain(&self.externally_blocked_ids)
.cloned()
.collect()
}
pub(super) fn is_ordinary_queue_eligible(&self, change_id: &str) -> bool {
self.ordinary_eligible_ids.contains(change_id)
}
pub(super) fn is_final_terminal_dispatch_stop(&self, change_id: &str) -> bool {
self.final_terminal_stop_ids.contains(change_id)
}
}