diff --git a/dev-tools/reconfigurator-cli/src/lib.rs b/dev-tools/reconfigurator-cli/src/lib.rs index edebf2855f4..e9bd95d67e4 100644 --- a/dev-tools/reconfigurator-cli/src/lib.rs +++ b/dev-tools/reconfigurator-cli/src/lib.rs @@ -61,7 +61,7 @@ use omicron_repl_utils::run_repl_from_file; use omicron_repl_utils::run_repl_on_stdin; use omicron_uuid_kinds::GenericUuid; use omicron_uuid_kinds::OmicronZoneUuid; -use omicron_uuid_kinds::ReconfiguratorSimUuid; +use omicron_uuid_kinds::ReconfiguratorSimStateUuid; use omicron_uuid_kinds::SledUuid; use omicron_uuid_kinds::VnicUuid; use omicron_uuid_kinds::{BlueprintUuid, MupdateOverrideUuid}; @@ -89,7 +89,7 @@ struct ReconfiguratorSim { // The simulator currently being used. sim: Simulator, // The current state. - current: ReconfiguratorSimUuid, + current: ReconfiguratorSimStateUuid, // The current system state log: slog::Logger, } @@ -1456,7 +1456,7 @@ enum StateArgs { struct StateLogArgs { /// Starting state ID (defaults to current state) #[clap(long)] - from: Option, + from: Option, /// Limit number of states to display #[clap(long, short = 'n')] @@ -2829,7 +2829,7 @@ fn cmd_state_switch( args: StateSwitchArgs, ) -> anyhow::Result> { // Try parsing as a full UUID first, then fall back to prefix matching. - let target_id = match args.state_id.parse::() { + let target_id = match args.state_id.parse::() { Ok(id) => id, Err(_) => sim.sim.get_state_by_prefix(&args.state_id)?, }; diff --git a/nexus/reconfigurator/simulation/src/errors.rs b/nexus/reconfigurator/simulation/src/errors.rs index cab7dc18ef2..e7082c731dc 100644 --- a/nexus/reconfigurator/simulation/src/errors.rs +++ b/nexus/reconfigurator/simulation/src/errors.rs @@ -7,7 +7,7 @@ use std::collections::BTreeSet; use indent_write::indentable::Indentable as _; use itertools::Itertools; use omicron_common::api::external::{Generation, Name}; -use omicron_uuid_kinds::ReconfiguratorSimUuid; +use omicron_uuid_kinds::ReconfiguratorSimStateUuid; use swrite::{SWrite, swriteln}; use thiserror::Error; @@ -170,7 +170,7 @@ impl UnknownZoneNamesError { #[derive(Clone, Debug)] pub struct StateMatch { /// The state ID. - pub id: ReconfiguratorSimUuid, + pub id: ReconfiguratorSimStateUuid, /// The state generation. pub generation: Generation, /// The state description. diff --git a/nexus/reconfigurator/simulation/src/render_graph.rs b/nexus/reconfigurator/simulation/src/render_graph.rs index 2ef603fc24b..258b1fc7152 100644 --- a/nexus/reconfigurator/simulation/src/render_graph.rs +++ b/nexus/reconfigurator/simulation/src/render_graph.rs @@ -6,7 +6,7 @@ use std::collections::{HashMap, HashSet}; -use omicron_uuid_kinds::ReconfiguratorSimUuid; +use omicron_uuid_kinds::ReconfiguratorSimStateUuid; use renderdag::{Ancestor, GraphRowRenderer, Renderer}; use swrite::{SWrite, swrite, swriteln}; @@ -17,13 +17,13 @@ use crate::{SimState, Simulator, utils::DisplayUuidPrefix}; pub struct GraphRenderOptions { verbose: bool, limit: Option, - from: Option, - current: ReconfiguratorSimUuid, + from: Option, + current: ReconfiguratorSimStateUuid, } impl GraphRenderOptions { /// Create new render options with the current state. - pub fn new(current: ReconfiguratorSimUuid) -> Self { + pub fn new(current: ReconfiguratorSimStateUuid) -> Self { Self { verbose: false, limit: None, from: None, current } } @@ -40,7 +40,10 @@ impl GraphRenderOptions { } /// Set the starting state for ancestry filtering. - pub fn with_from(mut self, from: Option) -> Self { + pub fn with_from( + mut self, + from: Option, + ) -> Self { self.from = from; self } @@ -59,7 +62,7 @@ impl Simulator { &self, options: &GraphRenderOptions, ) -> Vec<&SimState> { - let mut remaining_heads: Vec = + let mut remaining_heads: Vec = if let Some(from_id) = options.from { vec![from_id] } else { @@ -106,10 +109,10 @@ impl Simulator { /// Recursively walk a branch, processing merge points along the way. fn walk_branch_recursive<'a>( &'a self, - mut current_id: ReconfiguratorSimUuid, + mut current_id: ReconfiguratorSimStateUuid, node_to_heads: &HashMap< - ReconfiguratorSimUuid, - Vec, + ReconfiguratorSimStateUuid, + Vec, >, walk_state: &mut WalkState<'a>, ) { @@ -151,12 +154,12 @@ impl Simulator { /// State accumulated during graph traversal. struct WalkState<'a> { states: Vec<&'a SimState>, - visited: HashSet, - remaining_heads: Vec, + visited: HashSet, + remaining_heads: Vec, } impl<'a> WalkState<'a> { - fn new(heads: Vec) -> Self { + fn new(heads: Vec) -> Self { Self { states: Vec::new(), visited: HashSet::new(), diff --git a/nexus/reconfigurator/simulation/src/sim.rs b/nexus/reconfigurator/simulation/src/sim.rs index 5ee39ac1c4d..c026cd04658 100644 --- a/nexus/reconfigurator/simulation/src/sim.rs +++ b/nexus/reconfigurator/simulation/src/sim.rs @@ -8,7 +8,9 @@ use std::{collections::HashMap, sync::Arc}; use indexmap::IndexSet; -use omicron_uuid_kinds::{ReconfiguratorSimKind, ReconfiguratorSimUuid}; +use omicron_uuid_kinds::{ + ReconfiguratorSimStateKind, ReconfiguratorSimStateUuid, +}; use typed_rng::TypedUuidRng; use crate::{ @@ -48,8 +50,8 @@ pub struct Simulator { // In the future, it would be interesting to store a chain of every set of // heads over time, similar to `jj op log`. That would let us implement undo // and restore operations. - heads: IndexSet, - states: HashMap>, + heads: IndexSet, + states: HashMap>, // This state corresponds to `ROOT_ID`. // // Storing it in the Arc is extremely important! `SimStateBuilder` stores a @@ -59,7 +61,7 @@ pub struct Simulator { // points to the same memory address. root_state: Arc, // Top-level (unversioned) RNG. - sim_uuid_rng: TypedUuidRng, + sim_uuid_rng: TypedUuidRng, } impl Simulator { @@ -67,7 +69,8 @@ impl Simulator { /// /// This is always defined to be the nil UUID, and if queried will always /// have a state associated with it. - pub const ROOT_ID: ReconfiguratorSimUuid = ReconfiguratorSimUuid::nil(); + pub const ROOT_ID: ReconfiguratorSimStateUuid = + ReconfiguratorSimStateUuid::nil(); /// Create a new simulator with the given initial seed. pub fn new(log: &slog::Logger, seed: Option) -> Self { @@ -77,6 +80,8 @@ impl Simulator { fn new_inner(log: &slog::Logger, seed: String) -> Self { let log = log.new(slog::o!("component" => "SimStore")); + // The ReconfiguratorSimStateUuid type used to be ReconfiguratorSimUuid. + // Retain the old name in the seed for generated ID compatibility. let sim_uuid_rng = TypedUuidRng::from_seed(&seed, "ReconfiguratorSimUuid"); let root_state = SimState::new_root(seed); @@ -99,12 +104,15 @@ impl Simulator { /// Get the current heads of the store. #[inline] - pub fn heads(&self) -> &IndexSet { + pub fn heads(&self) -> &IndexSet { &self.heads } /// Get the state for the given UUID. - pub fn get_state(&self, id: ReconfiguratorSimUuid) -> Option<&SimState> { + pub fn get_state( + &self, + id: ReconfiguratorSimStateUuid, + ) -> Option<&SimState> { if id == Self::ROOT_ID { return Some(&self.root_state); } @@ -126,7 +134,7 @@ impl Simulator { pub fn get_state_by_prefix( &self, prefix: &str, - ) -> Result { + ) -> Result { let mut matching_ids = Vec::new(); if Self::ROOT_ID.to_string().starts_with(prefix) { @@ -170,7 +178,7 @@ impl Simulator { } #[inline] - pub(crate) fn next_sim_uuid(&mut self) -> ReconfiguratorSimUuid { + pub(crate) fn next_sim_uuid(&mut self) -> ReconfiguratorSimStateUuid { self.sim_uuid_rng.next() } diff --git a/nexus/reconfigurator/simulation/src/state.rs b/nexus/reconfigurator/simulation/src/state.rs index d469849512d..1b3fae36ce1 100644 --- a/nexus/reconfigurator/simulation/src/state.rs +++ b/nexus/reconfigurator/simulation/src/state.rs @@ -8,7 +8,7 @@ use anyhow::{Context, anyhow, bail}; use nexus_inventory::CollectionBuilder; use nexus_types::deployment::UnstableReconfiguratorState; use omicron_common::api::external::Generation; -use omicron_uuid_kinds::{CollectionUuid, ReconfiguratorSimUuid}; +use omicron_uuid_kinds::{CollectionUuid, ReconfiguratorSimStateUuid}; use sync_ptr::SyncConstPtr; use crate::{ @@ -31,9 +31,9 @@ pub struct SimState { // is stored behind an `Arc`. This means that the address stays stable even // if the `Simulator` struct is cloned or moved in memory. root_state: SyncConstPtr, - id: ReconfiguratorSimUuid, + id: ReconfiguratorSimStateUuid, // The parent state that this state was derived from. - parent: Option, + parent: Option, // The state's generation, starting from 0. // // TODO: Should this be its own type to avoid confusion with other @@ -79,13 +79,13 @@ impl SimState { #[inline] #[must_use] - pub fn id(&self) -> ReconfiguratorSimUuid { + pub fn id(&self) -> ReconfiguratorSimStateUuid { self.id } #[inline] #[must_use] - pub fn parent(&self) -> Option { + pub fn parent(&self) -> Option { self.parent } @@ -185,7 +185,7 @@ pub struct SimStateBuilder { // Used to check that the simulator is the same as the one that created // this state. root_state: SyncConstPtr, - parent: ReconfiguratorSimUuid, + parent: ReconfiguratorSimStateUuid, parent_gen: Generation, system: SimSystemBuilder, config: SimConfigBuilder, @@ -195,7 +195,7 @@ pub struct SimStateBuilder { impl SimStateBuilder { #[inline] #[must_use] - pub fn parent(&self) -> ReconfiguratorSimUuid { + pub fn parent(&self) -> ReconfiguratorSimStateUuid { self.parent } @@ -271,7 +271,7 @@ impl SimStateBuilder { self, description: String, sim: &mut Simulator, - ) -> ReconfiguratorSimUuid { + ) -> ReconfiguratorSimStateUuid { // Check for unrelated histories. if !std::ptr::eq(sim.root_state(), self.root_state.inner()) { panic!( diff --git a/uuid-kinds/src/lib.rs b/uuid-kinds/src/lib.rs index 354c6771494..295fbfc6805 100644 --- a/uuid-kinds/src/lib.rs +++ b/uuid-kinds/src/lib.rs @@ -70,7 +70,7 @@ impl_typed_uuid_kinds! { Rack = {}, RackInit = {}, RackReset = {}, - ReconfiguratorSim = {}, + ReconfiguratorSimState = {}, Region = {}, SiloGroup = {}, SiloUser = {},