Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nexus] move inventory collection IDs to TypedUuid #5517

Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions clients/nexus-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ progenitor::generate_api!(
NewPasswordHash = omicron_passwords::NewPasswordHash,
NetworkInterface = omicron_common::api::internal::shared::NetworkInterface,
NetworkInterfaceKind = omicron_common::api::internal::shared::NetworkInterfaceKind,
TypedUuidForCollectionKind = omicron_uuid_kinds::CollectionUuid,
TypedUuidForDownstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::DownstairsKind>,
TypedUuidForUpstairsKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::UpstairsKind>,
TypedUuidForUpstairsRepairKind = omicron_uuid_kinds::TypedUuid<omicron_uuid_kinds::UpstairsRepairKind>,
Expand Down
1 change: 1 addition & 0 deletions dev-tools/omdb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ nexus-db-queries.workspace = true
nexus-reconfigurator-preparation.workspace = true
nexus-types.workspace = true
omicron-common.workspace = true
omicron-uuid-kinds.workspace = true
oximeter-client.workspace = true
# See omicron-rpaths for more about the "pq-sys" dependency.
pq-sys = "*"
Expand Down
9 changes: 5 additions & 4 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ use omicron_common::api::external::DataPageParams;
use omicron_common::api::external::Generation;
use omicron_common::api::external::InstanceState;
use omicron_common::api::external::MacAddr;
use omicron_uuid_kinds::CollectionUuid;
use sled_agent_client::types::VolumeConstructionRequest;
use std::borrow::Cow;
use std::cmp::Ordering;
Expand Down Expand Up @@ -385,7 +386,7 @@ enum CollectionsCommands {
#[derive(Debug, Args)]
struct CollectionsShowArgs {
/// id of the collection
id: Uuid,
id: CollectionUuid,
/// show long strings in their entirety
#[clap(long)]
show_long_strings: bool,
Expand Down Expand Up @@ -2918,7 +2919,7 @@ async fn cmd_db_inventory_collections_list(
#[derive(Tabled)]
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct CollectionRow {
id: Uuid,
id: CollectionUuid,
started: String,
took: String,
nsps: i64,
Expand Down Expand Up @@ -2967,7 +2968,7 @@ async fn cmd_db_inventory_collections_list(
.num_milliseconds()
);
rows.push(CollectionRow {
id: collection.id,
id: collection.id.into(),
started: humantime::format_rfc3339_seconds(
collection.time_started.into(),
)
Expand All @@ -2991,7 +2992,7 @@ async fn cmd_db_inventory_collections_list(
async fn cmd_db_inventory_collections_show(
opctx: &OpContext,
datastore: &DataStore,
id: Uuid,
id: CollectionUuid,
long_string_formatter: LongStringFormatter,
) -> Result<(), anyhow::Error> {
let collection = datastore
Expand Down
3 changes: 2 additions & 1 deletion dev-tools/omdb/src/bin/omdb/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use nexus_client::types::UninitializedSledId;
use nexus_db_queries::db::lookup::LookupPath;
use nexus_types::deployment::Blueprint;
use nexus_types::inventory::BaseboardId;
use omicron_uuid_kinds::CollectionUuid;
use reedline::DefaultPrompt;
use reedline::DefaultPromptSegment;
use reedline::Reedline;
Expand Down Expand Up @@ -117,7 +118,7 @@ struct BlueprintIdsArgs {
#[derive(Debug, Args)]
struct CollectionIdArgs {
/// id of an inventory collection
collection_id: Uuid,
collection_id: CollectionUuid,
}

#[derive(Debug, Args)]
Expand Down
13 changes: 7 additions & 6 deletions dev-tools/reconfigurator-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use nexus_types::inventory::OmicronZonesConfig;
use nexus_types::inventory::SledRole;
use omicron_common::api::external::Generation;
use omicron_common::api::external::Name;
use omicron_uuid_kinds::CollectionUuid;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::OmicronZoneUuid;
use omicron_uuid_kinds::SledUuid;
Expand All @@ -55,7 +56,7 @@ struct ReconfiguratorSim {
system: SystemDescription,

/// inventory collections created by the user
collections: IndexMap<Uuid, Collection>,
collections: IndexMap<CollectionUuid, Collection>,

/// blueprints created by the user
blueprints: IndexMap<Uuid, Blueprint>,
Expand Down Expand Up @@ -424,15 +425,15 @@ struct SiloAddRemoveArgs {
#[derive(Debug, Args)]
struct InventoryArgs {
/// id of the inventory collection to use in planning
collection_id: Uuid,
collection_id: CollectionUuid,
}

#[derive(Debug, Args)]
struct BlueprintPlanArgs {
/// id of the blueprint on which this one will be based
parent_blueprint_id: Uuid,
/// id of the inventory collection to use in planning
collection_id: Uuid,
collection_id: CollectionUuid,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -483,7 +484,7 @@ enum CliDnsGroup {
#[derive(Debug, Args)]
struct BlueprintDiffInventoryArgs {
/// id of the inventory collection
collection_id: Uuid,
collection_id: CollectionUuid,
/// id of the blueprint
blueprint_id: Uuid,
}
Expand Down Expand Up @@ -519,7 +520,7 @@ struct LoadArgs {

/// id of inventory collection to use for sled details
/// (may be omitted only if the file contains only one collection)
collection_id: Option<Uuid>,
collection_id: Option<CollectionUuid>,
}

#[derive(Debug, Args)]
Expand Down Expand Up @@ -642,7 +643,7 @@ fn cmd_inventory_list(
#[derive(Tabled)]
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct InventoryRow {
id: Uuid,
id: CollectionUuid,
nerrors: usize,
time_done: String,
}
Expand Down
78 changes: 52 additions & 26 deletions nexus/db-model/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::schema::{
inv_sled_agent, inv_sled_omicron_zones, inv_zpool, sw_caboose,
sw_root_of_trust_page,
};
use crate::typed_uuid::DbTypedUuid;
use crate::PhysicalDiskKind;
use crate::{
impl_enum_type, ipv6, ByteCount, Generation, MacAddr, Name, ServiceKind,
Expand All @@ -31,8 +32,8 @@ use nexus_types::inventory::{
BaseboardId, Caboose, Collection, PowerState, RotPage, RotSlot,
};
use omicron_common::api::internal::shared::NetworkInterface;
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::ZpoolUuid;
use omicron_uuid_kinds::{CollectionKind, GenericUuid};
use omicron_uuid_kinds::{CollectionUuid, ZpoolUuid};
use uuid::Uuid;

// See [`nexus_types::inventory::PowerState`].
Expand Down Expand Up @@ -248,16 +249,33 @@ impl From<SpType> for nexus_types::inventory::SpType {
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = inv_collection)]
pub struct InvCollection {
pub id: Uuid,
pub id: DbTypedUuid<CollectionKind>,
pub time_started: DateTime<Utc>,
pub time_done: DateTime<Utc>,
pub collector: String,
}

impl InvCollection {
/// Creates a new `InvCollection`.
pub fn new(
id: CollectionUuid,
time_started: DateTime<Utc>,
time_done: DateTime<Utc>,
collector: String,
) -> Self {
InvCollection { id: id.into(), time_started, time_done, collector }
}

/// Returns the ID.
pub fn id(&self) -> CollectionUuid {
self.id.into()
}
}

impl<'a> From<&'a Collection> for InvCollection {
fn from(c: &'a Collection) -> Self {
InvCollection {
id: c.id,
id: c.id.into(),
time_started: c.time_started,
time_done: c.time_done,
collector: c.collector.clone(),
Expand Down Expand Up @@ -371,26 +389,34 @@ impl From<SwRotPage> for RotPage {
#[derive(Queryable, Insertable, Clone, Debug, Selectable)]
#[diesel(table_name = inv_collection_error)]
pub struct InvCollectionError {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub idx: SqlU16,
pub message: String,
}

impl InvCollectionError {
pub fn new(inv_collection_id: Uuid, idx: u16, message: String) -> Self {
pub fn new(
inv_collection_id: CollectionUuid,
idx: u16,
message: String,
) -> Self {
InvCollectionError {
inv_collection_id,
inv_collection_id: inv_collection_id.into(),
idx: SqlU16::from(idx),
message,
}
}

pub fn inv_collection_id(&self) -> CollectionUuid {
self.inv_collection_id.into()
}
}

/// See [`nexus_types::inventory::ServiceProcessor`].
#[derive(Queryable, Clone, Debug, Selectable)]
#[diesel(table_name = inv_service_processor)]
pub struct InvServiceProcessor {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub hw_baseboard_id: Uuid,
pub time_collected: DateTime<Utc>,
pub source: String,
Expand Down Expand Up @@ -598,7 +624,7 @@ impl From<SledRole> for nexus_types::inventory::SledRole {
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = inv_sled_agent)]
pub struct InvSledAgent {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub time_collected: DateTime<Utc>,
pub source: String,
pub sled_id: Uuid,
Expand All @@ -613,7 +639,7 @@ pub struct InvSledAgent {

impl InvSledAgent {
pub fn new_without_baseboard(
collection_id: Uuid,
collection_id: CollectionUuid,
sled_agent: &nexus_types::inventory::SledAgent,
) -> Result<InvSledAgent, anyhow::Error> {
// It's irritating to have to check this case at runtime. The challenge
Expand All @@ -635,7 +661,7 @@ impl InvSledAgent {
))
} else {
Ok(InvSledAgent {
inv_collection_id: collection_id,
inv_collection_id: collection_id.into(),
time_collected: sled_agent.time_collected,
source: sled_agent.source.clone(),
sled_id: sled_agent.sled_id,
Expand All @@ -661,7 +687,7 @@ impl InvSledAgent {
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = inv_physical_disk)]
pub struct InvPhysicalDisk {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub sled_id: Uuid,
pub slot: i64,
pub vendor: String,
Expand All @@ -672,12 +698,12 @@ pub struct InvPhysicalDisk {

impl InvPhysicalDisk {
pub fn new(
inv_collection_id: Uuid,
inv_collection_id: CollectionUuid,
sled_id: Uuid,
disk: nexus_types::inventory::PhysicalDisk,
) -> Self {
Self {
inv_collection_id,
inv_collection_id: inv_collection_id.into(),
sled_id,
slot: disk.slot,
vendor: disk.identity.vendor,
Expand Down Expand Up @@ -706,7 +732,7 @@ impl From<InvPhysicalDisk> for nexus_types::inventory::PhysicalDisk {
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = inv_zpool)]
pub struct InvZpool {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub time_collected: DateTime<Utc>,
pub id: Uuid,
pub sled_id: Uuid,
Expand All @@ -715,12 +741,12 @@ pub struct InvZpool {

impl InvZpool {
pub fn new(
inv_collection_id: Uuid,
inv_collection_id: CollectionUuid,
sled_id: Uuid,
zpool: &nexus_types::inventory::Zpool,
) -> Self {
Self {
inv_collection_id,
inv_collection_id: inv_collection_id.into(),
time_collected: zpool.time_collected,
id: zpool.id.into_untyped_uuid(),
sled_id,
Expand All @@ -743,7 +769,7 @@ impl From<InvZpool> for nexus_types::inventory::Zpool {
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = inv_sled_omicron_zones)]
pub struct InvSledOmicronZones {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub time_collected: DateTime<Utc>,
pub source: String,
pub sled_id: Uuid,
Expand All @@ -752,11 +778,11 @@ pub struct InvSledOmicronZones {

impl InvSledOmicronZones {
pub fn new(
inv_collection_id: Uuid,
inv_collection_id: CollectionUuid,
zones_found: &nexus_types::inventory::OmicronZonesFound,
) -> InvSledOmicronZones {
InvSledOmicronZones {
inv_collection_id,
inv_collection_id: inv_collection_id.into(),
time_collected: zones_found.time_collected,
source: zones_found.source.clone(),
sled_id: zones_found.sled_id,
Expand Down Expand Up @@ -823,7 +849,7 @@ impl From<ZoneType> for ServiceKind {
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = inv_omicron_zone)]
pub struct InvOmicronZone {
pub inv_collection_id: Uuid,
pub inv_collection_id: DbTypedUuid<CollectionKind>,
pub sled_id: Uuid,
pub id: Uuid,
pub underlay_address: ipv6::Ipv6Addr,
Expand All @@ -848,13 +874,13 @@ pub struct InvOmicronZone {

impl InvOmicronZone {
pub fn new(
inv_collection_id: Uuid,
inv_collection_id: CollectionUuid,
sled_id: Uuid,
zone: &nexus_types::inventory::OmicronZoneConfig,
) -> Result<InvOmicronZone, anyhow::Error> {
let zone = OmicronZone::new(sled_id, zone)?;
Ok(Self {
inv_collection_id,
inv_collection_id: inv_collection_id.into(),
sled_id: zone.sled_id,
id: zone.id,
underlay_address: zone.underlay_address,
Expand Down Expand Up @@ -911,7 +937,7 @@ impl InvOmicronZone {
#[derive(Queryable, Clone, Debug, Selectable, Insertable)]
#[diesel(table_name = inv_omicron_zone_nic)]
pub struct InvOmicronZoneNic {
inv_collection_id: Uuid,
inv_collection_id: DbTypedUuid<CollectionKind>,
pub id: Uuid,
name: Name,
ip: IpNetwork,
Expand Down Expand Up @@ -939,12 +965,12 @@ impl From<InvOmicronZoneNic> for OmicronZoneNic {

impl InvOmicronZoneNic {
pub fn new(
inv_collection_id: Uuid,
inv_collection_id: CollectionUuid,
zone: &nexus_types::inventory::OmicronZoneConfig,
) -> Result<Option<InvOmicronZoneNic>, anyhow::Error> {
let zone_nic = OmicronZoneNic::new(zone)?;
Ok(zone_nic.map(|nic| Self {
inv_collection_id,
inv_collection_id: inv_collection_id.into(),
id: nic.id,
name: nic.name,
ip: nic.ip,
Expand Down
Loading
Loading