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

[wicketd] allow starting multiple updates with one API call #4039

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
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.

97 changes: 52 additions & 45 deletions openapi/wicketd.json
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,33 @@
}
}
},
"/update": {
"post": {
"summary": "An endpoint to start updating one or more sleds, switches and PSCs.",
"operationId": "post_start_update",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartUpdateParams"
}
}
},
"required": true
},
"responses": {
"204": {
"description": "resource updated"
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/update/{type}/{slot}": {
"get": {
"summary": "An endpoint to get the status of any update being performed or recently",
Expand Down Expand Up @@ -641,51 +668,6 @@
"$ref": "#/components/responses/Error"
}
}
},
"post": {
"summary": "An endpoint to start updating a sled.",
"operationId": "post_start_update",
"parameters": [
{
"in": "path",
"name": "slot",
"required": true,
"schema": {
"type": "integer",
"format": "uint32",
"minimum": 0
}
},
{
"in": "path",
"name": "type",
"required": true,
"schema": {
"$ref": "#/components/schemas/SpType"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartUpdateOptions"
}
}
},
"required": true
},
"responses": {
"204": {
"description": "resource updated"
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
}
},
Expand Down Expand Up @@ -2761,6 +2743,31 @@
"skip_sp_version_check"
]
},
"StartUpdateParams": {
"type": "object",
"properties": {
"options": {
"description": "Options for the update.",
"allOf": [
{
"$ref": "#/components/schemas/StartUpdateOptions"
}
]
},
"targets": {
"description": "The SP identifiers to start the update with. Must be non-empty.",
"type": "array",
"items": {
"$ref": "#/components/schemas/SpIdentifier"
},
"uniqueItems": true
}
},
"required": [
"options",
"targets"
]
},
"StepComponentSummaryForGenericSpec": {
"type": "object",
"properties": {
Expand Down
11 changes: 6 additions & 5 deletions wicket/src/wicketd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tokio::time::{interval, Duration, MissedTickBehavior};
use wicketd_client::types::{
AbortUpdateOptions, ClearUpdateStateOptions, GetInventoryParams,
GetInventoryResponse, GetLocationResponse, IgnitionCommand, SpIdentifier,
SpType, StartUpdateOptions,
SpType, StartUpdateOptions, StartUpdateParams,
};

use crate::events::EventReportMap;
Expand Down Expand Up @@ -164,10 +164,11 @@ impl WicketdManager {
tokio::spawn(async move {
let update_client =
create_wicketd_client(&log, addr, WICKETD_TIMEOUT);
let sp: SpIdentifier = component_id.into();
let response = match update_client
.post_start_update(sp.type_, sp.slot, &options)
.await
let params = StartUpdateParams {
targets: vec![component_id.into()],
options,
};
let response = match update_client.post_start_update(&params).await
{
Ok(_) => Ok(()),
Err(error) => Err(error.to_string()),
Expand Down
1 change: 1 addition & 0 deletions wicketd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ hubtools.workspace = true
http.workspace = true
hyper.workspace = true
illumos-utils.workspace = true
itertools.workspace = true
reqwest.workspace = true
schemars.workspace = true
serde.workspace = true
Expand Down
41 changes: 41 additions & 0 deletions wicketd/src/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Helpers and utility functions for wicketd.

use std::fmt;

use gateway_client::types::{SpIdentifier, SpType};
use itertools::Itertools;

#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub(crate) struct SpIdentifierDisplay(pub(crate) SpIdentifier);

impl From<SpIdentifier> for SpIdentifierDisplay {
fn from(id: SpIdentifier) -> Self {
SpIdentifierDisplay(id)
}
}

impl<'a> From<&'a SpIdentifier> for SpIdentifierDisplay {
fn from(id: &'a SpIdentifier) -> Self {
SpIdentifierDisplay(*id)
}
}

impl fmt::Display for SpIdentifierDisplay {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.0.type_ {
SpType::Sled => write!(f, "sled {}", self.0.slot),
SpType::Switch => write!(f, "switch {}", self.0.slot),
SpType::Power => write!(f, "PSC {}", self.0.slot),
}
}
}

pub(crate) fn sps_to_string<S: Into<SpIdentifierDisplay>>(
sps: impl IntoIterator<Item = S>,
) -> String {
sps.into_iter().map_into().join(", ")
}
Loading
Loading