Skip to content

Commit 05945f2

Browse files
committed
add migration state to nexus API
1 parent df8e542 commit 05945f2

File tree

6 files changed

+59
-16
lines changed

6 files changed

+59
-16
lines changed

clients/sled-agent-client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl From<types::SledInstanceState>
315315
instance_state: s.instance_state.into(),
316316
propolis_id: s.propolis_id,
317317
vmm_state: s.vmm_state.into(),
318+
migration_state: None,
318319
}
319320
}
320321
}

common/src/api/internal/nexus.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use omicron_uuid_kinds::UpstairsSessionKind;
1616
use parse_display::{Display, FromStr};
1717
use schemars::JsonSchema;
1818
use serde::{Deserialize, Serialize};
19+
use std::fmt;
1920
use std::net::SocketAddr;
2021
use std::time::Duration;
2122
use strum::{EnumIter, IntoEnumIterator};
@@ -83,6 +84,47 @@ pub struct SledInstanceState {
8384

8485
/// The most recent state of the sled's VMM process.
8586
pub vmm_state: VmmRuntimeState,
87+
88+
/// The current state of any in-progress migration for this instance, as
89+
/// understood by this sled.
90+
pub migration_state: Option<MigrationRuntimeState>,
91+
}
92+
93+
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
94+
pub struct MigrationRuntimeState {
95+
pub migration_id: Uuid,
96+
97+
pub state: MigrationState,
98+
}
99+
100+
/// The state of an instance's live migration.
101+
#[derive(
102+
Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema,
103+
)]
104+
#[serde(rename_all = "snake_case")]
105+
pub enum MigrationState {
106+
/// The migration is in progress.
107+
InProgress,
108+
/// The migration has failed.
109+
Failed,
110+
/// The migration has completed.
111+
Completed,
112+
}
113+
114+
impl MigrationState {
115+
pub fn label(&self) -> &'static str {
116+
match self {
117+
Self::InProgress => "in_progress",
118+
Self::Completed => "completed",
119+
Self::Failed => "failed",
120+
}
121+
}
122+
}
123+
124+
impl fmt::Display for MigrationState {
125+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
126+
f.write_str(self.label())
127+
}
86128
}
87129

88130
// Oximeter producer/collector objects.

nexus/db-model/src/migration_state.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,36 @@
44

55
//! Database representation of a migration's state as understood by Nexus.
66
7-
use super::impl_enum_type;
8-
use serde::{Deserialize, Serialize};
7+
use super::impl_enum_wrapper;
8+
use omicron_common::api::internal::nexus;
9+
use serde::Deserialize;
10+
use serde::Serialize;
911
use std::fmt;
12+
use std::io::Write;
1013

11-
impl_enum_type!(
14+
impl_enum_wrapper!(
1215
#[derive(Clone, SqlType, Debug, QueryId)]
1316
#[diesel(postgres_type(name = "migration_state", schema = "public"))]
1417
pub struct MigrationStateEnum;
1518

1619
#[derive(Clone, Copy, Debug, AsExpression, FromSqlRow, Serialize, Deserialize, PartialEq, Eq)]
1720
#[diesel(sql_type = MigrationStateEnum)]
18-
// match the database representation when serializing
19-
#[serde(rename_all = "snake_case")]
20-
pub enum MigrationState;
21+
pub struct MigrationState(pub nexus::MigrationState);
2122

2223
// Enum values
2324
InProgress => b"in_progress"
2425
Completed => b"completed"
2526
Failed => b"failed"
2627
);
2728

28-
impl MigrationState {
29-
pub fn label(&self) -> &'static str {
30-
match self {
31-
Self::InProgress => "in_progress",
32-
Self::Completed => "completed",
33-
Self::Failed => "failed",
34-
}
29+
impl fmt::Display for MigrationState {
30+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31+
fmt::Display::fmt(&self.0, f)
3532
}
3633
}
3734

38-
impl fmt::Display for MigrationState {
39-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40-
f.write_str(self.label())
35+
impl From<nexus::MigrationState> for MigrationState {
36+
fn from(s: nexus::MigrationState) -> Self {
37+
Self(s)
4138
}
4239
}

sled-agent/src/common/instance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ impl InstanceStates {
229229
instance_state: self.instance.clone(),
230230
vmm_state: self.vmm.clone(),
231231
propolis_id: self.propolis_id,
232+
migration_state: None, // TODO(eliza): add this
232233
}
233234
}
234235

sled-agent/src/sim/collection.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ mod test {
451451
instance_state: instance_vmm,
452452
vmm_state,
453453
propolis_id,
454+
migration_state: None,
454455
};
455456

456457
SimObject::new_simulated_auto(&state, logctx.log.new(o!()))

sled-agent/src/sim/sled_agent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ impl SledAgent {
341341
instance_state: instance_runtime,
342342
vmm_state: vmm_runtime,
343343
propolis_id,
344+
migration_state: None,
344345
},
345346
None,
346347
)

0 commit comments

Comments
 (0)