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

Add omdb sled-agent bootstore status #5041

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions bootstore/src/schemes/v0/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ pub enum NodeRequestError {
},
}

impl From<NodeRequestError> for omicron_common::api::external::Error {
fn from(error: NodeRequestError) -> Self {
omicron_common::api::external::Error::internal_error(&format!(
"{:#}",
andrewjstone marked this conversation as resolved.
Show resolved Hide resolved
error
))
}
}

/// A request sent to the `Node` task from the `NodeHandle`
pub enum NodeApiRequest {
/// Initialize a rack at the behest of RSS running on the same scrimlet as
Expand Down
22 changes: 22 additions & 0 deletions dev-tools/omdb/src/bin/omdb/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ enum SledAgentCommands {
/// print information about zpools
#[clap(subcommand)]
Zpools(ZpoolCommands),

/// print information about the local bootstore node
#[clap(subcommand)]
Bootstore(BootstoreCommands),
}

#[derive(Debug, Subcommand)]
Expand All @@ -45,6 +49,12 @@ enum ZpoolCommands {
List,
}

#[derive(Debug, Subcommand)]
enum BootstoreCommands {
/// Show the internal state of the local bootstore node
Status,
}

impl SledAgentArgs {
/// Run a `omdb sled-agent` subcommand.
pub(crate) async fn run_cmd(
Expand All @@ -70,6 +80,9 @@ impl SledAgentArgs {
SledAgentCommands::Zpools(ZpoolCommands::List) => {
cmd_zpools_list(&client).await
}
SledAgentCommands::Bootstore(BootstoreCommands::Status) => {
cmd_bootstore_status(&client).await
}
}
}
}
Expand Down Expand Up @@ -110,3 +123,12 @@ async fn cmd_zpools_list(

Ok(())
}

/// Runs `omdb sled-agent bootstore status`
async fn cmd_bootstore_status(
client: &sled_agent_client::Client,
) -> Result<(), anyhow::Error> {
let status = client.bootstore_status().await.context("bootstore status")?;
println!("{status}");
Ok(())
}
25 changes: 25 additions & 0 deletions openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,31 @@
}
}
},
"/bootstore/status": {
"get": {
"summary": "Get the internal state of the local bootstore node",
"operationId": "bootstore_status",
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"title": "String",
"type": "string"
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/cockroachdb": {
"post": {
"summary": "Initializes a CockroachDB cluster",
Expand Down
21 changes: 21 additions & 0 deletions sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn api() -> SledApiDescription {
api.register(host_os_write_status_get)?;
api.register(host_os_write_status_delete)?;
api.register(inventory)?;
api.register(bootstore_status)?;

Ok(())
}
Expand Down Expand Up @@ -972,3 +973,23 @@ async fn inventory(
let sa = request_context.context();
Ok(HttpResponseOk(sa.inventory()?))
}

/// Get the internal state of the local bootstore node
#[endpoint {
method = GET,
path = "/bootstore/status",
}]
async fn bootstore_status(
request_context: RequestContext<SledAgent>,
) -> Result<HttpResponseOk<String>, HttpError> {
let sa = request_context.context();
let bootstore = sa.bootstore();
let status = bootstore.get_status().await.map_err(|e| {
HttpError::from(omicron_common::api::external::Error::from(e))
})?;
// Status is full of maps with non-string keys, and using `serde_as`
// doesn't work with JSON. Since this is just used for omdb right now,
andrewjstone marked this conversation as resolved.
Show resolved Hide resolved
// return a string.
let status_str = format!("{status:#?}");
Ok(HttpResponseOk(status_str))
}
Loading