Skip to content

Commit

Permalink
[π˜€π—½π—Ώ] initial version
Browse files Browse the repository at this point in the history
Created using spr 1.3.6-beta.1
  • Loading branch information
sunshowers committed Jul 19, 2024
1 parent 92c39e5 commit 90bfd48
Show file tree
Hide file tree
Showing 14 changed files with 682 additions and 584 deletions.
30 changes: 30 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ members = [
"clients/sled-agent-client",
"clients/wicketd-client",
"cockroach-admin",
"cockroach-admin-api",
"cockroach-admin-types",
"common",
"dev-tools/crdb-seed",
"dev-tools/omdb",
Expand Down Expand Up @@ -110,6 +112,8 @@ default-members = [
"clients/sled-agent-client",
"clients/wicketd-client",
"cockroach-admin",
"cockroach-admin-api",
"cockroach-admin-types",
"common",
"dev-tools/crdb-seed",
"dev-tools/omdb",
Expand Down Expand Up @@ -263,7 +267,9 @@ ciborium = "0.2.2"
cfg-if = "1.0"
chrono = { version = "0.4", features = [ "serde" ] }
clap = { version = "4.5", features = ["cargo", "derive", "env", "wrap_help"] }
cockroach-admin-api = { path = "cockroach-admin-api" }
cockroach-admin-client = { path = "clients/cockroach-admin-client" }
cockroach-admin-types = { path = "cockroach-admin-types" }
colored = "2.1"
const_format = "0.2.32"
cookie = "0.18"
Expand Down
17 changes: 17 additions & 0 deletions cockroach-admin-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cockroach-admin-api"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
cockroach-admin-types.workspace = true
dropshot.workspace = true
omicron-common.workspace = true
omicron-uuid-kinds.workspace = true
omicron-workspace-hack.workspace = true
schemars.workspace = true
serde.workspace = true
76 changes: 76 additions & 0 deletions cockroach-admin-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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/.

use cockroach_admin_types::{NodeDecommission, NodeStatus};
use dropshot::{HttpError, HttpResponseOk, RequestContext, TypedBody};
use omicron_uuid_kinds::OmicronZoneUuid;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[dropshot::api_description {
module = "cockroach_admin_api_mod",
}]
pub trait CockroachAdminApi {
type Context;

/// Get the status of all nodes in the CRDB cluster.
#[endpoint {
method = GET,
path = "/node/status",
}]
async fn node_status(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<ClusterNodeStatus>, HttpError>;

/// Get the CockroachDB node ID of the local cockroach instance.
#[endpoint {
method = GET,
path = "/node/id",
}]
async fn local_node_id(
rqctx: RequestContext<Self::Context>,
) -> Result<HttpResponseOk<LocalNodeId>, HttpError>;

/// Decommission a node from the CRDB cluster.
#[endpoint {
method = POST,
path = "/node/decommission",
}]
async fn node_decommission(
rqctx: RequestContext<Self::Context>,
body: TypedBody<NodeId>,
) -> Result<HttpResponseOk<NodeDecommission>, HttpError>;
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct ClusterNodeStatus {
pub all_nodes: Vec<NodeStatus>,
}

/// CockroachDB Node ID
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct LocalNodeId {
/// The ID of this Omicron zone.
///
/// This is included to ensure correctness even if a socket address on a
/// sled is reused for a different zone; if our caller is trying to
/// determine the node ID for a particular Omicron CockroachDB zone, they'll
/// contact us by socket address. We include our zone ID in the response for
/// their confirmation that we are the zone they intended to contact.
pub zone_id: OmicronZoneUuid,
// CockroachDB node IDs are integers, in practice, but our use of them is as
// input and output to the `cockroach` CLI. We use a string which is a bit
// more natural (no need to parse CLI output or stringify an ID to send it
// as input) and leaves open the door for the format to change in the
// future.
pub node_id: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct NodeId {
pub node_id: String,
}
20 changes: 20 additions & 0 deletions cockroach-admin-types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "cockroach-admin-types"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[lints]
workspace = true

[dependencies]
chrono.workspace = true
csv.workspace = true
omicron-common.workspace = true
omicron-workspace-hack.workspace = true
schemars.workspace = true
serde.workspace = true

[dev-dependencies]
proptest.workspace = true
test-strategy.workspace = true
Loading

0 comments on commit 90bfd48

Please sign in to comment.