diff --git a/CHANGELOG.md b/CHANGELOG.md index 711d3171..8be1f088 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,12 @@ and listed with their assets on the or off, and a mute per stack or lane, behind the bell in the dashboard's top bar or with `devstack hub notify [on|off …|test]`; `DEVSTACK_NO_NOTIFY` switches them off. +- **Lanes of other members on this machine are shown**: a banner below the + dashboard's top bar (hidden until a lane comes or goes), a tile in the + sidebar, and *On this machine* in the pool area (whose, repository, + since when, what it reserved); a lane that starts running here notifies + (`guest_lane`, on by default). The hub reads them from the pool's leases + every 15 s and sends them on `/hub/events` (`guests`). - A `devstack://open?stack=…&lane=…&service=…` link opens the dashboard there, paired; `/auth` takes `next`, a dashboard route, and keeps the session of a browser that is paired already. diff --git a/crates/devstack-hub/src/guests.rs b/crates/devstack-hub/src/guests.rs new file mode 100644 index 00000000..02963aae --- /dev/null +++ b/crates/devstack-hub/src/guests.rs @@ -0,0 +1,212 @@ +//! Lanes of other members that run on this machine ("guest lanes"): whoever +//! sits at a machine that runs the pool's lanes sees, without asking, that +//! someone else's code runs on it. The coordinator lists every lease of the +//! pool to every member; those whose node is this machine and whose owner is +//! someone else are the guests. The share loop (`share.rs`) asks after each +//! report, every 15 s per pool. The dashboard hears them on `/hub/events` +//! (`guests`), and a guest lane that starts notifies (ADR-0045, +//! `guest_lane`). + +use devstack_node::coordinator::{Lease, NodeView}; +use serde::Serialize; +use std::collections::{BTreeMap, HashSet}; +use std::sync::{Mutex, OnceLock}; +use tokio::sync::watch; + +#[derive(Debug, Clone, PartialEq, Serialize)] +pub struct Guest { + pub pool: String, + pub lease: String, + /// The member whose lane it is, and how the pool names them. + pub member: String, + pub owner: String, + pub repo: String, + pub lane: String, + /// `offered` (admitted by the coordinator, not started yet) or `running`. + pub state: String, + /// Unix seconds. + pub since: u64, + /// What it asked for. + pub cpus: f64, + pub memory: u64, +} + +type Started = Box; + +struct Guests { + tx: watch::Sender>, + /// Per pool, as last read; a pool that could not be asked keeps its last. + by_pool: Mutex>>, + /// Per pool, the running leases already told (or there when the hub + /// first read the pool). + told: Mutex>>, + started: OnceLock, +} + +static GUESTS: OnceLock = OnceLock::new(); + +fn guests() -> &'static Guests { + GUESTS.get_or_init(|| Guests { + tx: watch::channel(Vec::new()).0, + by_pool: Mutex::new(BTreeMap::new()), + told: Mutex::new(BTreeMap::new()), + started: OnceLock::new(), + }) +} + +/// The guest lanes now, and each change. +pub fn subscribe() -> watch::Receiver> { + guests().tx.subscribe() +} + +/// What to do when a guest lane starts running here (the hub's notification). +pub fn on_started(f: impl Fn(&Guest) + Send + Sync + 'static) { + let _ = guests().started.set(Box::new(f)); +} + +/// The guests in `leases` of `pool`, for the member `me`; owners named from +/// `nodes` (every member reports, so every member is listed there). +pub fn of(pool: &str, me: &str, leases: &[Lease], nodes: &[NodeView]) -> Vec { + leases + .iter() + .filter(|l| l.node == me && l.member != me) + .map(|l| Guest { + pool: pool.to_string(), + lease: l.id.clone(), + member: l.member.clone(), + owner: nodes + .iter() + .find(|n| n.id == l.member) + .map_or_else(|| l.member.clone(), |n| n.name.clone()), + repo: l.repo.clone(), + lane: l.lane.clone(), + state: l.state.clone(), + since: l.created, + cpus: l.need.cpus, + memory: l.need.memory, + }) + .collect() +} + +/// The guests of `pool` as just read (`None`: it could not be asked, the +/// last list stands). A pool's first reading is its baseline: guest lanes +/// running then are not told. +pub fn seen(pool: &str, now: Option>) { + let g = guests(); + let Some(list) = now else { return }; + let running: Vec<&Guest> = list.iter().filter(|x| x.state == "running").collect(); + let fresh: Vec = { + let mut told = g.told.lock().unwrap(); + match told.get_mut(pool) { + None => { + let set = running.iter().map(|x| x.lease.clone()).collect(); + told.insert(pool.to_string(), set); + Vec::new() + } + Some(set) => { + // Forget leases that are gone, so the set never only grows. + set.retain(|l| list.iter().any(|x| &x.lease == l)); + running + .iter() + .filter(|x| set.insert(x.lease.clone())) + .map(|x| (*x).clone()) + .collect() + } + } + }; + let all: Vec = { + let mut by_pool = g.by_pool.lock().unwrap(); + by_pool.insert(pool.to_string(), list); + by_pool.values().flatten().cloned().collect() + }; + g.tx.send_if_modified(|cur| { + if *cur == all { + false + } else { + *cur = all; + true + } + }); + if let Some(f) = g.started.get() { + for x in &fresh { + f(x); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn lease(id: &str, node: &str, member: &str, state: &str) -> Lease { + serde_json::from_value(serde_json::json!({ + "id": id, "node": node, "member": member, "repo": "shop", "lane": "feat-cart", + "need": { "cpus": 2.0, "memory": 4_000_000_000u64 }, "state": state, "created": 1_700_000_000u64, + })) + .unwrap() + } + + fn node(id: &str, name: &str) -> NodeView { + serde_json::from_value(serde_json::json!({ "id": id, "name": name, "online": true })) + .unwrap() + } + + #[test] + fn guests_are_others_lanes_on_this_machine() { + let leases = [ + lease("l1", "me", "anna", "running"), + lease("l2", "me", "me", "running"), // my own lane here + lease("l3", "server", "anna", "running"), // anna's lane elsewhere + lease("l4", "me", "ghost", "offered"), + ]; + let g = of("default", "me", &leases, &[node("anna", "ANNA-LAPTOP")]); + assert_eq!(g.len(), 2); + assert_eq!( + (g[0].lease.as_str(), g[0].owner.as_str()), + ("l1", "ANNA-LAPTOP") + ); + // An owner the node list does not name is shown by id. + assert_eq!( + (g[1].owner.as_str(), g[1].state.as_str()), + ("ghost", "offered") + ); + assert_eq!((g[0].cpus, g[0].memory), (2.0, 4_000_000_000)); + } + + #[test] + fn a_guest_lane_that_starts_is_told_once_and_a_pools_first_reading_is_none() { + static TOLD: Mutex> = Mutex::new(Vec::new()); + on_started(|g| TOLD.lock().unwrap().push(g.lease.clone())); + let rx = subscribe(); + let read = |pool: &str, leases: &[Lease]| seen(pool, Some(of(pool, "me", leases, &[]))); + // What runs when the hub first reads a pool is the baseline. + read("t-a", &[lease("a1", "me", "anna", "running")]); + read("t-b", &[lease("b1", "me", "ben", "running")]); + assert!(TOLD.lock().unwrap().is_empty()); + // Offered, then running: told when it runs, once. + read( + "t-a", + &[ + lease("a1", "me", "anna", "running"), + lease("a2", "me", "anna", "offered"), + ], + ); + read( + "t-a", + &[ + lease("a1", "me", "anna", "running"), + lease("a2", "me", "anna", "running"), + ], + ); + read("t-a", &[lease("a2", "me", "anna", "running")]); + // A pool that could not be asked keeps its guests. + seen("t-b", None); + assert_eq!(*TOLD.lock().unwrap(), ["a2"]); + let now: Vec = rx.borrow().iter().map(|g| g.lease.clone()).collect(); + assert!( + now.contains(&"a2".to_string()) && now.contains(&"b1".to_string()), + "{now:?}" + ); + assert!(!now.contains(&"a1".to_string()), "{now:?}"); + } +} diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 978c88c9..4143c930 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -34,6 +34,7 @@ use tokio_stream::StreamExt; static UI: Dir<'_> = include_dir!("$OUT_DIR/ui"); mod dialog; +mod guests; mod notify; mod pool; pub mod release; @@ -372,6 +373,12 @@ pub fn serve() -> Result<(), String> { Arc::new(move |t: ¬ify::Target| open_dashboard(port, &codes, &t.path())) }; let notify = Arc::new(notify::Center::new(&dir, notify::platform_sink(port, open))); + { + let notify = notify.clone(); + guests::on_started(move |g| { + notify.guest_started(g); + }); + } let state = AppState { port, token: Arc::new(token), @@ -1321,7 +1328,13 @@ fn hub_events(s: &AppState) -> impl tokio_stream::Stream Option { diff --git a/crates/devstack-hub/src/notify/mod.rs b/crates/devstack-hub/src/notify/mod.rs index d008e27e..953dedce 100644 --- a/crates/devstack-hub/src/notify/mod.rs +++ b/crates/devstack-hub/src/notify/mod.rs @@ -53,12 +53,17 @@ pub(crate) struct Target { pub stack: Option, pub lane: Option, pub service: Option, + /// The pool area instead (guest lanes). + pub pool: bool, } impl Target { /// The dashboard's route for it (hash history). `lane=` (empty) shows /// the main working tree, whichever lane was shown last. pub fn path(&self) -> String { + if self.pool { + return "/#/pool".into(); + } let Some(stack) = &self.stack else { return "/#/".into(); }; @@ -76,6 +81,9 @@ impl Target { /// The `devstack://open` link that opens it (`devstack open-url`). #[cfg_attr(not(windows), allow(dead_code))] pub fn link(&self) -> String { + if self.pool { + return "devstack://open?page=pool".into(); + } let mut q = Vec::new(); for (k, v) in [ ("stack", &self.stack), @@ -258,6 +266,39 @@ impl Center { stack: Some(stack.to_string()), lane: lane.map(str::to_string), service: n.service, + pool: false, + }, + tag: blake3::hash(key.as_bytes()).to_hex()[..16].to_string(), + }); + true + } + + /// A lane of another member started running on this machine + /// (`guests.rs`). Once per lease; whether it was told. + pub fn guest_started(&self, g: &crate::guests::Guest) -> bool { + if !self.settings.lock().unwrap().on(Kind::GuestLane) { + return false; + } + let key = format!("guest/{}/{}", g.pool, g.lease); + diag::info( + "notice", + serde_json::json!({ + "kind": Kind::GuestLane.key(), "pool": g.pool, "owner": g.owner, + "repo": g.repo, "lane": g.lane, "shown": self.sink.status().is_ok(), + }), + ); + let pool = if g.pool == devstack_node::member::DEFAULT_POOL { + String::new() + } else { + format!(" · pool {}", g.pool) + }; + self.sink.show(Shown { + title: format!("{}'s lane {} runs on this machine", g.owner, g.lane), + context: format!("{}{pool}", g.repo), + body: "The pool area shows it; pausing the node there takes no new lanes.".into(), + target: Target { + pool: true, + ..Target::default() }, tag: blake3::hash(key.as_bytes()).to_hex()[..16].to_string(), }); @@ -582,6 +623,7 @@ mod tests { stack: Some("ab12".into()), lane: Some("feat-x".into()), service: Some("api".into()), + pool: false, } ); } @@ -668,6 +710,7 @@ mod tests { stack: Some("ab12".into()), lane: Some("feat x".into()), service: Some("api".into()), + pool: false, }; assert_eq!(t.path(), "/#/s/ab12/services/api?lane=feat%20x"); assert_eq!( @@ -682,5 +725,13 @@ mod tests { assert_eq!(main.link(), "devstack://open?stack=ab12"); assert_eq!(Target::default().path(), "/#/"); assert_eq!(Target::default().link(), "devstack://open"); + let pool = Target { + pool: true, + ..Target::default() + }; + assert_eq!( + (pool.path().as_str(), pool.link().as_str()), + ("/#/pool", "devstack://open?page=pool") + ); } } diff --git a/crates/devstack-hub/src/notify/rules.rs b/crates/devstack-hub/src/notify/rules.rs index 9ca043e7..cdeb06cf 100644 --- a/crates/devstack-hub/src/notify/rules.rs +++ b/crates/devstack-hub/src/notify/rules.rs @@ -18,16 +18,18 @@ pub enum Kind { LaneFailed, MainPorts, Live, + GuestLane, } impl Kind { - pub const ALL: [Kind; 6] = [ + pub const ALL: [Kind; 7] = [ Kind::BuildFailed, Kind::Held, Kind::ServiceFailed, Kind::LaneFailed, Kind::MainPorts, Kind::Live, + Kind::GuestLane, ]; pub fn key(self) -> &'static str { @@ -38,6 +40,7 @@ impl Kind { Kind::LaneFailed => "lane_failed", Kind::MainPorts => "main_ports", Kind::Live => "live", + Kind::GuestLane => "guest_lane", } } @@ -53,6 +56,7 @@ impl Kind { Kind::LaneFailed => "A lane's start or move on a node failed", Kind::MainPorts => "A lane took or gave back the main ports", Kind::Live => "A candidate went live", + Kind::GuestLane => "A lane of another member started on this machine", } } diff --git a/crates/devstack-hub/src/share.rs b/crates/devstack-hub/src/share.rs index 617819b0..2002d38f 100644 --- a/crates/devstack-hub/src/share.rs +++ b/crates/devstack-hub/src/share.rs @@ -161,10 +161,30 @@ fn run(poked: &mpsc::Receiver<()>) { } Err(e) => st.error = Some(e), } + drop(map); + crate::guests::seen(&pool, guests(&pool)); } } } +/// Other members' lanes on this machine in `pool`; `None` when the +/// coordinator could not be asked. The member list is read only when a +/// lease names this machine. +fn guests(pool: &str) -> Option> { + let local = devstack_node::member::Local::new(&dir(pool)); + let m = match local.membership() { + Ok(Some(m)) if m.state == State::Approved => m, + Ok(_) => return Some(Vec::new()), + Err(_) => return None, + }; + let leases = local.leases().ok()?; + if !leases.iter().any(|l| l.node == m.id && l.member != m.id) { + return Some(Vec::new()); + } + let nodes = local.nodes().ok()?; + Some(crate::guests::of(pool, &m.id, &leases, &nodes)) +} + /// Report to the coordinator: what it says it runs; `Ok(None)` when this /// machine is no approved member (nothing to report to). fn report( diff --git a/crates/devstack/src/integration.rs b/crates/devstack/src/integration.rs index 789c369e..f9eccfff 100644 --- a/crates/devstack/src/integration.rs +++ b/crates/devstack/src/integration.rs @@ -136,7 +136,7 @@ pub fn open_url(url: &str) -> Result<()> { /// value must be a name (a stack's id, a lane's, a service's), so nothing /// else can be smuggled into the route. fn dashboard_route(query: &str) -> Result { - let (mut stack, mut lane, mut service) = (None, None, None); + let (mut stack, mut lane, mut service, mut page) = (None, None, None, None); for pair in query.split('&').filter(|p| !p.is_empty()) { let (k, v) = pair.split_once('=').unwrap_or((pair, "")); let v = percent_decode(v).ok_or_else(|| anyhow!("bad value in devstack link"))?; @@ -151,9 +151,16 @@ fn dashboard_route(query: &str) -> Result { "stack" => stack = Some(v), "lane" => lane = Some(v), "service" => service = Some(v), + "page" => page = Some(v), _ => return Err(anyhow!("unknown `{k}` in devstack link")), } } + match page.as_deref() { + None => {} + // Guest lanes on this machine (a notification's). + Some("pool") if stack.is_none() => return Ok("/#/pool".into()), + Some(p) => return Err(anyhow!("unknown page `{p}` in devstack link")), + } let Some(stack) = stack else { return Ok("/#/".into()); }; @@ -442,6 +449,8 @@ mod tests { ); assert_eq!(dashboard_route("stack=ab12").unwrap(), "/#/s/ab12?lane="); assert_eq!(dashboard_route("").unwrap(), "/#/"); + assert_eq!(dashboard_route("page=pool").unwrap(), "/#/pool"); + assert!(dashboard_route("page=settings").is_err()); for bad in [ "stack=shop", "stack=ab12&lane=..%2F..", diff --git a/docs/adr/0045-the-hub-notifies-the-desktop.md b/docs/adr/0045-the-hub-notifies-the-desktop.md index 3a073d4b..f3569341 100644 --- a/docs/adr/0045-the-hub-notifies-the-desktop.md +++ b/docs/adr/0045-the-hub-notifies-the-desktop.md @@ -1,6 +1,6 @@ # ADR-0045: The hub notifies the desktop of what needs attention, without a tray -- **Status:** Accepted (2026-10-21) +- **Status:** Accepted (2026-10-21), amended 2026-10-21 (`guest_lane`) - **Date:** 2026-10-21 - **Deciders:** project owner - **Related:** [#156](https://github.com/nuetzliches/devstack/issues/156), [#1](https://github.com/nuetzliches/devstack/issues/1) (the tray), [ADR-0018](0018-dashboard-is-a-browser-page.md) (point 2 amended here), [ADR-0019](0019-control-api-security.md), [ADR-0021](0021-a-hub-serves-the-dashboard.md), [ADR-0024](0024-a-lane-is-a-supervisor-in-the-main-trees-daemon.md), [ADR-0025](0025-a-lane-can-run-on-another-node.md) @@ -129,3 +129,9 @@ before that Windows answers "not found". node going offline): the kinds above are about one's own stacks. - That a notification carries anything to act on (promote, restart): a click opens the dashboard, where the action is. + +*Amended 2026-10-21.* A seventh kind, `guest_lane`, on by default: a lane of +another member started running on this machine (#167). The hub reads the +pool's leases after each report to the coordinator; a pool's first reading +is the baseline, and a lease is told once, when it runs. A click opens the +pool area (`devstack://open?page=pool`). diff --git a/docs/adr/README.md b/docs/adr/README.md index f453a645..7174724c 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -93,4 +93,4 @@ stay. | [0042](0042-a-dev-servers-rebuilds-show-like-builds.md) | A dev server's rebuilds show like builds, read from its output | Accepted | | [0043](0043-a-dev-servers-fixed-port-is-devstacks.md) | A dev server's fixed port is devstack's, forwarded to its instance | Accepted | | [0044](0044-a-lanes-prepared-directories-can-be-linked-into-its-worktree.md) | A lane's prepared directories can be linked into its worktree | Accepted | -| [0045](0045-the-hub-notifies-the-desktop.md) | The hub notifies the desktop of what needs attention, without a tray | Accepted | +| [0045](0045-the-hub-notifies-the-desktop.md) | The hub notifies the desktop of what needs attention, without a tray | Accepted, amended 2026-10-21 (`guest_lane`) | diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index 3d7f1088..ace4c467 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -49,7 +49,7 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | `GET /hub/session` | cookie | `200 {"version": ""}`, or `401` (not paired: show "run `devstack ui`") | | `GET /hub/stacks` | cookie | `[StackEntry]` | | `GET /hub/ws?path=` | cookie + Origin | WebSocket that carries the server-sent event stream at `` (`/hub/events`, `/hub/stacks/{id}/api/v1/...`, or `/hub/pool/shared/{lease}/api/v1/...[?pool=]` for a lane shared with this machine), one text message per event's `data`; how the dashboard reads every stream (a browser allows six HTTP/1.1 connections per host across all its tabs, WebSockets do not count; ADR-0021). The upstream is opened before the upgrade: `503` for a stack not running, `400` for another path. When the stream ends the socket closes | -| `GET /hub/events` | cookie | SSE: `{"type":"stacks","stacks":[StackEntry]}` and `{"type":"docker","docker":DockerEngine}` and `{"type":"release","current","newer":string|null}` (a newer devstack; checked at start, every 12 h by the clock and when a dashboard connects and the last answer is over an hour old, unless `DEVSTACK_NO_UPDATE_CHECK`) and `{"type":"update","update":{"running":bool,"error":string|null,"installed":string|null,"finished":ms|null}}` (the dashboard's update; `finished` is when the last one ended, `installed` the version it installed, told by the hub it started), each first and on every change | +| `GET /hub/events` | cookie | SSE: `{"type":"stacks","stacks":[StackEntry]}` and `{"type":"docker","docker":DockerEngine}` and `{"type":"release","current","newer":string|null}` (a newer devstack; checked at start, every 12 h by the clock and when a dashboard connects and the last answer is over an hour old, unless `DEVSTACK_NO_UPDATE_CHECK`) and `{"type":"update","update":{"running":bool,"error":string|null,"installed":string|null,"finished":ms|null}}` (the dashboard's update; `finished` is when the last one ended, `installed` the version it installed, told by the hub it started) and `{"type":"guests","guests":[Guest]}` (lanes of other members on this machine, every pool: `{pool, lease, member, owner, repo, lane, state: "offered"\|"running", since: unix s, cpus, memory}`, the leases whose node is this machine; read after each share report, every 15 s per pool), each first and on every change | | `POST /hub/update` | cookie + Origin | `202`: `devstack update` in the background (output in `hub/update.log`); on success it restarts the hub on the new version, so the dashboard reconnects to it, and the new hub's `update` event names the installed version (the old hub leaves `hub/update.json` for it; a hub that starts on the old version while the updater runs waits for it and reports a failure); on failure the `update` event carries the end of its output. `409` while one runs (checked and claimed in one step). Running stacks switch at their next restart | | `POST /hub/update/check` | cookie + Origin | look for a newer release now: `{"current", "newer": string\|null}`, the same as the next `release` event; asked again within 30 s, the last answer (GitHub allows 60 unauthenticated requests an hour). `409` with `DEVSTACK_NO_UPDATE_CHECK`, `502` when GitHub cannot be asked, `504` after 30 s | | `POST /hub/stacks/scan` | cookie + Origin | `{"path", "add"?, "depth"?}`: every repository with a `devstack.toml` below a folder (default three levels, `depth` is clamped to 1 to 6; a repository only at its root, linked worktrees skipped), `[{repo, id, name, error, registered, added}]`; with `add` the valid new ones are registered | diff --git a/docs/pool.md b/docs/pool.md index bd45f377..45f96956 100644 --- a/docs/pool.md +++ b/docs/pool.md @@ -68,6 +68,14 @@ A member that only asks for lanes needs nothing else. The **share switch** (sidebar, pool area) lets the pool run other members' lanes on your machine: half of what is free, never more than the caps you set; off by default. +Lanes of other members on your machine always show: a banner below the +dashboard's top bar (it can be hidden until a lane comes or goes), a tile in +the sidebar, and **On this machine** in the pool area, with whose lane +it is, its repository, since when and what it reserved. A lane that starts +running here also notifies the desktop (`guest_lane`, +[ADR-0045](adr/0045-the-hub-notifies-the-desktop.md)). The hub reads them from +the pool's leases after each share report. + ## Run a node A machine that runs lanes for others, typically a server, runs the node diff --git a/ui/src/App.vue b/ui/src/App.vue index a46aebd4..10bf6732 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -8,6 +8,7 @@ import GlobalDialogs from '@/components/GlobalDialogs.vue'; import CommandPalette from '@/components/CommandPalette.vue'; import Icon from '@/components/icons/Icon.vue'; import Sidebar from '@/components/Sidebar.vue'; +import GuestBanner from '@/components/GuestBanner.vue'; import UnpairedView from '@/views/UnpairedView.vue'; const hub = useHub(); @@ -64,6 +65,7 @@ async function startHub() { +
diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index fb2f9e30..1c89297d 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -8,7 +8,7 @@ // ?mock=nodocker the Docker engine is stopped; "Start Docker" brings it up after 4 s // ?mock=nopool this machine is in no pool; ?mock=poolmember: a member, not an admin // ?mock=hubdown the hub is unreachable (toggle at runtime: window.devstackMock.hubDown(false)) -import type { DockerEngine, HubEvent, NotifySettings, ShareSettings, LogStreamEvent, RunLogEvent, StackEvent, StackEntry } from '../types'; +import type { DockerEngine, Guest, HubEvent, NotifySettings, ShareSettings, LogStreamEvent, RunLogEvent, StackEvent, StackEntry } from '../types'; import type { Response, StreamHandlers, Subscription, Transport } from '../transport'; import { Unreachable } from '../transport'; import { persist } from '@/lib/persist'; @@ -53,6 +53,11 @@ function startMove(to: string, t0: number) { class MockHub { stacks: MockStack[] = []; hubSubs = new Set>(); + /** A lane of laptop-anna's runs here, a second one is admitted. */ + guests: Guest[] = [ + { pool: 'default', lease: 'l-7f3a', member: '1122334455667788', owner: 'laptop-anna', repo: 'shop', lane: 'feat-cart', state: 'running', since: Math.floor(Date.now() / 1000) - 2400, cpus: 2, memory: 4 * 2 ** 30 }, + { pool: 'default', lease: 'l-91c2', member: '1122334455667788', owner: 'laptop-anna', repo: 'crm', lane: 'agent-1242', state: 'offered', since: Math.floor(Date.now() / 1000) - 20, cpus: 1.5, memory: 3 * 2 ** 30 }, + ]; hubDown = false; unpaired = false; empty = false; @@ -217,6 +222,7 @@ const notify: NotifySettings = { { kind: 'lane_failed', label: "A lane's start or move on a node failed", on: true, default: true }, { kind: 'main_ports', label: 'A lane took or gave back the main ports', on: false, default: false }, { kind: 'live', label: 'A candidate went live', on: false, default: false }, + { kind: 'guest_lane', label: 'A lane of another member started on this machine', on: true, default: true }, ], muted: [], }; @@ -741,6 +747,7 @@ export class MockTransport implements Transport { l.send({ type: 'stacks', stacks: hub.entries() }); l.send({ type: 'docker', docker: hub.docker }); l.send({ type: 'release', current: '0.4.0', newer: hub.newer }); + l.send({ type: 'guests', guests: hub.guests }); hub.hubSubs.add(l); return { stop: () => hub.hubSubs.delete(l) }; } diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index 043611fc..466bbdbe 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -31,7 +31,27 @@ export type HubEvent = /** A newer release than the hub (`newer`), or none. */ | { type: 'release'; current: string; newer: string | null } /** The dashboard's update (`POST /hub/update`): running, or how the last one ended. Older hubs never send it. */ - | { type: 'update'; update: UpdateState }; + | { type: 'update'; update: UpdateState } + /** Lanes of other members that run on this machine, every pool; older hubs never send it. */ + | { type: 'guests'; guests: Guest[] }; + +/** A lane of another member on this machine (a lease whose node is this machine). */ +export type Guest = { + pool: string; + lease: string; + member: string; + /** How the pool names the member. */ + owner: string; + repo: string; + lane: string; + /** `offered`: admitted, not started yet. */ + state: 'offered' | 'running' | (string & {}); + /** Unix seconds. */ + since: number; + /** What it asked for. */ + cpus: number; + memory: number; +}; /** * The dashboard's update. A successful one stops the hub that started it; the diff --git a/ui/src/components/GuestBanner.vue b/ui/src/components/GuestBanner.vue new file mode 100644 index 00000000..4fdfcbe7 --- /dev/null +++ b/ui/src/components/GuestBanner.vue @@ -0,0 +1,73 @@ + + + + + diff --git a/ui/src/components/GuestTile.vue b/ui/src/components/GuestTile.vue new file mode 100644 index 00000000..69b8a8ff --- /dev/null +++ b/ui/src/components/GuestTile.vue @@ -0,0 +1,50 @@ + + + + + diff --git a/ui/src/components/Sidebar.vue b/ui/src/components/Sidebar.vue index 32e7319d..dca499bd 100644 --- a/ui/src/components/Sidebar.vue +++ b/ui/src/components/Sidebar.vue @@ -21,6 +21,7 @@ import { useStack } from '@/stores/stack'; import { useUi } from '@/stores/ui'; import AddStackDialog from './AddStackDialog.vue'; import ShareSwitch from './ShareSwitch.vue'; +import GuestTile from './GuestTile.vue'; import Icon from './icons/Icon.vue'; const hub = useHub(); @@ -353,6 +354,7 @@ async function copyPath(s: StackEntry) {
+
+
+
+ +

On this machine

+ {{ guests.length === 1 ? '1 lane of another member' : `${guests.length} lanes of other members` }} · {{ guestsReserved(guests) }} reserved +
+ + + + + + + + + + + + + + + + + + + + + + + +
LaneRepositoryOfPoolStateSinceReserved
{{ g.lane }}{{ g.repo }}{{ g.owner }}{{ g.pool }} + {{ g.state === 'running' ? 'running' : 'starting' }} + {{ ago(g.since * 1000, now) }}{{ g.cpus }} CPU · {{ bytes(g.memory) }}
+

+ They run in containers of this machine's Docker, as this node's policy allows. An admin's Pause on this node in the list below takes + no new lanes; those running stay until their owners stop them. +

+
+
@@ -743,6 +785,13 @@ function policyText(id: string) {