diff --git a/nexus/db-model/src/inventory.rs b/nexus/db-model/src/inventory.rs index ae6aefe3aa0..352f3a6f223 100644 --- a/nexus/db-model/src/inventory.rs +++ b/nexus/db-model/src/inventory.rs @@ -1686,31 +1686,33 @@ impl InvZoneManifestZone { collection_id: CollectionUuid, sled_id: SledUuid, artifact: &ZoneArtifactInventory, - ) -> Self { - Self { + ) -> Result { + Ok(Self { inv_collection_id: collection_id.into(), sled_id: sled_id.into(), zone_file_name: artifact.file_name.clone(), path: artifact.path.clone().into(), - expected_size: artifact.expected_size as i64, + expected_size: artifact.expected_size.try_into()?, expected_sha256: artifact.expected_hash.into(), error: artifact.status.as_ref().err().cloned(), - } + }) } } -impl From for ZoneArtifactInventory { - fn from(row: InvZoneManifestZone) -> Self { - Self { +impl TryFrom for ZoneArtifactInventory { + type Error = anyhow::Error; + + fn try_from(row: InvZoneManifestZone) -> Result { + Ok(Self { file_name: row.zone_file_name, path: row.path.into(), - expected_size: row.expected_size as u64, + expected_size: row.expected_size.try_into()?, expected_hash: row.expected_sha256.into(), status: match row.error { None => Ok(()), Some(error) => Err(error), }, - } + }) } } diff --git a/nexus/db-queries/src/db/datastore/inventory.rs b/nexus/db-queries/src/db/datastore/inventory.rs index e22f06a8b37..f851b06173a 100644 --- a/nexus/db-queries/src/db/datastore/inventory.rs +++ b/nexus/db-queries/src/db/datastore/inventory.rs @@ -244,28 +244,27 @@ impl DataStore { .collect(); // Pull zone manifest zones out of all sled agents. - let zone_manifest_zones: Vec<_> = collection - .sled_agents - .iter() - .filter_map(|sled_agent| { - sled_agent - .zone_image_resolver - .zone_manifest - .boot_inventory - .as_ref() - .ok() - .map(|artifacts| { - artifacts.artifacts.iter().map(|artifact| { - InvZoneManifestZone::new( - collection_id, - sled_agent.sled_id, - artifact, - ) - }) - }) - }) - .flatten() - .collect(); + let mut zone_manifest_zones = Vec::new(); + for sled_agent in &collection.sled_agents { + if let Some(artifacts) = sled_agent + .zone_image_resolver + .zone_manifest + .boot_inventory + .as_ref() + .ok() + { + for artifact in artifacts.artifacts.iter() { + zone_manifest_zones.push( + InvZoneManifestZone::new( + collection_id, + sled_agent.sled_id, + artifact, + ) + .map_err(|e| Error::internal_error(&e.to_string()))?, + ); + } + } + } // Pull zone manifest non-boot info out of all sled agents. let zone_manifest_non_boot: Vec<_> = collection @@ -3632,7 +3631,11 @@ impl DataStore { by_sled_id .entry(row.sled_id.into()) .or_default() - .insert_unique(row.into()) + .insert_unique(row.try_into().map_err( + |e: anyhow::Error| { + Error::internal_error(&e.to_string()) + }, + )?) .expect("database ensures the row is unique"); } }