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
14 changes: 8 additions & 6 deletions wicket/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ use slog::Drain;
use crate::{
Runner,
cli::{CommandOutput, ShellApp},
wicketd::WicketdAddrs,
};

pub fn exec() -> Result<ExitCode> {
let wicketd_addr =
SocketAddrV6::new(Ipv6Addr::LOCALHOST, WICKETD_PORT, 0, 0);
let commission_addr =
SocketAddrV6::new(Ipv6Addr::LOCALHOST, WICKETD_COMMISSION_PORT, 0, 0);
let localhost = Ipv6Addr::LOCALHOST;
let addrs = WicketdAddrs {
wicketd: SocketAddrV6::new(localhost, WICKETD_PORT, 0, 0),
commission: SocketAddrV6::new(localhost, WICKETD_COMMISSION_PORT, 0, 0),
};

// SSH_ORIGINAL_COMMAND contains additional arguments, if any.
match std::env::var("SSH_ORIGINAL_COMMAND") {
Expand All @@ -37,7 +39,7 @@ pub fn exec() -> Result<ExitCode> {
let runtime = tokio::runtime::Runtime::new()
.context("creating tokio runtime")?;
runtime.block_on(exec_with_args(
wicketd_addr,
addrs.wicketd,
args,
OutputKind::Terminal,
))
Expand All @@ -46,7 +48,7 @@ pub fn exec() -> Result<ExitCode> {
// Do not expose log messages via standard error since they'll show up
// on top of the TUI.
let log = setup_log(&log_path()?, WithStderr::No)?;
Runner::new(log, wicketd_addr, commission_addr).run()?;
Runner::new(log, addrs).run()?;
Ok(ExitCode::SUCCESS)
}
}
Expand Down
1 change: 1 addition & 0 deletions wicket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ pub use events::{Action, Event, Recorder, Snapshot};
pub use keymap::{Cmd, KeyHandler};
pub use state::State;
pub use ui::{Control, Screen};
pub use wicketd::WicketdAddrs;
17 changes: 4 additions & 13 deletions wicket/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use slog::Logger;
use slog::{debug, error, info};
use slog_error_chain::InlineErrorChain;
use std::io::{Stdout, stdout};
use std::net::SocketAddrV6;
use std::time::Instant;
use tokio::sync::mpsc::{
UnboundedReceiver, UnboundedSender, unbounded_channel,
Expand All @@ -30,7 +29,7 @@ use crate::helpers::get_update_test_error;
use crate::state::CreateClearUpdateStateOptions;
use crate::state::CreateStartUpdateOptions;
use crate::ui::Screen;
use crate::wicketd::{self, WicketdHandle, WicketdManager};
use crate::wicketd::{self, WicketdAddrs, WicketdHandle, WicketdManager};
use crate::{Action, Cmd, Event, KeyHandler, Recorder, State, TICK_INTERVAL};

// We can avoid a bunch of unnecessary type parameters by picking them ahead of time.
Expand Down Expand Up @@ -283,22 +282,14 @@ pub struct Runner {

#[allow(clippy::new_without_default)]
impl Runner {
pub fn new(
log: slog::Logger,
wicketd_addr: SocketAddrV6,
commission_addr: SocketAddrV6,
) -> Runner {
pub fn new(log: slog::Logger, addrs: WicketdAddrs) -> Runner {
let (events_tx, events_rx) = unbounded_channel();
let tokio_rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
let (wicketd, wicketd_manager) = WicketdManager::new(
&log,
events_tx.clone(),
wicketd_addr,
commission_addr,
);
let (wicketd, wicketd_manager) =
WicketdManager::new(&log, events_tx.clone(), addrs);
let core = RunnerCore::new(log);
Runner {
core,
Expand Down
43 changes: 22 additions & 21 deletions wicket/src/wicketd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ use crate::keymap::ShowPopupCmd;
use crate::state::ComponentId;
use crate::{Cmd, Event};

/// The addresses of the wicketd server.
#[derive(Clone, Copy, Debug)]
pub struct WicketdAddrs {
/// The address of the lockstep wicketd API.
pub wicketd: SocketAddrV6,
/// The address of the stable commission API.
pub commission: SocketAddrV6,
}

impl From<ComponentId> for SpIdentifier {
fn from(id: ComponentId) -> Self {
match id {
Expand Down Expand Up @@ -78,27 +87,19 @@ pub struct WicketdManager {
log: Logger,
rx: mpsc::Receiver<Request>,
events_tx: UnboundedSender<Event>,
wicketd_addr: SocketAddrV6,
commission_addr: SocketAddrV6,
addrs: WicketdAddrs,
}

impl WicketdManager {
pub fn new(
log: &Logger,
events_tx: UnboundedSender<Event>,
wicketd_addr: SocketAddrV6,
commission_addr: SocketAddrV6,
addrs: WicketdAddrs,
) -> (WicketdHandle, WicketdManager) {
let log = log.new(o!("component" => "WicketdManager"));
let (tx, rx) = tokio::sync::mpsc::channel(CHANNEL_CAPACITY);
let handle = WicketdHandle { tx };
let manager = WicketdManager {
log,
rx,
events_tx,
wicketd_addr,
commission_addr,
};
let manager = WicketdManager { log, rx, events_tx, addrs };

(handle, manager)
}
Expand Down Expand Up @@ -164,7 +165,7 @@ impl WicketdManager {
options: StartUpdateOptions,
) {
let log = self.log.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
let events_tx = self.events_tx.clone();
tokio::spawn(async move {
let update_client =
Expand Down Expand Up @@ -197,7 +198,7 @@ impl WicketdManager {
options: AbortUpdateOptions,
) {
let log = self.log.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
let events_tx = self.events_tx.clone();
tokio::spawn(async move {
let update_client =
Expand Down Expand Up @@ -229,7 +230,7 @@ impl WicketdManager {
options: ClearUpdateStateOptions,
) {
let log = self.log.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
let events_tx = self.events_tx.clone();
tokio::spawn(async move {
let update_client =
Expand Down Expand Up @@ -266,7 +267,7 @@ impl WicketdManager {
poll_inventory_now: mpsc::Sender<SpIdentifier>,
) {
let log = self.log.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
tokio::spawn(async move {
let client = create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
let sp: SpIdentifier = component_id.into();
Expand All @@ -290,7 +291,7 @@ impl WicketdManager {

fn start_rack_initialization(&self) {
let log = self.log.clone();
let addr = self.commission_addr;
let addr = self.addrs.commission;
let events_tx = self.events_tx.clone();
tokio::spawn(async move {
let client = create_commission_client(&log, addr, WICKETD_TIMEOUT);
Expand All @@ -309,7 +310,7 @@ impl WicketdManager {
fn poll_rack_setup_status(&self) {
let log = self.log.clone();
let tx = self.events_tx.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
tokio::spawn(async move {
let client = create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
let mut ticker = interval(WICKETD_POLL_INTERVAL * 2);
Expand All @@ -335,7 +336,7 @@ impl WicketdManager {
fn poll_location(&self) {
let log = self.log.clone();
let tx = self.events_tx.clone();
let addr = self.commission_addr;
let addr = self.addrs.commission;
tokio::spawn(async move {
let client = create_commission_client(&log, addr, WICKETD_TIMEOUT);
let mut ticker = interval(WICKETD_POLL_INTERVAL * 2);
Expand Down Expand Up @@ -393,7 +394,7 @@ impl WicketdManager {
fn poll_rack_setup_config(&self) {
let log = self.log.clone();
let tx = self.events_tx.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
tokio::spawn(async move {
let client = create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
let mut ticker = interval(WICKETD_POLL_INTERVAL * 2);
Expand Down Expand Up @@ -426,7 +427,7 @@ impl WicketdManager {
fn poll_artifacts_and_event_reports(&self) {
let log = self.log.clone();
let tx = self.events_tx.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;
tokio::spawn(async move {
let client = create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
let mut ticker = interval(WICKETD_POLL_INTERVAL * 2);
Expand Down Expand Up @@ -455,7 +456,7 @@ impl WicketdManager {
fn poll_inventory(&self, mut poll_now: mpsc::Receiver<SpIdentifier>) {
let log = self.log.clone();
let tx = self.events_tx.clone();
let addr = self.wicketd_addr;
let addr = self.addrs.wicketd;

tokio::spawn(async move {
let client = create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
Expand Down
Loading