Skip to content

[api][nexus] Migrate DB-specific types into Nexus, away from API #188

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 16 commits into from
Aug 6, 2021
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
54 changes: 1 addition & 53 deletions omicron-common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl Display for ResourceType {

pub async fn to_list<T, U>(object_stream: ObjectStream<T>) -> Vec<U>
where
U: From<T>,
T: Into<U>,
{
object_stream
.filter(|maybe_object| ready(maybe_object.is_ok()))
Expand Down Expand Up @@ -532,12 +532,6 @@ pub struct ProjectView {
pub identity: IdentityMetadata,
}

impl From<crate::api::internal::nexus::Project> for ProjectView {
fn from(project: crate::api::internal::nexus::Project) -> Self {
ProjectView { identity: project.identity }
}
}

/**
* Create-time parameters for an [`Project`]
*/
Expand Down Expand Up @@ -728,19 +722,6 @@ pub struct InstanceView {
pub runtime: InstanceRuntimeStateView,
}

impl From<crate::api::internal::nexus::Instance> for InstanceView {
fn from(instance: crate::api::internal::nexus::Instance) -> Self {
InstanceView {
identity: instance.identity.clone(),
project_id: instance.project_id,
ncpus: instance.ncpus,
memory: instance.memory,
hostname: instance.hostname.clone(),
runtime: instance.runtime.into(),
}
}
}

/**
* Create-time parameters for an [`Instance`]
*/
Expand Down Expand Up @@ -788,24 +769,6 @@ pub struct DiskView {
pub device_path: String,
}

impl From<crate::api::internal::nexus::Disk> for DiskView {
fn from(disk: crate::api::internal::nexus::Disk) -> Self {
/*
* TODO-correctness: can the name always be used as a path like this
* or might it need to be sanitized?
*/
let device_path = format!("/mnt/{}", disk.identity.name.as_str());
DiskView {
identity: disk.identity.clone(),
project_id: disk.project_id,
snapshot_id: disk.create_snapshot_id,
size: disk.size,
state: disk.runtime.disk_state,
device_path,
}
}
}

/**
* State of a Disk (primarily: attached or not)
*/
Expand Down Expand Up @@ -948,12 +911,6 @@ pub struct RackView {
pub identity: IdentityMetadata,
}

impl From<crate::api::internal::nexus::Rack> for RackView {
fn from(rack: crate::api::internal::nexus::Rack) -> Self {
RackView { identity: rack.identity }
}
}

/*
* SLEDS
*/
Expand All @@ -969,15 +926,6 @@ pub struct SledView {
pub service_address: SocketAddr,
}

impl From<crate::api::internal::nexus::Sled> for SledView {
fn from(sled: crate::api::internal::nexus::Sled) -> Self {
SledView {
identity: sled.identity.clone(),
service_address: sled.service_address,
}
}
}

/*
* Sagas
*
Expand Down
66 changes: 1 addition & 65 deletions omicron-common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,13 @@
//! APIs exposed by Nexus.

use crate::api::external::{
ByteCount, DiskState, Generation, IdentityMetadata, InstanceCpuCount,
InstanceState,
};
use crate::api::external::{DiskState, Generation, InstanceState};
use chrono::{DateTime, Utc};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use std::time::Duration;
use uuid::Uuid;

pub struct Rack {
pub identity: IdentityMetadata,
}

pub struct Sled {
pub identity: IdentityMetadata,
pub service_address: SocketAddr,
}

/// A collection of associated resources.
pub struct Project {
/// common identifying metadata.
pub identity: IdentityMetadata,
}

/// A Disk (network block device).
#[derive(Clone, Debug)]
pub struct Disk {
/// common identifying metadata.
pub identity: IdentityMetadata,
/// id for the project containing this Disk
pub project_id: Uuid,
/// id for the snapshot from which this Disk was created (None means a blank
/// disk)
pub create_snapshot_id: Option<Uuid>,
/// size of the Disk
pub size: ByteCount,
/// runtime state of the Disk
pub runtime: DiskRuntimeState,
}

/// Runtime state of the Disk, which includes its attach state and some minimal
/// metadata
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
Expand All @@ -54,28 +20,6 @@ pub struct DiskRuntimeState {
pub time_updated: DateTime<Utc>,
}

/// An Instance (VM).
#[derive(Clone, Debug)]
pub struct Instance {
/// common identifying metadata
pub identity: IdentityMetadata,

/// id for the project containing this Instance
pub project_id: Uuid,

/// number of CPUs allocated for this Instance
pub ncpus: InstanceCpuCount,
/// memory allocated for this Instance
pub memory: ByteCount,
/// RFC1035-compliant hostname for the Instance.
// TODO-cleanup different type?
pub hostname: String,

/// state owned by the data plane
pub runtime: InstanceRuntimeState,
// TODO-completeness: add disks, network, tags, metrics
}

/// Runtime state of the Instance, including the actual running state and minimal
/// metadata
///
Expand Down Expand Up @@ -129,11 +73,3 @@ pub struct OximeterInfo {
/// The address on which this oximeter instance listens for requests
pub address: SocketAddr,
}

/// An assignment of an Oximeter instance to a metric producer for collection.
// TODO: Goes to storage
#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)]
pub struct OximeterAssignment {
pub oximeter_id: Uuid,
pub producer_id: Uuid,
}
5 changes: 4 additions & 1 deletion omicron-common/src/api/internal/sled_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,15 @@ impl DiskStateRequested {
}
}

/// Runtime state of an instance.
pub type InstanceRuntimeState = internal::nexus::InstanceRuntimeState;

/// Sent to a sled agent to establish the runtime state of an Instance
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct InstanceEnsureBody {
/// Last runtime state of the Instance known to Nexus (used if the agent
/// has never seen this Instance before).
pub initial_runtime: internal::nexus::InstanceRuntimeState,
pub initial_runtime: InstanceRuntimeState,
/// requested runtime state of the Instance
pub target: InstanceRuntimeStateRequested,
}
Expand Down
Loading