Skip to content

Rip InstanceRuntimeState out of the internal API #6556

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

Merged
merged 7 commits into from
Sep 11, 2024
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
30 changes: 0 additions & 30 deletions clients/sled-agent-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,6 @@ impl omicron_common::api::external::ClientError for types::Error {
}
}

impl From<omicron_common::api::internal::nexus::InstanceRuntimeState>
for types::InstanceRuntimeState
{
fn from(
s: omicron_common::api::internal::nexus::InstanceRuntimeState,
) -> Self {
Self {
propolis_id: s.propolis_id,
dst_propolis_id: s.dst_propolis_id,
migration_id: s.migration_id,
gen: s.gen,
time_updated: s.time_updated,
}
}
}

impl From<omicron_common::api::internal::nexus::VmmState> for types::VmmState {
fn from(s: omicron_common::api::internal::nexus::VmmState) -> Self {
use omicron_common::api::internal::nexus::VmmState as Input;
Expand All @@ -126,20 +110,6 @@ impl From<omicron_common::api::external::InstanceCpuCount>
}
}

impl From<types::InstanceRuntimeState>
for omicron_common::api::internal::nexus::InstanceRuntimeState
{
fn from(s: types::InstanceRuntimeState) -> Self {
Self {
propolis_id: s.propolis_id,
dst_propolis_id: s.dst_propolis_id,
migration_id: s.migration_id,
gen: s.gen,
time_updated: s.time_updated,
}
}
}

impl From<types::VmmState> for omicron_common::api::internal::nexus::VmmState {
fn from(s: types::VmmState) -> Self {
use omicron_common::api::internal::nexus::VmmState as Output;
Expand Down
18 changes: 0 additions & 18 deletions common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::api::external::{
};
use chrono::{DateTime, Utc};
use omicron_uuid_kinds::DownstairsRegionKind;
use omicron_uuid_kinds::PropolisUuid;
use omicron_uuid_kinds::TypedUuid;
use omicron_uuid_kinds::UpstairsRepairKind;
use omicron_uuid_kinds::UpstairsSessionKind;
Expand Down Expand Up @@ -60,23 +59,6 @@ pub struct InstanceProperties {
pub hostname: Hostname,
}

/// The dynamic runtime properties of an instance: its current VMM ID (if any),
/// migration information (if any), and the instance state to report if there is
/// no active VMM.
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
pub struct InstanceRuntimeState {
/// The instance's currently active VMM ID.
pub propolis_id: Option<PropolisUuid>,
/// If a migration is active, the ID of the target VMM.
pub dst_propolis_id: Option<PropolisUuid>,
/// If a migration is active, the ID of that migration.
pub migration_id: Option<Uuid>,
/// Generation number for this state.
pub gen: Generation,
/// Timestamp for this information.
pub time_updated: DateTime<Utc>,
}

/// One of the states that a VMM can be in.
#[derive(
Copy, Clone, Debug, Deserialize, Serialize, JsonSchema, Eq, PartialEq,
Expand Down
43 changes: 1 addition & 42 deletions nexus/db-model/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::schema::{disk, external_ip, instance};
use chrono::{DateTime, Utc};
use db_macros::Resource;
use nexus_types::external_api::params;
use omicron_uuid_kinds::{GenericUuid, InstanceUuid, PropolisUuid};
use omicron_uuid_kinds::{GenericUuid, InstanceUuid};
use serde::Deserialize;
use serde::Serialize;
use uuid::Uuid;
Expand Down Expand Up @@ -223,44 +223,3 @@ impl InstanceRuntimeState {
}
}
}

impl From<omicron_common::api::internal::nexus::InstanceRuntimeState>
for InstanceRuntimeState
{
fn from(
state: omicron_common::api::internal::nexus::InstanceRuntimeState,
) -> Self {
let nexus_state = if state.propolis_id.is_some() {
InstanceState::Vmm
} else {
InstanceState::NoVmm
};

Self {
nexus_state,
time_updated: state.time_updated,
gen: state.gen.into(),
propolis_id: state.propolis_id.map(|id| id.into_untyped_uuid()),
dst_propolis_id: state
.dst_propolis_id
.map(|id| id.into_untyped_uuid()),
migration_id: state.migration_id,
}
}
}

impl From<InstanceRuntimeState>
for sled_agent_client::types::InstanceRuntimeState
{
fn from(state: InstanceRuntimeState) -> Self {
Self {
dst_propolis_id: state
.dst_propolis_id
.map(PropolisUuid::from_untyped_uuid),
gen: state.gen.into(),
migration_id: state.migration_id,
propolis_id: state.propolis_id.map(PropolisUuid::from_untyped_uuid),
time_updated: state.time_updated,
}
}
}
2 changes: 1 addition & 1 deletion nexus/src/app/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ impl super::Nexus {
propolis_id,
&sled_agent_client::types::InstanceEnsureBody {
hardware: instance_hardware,
instance_runtime: db_instance.runtime().clone().into(),
migration_id: db_instance.runtime().migration_id,
vmm_runtime,
instance_id,
propolis_addr: SocketAddr::new(
Expand Down
70 changes: 10 additions & 60 deletions openapi/sled-agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -3137,14 +3137,6 @@
}
]
},
"instance_runtime": {
"description": "The instance runtime state for the instance being registered.",
"allOf": [
{
"$ref": "#/components/schemas/InstanceRuntimeState"
}
]
},
"metadata": {
"description": "Metadata used to track instance statistics.",
"allOf": [
Expand All @@ -3153,6 +3145,12 @@
}
]
},
"migration_id": {
"nullable": true,
"description": "The ID of the migration in to this VMM, if this VMM is being ensured is part of a migration in. If this is `None`, the VMM is not being created due to a migration.",
"type": "string",
"format": "uuid"
},
"propolis_addr": {
"description": "The address at which this VMM should serve a Propolis server API.",
"type": "string"
Expand All @@ -3169,7 +3167,6 @@
"required": [
"hardware",
"instance_id",
"instance_runtime",
"metadata",
"propolis_addr",
"vmm_runtime"
Expand Down Expand Up @@ -3339,53 +3336,6 @@
"ncpus"
]
},
"InstanceRuntimeState": {
"description": "The dynamic runtime properties of an instance: its current VMM ID (if any), migration information (if any), and the instance state to report if there is no active VMM.",
"type": "object",
"properties": {
"dst_propolis_id": {
"nullable": true,
"description": "If a migration is active, the ID of the target VMM.",
"allOf": [
{
"$ref": "#/components/schemas/TypedUuidForPropolisKind"
}
]
},
"gen": {
"description": "Generation number for this state.",
"allOf": [
{
"$ref": "#/components/schemas/Generation"
}
]
},
"migration_id": {
"nullable": true,
"description": "If a migration is active, the ID of that migration.",
"type": "string",
"format": "uuid"
},
"propolis_id": {
"nullable": true,
"description": "The instance's currently active VMM ID.",
"allOf": [
{
"$ref": "#/components/schemas/TypedUuidForPropolisKind"
}
]
},
"time_updated": {
"description": "Timestamp for this information.",
"type": "string",
"format": "date-time"
}
},
"required": [
"gen",
"time_updated"
]
},
"Inventory": {
"description": "Identity and basic status information about this sled agent",
"type": "object",
Expand Down Expand Up @@ -5133,10 +5083,6 @@
"type": "string",
"format": "uuid"
},
"TypedUuidForPropolisKind": {
"type": "string",
"format": "uuid"
},
"TypedUuidForZpoolKind": {
"type": "string",
"format": "uuid"
Expand Down Expand Up @@ -5769,6 +5715,10 @@
"A",
"B"
]
},
"TypedUuidForPropolisKind": {
"type": "string",
"format": "uuid"
}
},
"responses": {
Expand Down
11 changes: 1 addition & 10 deletions sled-agent/src/http_entrypoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,7 @@ impl SledAgentApi for SledAgentImpl {
let propolis_id = path_params.into_inner().propolis_id;
let body_args = body.into_inner();
Ok(HttpResponseOk(
sa.instance_ensure_registered(
body_args.instance_id,
propolis_id,
body_args.hardware,
body_args.instance_runtime,
body_args.vmm_runtime,
body_args.propolis_addr,
body_args.metadata,
)
.await?,
sa.instance_ensure_registered(propolis_id, body_args).await?,
))
}

Expand Down
26 changes: 9 additions & 17 deletions sled-agent/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1594,9 +1594,7 @@ mod tests {
use omicron_common::api::external::{
ByteCount, Generation, Hostname, InstanceCpuCount,
};
use omicron_common::api::internal::nexus::{
InstanceProperties, InstanceRuntimeState, VmmState,
};
use omicron_common::api::internal::nexus::{InstanceProperties, VmmState};
use omicron_common::api::internal::shared::{DhcpConfig, SledIdentifiers};
use omicron_common::FileKv;
use sled_agent_types::zone_bundle::CleanupContext;
Expand Down Expand Up @@ -2251,23 +2249,17 @@ mod tests {
serial: "fake-serial".into(),
};

let instance_runtime = InstanceRuntimeState {
propolis_id: Some(propolis_id),
dst_propolis_id: None,
migration_id: None,
gen: Generation::new(),
time_updated: Default::default(),
};

mgr.ensure_registered(
instance_id,
propolis_id,
hardware,
instance_runtime,
vmm_runtime,
propolis_addr,
InstanceEnsureBody {
instance_id,
migration_id: None,
hardware,
vmm_runtime,
propolis_addr,
metadata,
},
sled_identifiers,
metadata,
)
.await
.unwrap();
Expand Down
Loading
Loading