Skip to content

Commit 542970f

Browse files
authored
[update] rename UpdateArtifact to UpdateArtifactId, add derives (#2292)
In #2192 and elsewhere, we treat the (name, version, kind) triple as a unique identifier for artifacts. Rename `UpdateArtifact` to `UpdateArtifactId`, and add some derives to allow it to be used as keys to unordered and ordered maps.
1 parent 65da741 commit 542970f

File tree

11 files changed

+55
-26
lines changed

11 files changed

+55
-26
lines changed

common/src/api/internal/nexus.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,27 @@ impl ProducerEndpoint {
7777
}
7878
}
7979

80-
/// Description of a single update artifact.
81-
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
82-
pub struct UpdateArtifact {
80+
/// An identifier for a single update artifact.
81+
#[derive(
82+
Clone,
83+
Debug,
84+
Eq,
85+
PartialEq,
86+
Hash,
87+
Ord,
88+
PartialOrd,
89+
Deserialize,
90+
Serialize,
91+
JsonSchema,
92+
)]
93+
pub struct UpdateArtifactId {
94+
/// The artifact's name.
8395
pub name: String,
96+
97+
/// The artifact's version.
8498
pub version: String,
99+
100+
/// The kind of update artifact this is.
85101
pub kind: UpdateArtifactKind,
86102
}
87103

@@ -93,6 +109,9 @@ pub struct UpdateArtifact {
93109
Debug,
94110
PartialEq,
95111
Eq,
112+
Hash,
113+
Ord,
114+
PartialOrd,
96115
Display,
97116
Deserialize,
98117
Serialize,

common/src/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct ArtifactsDocument {
1414

1515
/// Describes an artifact available in the repository.
1616
///
17-
/// See also [`crate::api::internal::nexus::UpdateArtifact`], which is used
17+
/// See also [`crate::api::internal::nexus::UpdateArtifactId`], which is used
1818
/// internally between Nexus and Sled Agent.
1919
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
2020
pub struct Artifact {

nexus/src/app/update.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use omicron_common::api::external::{
1717
self, CreateResult, DataPageParams, Error, ListResultVec, LookupResult,
1818
PaginationOrder, UpdateResult,
1919
};
20-
use omicron_common::api::internal::nexus::UpdateArtifact;
20+
use omicron_common::api::internal::nexus::UpdateArtifactId;
2121
use rand::Rng;
2222
use ring::digest;
2323
use std::convert::TryFrom;
@@ -119,7 +119,7 @@ impl super::Nexus {
119119
);
120120
client
121121
.update_artifact(
122-
&sled_agent_client::types::UpdateArtifact {
122+
&sled_agent_client::types::UpdateArtifactId {
123123
name: artifact.name.clone(),
124124
version: artifact.version.clone(),
125125
kind: artifact.kind.0.into(),
@@ -136,7 +136,7 @@ impl super::Nexus {
136136
pub async fn download_artifact(
137137
&self,
138138
opctx: &OpContext,
139-
artifact: UpdateArtifact,
139+
artifact: UpdateArtifactId,
140140
) -> Result<Vec<u8>, Error> {
141141
let mut base_url =
142142
self.tuf_base_url(opctx).await?.ok_or_else(|| {

nexus/src/internal_api/http_entrypoints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use hyper::Body;
2525
use omicron_common::api::internal::nexus::DiskRuntimeState;
2626
use omicron_common::api::internal::nexus::InstanceRuntimeState;
2727
use omicron_common::api::internal::nexus::ProducerEndpoint;
28-
use omicron_common::api::internal::nexus::UpdateArtifact;
28+
use omicron_common::api::internal::nexus::UpdateArtifactId;
2929
use oximeter::types::ProducerResults;
3030
use oximeter_producer::{collect, ProducerIdPathParams};
3131
use schemars::JsonSchema;
@@ -368,7 +368,7 @@ async fn cpapi_metrics_collect(
368368
}]
369369
async fn cpapi_artifact_download(
370370
request_context: RequestContext<Arc<ServerContext>>,
371-
path_params: Path<UpdateArtifact>,
371+
path_params: Path<UpdateArtifactId>,
372372
) -> Result<HttpResponseOk<FreeformBody>, HttpError> {
373373
let context = request_context.context();
374374
let nexus = &context.nexus;

openapi/nexus-internal.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
{
1919
"in": "path",
2020
"name": "kind",
21+
"description": "The kind of update artifact this is.",
2122
"required": true,
2223
"schema": {
2324
"$ref": "#/components/schemas/UpdateArtifactKind"
@@ -26,6 +27,7 @@
2627
{
2728
"in": "path",
2829
"name": "name",
30+
"description": "The artifact's name.",
2931
"required": true,
3032
"schema": {
3133
"type": "string"
@@ -34,6 +36,7 @@
3436
{
3537
"in": "path",
3638
"name": "version",
39+
"description": "The artifact's version.",
3740
"required": true,
3841
"schema": {
3942
"type": "string"

openapi/sled-agent.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
"content": {
326326
"application/json": {
327327
"schema": {
328-
"$ref": "#/components/schemas/UpdateArtifact"
328+
"$ref": "#/components/schemas/UpdateArtifactId"
329329
}
330330
}
331331
},
@@ -1595,17 +1595,24 @@
15951595
"last_port"
15961596
]
15971597
},
1598-
"UpdateArtifact": {
1599-
"description": "Description of a single update artifact.",
1598+
"UpdateArtifactId": {
1599+
"description": "An identifier for a single update artifact.",
16001600
"type": "object",
16011601
"properties": {
16021602
"kind": {
1603-
"$ref": "#/components/schemas/UpdateArtifactKind"
1603+
"description": "The kind of update artifact this is.",
1604+
"allOf": [
1605+
{
1606+
"$ref": "#/components/schemas/UpdateArtifactKind"
1607+
}
1608+
]
16041609
},
16051610
"name": {
1611+
"description": "The artifact's name.",
16061612
"type": "string"
16071613
},
16081614
"version": {
1615+
"description": "The artifact's version.",
16091616
"type": "string"
16101617
}
16111618
},

sled-agent-client/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,11 @@ impl From<omicron_common::api::external::L4PortRange> for types::L4PortRange {
287287
}
288288
}
289289

290-
impl From<omicron_common::api::internal::nexus::UpdateArtifact>
291-
for types::UpdateArtifact
290+
impl From<omicron_common::api::internal::nexus::UpdateArtifactId>
291+
for types::UpdateArtifactId
292292
{
293-
fn from(s: omicron_common::api::internal::nexus::UpdateArtifact) -> Self {
294-
types::UpdateArtifact {
293+
fn from(s: omicron_common::api::internal::nexus::UpdateArtifactId) -> Self {
294+
types::UpdateArtifactId {
295295
name: s.name,
296296
version: s.version,
297297
kind: s.kind.into(),

sled-agent/src/http_entrypoints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use dropshot::{
1717
use omicron_common::api::external::Error;
1818
use omicron_common::api::internal::nexus::DiskRuntimeState;
1919
use omicron_common::api::internal::nexus::InstanceRuntimeState;
20-
use omicron_common::api::internal::nexus::UpdateArtifact;
20+
use omicron_common::api::internal::nexus::UpdateArtifactId;
2121
use schemars::JsonSchema;
2222
use serde::{Deserialize, Serialize};
2323
use uuid::Uuid;
@@ -162,7 +162,7 @@ async fn disk_put(
162162
}]
163163
async fn update_artifact(
164164
rqctx: RequestContext<SledAgent>,
165-
artifact: TypedBody<UpdateArtifact>,
165+
artifact: TypedBody<UpdateArtifactId>,
166166
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
167167
let sa = rqctx.context();
168168
sa.update_artifact(artifact.into_inner()).await.map_err(Error::from)?;

sled-agent/src/sim/http_entrypoints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use dropshot::RequestContext;
2020
use dropshot::TypedBody;
2121
use omicron_common::api::internal::nexus::DiskRuntimeState;
2222
use omicron_common::api::internal::nexus::InstanceRuntimeState;
23-
use omicron_common::api::internal::nexus::UpdateArtifact;
23+
use omicron_common::api::internal::nexus::UpdateArtifactId;
2424
use schemars::JsonSchema;
2525
use serde::{Deserialize, Serialize};
2626
use std::sync::Arc;
@@ -141,7 +141,7 @@ async fn disk_poke_post(
141141
}]
142142
async fn update_artifact(
143143
rqctx: RequestContext<Arc<SledAgent>>,
144-
artifact: TypedBody<UpdateArtifact>,
144+
artifact: TypedBody<UpdateArtifactId>,
145145
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
146146
crate::updates::download_artifact(
147147
artifact.into_inner(),

sled-agent/src/sled_agent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use omicron_common::address::{
2929
};
3030
use omicron_common::api::{
3131
internal::nexus::DiskRuntimeState, internal::nexus::InstanceRuntimeState,
32-
internal::nexus::UpdateArtifact,
32+
internal::nexus::UpdateArtifactId,
3333
};
3434
use omicron_common::backoff::{
3535
retry_notify, retry_policy_internal_service_aggressive, BackoffError,
@@ -601,7 +601,7 @@ impl SledAgent {
601601
/// Downloads and applies an artifact.
602602
pub async fn update_artifact(
603603
&self,
604-
artifact: UpdateArtifact,
604+
artifact: UpdateArtifactId,
605605
) -> Result<(), Error> {
606606
let nexus_client = self.inner.lazy_nexus_client.get().await?;
607607
crate::updates::download_artifact(artifact, &nexus_client).await?;

0 commit comments

Comments
 (0)