Skip to content
Draft
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
74 changes: 3 additions & 71 deletions crates/lantern-app/src/application.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::sync::Arc;

use lantern_domain::{DriveState, ProfileId, SessionId};
use lantern_domain::{DriveState, ProfileId};

use crate::{
AuditHealth, Authorization, BackupCaptureRequest, BackupRestoreAction, BackupRestoreEffect,
BackupRestoreState, ConnectionAttemptKind, ConnectionEffect, ConnectionFailure, ConnectionStep,
ConnectionWizardState, Connectivity, CsvLoggingFaultSummary, CsvLoggingStateView, FaultTracker,
BackupRestoreState, ConnectionStep, ConnectionWizardState, Connectivity, FaultTracker,
MAX_PARAMETER_BROWSER_VISIBLE, MonitoringEffect, OperationState, ParameterAction,
ParameterIntentContext, ProfileRegistry, RestoreConfirmation, SessionEffect, SessionState,
SessionStateMachine, WriteConfirmation, WriteConfirmationModel, WriteEffect,
Expand All @@ -16,6 +15,7 @@ mod connection;
mod faults;
mod monitoring;
mod runtime;
mod session;
mod state;
mod view;

Expand Down Expand Up @@ -468,74 +468,6 @@ impl ApplicationState {
}
}

fn csv_stop_effect(&self, session_id: Option<SessionId>) -> Option<ApplicationEffect> {
if !matches!(
self.monitoring.csv_status.state,
CsvLoggingStateView::Starting | CsvLoggingStateView::Running
) {
return None;
}
let session_id = session_id?;
let fault_view = self.faults.view();
Some(ApplicationEffect::Monitoring(
MonitoringEffect::StopCsvLogging {
session_id,
faults: CsvLoggingFaultSummary {
events: u64::try_from(fault_view.events.len()).unwrap_or(u64::MAX),
acknowledged: u64::try_from(
fault_view
.events
.iter()
.filter(|event| event.event.acknowledged)
.count(),
)
.unwrap_or(u64::MAX),
evicted: fault_view.evicted_events,
},
},
))
}

fn translate_session_effects(&mut self, effects: Vec<SessionEffect>) -> Vec<ApplicationEffect> {
let mut translated = Vec::with_capacity(effects.len() + 1);
if effects.contains(&SessionEffect::StopPlanner)
&& let Some(effect) = self.csv_stop_effect(self.session.session_id())
{
translated.push(effect);
}
for effect in effects {
match effect {
SessionEffect::ClosePort => {
translated.push(ApplicationEffect::Connection(ConnectionEffect::ClosePort))
}
SessionEffect::ScheduleReconnect { at } => translated.push(
ApplicationEffect::Connection(ConnectionEffect::ScheduleReconnect { at }),
),
SessionEffect::CancelReconnect => translated.push(ApplicationEffect::Connection(
ConnectionEffect::CancelReconnect,
)),
SessionEffect::OpenPort => {
if let Some(profile) = self.selected_profile() {
match self
.connection
.open_effect(&profile, ConnectionAttemptKind::Reconnect)
{
Ok(effect) => translated.push(ApplicationEffect::Connection(effect)),
Err(error) => self.connection.failure = Some(error),
}
}
}
SessionEffect::StartIdentification
| SessionEffect::StartReconnectIdentification => {
self.connection.failure = Some(ConnectionFailure::Validation(
"identification start lacked an opened adapter result".to_owned(),
));
}
other => translated.push(ApplicationEffect::Session(other)),
}
}
translated
}
}

#[cfg(test)]
Expand Down
85 changes: 85 additions & 0 deletions crates/lantern-app/src/application/session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use lantern_domain::SessionId;

use crate::{
ConnectionAttemptKind, ConnectionEffect, ConnectionFailure, CsvLoggingFaultSummary,
CsvLoggingStateView, MonitoringEffect, SessionEffect,
};

use super::{ApplicationEffect, ApplicationState};

impl ApplicationState {
pub(super) fn csv_stop_effect(
&self,
session_id: Option<SessionId>,
) -> Option<ApplicationEffect> {
if !matches!(
self.monitoring.csv_status.state,
CsvLoggingStateView::Starting | CsvLoggingStateView::Running
) {
return None;
}
let session_id = session_id?;
let fault_view = self.faults.view();
Some(ApplicationEffect::Monitoring(
MonitoringEffect::StopCsvLogging {
session_id,
faults: CsvLoggingFaultSummary {
events: u64::try_from(fault_view.events.len()).unwrap_or(u64::MAX),
acknowledged: u64::try_from(
fault_view
.events
.iter()
.filter(|event| event.event.acknowledged)
.count(),
)
.unwrap_or(u64::MAX),
evicted: fault_view.evicted_events,
},
},
))
}

pub(super) fn translate_session_effects(
&mut self,
effects: Vec<SessionEffect>,
) -> Vec<ApplicationEffect> {
let mut translated = Vec::with_capacity(effects.len() + 1);
if effects.contains(&SessionEffect::StopPlanner)
&& let Some(effect) = self.csv_stop_effect(self.session.session_id())
{
translated.push(effect);
}
for effect in effects {
match effect {
SessionEffect::ClosePort => {
translated.push(ApplicationEffect::Connection(ConnectionEffect::ClosePort))
}
SessionEffect::ScheduleReconnect { at } => translated.push(
ApplicationEffect::Connection(ConnectionEffect::ScheduleReconnect { at }),
),
SessionEffect::CancelReconnect => translated.push(ApplicationEffect::Connection(
ConnectionEffect::CancelReconnect,
)),
SessionEffect::OpenPort => {
if let Some(profile) = self.selected_profile() {
match self
.connection
.open_effect(&profile, ConnectionAttemptKind::Reconnect)
{
Ok(effect) => translated.push(ApplicationEffect::Connection(effect)),
Err(error) => self.connection.failure = Some(error),
}
}
}
SessionEffect::StartIdentification
| SessionEffect::StartReconnectIdentification => {
self.connection.failure = Some(ConnectionFailure::Validation(
"identification start lacked an opened adapter result".to_owned(),
));
}
other => translated.push(ApplicationEffect::Session(other)),
}
}
translated
}
}
Loading