Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

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

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ fn do_object_identity(item: TokenStream) -> Result<TokenStream, syn::Error> {
};

let stream = quote! {
impl crate::api::external::ObjectIdentity for #name {
fn identity(&self) -> &crate::api::external::IdentityMetadata {
impl ObjectIdentity for #name {
fn identity(&self) -> &IdentityMetadata {
&self.identity
}
}
Expand All @@ -68,8 +68,8 @@ mod test {
);

let expected = quote! {
impl crate::api::external::ObjectIdentity for Foo {
fn identity(&self) -> &crate::api::external::IdentityMetadata {
impl ObjectIdentity for Foo {
fn identity(&self) -> &IdentityMetadata {
&self.identity
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ progenitor = { git = "https://github.com/oxidecomputer/progenitor" }
percent-encoding = "2.1.0"

[dependencies.api_identity]
path = "src/api/external/api_identity"
path = "../api_identity"

[dependencies.backoff]
version = "0.3.0"
Expand Down
73 changes: 0 additions & 73 deletions common/src/api/external/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,79 +558,6 @@ pub struct IdentityMetadataUpdateParams {
* Specific API resources
*/

/*
* ORGANIZATIONS
*/

/**
* Client view of an [`Organization`]
*/
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct Organization {
#[serde(flatten)]
pub identity: IdentityMetadata,
}

/**
* Create-time parameters for an [`Organization`]
*/
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct OrganizationCreateParams {
#[serde(flatten)]
pub identity: IdentityMetadataCreateParams,
}

/**
* Updateable properties of an [`Organization`]
*/
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct OrganizationUpdateParams {
#[serde(flatten)]
pub identity: IdentityMetadataUpdateParams,
}

/*
* PROJECTS
*/

/**
* Client view of an [`Project`]
*/
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct Project {
/*
* TODO-correctness is flattening here (and in all the other types) the
* intent in RFD 4?
*/
#[serde(flatten)]
pub identity: IdentityMetadata,
pub organization_id: Uuid,
}

/**
* Create-time parameters for an [`Project`]
*/
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ProjectCreateParams {
#[serde(flatten)]
pub identity: IdentityMetadataCreateParams,
}

/**
* Updateable properties of an [`Project`]
*/
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct ProjectUpdateParams {
#[serde(flatten)]
pub identity: IdentityMetadataUpdateParams,
}

/*
* INSTANCES
*/
Expand Down
17 changes: 0 additions & 17 deletions common/src/api/internal/nexus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ pub struct InstanceRuntimeState {
pub time_updated: DateTime<Utc>,
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the goal should be to move all this content out of common and into nexus, is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. but it's a big, ugly diff

/// Sent by a sled agent on startup to Nexus to request further instruction
#[derive(Serialize, Deserialize, JsonSchema)]
pub struct SledAgentStartupInfo {
/// the address of the sled agent's API endpoint
pub sa_address: SocketAddr,
}

// Oximeter producer/collector objects.

/// Information announced by a metric server, used so that clients can contact it and collect
Expand All @@ -72,13 +65,3 @@ impl ProducerEndpoint {
format!("{}/{}", &self.base_route, &self.id)
}
}

/// Message used to notify Nexus that this oximeter instance is up and running.
#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)]
pub struct OximeterInfo {
/// The ID for this oximeter instance.
pub collector_id: Uuid,

/// The address on which this oximeter instance listens for requests
pub address: SocketAddr,
}
3 changes: 3 additions & 0 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ structopt = "0.3"
thiserror = "1.0"
toml = "0.5.6"

[dependencies.api_identity]
path = "../api_identity"

[dependencies.chrono]
version = "0.4"
features = [ "serde" ]
Expand Down
10 changes: 4 additions & 6 deletions nexus/src/db/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1737,11 +1737,9 @@ mod test {
use crate::db::identity::Resource;
use crate::db::model::{ConsoleSession, Organization, Project};
use crate::db::DataStore;
use crate::external_api::params;
use chrono::{Duration, Utc};
use omicron_common::api::external::{
Error, IdentityMetadataCreateParams, OrganizationCreateParams,
ProjectCreateParams,
};
use omicron_common::api::external::{Error, IdentityMetadataCreateParams};
use omicron_test_utils::dev;
use std::sync::Arc;
use uuid::Uuid;
Expand All @@ -1755,7 +1753,7 @@ mod test {
let pool = db::Pool::new(&cfg);
let datastore = DataStore::new(Arc::new(pool));

let organization = Organization::new(OrganizationCreateParams {
let organization = Organization::new(params::OrganizationCreate {
identity: IdentityMetadataCreateParams {
name: "org".parse().unwrap(),
description: "desc".to_string(),
Expand All @@ -1766,7 +1764,7 @@ mod test {

let project = Project::new(
organization.id(),
ProjectCreateParams {
params::ProjectCreate {
identity: IdentityMetadataCreateParams {
name: "project".parse().unwrap(),
description: "desc".to_string(),
Expand Down
34 changes: 9 additions & 25 deletions nexus/src/db/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use crate::db::schema::{
organization, oximeter, project, rack, router_route, sled, vpc, vpc_router,
vpc_subnet,
};
use crate::external_api::params;
use crate::internal_api;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this asymmetry is a little janky, but there are so few internal ones that it kind of works. could do external_params and internal_params, but again the vast majority are external so would be unnecessarily verbose

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's that bad. In particular having to be explicit about internal params is definitely good. We really do want to see that from the call site.

use chrono::{DateTime, Utc};
use db_macros::{Asset, Resource};
use diesel::backend::{Backend, BinaryRawValue, RawValue};
Expand Down Expand Up @@ -343,7 +345,7 @@ pub struct Organization {

impl Organization {
/// Creates a new database Organization object.
pub fn new(params: external::OrganizationCreateParams) -> Self {
pub fn new(params: params::OrganizationCreate) -> Self {
let id = Uuid::new_v4();
Self {
identity: OrganizationIdentity::new(id, params.identity),
Expand All @@ -359,12 +361,6 @@ impl DatastoreCollection<Project> for Organization {
type CollectionIdColumn = project::dsl::organization_id;
}

impl Into<external::Organization> for Organization {
fn into(self) -> external::Organization {
external::Organization { identity: self.identity() }
}
}

/// Describes a set of updates for the [`Organization`] model.
#[derive(AsChangeset)]
#[table_name = "organization"]
Expand All @@ -374,8 +370,8 @@ pub struct OrganizationUpdate {
pub time_modified: DateTime<Utc>,
}

impl From<external::OrganizationUpdateParams> for OrganizationUpdate {
fn from(params: external::OrganizationUpdateParams) -> Self {
impl From<params::OrganizationUpdate> for OrganizationUpdate {
fn from(params: params::OrganizationUpdate) -> Self {
Self {
name: params.identity.name.map(|n| n.into()),
description: params.identity.description,
Expand All @@ -396,26 +392,14 @@ pub struct Project {

impl Project {
/// Creates a new database Project object.
pub fn new(
organization_id: Uuid,
params: external::ProjectCreateParams,
) -> Self {
pub fn new(organization_id: Uuid, params: params::ProjectCreate) -> Self {
Self {
identity: ProjectIdentity::new(Uuid::new_v4(), params.identity),
organization_id: organization_id,
}
}
}

impl Into<external::Project> for Project {
fn into(self) -> external::Project {
external::Project {
identity: self.identity(),
organization_id: self.organization_id,
}
}
}

/// Describes a set of updates for the [`Project`] model.
#[derive(AsChangeset)]
#[table_name = "project"]
Expand All @@ -425,8 +409,8 @@ pub struct ProjectUpdate {
pub time_modified: DateTime<Utc>,
}

impl From<external::ProjectUpdateParams> for ProjectUpdate {
fn from(params: external::ProjectUpdateParams) -> Self {
impl From<params::ProjectUpdate> for ProjectUpdate {
fn from(params: params::ProjectUpdate) -> Self {
Self {
name: params.identity.name.map(Name),
description: params.identity.description,
Expand Down Expand Up @@ -852,7 +836,7 @@ pub struct OximeterInfo {
}

impl OximeterInfo {
pub fn new(info: &internal::nexus::OximeterInfo) -> Self {
pub fn new(info: &internal_api::params::OximeterInfo) -> Self {
let now = Utc::now();
Self {
id: info.collector_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
* Handler functions (entrypoints) for external HTTP APIs
*/

use super::ServerContext;
use crate::db;
use crate::db::model::Name;
use crate::ServerContext;

use super::params;
use super::views::{Organization, Project};
use crate::context::OpContext;
use dropshot::endpoint;
use dropshot::ApiDescription;
Expand Down Expand Up @@ -38,13 +40,7 @@ use omicron_common::api::external::DiskAttachment;
use omicron_common::api::external::DiskCreateParams;
use omicron_common::api::external::Instance;
use omicron_common::api::external::InstanceCreateParams;
use omicron_common::api::external::Organization;
use omicron_common::api::external::OrganizationCreateParams;
use omicron_common::api::external::OrganizationUpdateParams;
use omicron_common::api::external::PaginationOrder;
use omicron_common::api::external::Project;
use omicron_common::api::external::ProjectCreateParams;
use omicron_common::api::external::ProjectUpdateParams;
use omicron_common::api::external::Rack;
use omicron_common::api::external::RouterRoute;
use omicron_common::api::external::RouterRouteCreateParams;
Expand Down Expand Up @@ -234,7 +230,7 @@ async fn organizations_get(
}]
async fn organizations_post(
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
new_organization: TypedBody<OrganizationCreateParams>,
new_organization: TypedBody<params::OrganizationCreate>,
) -> Result<HttpResponseCreated<Organization>, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
Expand Down Expand Up @@ -317,7 +313,7 @@ async fn organizations_delete_organization(
async fn organizations_put_organization(
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
path_params: Path<OrganizationPathParam>,
updated_organization: TypedBody<OrganizationUpdateParams>,
updated_organization: TypedBody<params::OrganizationUpdate>,
) -> Result<HttpResponseOk<Organization>, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
Expand Down Expand Up @@ -391,7 +387,7 @@ async fn organization_projects_get(
async fn organization_projects_post(
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
path_params: Path<OrganizationPathParam>,
new_project: TypedBody<ProjectCreateParams>,
new_project: TypedBody<params::ProjectCreate>,
) -> Result<HttpResponseCreated<Project>, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
Expand Down Expand Up @@ -480,7 +476,7 @@ async fn organization_projects_delete_project(
async fn organization_projects_put_project(
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
path_params: Path<ProjectPathParam>,
updated_project: TypedBody<ProjectUpdateParams>,
updated_project: TypedBody<params::ProjectUpdate>,
) -> Result<HttpResponseOk<Project>, HttpError> {
let apictx = rqctx.context();
let nexus = &apictx.nexus;
Expand Down
3 changes: 3 additions & 0 deletions nexus/src/external_api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod http_entrypoints;
pub mod params;
pub mod views;
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why pull these apart?

Copy link
Contributor Author

@david-crespo david-crespo Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the way I picture it, models know about params (they are the arguments to the model constructor) but not views (views are functions from model to serializable form). So in the models file we can import the params and refer to them as, e.g., params::ProjectCreate and not know anything about views. Obviously we could have them all in the same file and import only the ones we want, but the simplicity of the import exhibits the relationship. Even in the entrypoints file, it's cute to be able to do params::ProjectCreate.

Also discussed here and here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, the PR description gives a more long-winded version of the picture. I wrote that last, so it's the most polished.

Loading