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
20 changes: 11 additions & 9 deletions nexus/db-model/src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1686,31 +1686,33 @@ impl InvZoneManifestZone {
collection_id: CollectionUuid,
sled_id: SledUuid,
artifact: &ZoneArtifactInventory,
) -> Self {
Self {
) -> Result<Self, anyhow::Error> {
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<InvZoneManifestZone> for ZoneArtifactInventory {
fn from(row: InvZoneManifestZone) -> Self {
Self {
impl TryFrom<InvZoneManifestZone> for ZoneArtifactInventory {
type Error = anyhow::Error;

fn try_from(row: InvZoneManifestZone) -> Result<Self, Self::Error> {
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),
},
}
})
}
}

Expand Down
49 changes: 26 additions & 23 deletions nexus/db-queries/src/db/datastore/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
}
Expand Down
Loading