Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 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/sled-agent-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ workspace = true
[dependencies]
anyhow.workspace = true
async-trait.workspace = true
byte-wrapper.workspace = true
chrono.workspace = true
omicron-generation-kinds.workspace = true
sled-agent-types-versions.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ progenitor::generate_api!(
VirtualNetworkInterfaceHost = { derives = [Eq, Hash] },
},
crates = {
"byte-wrapper" = "0.1.0",
"omicron-uuid-kinds" = "*",
"oxnet" = "0.1.0",
},
replace = {
ArtifactConfig = sled_agent_types::artifact::ArtifactConfig,
ArtifactConfigGeneration = omicron_generation_kinds::ArtifactConfigGeneration,
Attestation = sled_agent_types_versions::latest::rot::Attestation,
Baseboard = sled_agent_types_versions::latest::inventory::Baseboard,
BaseboardId = sled_hardware_types::BaseboardId,
Expand Down
1 change: 1 addition & 0 deletions generation-kinds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ impl_typed_generation_kinds! {
},
kinds = {
Alert = {},
ArtifactConfig = {},
InstanceState = {},
InstanceUpdater = {},
Nexus = {},
Expand Down
12 changes: 8 additions & 4 deletions nexus/db-model/src/tuf_repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use std::collections::BTreeMap;
use std::str::FromStr;

use crate::{ByteCount, Generation, SemverVersion, typed_uuid::DbTypedUuid};
use crate::typed_generation::DbTypedGeneration;
use crate::{ByteCount, SemverVersion, typed_uuid::DbTypedUuid};
use chrono::{DateTime, Utc};
use diesel::sql_types::{Jsonb, Text};
use diesel::{deserialize::FromSql, serialize::ToSql};
Expand All @@ -16,6 +17,9 @@ use nexus_db_schema::schema::{
};
use nexus_types::external_api::update as update_types;
use omicron_common::api::external;
use omicron_generation_kinds::{
ArtifactConfigGeneration, ArtifactConfigGenerationKind,
};
use omicron_uuid_kinds::GenericUuid;
use omicron_uuid_kinds::TufArtifactKind;
use omicron_uuid_kinds::TufRepoKind;
Expand Down Expand Up @@ -48,7 +52,7 @@ impl TufRepoDescription {
/// [`nexus_types::tuf_repo::TufRepoDescription`].
pub fn new(
description: nexus_types::tuf_repo::TufRepoDescription,
generation_added: omicron_generation_kinds::Generation,
generation_added: ArtifactConfigGeneration,
) -> Result<Self, external::ByteCountRangeError> {
let id = TypedUuid::new_v4().into();
Ok(Self {
Expand Down Expand Up @@ -117,7 +121,7 @@ impl TufArtifactDescription {
/// [`tufaceous_artifact::Artifact`].
pub fn new(
artifact: tufaceous_artifact::Artifact,
generation_added: omicron_generation_kinds::Generation,
generation_added: ArtifactConfigGeneration,
) -> Result<Self, external::ByteCountRangeError> {
let id = TypedUuid::new_v4().into();
Ok(Self {
Expand Down Expand Up @@ -237,7 +241,7 @@ pub struct TufArtifact {
pub id: DbTypedUuid<TufArtifactKind>,
pub time_created: DateTime<Utc>,
pub sha256: ArtifactHash,
pub generation_added: Generation,
pub generation_added: DbTypedGeneration<ArtifactConfigGenerationKind>,
}

impl TufArtifact {
Expand Down
35 changes: 19 additions & 16 deletions nexus/db-queries/src/db/datastore/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ use nexus_db_errors::OptionalError;
use nexus_db_errors::{ErrorHandler, public_error_from_diesel};
use nexus_db_lookup::DbConnection;
use nexus_db_model::{
ArtifactHash, TargetRelease, TufArtifact, TufArtifactDescription,
TufArtifactFile, TufArtifactTag, TufMetadataEntry, TufRepo,
TufRepoDescription, TufRepoUpload, TufTrustRoot, to_db_typed_uuid,
ArtifactHash, DbTypedGeneration, TargetRelease, TufArtifact,
TufArtifactDescription, TufArtifactFile, TufArtifactTag, TufMetadataEntry,
TufRepo, TufRepoDescription, TufRepoUpload, TufTrustRoot, to_db_typed_uuid,
};
use nexus_types::external_api::update::TufRepoUploadStatus;
use omicron_common::api::external::{
self, ByteCountRangeError, CreateResult, DataPageParams, DeleteResult,
ListResultVec, LookupResult, LookupType, ResourceType, UpdateResult,
};
use omicron_common::api::external::{Error, InternalContext};
use omicron_generation_kinds::Generation;
use omicron_generation_kinds::{
ArtifactConfigGeneration, ArtifactConfigGenerationKind,
};
use omicron_uuid_kinds::{GenericUuid, TufRepoUuid};
use semver::Version;
use sled_agent_types::artifact::ArtifactConfig;
Expand Down Expand Up @@ -417,7 +419,7 @@ impl DataStore {
pub async fn tuf_repo_mark_pruned(
&self,
opctx: &OpContext,
initial_tuf_generation: Generation,
initial_tuf_generation: ArtifactConfigGeneration,
recent_releases: &RecentTargetReleases,
tuf_repo_id: TufRepoUuid,
) -> UpdateResult<()> {
Expand Down Expand Up @@ -578,7 +580,7 @@ impl DataStore {
pub async fn tuf_get_generation(
&self,
opctx: &OpContext,
) -> LookupResult<Generation> {
) -> LookupResult<ArtifactConfigGeneration> {
opctx.authorize(authz::Action::Read, &authz::FLEET).await?;
get_generation(&*self.pool_connection_authorized(opctx).await?)
.await
Expand Down Expand Up @@ -1110,22 +1112,23 @@ async fn insert_impl(

async fn get_generation(
conn: &async_bb8_diesel::Connection<DbConnection>,
) -> Result<Generation, DieselError> {
) -> Result<ArtifactConfigGeneration, DieselError> {
use nexus_db_schema::schema::tuf_generation::dsl;

let generation: nexus_db_model::Generation = dsl::tuf_generation
.filter(dsl::singleton.eq(true))
.select(dsl::generation)
.get_result_async(conn)
.await?;
Ok(generation.0)
let generation: DbTypedGeneration<ArtifactConfigGenerationKind> =
dsl::tuf_generation
.filter(dsl::singleton.eq(true))
.select(dsl::generation)
.get_result_async(conn)
.await?;
Ok(generation.into())
}

async fn put_generation(
conn: &async_bb8_diesel::Connection<DbConnection>,
old_generation: nexus_db_model::Generation,
new_generation: nexus_db_model::Generation,
) -> Result<nexus_db_model::Generation, DieselError> {
old_generation: DbTypedGeneration<ArtifactConfigGenerationKind>,
new_generation: DbTypedGeneration<ArtifactConfigGenerationKind>,
) -> Result<DbTypedGeneration<ArtifactConfigGenerationKind>, DieselError> {
use nexus_db_schema::schema::tuf_generation::dsl;

// We use `get_result_async` instead of `execute_async` to check that we
Expand Down
6 changes: 3 additions & 3 deletions nexus/src/app/background/tasks/tuf_artifact_replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use nexus_types::internal_api::background::{
TufArtifactReplicationCounters, TufArtifactReplicationOperation,
TufArtifactReplicationRequest, TufArtifactReplicationStatus,
};
use omicron_generation_kinds::Generation;
use omicron_generation_kinds::ArtifactConfigGeneration;
use omicron_uuid_kinds::SledUuid;
use rand::seq::{IndexedRandom, SliceRandom};
use serde_json::json;
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<'a> Requests<'a> {
fn into_stream(
self,
log: &'a slog::Logger,
generation: Generation,
generation: ArtifactConfigGeneration,
) -> impl Stream<
Item = impl Future<Output = TufArtifactReplicationRequest> + use<'a>,
> + use<'a> {
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Request<'_> {
async fn execute(
self,
log: &slog::Logger,
generation: Generation,
generation: ArtifactConfigGeneration,
_permit: Option<OwnedSemaphorePermit>,
) -> TufArtifactReplicationRequest {
let err: Option<Box<dyn std::error::Error>> = async {
Expand Down
6 changes: 3 additions & 3 deletions nexus/types/src/internal_api/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use gateway_types::component::SpType;
use iddqd::IdOrdItem;
use iddqd::IdOrdMap;
use iddqd::id_upcast;
use omicron_generation_kinds::Generation;
use omicron_generation_kinds::ArtifactConfigGeneration;
use omicron_uuid_kinds::AlertReceiverUuid;
use omicron_uuid_kinds::AlertUuid;
use omicron_uuid_kinds::BlueprintUuid;
Expand Down Expand Up @@ -372,7 +372,7 @@ impl SupportBundleCollectionReport {
/// The status of a `tuf_artifact_replication` background task activation
#[derive(Debug, Serialize, Deserialize, PartialEq)]
pub struct TufArtifactReplicationStatus {
pub generation: Generation,
pub generation: ArtifactConfigGeneration,
pub last_run_counters: TufArtifactReplicationCounters,
pub lifetime_counters: TufArtifactReplicationCounters,
pub request_debug_ringbuf: Arc<VecDeque<TufArtifactReplicationRequest>>,
Expand Down Expand Up @@ -472,7 +472,7 @@ pub struct TufArtifactReplicationRequest {
)]
#[serde(tag = "operation", rename_all = "snake_case")]
pub enum TufArtifactReplicationOperation {
PutConfig { generation: Generation },
PutConfig { generation: ArtifactConfigGeneration },
List,
Put { hash: ArtifactHash },
Copy { hash: ArtifactHash, source_sled: SledUuid },
Expand Down
1 change: 1 addition & 0 deletions openapi/sled-agent/sled-agent-51.0.0-9a12e4.json.gitstub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cb538d50fc99c594c0eecb8e8a577b874dac37d1:openapi/sled-agent/sled-agent-51.0.0-9a12e4.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://oxide.computer",
"email": "api@oxide.computer"
},
"version": "51.0.0"
"version": "52.0.0"
},
"paths": {
"/artifacts": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"name": "generation",
"required": true,
"schema": {
"$ref": "#/components/schemas/Generation"
"$ref": "#/components/schemas/ArtifactConfigGeneration"
}
}
],
Expand Down Expand Up @@ -104,7 +104,7 @@
"name": "generation",
"required": true,
"schema": {
"$ref": "#/components/schemas/Generation"
"$ref": "#/components/schemas/ArtifactConfigGeneration"
}
}
],
Expand Down Expand Up @@ -2966,20 +2966,38 @@
"artifacts": {
"type": "array",
"items": {
"x-rust-type": {
"crate": "byte-wrapper",
"path": "byte_wrapper::HexArray::<32>",
"version": "0.1.0"
},
"type": "string",
"format": "hex string (32 bytes)"
"pattern": "^[0-9a-fA-F]{64}$",
"minLength": 64,
"maxLength": 64
},
"uniqueItems": true
},
"generation": {
"$ref": "#/components/schemas/Generation"
"$ref": "#/components/schemas/ArtifactConfigGeneration"
}
},
"required": [
"artifacts",
"generation"
]
},
"ArtifactConfigGeneration": {
"description": "Generation numbers stored in the database, used for optimistic concurrency control",
"x-rust-type": {
"crate": "omicron-generation-kinds",
"path": "omicron_generation_kinds::ArtifactConfigGeneration",
"version": "*"
},
"type": "integer",
"format": "uint64",
"minimum": 0
},
"ArtifactCopyFromDepotBody": {
"description": "Request body for copying artifacts from a depot.",
"type": "object",
Expand All @@ -3001,7 +3019,7 @@
"type": "object",
"properties": {
"generation": {
"$ref": "#/components/schemas/Generation"
"$ref": "#/components/schemas/ArtifactConfigGeneration"
},
"list": {
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion openapi/sled-agent/sled-agent-latest.json
Loading
Loading